我有一个@EventHandler,我想使用constructor.package进行异步工作
public class MonsterLevel implements Listener{
public MonsterLevel(int level, Player p) {
switch (level) { //The onclick Event should Increment this level whenever it is activated.
case 1:
//Changes Here
return;
case 2:
//Changes Here
return;
default:
System.out.println("Level is too high");
return;
}
}
@EventHandler //When the player activates this event it should run the MonsterLevel Constructor Method.
public MonsterLevel LevelUp(PlayerInteractEvent event){
MonsterLevel level1 = new MonsterLevel(1,p);
MonsterLevel level2 = new MonsterLevel(2,p);
if(level==1) {
level++;
p.sendMessage(ChatColor.AQUA + "Level: " + level);
return level1;
}
if(level==2) {
level++;
p.sendMessage(ChatColor.AQUA + "Level: " + level);
return level2;
}return level4;
}
} else {
p.sendMessage(ChatColor.AQUA + "Failed to Level Up");
}
return null; // Goes to switch's default?
}
}
我已经评论了上面的代码。但我要问的是,作为Java的标准,我可以让eventhandler使用构造函数吗?如果没有,有人可以指示我正确的方向吗?
由于