2
我不知道我怎麼會從不同的@EventHandler得到一個變量。我的變量在這個實例中是一個數組列表。Bukkit - 從其他@EventHandlers獲取變量?
我的代碼如下:
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
ArrayList<String> build = new ArrayList();
Player player = event.getPlayer();
if(!player.isOp()) {
event.setCancelled(true);
}else if(!build.contains(player)) {
event.setCancelled(true);
}else if(build.contains(player)) {
event.setCancelled(false);
}
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
event.setJoinMessage("§4§l>>§a§l " + player + " §b§ljoined! §4§l<<");
if(build.contains(player)) {
build.remove(player);
現在,在第二@EventHandler它無法解析變量「打造」這是我在以前的@EventHandler定義。那麼我怎麼才能做到這一點呢?
的問題是變量的作用域。 – BitNinja