Bukkit custom inventory acting strange

Discussion in 'Plugin Development' started by rcth, Jun 1, 2014.

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

    rcth

    Hello all,

    I'm trying to make a simple API for my own plugin, to simply make custom inventories. It just... doesn't work as expected.
    [​IMG]

    My InventoryAPI class:
    PHP:
    public class InventoryAPI {
        
        public static 
    void setItem(Inventory inventoryint slotItemStack item) {
            
    inventory.setItem(slotitem);
        }
        
        public static 
    void removeItem(Inventory inventoryItemStack item) {
            
    inventory.removeItem(item);
        }
        
        public static 
    void addItem(Inventory inventoryItemStack item) {
            
    inventory.addItem(item);
        }
        
        public static 
    void clearInv(Inventory inventory) {
            
    inventory.clear();
        }
        
        public static 
    void openInventory(Player playerInventory inventory) {
            
    player.openInventory(inventory);
        }
        
        public static 
    void closeInventory(Player player) {
            
    player.closeInventory();
        }
    }
    My ItemStacks class:
    PHP:
    public class ItemStacks {
        
        public static 
    ItemStack GameMenu() {
            
    ItemStack is = new ItemStack(Material.BOOK1);
            
    ItemMeta im is.getItemMeta();
            
    im.setDisplayName(ChatColor.BLUE "" ChatColor.MAGIC "|" ChatColor.GOLD " GameMenu " ChatColor.BLUE
                    
    "" ChatColor.MAGIC "|");
            
    im.setLore(Arrays.asList(ChatColor.GOLD "Gain the knowledge of this magical park."));
            
    is.addUnsafeEnchantment(Enchantment.THORNS10);
            
    is.setItemMeta(im);
            return 
    is;
        }
        
        public static 
    ItemStack Spawn() {
            
    ItemStack is = new ItemStack(Material.DIAMOND_BOOTS1);
            
    ItemMeta im is.getItemMeta();
            
    im.setDisplayName(ChatColor.AQUA "Spawn");
            
    im.setLore(Arrays.asList(ChatColor.DARK_AQUA "Go to the spawn... With the speed of light!"));
            
    is.setItemMeta(im);
            return 
    is;
        }
    }
    My inventory class:
    PHP:
    public class InventoryGameMenu implements Listener {
        private 
    ThemeCraft plugin;
        
        public 
    InventoryGameMenu(ThemeCraft plugin) {
            
    this.plugin plugin;
        }
        
        @
    EventHandler
        
    public void onPlayerInteract(PlayerInteractEvent event) {
            
    Player player event.getPlayer();
            if (((
    event.getAction() == Action.RIGHT_CLICK_AIR) || (event.getAction() == Action.RIGHT_CLICK_BLOCK))
                    && (
    event.getPlayer().getItemInHand().equals(ItemStacks.GameMenu()))) {
                
    InventoryAPI.closeInventory(player);
                
    Inventory GameMenu Bukkit.createInventory(null7*7ChatColor.DARK_GRAY "General information");
                
    InventoryAPI.setItem(GameMenu0ItemStacks.Spawn());
                
    InventoryAPI.openInventory(playerGameMenu);
            }
        }
        
        @
    EventHandler
        
    public void onClick(InventoryClickEvent event) {
            
    Inventory GameMenu Bukkit.createInventory(null7*7,
                    
    ChatColor.DARK_GRAY "General information");
            
    Player player = (Playerevent.getWhoClicked();
            if (
    event.getInventory().getName().equalsIgnoreCase(GameMenu.getName())) {
                
    event.setCancelled(true);
                
                if (
    event.getCurrentItem() == null) {
                    return;
                }
                
                if (
    event.getCurrentItem().equals(new ItemStack(ItemStacks.Spawn()))) {
                    
    InventoryAPI.closeInventory(player);
                    
    EffectsAPI.playSound(playerSound.BURP1.0F1.0F);
                    
    player.teleport(player.getWorld().getSpawnLocation());
                }
            }
        }
    }

    Does anyone know how this weird thing comes from?
     
  2. Offline

    rsod

    You can't create inventories larger then 6 rows. Well, technically you can, but it will result them to display that weird.
     
  3. Offline

    rcth

    Changing it to 6*6 actually solved it. Through I've always used 9*9, so I don't know why it didn't work this time.
     
  4. Offline

    rsod

    size - The size of inventory to create; must be a multiple of 9.
    You should use 9, 2*9, 3*9 etc. 6*6 = 36 = 9*4, that's why it solved it.
     
  5. Offline

    rcth

    Ah, that explains it. Thanks.
     
Thread Status:
Not open for further replies.

Share This Page