Icon Menu problem (again)

Discussion in 'Plugin Development' started by Redzdaz, May 14, 2013.

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

    Redzdaz

    So yeah im back, with another problem with the class IconMenus (http://forums.bukkit.org/threads/icon-menu.108342)
    So i keep getting the same error since i began to use the craftbukkit-1.5.2-R0.1 build.

    I keep getting this error when i use the command:
    HTML:
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:189)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.dispatchCommand(CraftServer.java:523)
        at net.minecraft.server.v1_5_R3.PlayerConnection.handleCommand(PlayerConnection.java:965)
        at net.minecraft.server.v1_5_R3.PlayerConnection.chat(PlayerConnection.java:883)
        at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java:840)
        at net.minecraft.server.v1_5_R3.Packet3Chat.handle(Packet3Chat.java:44)
        at net.minecraft.server.v1_5_R3.NetworkManager.b(NetworkManager.java:292)
        at net.minecraft.server.v1_5_R3.PlayerConnection.d(PlayerConnection.java:109)
        at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
        at net.minecraft.server.v1_5_R3.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:581)
        at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:226)
        at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:477)
        at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:410)
        at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.IllegalArgumentException: Chests must have a size that is a multiple of 9!
        at org.apache.commons.lang.Validate.isTrue(Validate.java:157)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.createInventory(CraftServer.java:1273)
        at org.bukkit.Bukkit.createInventory(Bukkit.java:357)
        at me.Patrick.Random.IconMenu.open(IconMenu.java:53)
        at me.Patrick.Random.Main.onCommand(Main.java:132)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        ... 15 more
    And i can see that it says "Chests must have a size that is a multiple of 9!" so it must be something with that.

    Main.java
    PHP:
    package me.Patrick.Random;
    import java.util.Arrays;
     
    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.inventory.ItemStack;
    import org.bukkit.inventory.meta.BookMeta;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class 
    Main extends JavaPlugin {
     
        public static 
    IconMenu im;
     
        public static 
    Main instance;
     
        @
    Override
        
    public void onEnable() {
     
            
    instance this;
     
            
    PluginManager pm Bukkit.getPluginManager();
     
            
    im = new IconMenu("MiniGames"9, new IconMenu.OptionClickEventHandler() {
     
                @
    Override
                
    public void onOptionClick(final IconMenu.OptionClickEvent event) {
                    
    event.setWillClose(false);
                    if (
    event.getName().equals("Help")) {
                        
    ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
                        
    BookMeta bm = (BookMetabook.getItemMeta();
                        
    bm.setPages(Arrays.asList("Omkring FedtFattigBacon" ChatColor.GOLD "Bla bla bla."));
                        
    bm.setAuthor("FFB - Redzdaz");
                        
    bm.setTitle("FedtFattigBacon");
                        
    book.setItemMeta(bm);
                        
    event.getPlayer().getInventory().addItem(book);
                 
                    }else if (
    event.getName().equals("Stuff2")) {
                    }
     
                    if (
    event.getName().equals("Stuff3")) {
                    }
                    if (
    event.getName().equals("Stuff4")) {
                    }
                    if (
    event.getName().equals("Stuff5")) {
                    }
                    if (
    event.getName().equals("Stuff6")) {
                    }
     
                    if (
    event.getName().equals("Stuff7")) {
                    }
                    if (
    event.getName().equals("Stuff8")) {
                    }
         
                }
            }, 
    this)
            .
    setOption(0, new ItemStack(Material.ENCHANTED_BOOK1), "Help""How to use Stuffs.")
            .
    setOption(2, new ItemStack(Material.BOOK1), "Stuff1""Unlocked at Stuff 2")
            .
    setOption(3, new ItemStack(Material.BOOK1), "Stuff2""Unlocked at Stuff 4")
            .
    setOption(4, new ItemStack(Material.BOOK1), "Stuff3""Unlocked at Stuff 6")
            .
    setOption(5, new ItemStack(Material.BOOK1), "Stuff4""Unlocked at Stuff 10")
            .
    setOption(6, new ItemStack(Material.BOOK1), "Stuff5""Unlocked at Stuff 12")
            .
    setOption(7, new ItemStack(Material.BOOK1), "Stuff6""Unlocked at Stuff 14")
            .
    setOption(8, new ItemStack(Material.BOOK1), "Stuff7""Unlocked at Stuff 16");
     
            
    pm.registerEvents(imthis);
        }
     
        @
    Override
        
    public boolean onCommand(CommandSender sCommand cmdString clString[] args) {
            final 
    Player p = (Players;
            if (
    cl.equalsIgnoreCase("Mg")) {
                
    im.open(p);
            }
            return 
    false;
        }
    }
    IconMenu.java
    PHP:
    package me.Patrick.Random;
     
    import java.util.Arrays;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.HandlerList;
    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.Plugin;
     
    public class 
    IconMenu implements Listener {
     
    private 
    String name;
    private 
    int size;
    private 
    OptionClickEventHandler handler;
    private 
    Plugin plugin;
     
    private 
    String[] optionNames;
    private 
    ItemStack[] optionIcons;
     
    public 
    IconMenu(String nameint sizeOptionClickEventHandler handlerPlugin plugin) {
    this.name name;
    this.size size;
    this.handler handler;
    this.plugin plugin;
    this.optionNames = new String[size];
    this.optionIcons = new ItemStack[size];
    plugin.getServer().getPluginManager().registerEvents(thisplugin);
    }
     
    public 
    IconMenu setOption(int positionItemStack iconString nameString... info) {
    optionNames[position] = name;
    optionIcons[position] = setItemNameAndLore(iconnameinfo);
    return 
    this;
    }
     
    public 
    void open(Player player) {
    Inventory inventory Bukkit.createInventory(playersizename);
    for (
    int i 0optionIcons.lengthi++) {
    if (
    optionIcons != null) {
    inventory.setItem(ioptionIcons);
    }
    }
    player.openInventory(inventory);
    }
     
    public 
    void destroy() {
    HandlerList.unregisterAll(this);
    handler null;
    plugin null;
    optionNames null;
    optionIcons null;
    }
     
    @
    EventHandler(priority=EventPriority.MONITOR)
    void onInventoryClose(InventoryCloseEvent event) {
    if (
    event.getInventory().getTitle().equals(name)) {
    destroy();
    }
    }
     
    @
    EventHandler(priority=EventPriority.MONITOR)
    void onInventoryClick(InventoryClickEvent event) {
    if (
    event.getInventory().getTitle().equals(name)) {
    event.setCancelled(true);
    int slot event.getRawSlot();
    if (
    slot >= && slot size && optionNames[slot] != null) {
    Plugin plugin this.plugin;
    OptionClickEvent e = new OptionClickEvent((Player)event.getWhoClicked(), slotoptionNames[slot]);
    handler.onOptionClick(e);
    if (
    e.willClose()) {
    final 
    Player p = (Player)event.getWhoClicked();
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    public 
    void run() {
    p.closeInventory();
    }
    }, 
    1);
    }
    if (
    e.willDestroy()) {
    destroy();
    }
    }
    }
    }
     
    public interface 
    OptionClickEventHandler {
    public 
    void onOptionClick(OptionClickEvent event);
    }
     
    public class 
    OptionClickEvent {
    private 
    Player player;
    private 
    int position;
    private 
    String name;
    private 
    boolean close;
    private 
    boolean destroy;
     
    public 
    OptionClickEvent(Player playerint positionString name) {
    this.player player;
    this.position position;
    this.name name;
    this.close true;
    this.destroy false;
    }
     
    public 
    Player getPlayer() {
    return 
    player;
    }
     
    public 
    int getPosition() {
    return 
    position;
    }
     
    public 
    String getName() {
    return 
    name;
    }
     
    public 
    boolean willClose() {
    return 
    close;
    }
     
    public 
    boolean willDestroy() {
    return 
    destroy;
    }
     
    public 
    void setWillClose(boolean close) {
    this.close close;
    }
     
    public 
    void setWillDestroy(boolean destroy) {
    this.destroy destroy;
    }
    }
     
    private 
    ItemStack setItemNameAndLore(ItemStack itemString nameString[] lore) {
    ItemMeta im item.getItemMeta();
    im.setDisplayName(name);
    im.setLore(Arrays.asList(lore));
    item.setItemMeta(im);
    return 
    item;
    }
     
    }
    Anyone that know what the problem is?
     
  2. Offline

    Aqua

    Code:
    Inventory inventory = Bukkit.createInventory(player, size, name);
    Change it to:
    Code:
    Inventory inventory = Bukkit.createInventory(player, size * 9, name);
    And change the
    Code:
    im = new IconMenu("MiniGames", 9, new IconMenu.OptionClickEventHandler() {
    to
    Code:
    im = new IconMenu("MiniGames", 1, new IconMenu.OptionClickEventHandler() {
     
  3. Offline

    Redzdaz

    Thanks for the quick answer!
    But still dosent work. It keep showing the same error as before.

    Main
    PHP:
    package me.Patrick.Random;
    import java.util.Arrays;
     
    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.inventory.ItemStack;
    import org.bukkit.inventory.meta.BookMeta;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class 
    Main extends JavaPlugin {
     
        public static 
    IconMenu im;
     
        public static 
    Main instance;
     
        @
    Override
        
    public void onEnable() {
     
            
    instance this;
     
            
    PluginManager pm Bukkit.getPluginManager();
     
            
    im = new IconMenu("MiniGames"1, new IconMenu.OptionClickEventHandler() {
     
                @
    Override
                
    public void onOptionClick(final IconMenu.OptionClickEvent event) {
                    
    event.setWillClose(false);
                    if (
    event.getName().equals("Help")) {
                        
    ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
                        
    BookMeta bm = (BookMetabook.getItemMeta();
                        
    bm.setPages(Arrays.asList("Omkring FedtFattigBacon" ChatColor.GOLD "Bla bla bla."));
                        
    bm.setAuthor("FFB - Redzdaz");
                        
    bm.setTitle("FedtFattigBacon");
                        
    book.setItemMeta(bm);
                        
    event.getPlayer().getInventory().addItem(book);
               
                    }else if (
    event.getName().equals("Stuff2")) {
                    }
     
                    if (
    event.getName().equals("Stuff3")) {
                    }
                    if (
    event.getName().equals("Stuff4")) {
                    }
                    if (
    event.getName().equals("Stuff5")) {
                    }
                    if (
    event.getName().equals("Stuff6")) {
                    }
     
                    if (
    event.getName().equals("Stuff7")) {
                    }
                    if (
    event.getName().equals("Stuff8")) {
                    }
       
                }
            }, 
    this)
            .
    setOption(0, new ItemStack(Material.ENCHANTED_BOOK1), "Help""How to use Stuffs.")
            .
    setOption(2, new ItemStack(Material.BOOK1), "Stuff1""Unlocked at Stuff 2")
            .
    setOption(3, new ItemStack(Material.BOOK1), "Stuff2""Unlocked at Stuff 4")
            .
    setOption(4, new ItemStack(Material.BOOK1), "Stuff3""Unlocked at Stuff 6")
            .
    setOption(5, new ItemStack(Material.BOOK1), "Stuff4""Unlocked at Stuff 10")
            .
    setOption(6, new ItemStack(Material.BOOK1), "Stuff5""Unlocked at Stuff 12")
            .
    setOption(7, new ItemStack(Material.BOOK1), "Stuff6""Unlocked at Stuff 14")
            .
    setOption(8, new ItemStack(Material.BOOK1), "Stuff7""Unlocked at Stuff 16");
     
            
    pm.registerEvents(imthis);
        }
     
        @
    Override
        
    public boolean onCommand(CommandSender sCommand cmdString clString[] args) {
            final 
    Player p = (Players;
            if (
    cl.equalsIgnoreCase("Mg")) {
                
    im.open(p);
            }
            return 
    false;
        }
    }
    IconMenu
    PHP:
    package me.Patrick.Random;
     
    import java.util.Arrays;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.HandlerList;
    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.Plugin;
     
    public class 
    IconMenu implements Listener {
     
    private 
    String name;
    private 
    int size;
    private 
    OptionClickEventHandler handler;
    private 
    Plugin plugin;
     
    private 
    String[] optionNames;
    private 
    ItemStack[] optionIcons;
     
    public 
    IconMenu(String nameint sizeOptionClickEventHandler handlerPlugin plugin) {
    this.name name;
    this.size size;
    this.handler handler;
    this.plugin plugin;
    this.optionNames = new String[size];
    this.optionIcons = new ItemStack[size];
    plugin.getServer().getPluginManager().registerEvents(thisplugin);
    }
     
    public 
    IconMenu setOption(int positionItemStack iconString nameString... info) {
    optionNames[position] = name;
    optionIcons[position] = setItemNameAndLore(iconnameinfo);
    return 
    this;
    }
     
    public 
    void open(Player player) {
    Inventory inventory Bukkit.createInventory(playersizename);
    for (
    int i 0optionIcons.lengthi++) {
    if (
    optionIcons != null) {
    inventory.setItem(ioptionIcons);
    }
    }
    player.openInventory(inventory);
    }
     
    public 
    void destroy() {
    HandlerList.unregisterAll(this);
    handler null;
    plugin null;
    optionNames null;
    optionIcons null;
    }
     
    @
    EventHandler(priority=EventPriority.MONITOR)
    void onInventoryClose(InventoryCloseEvent event) {
    if (
    event.getInventory().getTitle().equals(name)) {
    destroy();
    }
    }
     
    @
    EventHandler(priority=EventPriority.MONITOR)
    void onInventoryClick(InventoryClickEvent event) {
    if (
    event.getInventory().getTitle().equals(name)) {
    event.setCancelled(true);
    int slot event.getRawSlot();
    if (
    slot >= && slot size && optionNames[slot] != null) {
    Plugin plugin this.plugin;
    OptionClickEvent e = new OptionClickEvent((Player)event.getWhoClicked(), slotoptionNames[slot]);
    handler.onOptionClick(e);
    if (
    e.willClose()) {
    final 
    Player p = (Player)event.getWhoClicked();
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    public 
    void run() {
    p.closeInventory();
    }
    }, 
    1);
    }
    if (
    e.willDestroy()) {
    destroy();
    }
    }
    }
    }
     
    public interface 
    OptionClickEventHandler {
    public 
    void onOptionClick(OptionClickEvent event);
    }
     
    public class 
    OptionClickEvent {
    private 
    Player player;
    private 
    int position;
    private 
    String name;
    private 
    boolean close;
    private 
    boolean destroy;
     
    public 
    OptionClickEvent(Player playerint positionString name) {
    this.player player;
    this.position position;
    this.name name;
    this.close true;
    this.destroy false;
    }
     
    public 
    Player getPlayer() {
    return 
    player;
    }
     
    public 
    int getPosition() {
    return 
    position;
    }
     
    public 
    String getName() {
    return 
    name;
    }
     
    public 
    boolean willClose() {
    return 
    close;
    }
     
    public 
    boolean willDestroy() {
    return 
    destroy;
    }
     
    public 
    void setWillClose(boolean close) {
    this.close close;
    }
     
    public 
    void setWillDestroy(boolean destroy) {
    this.destroy destroy;
    }
    }
     
    private 
    ItemStack setItemNameAndLore(ItemStack itemString nameString[] lore) {
    ItemMeta im item.getItemMeta();
    im.setDisplayName(name);
    im.setLore(Arrays.asList(lore));
    item.setItemMeta(im);
    return 
    item;
    }
     
    }
     
  4. Offline

    Aqua

    in public void open(Player player)
    Code:
    Inventory inventory = Bukkit.createInventory(player, size, name);
    Change that line to:
    Code:
    Inventory inventory = Bukkit.createInventory(player, size * 9, name);
     
  5. Offline

    Redzdaz

    For some reason i apprently copied the wrong file. I allready changed it to what you said.
    PHP:
     public void open(Player player) {
            
    Inventory inventory Bukkit.createInventory(playersize 9name);
            for (
    int i 0optionIcons.lengthi++) {
                if (
    optionIcons[i] != null) {
                    
    inventory.setItem(ioptionIcons[i]);
     
  6. Offline

    fireblast709

    Aqua is there any mathematical difference? because as far as I know 1 * 9 = 9 * 1, so changing that should not change much

    Redzdaz the code you posted looks fine, but according to the stacktrace there seems to be more code than you actually pasted (error occurs on line 132, while there is 81 lines pasted in the main class)
     
  7. Offline

    Redzdaz

    Then the error must be in my IconMenu class.

    Current code:
    PHP:
    package me.Patrick.Random;
    import java.util.Arrays;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.HandlerList;
    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.Plugin;
     
    public class 
    IconMenu implements Listener {
     
        private 
    String name;
        private 
    int size;
        private 
    OptionClickEventHandler handler;
        private 
    Plugin plugin;
     
        private 
    String[] optionNames;
        private 
    ItemStack[] optionIcons;
     
        public 
    IconMenu(String nameint sizeOptionClickEventHandler handlerPlugin plugin) {
            
    this.name name;
            
    this.size size;
            
    this.handler handler;
            
    this.plugin plugin;
            
    this.optionNames = new String[size];
            
    this.optionIcons = new ItemStack[size];
            
    plugin.getServer().getPluginManager().registerEvents(thisplugin);
        }
     
        public 
    IconMenu setOption(int positionItemStack iconString nameString... info) {
            
    optionNames[position] = name;
            
    optionIcons[position] = setItemNameAndLore(iconnameinfo);
            return 
    this;
        }
     
        public 
    void open(Player player) {
            
    Inventory inventory Bukkit.createInventory(playersize 9name);
            for (
    int i 0optionIcons.lengthi++) {
                if (
    optionIcons[i] != null) {
                    
    inventory.setItem(ioptionIcons[i]);
                }
            }
            
    player.openInventory(inventory);
        }
     
        public 
    void destroy() {
            
    HandlerList.unregisterAll(this);
            
    handler null;
            
    plugin null;
            
    optionNames null;
            
    optionIcons null;
        }
     
        @
    EventHandler(priority=EventPriority.MONITOR)
        
    void onInventoryClick(InventoryClickEvent event) {
            if (
    event.getInventory().getTitle().equals(name)) {
                
    event.setCancelled(true);
                
    int slot event.getRawSlot();
                if (
    slot >= && slot size && optionNames[slot] != null) {
                    
    Plugin plugin this.plugin;
                    
    OptionClickEvent e = new OptionClickEvent((Player)event.getWhoClicked(), slotoptionNames[slot]);
                    
    handler.onOptionClick(e);
                    if (
    e.willClose()) {
                        final 
    Player p = (Player)event.getWhoClicked();
                        
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                            public 
    void run() {
                                
    p.closeInventory();
                            }
                        }, 
    1);
                    }
                    if (
    e.willDestroy()) {
                        
    destroy();
                    }
                }
            }
        }
       
        public interface 
    OptionClickEventHandler {
            public 
    void onOptionClick(OptionClickEvent event);     
        }
       
        public class 
    OptionClickEvent {
            private 
    Player player;
            private 
    int position;
            private 
    String name;
            private 
    boolean close;
            private 
    boolean destroy;
         
            public 
    OptionClickEvent(Player playerint positionString name) {
                
    this.player player;
                
    this.position position;
                
    this.name name;
                
    this.close true;
                
    this.destroy false;
            }
         
            public 
    Player getPlayer() {
                return 
    player;
            }
         
            public 
    int getPosition() {
                return 
    position;
            }
         
            public 
    String getName() {
                return 
    name;
            }
         
            public 
    boolean willClose() {
                return 
    close;
            }
         
            public 
    boolean willDestroy() {
                return 
    destroy;
            }
         
            public 
    void setWillClose(boolean close) {
                
    this.close close;
            }
         
            public 
    void setWillDestroy(boolean destroy) {
                
    this.destroy destroy;
            }
        }
     
        private 
    ItemStack setItemNameAndLore(ItemStack itemString nameString[] lore) {
            
    ItemMeta im item.getItemMeta();
                
    im.setDisplayName(name);
                
    im.setLore(Arrays.asList(lore));
            
    item.setItemMeta(im);
            return 
    item;
        }
     
     
    }
    So maybe it's something to do with this?

    PHP:
        private ItemStack setItemNameAndLore(ItemStack itemString nameString[] lore) {
            
    ItemMeta im item.getItemMeta();
                
    im.setDisplayName(name);
                
    im.setLore(Arrays.asList(lore));
            
    item.setItemMeta(im);
            return 
    item;
        }
     
  8. Offline

    fireblast709

    if you multiply the size by 9 and use that in Bukkit#createInventory(InventoryHolder,int,String), the error must be different. Any natural number multiplied by 9 is a multiple of nine. If you really get the error, I suggest you post your whole Main class
     
  9. Offline

    Redzdaz

    I did post all of my main class. That's all i have.
     
  10. Offline

    JeroenV

    I posted some code on how to create a working menu system on this post a few moments back: http://forums.bukkit.org/threads/itemmenus.147457/.

    As far as I remember IconMenu was outdated so I adjusted and tweaked with a bunch of stuff and came up with that system. It should all be pretty clear.
     
  11. Offline

    Redzdaz

    Thank you very much for the reply. I tried using your code, but i'm getting some errors. (I'm pretty new to java.)
    I understood it as i should make a class called "MenuListener" and then a class called "BM_Handler", so i did that(Maybe i misunderstood?) I highlighted the erros below, and wrote next to them a note (With //)with the error Eclipse says.

    BM_Handler.java
    PHP:
    package me.Patrick.Random;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.Plugin;
     
    public class 
    BM_Handler{
     
        public 
    Plugin plugin MainMenu.plugin//MainMenu cannot be resolved to a variable
     
     
        
    public void openInvMenu(final Player player){
            
    Inventory inv Bukkit.createInventory(player27"menu_name");
            
    setOptions(inv,player);
            
    player.openInventory(inv);
        }
     
     
        public 
    void onOptionClick(final Player playerString name){
     
            if(
    name.equalsIgnoreCase("back")){
                    
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
       
                      [
    USER=90830440]Override[/USER]
                      public 
    void run() {
             
                          
    BM_Main BM = new BM_Main(); // BM_Main cannot be resolved to a type
                          
    BM.openInvMenu(player);
             
                      }
                          },
    1L);
                    return;
            }
     
        return;
        }
     
     
     
        public 
    void setOptions(Inventory invPlayer player){
        
    ML.setMenuOptions(inv,0, new ItemStack(Material.NETHER_STAR1),"Back","Go to the previous menu."); //ML cannot be resolved
        
    }
     
    }
    MenuListener.java
    PHP:
    package me.Patrick.Random;
     
    import java.util.Arrays;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.inventory.InventoryType;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.Plugin;
     
    public class 
    MenuListener implements Listener{
     
        public 
    Plugin plugin MainMenu.plugin//MainMenu cannot be resolved to a variable
     
        
    public void setMenuOptions(Inventory inv,int slot,ItemStack it,String title,String... lore){
        
    ItemStack option setItemNameAndLore(it,title,lore);
        
    inv.setItem(slot,option);
        }
     
        private 
    ItemStack setItemNameAndLore(ItemStack itemString nameString[] lore) {
        
    ItemMeta im item.getItemMeta();
        
    im.setDisplayName(name);
        
    im.setLore(Arrays.asList(lore));
        
    item.setItemMeta(im);
        return 
    item;
        }
     
     
      [
    USER=90830436]EventHandler[/USER]
        
    void onClickEvent(InventoryClickEvent e) {
     
        if(
    e.getWhoClicked() instanceof Player){
        
    Player player = (Player)e.getWhoClicked();
        
    ItemStack it e.getCurrentItem();
     
            if(
    it != null && it.getItemMeta() != null && it.getItemMeta().getDisplayName() != null){
     
     
                if(
    e.getInventory().getType() == InventoryType.CHEST){
     
                if(
    e.getInventory().getTitle().contains("(I)")){
                    
    closeInventory(player);
                    
    BM_Handler BH = new BM_Handler();
                    
    BH.onOptionClick(player,it.getItemMeta().getDisplayName());
                    
    e.setCancelled(true);
                    return;
                }
     
              }
            }
        }
     
        }
     
        public 
    void closeInventory(final Player player){
                
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
     
                [
    USER=90830440]Override[/USER]
                  public 
    void run() {
         
                  
    player.closeInventory();
           
                  }
                  },
    1L);
        }
     
     
    }
    As i said, i probably just misunderstood, how to set it up.
     
  12. Offline

    JeroenV

    Yeah, you took it too litteral :) The code I posted was a snapshot directly taken from my own code, it's meant for people to check out how the system works and then customize it for their own use.

    Ps. The in the code is an @ sign.
     
  13. Offline

    Redzdaz

    Ah okay. I'll try to find out how it works. Is it okay that i PM you some day, if i can't get it to work? :)
     
  14. Offline

    JeroenV

    Sure, no problem :)
     
Thread Status:
Not open for further replies.

Share This Page