加载Arenas返回一个奇怪的字符串

时间:2014-03-27 03:15:04

标签: java minecraft bukkit

        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);
            }
        }
    }

该代码获取文件列表,将它们添加到列表中,然后将其打印出来。 但这是打印出来的:

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

但当我尝试使用此代码进行签名时:

@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;

    }
}

它告诉我,竞技场名称不在列表中,即使它是。它永远不会改变。

竞技场课程:

公共类竞技场{     private static主插件;

// 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);
    }
}
}

1 个答案:

答案 0 :(得分:0)

当你在方法中使用object / class / whatever作为字符串时,它将使用toString方法来获取它需要用于该字符串的内容。要解决此问题,您有两种方法: 1.您可以覆盖类

中的toString()方法

示例:

    @Override
    public String toString(){
        return this.variable + "," + this.othervariable;
    }
  1. 您可以自己手动执行转换

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