부킷 키트 (bukkit arena) 플러그인을 만들고 있습니다. 그 상태에 대한 enum을 가진 Arena 클래스가 있습니다. 기본 상태는 Status.disabled입니다. 나는 on-Enable을 호출하는 방법을 가지고 있는데,이 방법은 경기장을 유휴 상태로 설정합니다. 문제는 모든 경기장에 대해이 메소드를 호출하면 경기장이 다시 사용 불가 상태로 표시된다는 것입니다. 여기 내 경기장 클래스의 일부입니다 다른 클래스에서 변수가 변경되지 않습니다
이제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...
}
}
, 여기 JavaPlugin 확장 내 메인 클래스 내 onEnable 방법입니다 :
이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());
}
}
"foo에"라는 나의 방법은 검사 모든 경기장의 상태. 경기장은 "foo"를 시도 할 때 장애인으로 나타납니다. 이것이 유용하다면, 각 경기장은 파일에 저장됩니다. 그래서 모든 경기장을 얻으려면, 나는 아우망 내거를 사용합니다.
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;
}
내가 (로그인에)에 PlayerInteractEvent에서뿐만 아니라 상태를 인쇄하려고했으나 경기장은 여전히 불가능으로 표시하십시오 onEnable에 사용되는 arenamanager에서 방법이다. 이 문제를 해결하는 방법에 대한 아이디어가 있습니까? 그런데 콘솔에 오류가 없습니다. 도움말 : 한마디로
정말 사용하는 코드입니까? 당신은'onEnable()'에서 무한 재귀를 가진 것처럼 보입니다. –
'getCourse()'의 코드는 어디에 있나요? 'getCourse()'가하는 일에 따라'getAllAreans()'가 반환되는리스트를위한 새로운'Arena' 객체를 생성하는 것처럼 보입니다. 그래서 당신이'getAllArenas()'를 호출 할 때마다'Status'가'Disabled'로 설정된 새로운 객체를 생성하게됩니다. – mdewitt
@ PM77-1 네, 그게 내가 onEnable에 사용하는 것입니다. 나는 자바를 처음 사용하므로 뭔가 잘못하고 있니? – user3091392