GUI Not coming up?

Discussion in 'Plugin Development' started by Bubbatron11, Apr 24, 2016.

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

    Bubbatron11

    So, I'm making a basic KitPVP plugin and I just did a tiny bit of it just to test it. Now i'm pretty sure i've done it right, but the GUI doesn't come up when I do the command I specified :/ Any ideas?
    Code:
    package me.Joel.KITPVP;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener{
        public void onEnable(){
         Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
        
        public boolean onCommand(CommandSender sender, Command cmd, String label,
                String[] args) {
            if(cmd.getName().equalsIgnoreCase("kits")){
               
                Player p = (Player) sender;
               
                if(p.hasPermission("kit.open")){
               
                ItemStack kit = new ItemStack(Material.DIAMOND_SWORD);
                   ItemMeta meta = kit.getItemMeta();
                   meta.setDisplayName(ChatColor.AQUA + "PVP Kit");
                   kit.setItemMeta(meta);
               
       
                  
                
                   Inventory inv = Bukkit.createInventory(null, 9, "Kits");
                   inv.setItem(1, kit);
               
                   p.getPlayer().openInventory(inv);
                }
               
               
    
                }
            return true;
    
            }
       
        @EventHandler
        public  void onClick(InventoryClickEvent e){
        
           
         Player p = (Player) e.getWhoClicked();
         if(p.hasPermission("kit.pvp")){
    
        
         if(e.getInventory().getTitle().equals(ChatColor.GREEN + "Kits")){
         
             ItemStack clicked = e.getCurrentItem();
             
             if (clicked.getType() == Material.DIAMOND_SWORD) {
                    e.setCancelled(true);
                    p.closeInventory();
                    p.getInventory().addItem(new ItemStack(Material.DIAMOND_HELMET, 1));
                    p.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD,1));
                   
             }
            }
        }
       
        }
    }
    
    
    
     
  2. Offline

    redraskal

    You are using p.getPlayer(), but p is already a player ;)
     
  3. @Bubbatron11 Check your log and think, what's wrong? Normally the problem is around the middle of the error, the 'ERROR' part can be important, I guess. Some stuff that can go wrong with gui's are:
    1. Invalid Argument for Inventory Slots,
    2. Invalid Player,
    3. Invalid input/output,
    4. You didn't follow me,
    5. ...
    Uh, whoops, focus on 1-3. There can also be a small error in your code that isn't noticing to you.
    Now forget 5 but keep 4 in mind ;).
     
Thread Status:
Not open for further replies.

Share This Page