Soup PVP plugin .destroyItemHeld(); don't work?

CanaryMod related discussions

Soup PVP plugin .destroyItemHeld(); don't work?

Postby Rash_SR » Sun Jan 24, 2016 8:06 pm

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)
Rash_SR
 
Posts: 11
Joined: Mon Jan 18, 2016 5:58 pm

Re: Soup PVP plugin .destroyItemHeld(); don't work?

Postby Scoin0 » Fri Jan 29, 2016 8:14 am

I don't really remember but try delete the item in the slot used. I believe there is something for that.

EDIT: Ah, I found some documentation. http://docs.visualillusionsent.net/CanaryLib/1.2.0-RC1/index.html
I help out when I can. :)
Discord: Scoin0#0002
User avatar
Scoin0
 
Posts: 27
Joined: Mon Aug 17, 2015 8:11 pm
Location: Kailua, Hawaii

Re: Soup PVP plugin .destroyItemHeld(); don't work?

Postby Rash_SR » Sun Jan 31, 2016 11:34 pm

Scoin0 wrote:I don't really remember but try delete the item in the slot used. I believe there is something for that.

EDIT: Ah, I found some documentation. http://docs.visualillusionsent.net/CanaryLib/1.2.0-RC1/index.html


thank you :)!
I solve my problem! I forget to cancel the event with "event.getCanceled();". I fix it and it works now :)
Rash_SR
 
Posts: 11
Joined: Mon Jan 18, 2016 5:58 pm


Return to Discussions

Who is online

Users browsing this forum: No registered users and 3 guests

cron