0
        public void loadArenas(){

        File folder = new File(plugin.getDataFolder().getPath() + "/arenas/");
        for (final File fileEntry : folder.listFiles()) {
            if (fileEntry.isDirectory()) {
            } else {
                //String fileNameWithOutPre = FilenameUtils.getBaseName(fileEntry.toString());
                Arena arena = new Arena(folder.toString());
                System.out.println(Arena.arenaObjects);
            }
        }
    }

That code gets the list of files, add them to a list, then prints them out. But this is what gets printed out:

[me.noraaron1.Tk.MultiArenas.Arena@3d2b2429]

But when I try to do a sign, with this code:

@EventHandler
public void onSignChange(SignChangeEvent e) {
    if (e.getLines().length > 0 && !e.getLine(0).equalsIgnoreCase("[TheKiller]")) return;
    if(!e.getPlayer().hasPermission("tk.MakeSign")) return;
    if (e.getLines().length < 3) {
        e.getBlock().breakNaturally();
        e.getPlayer().sendMessage("A TK sign must have at least 3 lines.");
        return;
    }
    if(Arena.arenaObjects.contains(e.getLine(2))){

        e.setLine(0, ChatColor.BLUE + "[TheKiller]");
        e.setLine(3, ChatColor.BLUE + "0" + ChatColor.GREEN + "/" + ChatColor.DARK_GREEN + "20");
    }else{
        e.getBlock().breakNaturally();
        e.getPlayer().sendMessage("The arena name you provided is not valid!");
        return;

    }
}

It tells me that the arena name is not in the list, even though it is. It never changes.

Arena class:

public class Arena { private static Main plugin;

// A list of all the Arena Objects
public static ArrayList<Arena> arenaObjects = new ArrayList<Arena>();

// Some fields we want each Arena object to store:
private Location joinLocation, escaperStartLocation, killerStartLocation,
        endLocation; // Some general arena locations

private String name; // Arena name
private ArrayList<String> players = new ArrayList<String>(); // And
                                                                // arraylist
                                                                // of
                                                                // players
                                                                // name

private int maxPlayers = 20;

private boolean inGame = false; // Boolean to determine if an Arena is
                                // ingame or not, automaticly make it false

// Now for a Constructor:
public Arena(String arenaName) {
    // So basicly: Arena myArena = new Arena("My Arena", joinLocation,
    // startLocation, endLocation, 17)
    // Lets initalize it all:
    this.name = arenaName;
    // Now lets add this object to the list of objects:
    arenaObjects.add(this);

}

public Arena(Main instance) {
    plugin = instance;
}

// Now for some Getters and Setters, so with our arena object, we can use
// special methods:
public Location getJoinLocation() {
    return this.joinLocation;
}

public void setJoinLocation(Location joinLocation) {
    this.joinLocation = joinLocation;
}

public void teleportEscaper(String s) {
    File report = new File(plugin.getDataFolder() + "/arenas/" + name
            + ".yml");
    FileConfiguration fc = YamlConfiguration.loadConfiguration(report);

    double X = fc.getInt("Teleportation.Esc.X");
    double Y = fc.getInt("Teleportation.Esc.Y");
    double Z = fc.getInt("Teleportation.Esc.Z");
    Bukkit.getPlayer(s).teleport(
            new Location(Bukkit.getWorld("TheKiller"), X, Y, Z));
}

public void teleportKiller(String killer) {
    File report = new File(plugin.getDataFolder() + "/arenas/" + name
            + ".yml");
    FileConfiguration fc = YamlConfiguration.loadConfiguration(report);

    double X = fc.getInt("Teleportation.Killer.X");
    double Y = fc.getInt("Teleportation.Killer.Y");
    double Z = fc.getInt("Teleportation.Killer.Z");
    Bukkit.getPlayer(killer).teleport(
            new Location(Bukkit.getWorld("TheKiller"), X, Y, Z));
}

public void setEscaperStartLocation(String arenaName,
        Location escaperStartLocation, Player p) throws IOException {
    FileConfiguration fc = YamlConfiguration.loadConfiguration(new File(
            plugin.getDataFolder().getPath() + "/arenas/" + arenaName
                    + ".yml"));
    fc.set("Teleportation.Esc", null);
    fc.set("Teleportation.Esc.X", escaperStartLocation.getBlockX());
    fc.set("Teleportation.Esc.Y", escaperStartLocation.getBlockY());
    fc.set("Teleportation.Esc.Z", escaperStartLocation.getBlockZ());
    fc.save(plugin.getDataFolder().getPath() + "/arenas/" + name + ".yml");
}

public void setKillerStartLocation(String arenaName,
        Location killerStartLocation) throws IOException {
    FileConfiguration fc = YamlConfiguration.loadConfiguration(new File(
            plugin.getDataFolder().getPath() + "/arenas/" + arenaName
                    + ".yml"));
    fc.set("Teleportation.Killer", null);
    fc.set("Teleportation.Killer.X", killerStartLocation.getBlockX());
    fc.set("Teleportation.Killer.Y", killerStartLocation.getBlockY());
    fc.set("Teleportation.Killer.Z", killerStartLocation.getBlockZ());
    fc.save(plugin.getDataFolder().getPath() + "/arenas/" + name + ".yml");
}

public Location getEndLocation() {
    return this.endLocation;
}

public void setEndLocation(Location endLocation) {
    this.endLocation = endLocation;
}

public String getName() {
    return this.name;
}

public void setName(String name) {
    this.name = name;
}

public int getMaxPlayers() {
    return this.maxPlayers;
}

public void setMaxPlayers(int maxPlayers) {
    this.maxPlayers = maxPlayers;
}

public ArrayList<String> getPlayers() {
    return this.players;
}

// And finally, some booleans:
public boolean isFull() { // Returns weather the arena is full or not
    if (players.size() >= maxPlayers) {
        return true;
    } else {
        return false;
    }
}

public boolean isInGame() {
    return inGame;
}

public void setInGame(boolean inGame) {
    this.inGame = inGame;
}

// To send each player in the arena a message
public void sendMessage(String message) {
    for (String s : players) {
        Bukkit.getPlayer(s).sendMessage(message);
    }
}
}
Marco Acierno
  • 14,682
  • 8
  • 43
  • 53
noraaron
  • 1
  • 2
  • `me.noraaron1.Tk.MultiArenas.Arena@3d2b2429` is the default output of the Object class's toString() method. That is the type of the object and a hexadecimal representation of the object's hashcode. – takendarkk Mar 27 '14 at 03:19
  • @Takendarkk So, how would I do this? If I don't do toString(), it will put a red line – noraaron Mar 27 '14 at 03:35
  • I think you should show us your Arena code too. But I think you didn't override toString() and equals() and hashCode() methods in Arena class which all cause the problem you are describing. – Alvin Mar 27 '14 at 06:52
  • @Alvin Okay, I'll edit my post to have the Arena code in it. – noraaron Mar 27 '14 at 23:47
  • Please, don't remove your question. – Marco Acierno Jul 04 '14 at 23:40
  • Just a note, I completely re-wrote my answer. The old one sucked. Even if you already got the point, you should still read the new one (it's also rather small- but it's no longer just a text block). – Zeusoflightning125 Jul 05 '14 at 15:36

1 Answers1

0

When you use an object/class/whatever as a string in a method, it will use the toString method to get what it needs to use for that string. To fix this, you have two methods: 1. You can override the toString() method in the class

Example:

    @Override
    public String toString(){
        return this.variable + "," + this.othervariable;
    }
  1. You can manually do the conversions yourself

    System.out.println(obj.variable + "," + obj.othervariable);