Hello im coding a plugin for the game minecraft using Bukkit. Basically when a player right clicks with a egg that egg has a specific durability. The durability does not change at all because the event is called every time someone does this and its individual. The code i currently have is not done but this is basically it:
if (e.getItem().getTypeId() == 383) {
if (!worldguardPlugin.canBuild(e.getPlayer(), loc)) {
e.setCancelled(true);
e.getPlayer().sendMessage(
ChatColor.YELLOW
+ "You cant use spawner eggs in this region!");
return;
}
switch (e.getItem().getDurability()) {
case 2:
expOrb(e);
break;
case 9:
painting(e);
break;
case 20:
primedTnt(e);
break;
case 40:
minecart(e);
break;
case 41:
boat(e);
break;
case 50:
creeper(e);
break;
case 51:
skeleton(e);
break;
case 52:
spider(e);
break;
case 53:
giant(e);
break;
case 54:
zombie(e);
break;
case 55:
slime(e);
break;
case 56:
ghast(e);
break;
case 57:
pigman(e);
break;
case 58:
enderman(e);
break;
case 59:
cavespider(e);
break;
case 60:
silverfish(e);
break;
case 61:
blaze(e);
break;
case 62:
cube(e);
break;
case 63:
dragon(e);
break;
case 90:
pig(e);
break;
case 91:
sheep(e);
break;
case 92:
cow(e);
break;
case 93:
chicken(e);
break;
case 94:
squid(e);
break;
case 95:
wolf(e);
break;
case 96:
moosh(e);
break;
case 97:
snowGolem(e);
break;
case 98:
ocelot(e);
break;
case 99:
ironGolem(e);
break;
case 120:
villager(e);
break;
case 200:
crystal(e);
break;
default:
break;
}
}
}
Since I’m using break, all of the methods i made won’t be called correct? That would cause lots of pointless code being executed and wasted performance, and the entire point of this design was for better work flow.
Your assumption is correct. Only the code that meets the specific
switchcase will be executed. After all, a switch statement is a substitute for a giantif-else if-elseblock.