it happens that I'm making a bukkit arena plugin. I have an Arena class, with an enum for its status. The default status is Status.disabled. I have a method that I call on the on-Enable, which sets the arena to Idle Status. The Problem is that after I call the method for every arena, the arena appears as Disabled status again. Here is part of my Arena class:
public class Arena {
protected final Main main;
public static enum Status{
Idle,
InLobby,
InCountdown,
InGame,
Disabled;
}
private Status status = Status.Disabled;
String name;
Location lobby;
Location start;
Location end;
List<Location> checkpoints = new ArrayList<Location>();
int lives;
int time;
public Arena(Main main, String name, Location lobby, Location start, List<Location> checkpoints, Location end, int lives, int time)
{
this.main = main;
this.name = name;
this.lobby = lobby;
this.start = start;
this.checkpoints = checkpoints;
this.end = end;
this.lives = lives;
this.time = time;
}
public void setStatus(Status statuss){
this.status = statuss;
}
public final Status getStatus(){
return status;
}
public final void onEnable(){
this.status = Status.Idle;
System.out.println(this.getStatus() + " Trying status set on OnEnable. This is made from an Arena class.");
//The message above says status is Idle...
}
}
Now, here's my onEnable method, which is on my Main class that extends to JavaPlugin:
ArenaManager manager;
public void onEnable(){
PluginDescriptionFile pdfFile;
pdfFile = this.getDescription();
getLogger().info(pdfFile.getName() + pdfFile.getVersion() + " has been enabled!");
manager = new ArenaManager(this);
PluginManager pm = this.getServer().getPluginManager();
pm.registerEvents(new events(this), this);
getConfig().options().copyDefaults(true);
saveDefaultConfig();
for(Arena arena : manager.getAllArenas()){
arena.onEnable();
}
getLogger().info("Plugin contains " + manager.getAllArenas().size() + " arena(s)!");
foo();
}
public void foo(){
for(Arena a : manager.getAllArenas()){
System.out.println("foo " + a.getStatus());
}
}
My method called "foo" checks the status for all arenas. The arenas appear as disabled when I try "foo". If this is useful, each arena is saved to a file, so to get all arenas, I use my arenamanager. The method from the arenamanager used in the onEnable is:
public List<Arena> getAllArenas(){
List<Arena> arenas = new ArrayList<Arena>();
File[] allfiles = new File(main.getDataFolder() + File.separator + "Courses" + File.separator).listFiles();
assert allfiles != null;
for(File f : allfiles){
FileConfiguration con = YamlConfiguration.loadConfiguration(f);
String name = con.getString("Name");
Arena a = getCourse(name);
arenas.add(a);
}
return arenas;
}
I tried printing out the status as well from the PlayerInteractEvent (on a sign), but the arena still shows as disabled. Any idea on how to fix this? There are no errors on the console by the way. Thanks for the help :)