1
I need some plugin coding help D:
Hey guys, i am attempting to make a plugin and im getting an error.
First here is my code:
@EventHandler
public void toggle(PlayerInteractEvent event){
Player player = event.getPlayer();
if(player.getInventory().getItemInhand().getItemMeta().getDisplayName() == "MobWand"){
if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
Player p = event.getPlayer();
Snowball snowball = p.getWorld().spawn(p.getEyeLocation(), Snowball.class);
snowball.setVelocity(p.getLocation().getDirection().multiply(1.5));
snowball.setShooter(p);
This code is suppose to allow a player to shoot a snowball if they interact with an item called "mobwand" in there inventory.
Everything works untill you move the item (mobwand) elseware in the inventory.
For example, i type a command to recieve the item and it works if i click it when it is in the slot that it apears in but the second i move it over a few slots it will stop shooting snowballs!
I understand this is random and specific but if there is anyone out there that can help a noob out i would greatly appreciate it! Thanks in advance!
First here is my code:
@EventHandler
public void toggle(PlayerInteractEvent event){
Player player = event.getPlayer();
if(player.getInventory().getItemInhand().getItemMeta().getDisplayName() == "MobWand"){
if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
Player p = event.getPlayer();
Snowball snowball = p.getWorld().spawn(p.getEyeLocation(), Snowball.class);
snowball.setVelocity(p.getLocation().getDirection().multiply(1.5));
snowball.setShooter(p);
This code is suppose to allow a player to shoot a snowball if they interact with an item called "mobwand" in there inventory.
Everything works untill you move the item (mobwand) elseware in the inventory.
For example, i type a command to recieve the item and it works if i click it when it is in the slot that it apears in but the second i move it over a few slots it will stop shooting snowballs!
I understand this is random and specific but if there is anyone out there that can help a noob out i would greatly appreciate it! Thanks in advance!
Create an account or sign in to comment.
4
1
NovaGamingBrianYou should just make an itemstack
Like Brian said, I'd try this.
The other problem might be that it doesn't re-check for the item. Maybe try having it say, on the action (clicks a block), check if they're holding an item with (name)
1
Please use the code formatting option when posting, as it makes your code a LOT easier to read, compared to just copying it into the post.
1
You should just make an itemstack and go to bukkit forums for these things
1
P.S the code is correct as in format and everything that i would generally need is there!
Also, there are no errors.
Also, there are no errors.