简体   繁体   中英

minecraft bukkit plugin public void doesnt work

i am trying to make a mixedmodeauth(my own version), but there is a problem, at the line with star linked, i get the error of [Syntax error on token "(", ; expected],[Syntax error on token ")", ; expected],[void is an invalid type for the variable onPlayerJoin], is the java still function-able or not?

    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");
    }
}

This isn't valid code. Java does not allow nested functions like you are currently doing(aka don't put onPlayerJoin inside of the onEnable method.

So put the method onPlayerJoin after onEnable not inside.

Example:

@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");
      }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM