-1
我正在爲Bukkit創建一個插件。但我需要將PlayerName存儲在列表中,現在我正在使用ArrayList,但它似乎不能保存它們?arrayList不保存名稱?
這裏是我的代碼:
public class Menu implements Listener {
private static Menu instance = new Menu();
public static Menu getInstance() {
return instance;
}
ArrayList<String> inMenu = new ArrayList<String>();
public void menuAdd(Player p) {
if(inMenu.contains(p.getName())) {return;}
inMenu.add(p.getName());
[1]p.sendMessage(inMenu.toString());
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent e) {
[2]e.getPlayer().sendMessage(inMenu.toString());
if(inMenu.contains(e.getPlayer().getName())) {
if(e.getMessage().contains("appel")) {
inMenu.remove(e.getPlayer().getName());
}
return;
} else{
e.getPlayer().sendMessage("Not in list");
}
}
在[1]它調試的playerName是ArrayList中,但是當我在[2]沒有調試它是在列表中?
主營:
public class Main extends JavaPlugin implements Listener {
private static Main instance;
private static Plugin plugin;
@Override
public void onEnable() {
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(this, this);
if(getServer().getPluginManager().getPlugin("Citizens") == null || getServer().getPluginManager().getPlugin("Citizens").isEnabled() == false) {
System.out.print("Citizens 2.0 not found or not enabled");
getServer().getPluginManager().disablePlugin(this);
return;
}
net.citizensnpcs.api.CitizensAPI.getTraitFactory().registerTrait(net.citizensnpcs.api.trait.TraitInfo.create(HorecaTrait.class).withName("Horeca"));
instance = this;
plugin = this;
registerEvents(this, new Menu(), new HorecaTrait());
}
向我們展示您在其中實例化菜單的代碼? – 2014-09-27 08:43:55
@Petar添加了主類 – user3375403 2014-09-27 09:05:18
告訴我們更多的信息? menuAdd方法的調用在哪裏? – 2014-09-27 10:37:31