Hello guys!
Is there someone who can help me?
I read a book about the CanaryMod and start to code some own plugins. I want to program a soup pvp plugin.(Who don't know what soup pvp is a short explanation: in a 1vs1 fight you have mushroomsoups in your inventory and if you right klick one you regenerate 4 hearts and the soup will be replaced to a bowl.)
Here is my code (without the imports)
public class Souppvp extends EZPlugin implements PluginListener{
@Override
public boolean enable() {
Canary.hooks().registerListener(this, this);
return super.enable();
}
@HookHandler
public void onInteract(ItemUseHook event) {
Player player = event.getPlayer();
if (player.getItemHeld().getType() == ItemType.MushroomSoup) {
float health = player.getHealth();
int food = player.getHunger();
if (health < 20){
player.setHealth(health + 8);
player.chat("get 4 hearts!");
player.destroyItemHeld();
player.getInventory().addItem(ItemType.Bowl);
}
if (health >=20){
if (food < 20){
player.setHunger(food + 4);
player.chat("2 food refilled");
player.destroyItemHeld();
player.getInventory().addItem(ItemType.Bowl);
}
}
}
}
}
My problem is that if i right klick the soup the soup doesn't disappear. I regenerate the hearts and can read the test text message in the chat and get a new bowl but the soup is still there . Do i use "player.destroyItemHeld();" wrong? or what's the problem? I hope someone can help me because i am very interested in programming and want to learn more! (excuse my language english is not my native speak)