Solved Custom Inv Issue

Discussion in 'Plugin Help/Development/Requests' started by NeerDev, Jun 17, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    NeerDev

    I'm trying to open a custom chest inventory with multiple item stacks for my hub navigator GUI, however upon attempting to open the inventory I keep getting errors and can't find where the problem lies for the life of me. The error occurs upon a player right clicking as it can't pass event PlayerInteractEvent (presumably due to calling the show() which shows the new inventory)

    I've simplified all my code to easily show the relevant parts. The actual ItemStacks's are created in a method which takes in data from the config but i removed it for now.

    Below is my nav menu class:

    Code:
    public class Navigator implements Listener {
     
        private Inventory inv;
     
     
        static Plugin hub = Bukkit.getPluginManager().getPlugin("NeerHub");
        static FileConfiguration cfg = hub.getConfig();
     
     
        //INITIALIZING ITEMSTACKS FOR MENU
     
        ItemStack one = new ItemStack(Material.ARROW); {
            ItemMeta onemeta = one.getItemMeta();
            ArrayList<String> lore1 = new ArrayList<String>();
            onemeta.setDisplayName(ChatColor.AQUA + "GAME NAME");
            lore1.add(ChatColor.BOLD + "" + ChatColor.GREEN + "Right click to play");
            onemeta.setLore(lore1);
            one.setItemMeta(onemeta);
        }
     
     
     
        @SuppressWarnings("deprecation")
        public Navigator(Plugin p) {
            inv = Bukkit.getServer().createInventory(null, 9, "Navigator");
         
         
            inv.setItem(5, one);
         
         
            Bukkit.getServer().getPluginManager().registerEvents(this, p);
        }
     
     
     
        public void show(Player p) {
            p.openInventory(inv);
        }
        //IGNORE BELOW FOR NOW
        @EventHandler
        public void onInventoryClick(InventoryClickEvent e) {
            if (!e.getInventory().equals(inv)) return;
            if (e.getCurrentItem().getItemMeta().getDisplayName().contains(cfg.getString("ChestCommands.items.item1name"))) {
                Bukkit.getServer().dispatchCommand(e.getWhoClicked(), "sethub");
    //IGNORE ABOVE ^^
            }
        }
    
     
    }
    
    And here's the listener in my Listener class for right click block to open inv. All the other listeners in the class work fine.

    Code:
    
    public Navigator nav;
    
    
    
    
    @EventHandler
    public void onInvisClick(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            Action eAction = e.getAction();
         
            if (eAction == Action.RIGHT_CLICK_BLOCK) {
            nav.show(p);
        }
    }
    And finally, my main.
    Code:
    package me.neerbutt;
    
    
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    public final class Main extends JavaPlugin implements Listener {
     
        Main plugin;
     
        @Override
        public void onEnable() {
         
            Config.setup();
            saveConfig();
         
            plugin = this;
         
         
            new Listeners(this);
            new Navigator(this);
         
            getServer().getPluginManager().registerEvents(this, this);
         
         
            getCommand("sethub").setExecutor(new Teleporter(this));
         
     
         
            Broadcaster.broadcasts();
     
    
        }
     
        @Override
        public void onDisable() {
         
            saveDefaultConfig();
         
        }
     
    
     
    }
    
    Any help/advice would be greatly appreciated! Thnx
     
    Last edited: Jun 18, 2015
  2. Offline

    Drkmaster83

    Well, a record of said errors would be appreciated... a stack-trace of sorts? We'd need to know what kind of exception was thrown that way we don't go chasing rabbits.

    My guess without any record of errors would be that your 'one' ItemStack needs to be called in the Navigator constructor so as to wait for instantiation of the plugin and CraftBukkit ItemFactory before attempting to access their methods.
     
  3. Offline

    NeerDev

    Never mind , fixed.

    The problem was I should have just used Navigator.show() as the pointer but instead I tried to define navigator in the listeners class and called that. I just had to change show(p) in the nav class to a static and everything's good :)

    thanks though
     
    Last edited: Jun 18, 2015
  4. Online

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives.
     
Thread Status:
Not open for further replies.

Share This Page