Solved [1.11.2] Having problems with PlayerInteractEvent and Inventories

Discussion in 'Spigot Help' started by Dotsy, Apr 22, 2017.

  1. Hello,

    I'm currently trying to make an Inventory pop-up whenever the player rightclicks a Compass.
    Sadly I'm getting this error:

    This is my code:
    Code (Text):
    package MFPlugin;

    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.plugin.Plugin;

    public class GUIs implements Listener {
        private Plugin plugin = Main.getPlugin(Main.class);
        public void newInventory(Player player){
            Inventory kitinv = plugin.getServer().createInventory(player, 9, ChatColor.MAGIC  + "i" + ChatColor.BLACK + ChatColor.BOLD + "Kit Selection" + ChatColor.DARK_GRAY + ChatColor.MAGIC  + "i");

           public void onPlayerInteractEvent(PlayerInteractEvent e){
           if(e.getPlayer().getItemInHand().equals(Material.COMPASS)) {

    I did manage to make an command (/inventory) which makes the custom inventory pop-up. It doesn't work when I try to attach it to an Item.

    Help would be appreciated.
    By the way could someone be kind and move this to Spigot Plugin Development?
  2. Bumping this.
  3. have you tried following this tutorial..?
  4. I recommend learning about the differences of fields, constants and local variables. You need to put kitinv up into your actual lass deceleration. Remember, OOP needs you to initialise that from a method.