2013-06-03 66 views
0

我想做一個mixedmodeauth(我自己的版本),但有一個問題,在與星鏈接的行,我得到[語法錯誤的令牌「(」 ;預期],[令牌上的語法錯誤)「,;;預期],[void是變量onPlayerJoin的無效類型],java是否仍然可以工作?我的世界bukkit插件公共無效不工作

public class MixedPlugin extends JavaPlugin implements Listener{ 
    @Override 
    public void onEnable(){ 
     getLogger().info("Mixed Mode: ON"); 
     getCommand("mm").setExecutor(new MixedCommand()); 

     @EventHandler 
     **public void onPlayerJoin(PlayerJoinEvent event) {** 
      Player player = event.getPlayer(); 
      String name = player.getName(); 
      boolean isGood = getURL("http://minecraft.net/haspaid.jsp?user=deadmau5" + name).equals("true"); 
      if (isGood) { 
       player.sendMessage("Welcome back to server!"); 
      } 
      else { 
       List<String> ex = getConfig().getStringList("allow"); 
       if (((MemorySection)ex).getStringList("allow").contains(player.getName())) { 
       player.sendMessage("Welcome back to server!"); 
       player.sendMessage("You are a few person that are using cracked minecraft and allowed to join this premium server!"); 
       } else { 
       player.kickPlayer("Failed to login: User not premium"); 
       } 
      } 
     } 
    } 
    public String getURL(String url){ 
     Logger log = Logger.getLogger("Minecraft"); 
     String inputLine = ""; 
     try{ 
      URL mcheck = new URL(url); 
      URLConnection mcheckc = mcheck.openConnection(); 
      mcheckc.setReadTimeout(1500); 
      BufferedReader in = new BufferedReader(new InputStreamReader(mcheckc.getInputStream())); 
      inputLine = in.readLine(); 
      in.close(); 
      return inputLine; 
     } catch(Exception e){ 
      log.warning("Error retrieving "+url+": "+e.getMessage()); 
     } 
     return "ERROR"; 
     } 
    @Override 
    public void onDisable(){ 
     getLogger().info("You have disable Mixed Mode"); 
    } 
} 

回答

4

這是無效的代碼。 Java不允許嵌套函數像你正在做(又名不要把onPlayerJoinonEnable方法的內部

這樣就把方法onPlayerJoinonEnable內部沒有經過

例:

@Override 
public void onEnable(){ 
    getLogger().info("Mixed Mode: ON"); 
    getCommand("mm").setExecutor(new MixedCommand()); 
} 

@EventHandler 
public void onPlayerJoin(PlayerJoinEvent event) { 
    Player player = event.getPlayer(); 
    String name = player.getName(); 
    boolean isGood = getURL("http://minecraft.net/haspaid.jsp?user=deadmau5" + name).equals("true"); 
    if (isGood) { 
     player.sendMessage("Welcome back to server!"); 
    } 
    else { 
     List<String> ex = getConfig().getStringList("allow"); 
     if (((MemorySection)ex).getStringList("allow").contains(player.getName())) { 
     player.sendMessage("Welcome back to server!"); 
     player.sendMessage("You are a few person that are using cracked minecraft and allowed to join this premium server!"); 
     } else { 
     player.kickPlayer("Failed to login: User not premium"); 
     } 
    } 
} 
+0

謝謝!但是代碼仍然有效? – wuiyang

+0

我沒有檢查其他錯誤,但是代碼仍然可以工作(如果它首先能夠工作:)) – greedybuddha