Can not get custom item event handler to work

Discussion in 'Spigot Plugin Development' started by FlawlessGaming, Apr 29, 2017.

  1. I have made a plugin that adds a custom name to a minecraft item then if you right click that item it sends a broadcast message. I got it to give the custom name and item but the event handler won't work and console shows no errors

    Code (Text):
    package me.awesomehenderson.haileyspussy;

    import java.util.Arrays;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.inventory.meta.ItemMeta;

    public class GiveCommand extends JavaPlugin {
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("HaileysPotato")) {
                Player p = (Player) sender;
                PlayerInventory pi = p.getInventory();
                ItemStack bpotato = new ItemStack(Material.BAKED_POTATO, 1);
                ItemMeta im = bpotato.getItemMeta();
                im.setDisplayName("Hailey Potato");
                im.setLore(Arrays.asList("§f§oClick Me"));
            return true;
        public void onPotatoClick(PlayerInteractEvent e) {
            if(e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getAction() == Action.RIGHT_CLICK_AIR) {
                if(e.getItem().getItemMeta().getDisplayName().equals("Hailey Potato")) {
                    Bukkit.broadcastMessage(e.getPlayer() + "test!");

  2. Looks like you're missing onEnable()

    And in that on enable you'll need a RegisterEvents()

    Sent from my iPhone using Tapatalk
  3. Code (Text):
    public void onEnable(){
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
    Just this?
  4. Yes
  5. Just put this in and it did not work.
  6. Console errors?

    Sent from my iPhone using Tapatalk
  7. Code (Java):

     if(e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getAction() == Action.RIGHT_CLICK_AIR) {
    issue is pretty self-evident..
  8. You have to implement Listener and CommandExecutor, make a plugin.yml if not done already. Register your command in your on enable method, and this:
  9. Ah skipped over that, yeah you can't have but one action ever happen at the same time. If you want it to match either of those use an OR || you used AND &&

    Sent from my iPhone using Tapatalk