我正在尝试制作一个混合模式(我自己的版本),但有一个问题,在星号链接的行,我得到[令牌上的语法错误“(”,;预期),[语法错误]的错误在令牌“)”,;预期],[void是变量onPlayerJoin的无效类型],java仍然可以运行吗?
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");
}
}
答案 0 :(得分:4)
这不是有效的代码。 Java不允许像您当前那样使用嵌套函数(也就是说不要将onPlayerJoin
放在onEnable
方法中。
所以在onPlayerJoin
之后放置方法onEnable
不在里面。
示例:
@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");
}
}
}