Development Assistance Internal Error On Inventory Close

Discussion in 'Plugin Help/Development/Requests' started by meguy26, Apr 19, 2015.

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

    meguy26

    so i have a custom inventory, and it is the exact same size as a doublechest, however whenever I force a player to close it after they click an item in one of the last 2 slots bukkit throws an error that does not indicate anything in my plugin being wrong.

    Inventory code:
    Code (open)

    Code:
    String title = "someTitle";
            ItemStack paper = new ItemStack(Material.PAPER);
            ItemMeta pm = paper.getItemMeta();
            pm.setDisplayName("Start typing!");
            List<String> lore = Arrays.asList("Begin typing!");
            pm.setLore(lore);
            paper.setItemMeta(pm);
            ItemStack space = new ItemStack(Material.WOOL, 1, (short) 9);
            ItemMeta spaceMeta = space.getItemMeta();
            spaceMeta.setDisplayName("spacebar");
            space.setItemMeta(spaceMeta);
            ItemStack back = new ItemStack(Material.WOOL, 1, (short) 9);
            ItemMeta backMeta = back.getItemMeta();
            backMeta.setDisplayName("backspace");
            back.setItemMeta(backMeta);
            ItemStack submit = new ItemStack(Material.WOOL, 1, (short) 5);
            ItemMeta submitMeta = submit.getItemMeta();
            submitMeta.setDisplayName("submit");
            submit.setItemMeta(submitMeta);
            ItemStack cancel = new ItemStack(Material.WOOL, 1, (short) 14);
            ItemMeta cancelMeta = cancel.getItemMeta();
            cancelMeta.setDisplayName("cancel");
            cancel.setItemMeta(cancelMeta);
            ItemStack shift = new ItemStack(Material.WOOL, 1, (short) 9);
            ItemMeta shiftMeta = shift.getItemMeta();
            shiftMeta.setDisplayName("shift");
            shift.setItemMeta(shiftMeta);           
    Inventory inv = Bukkit.createInventory(null, 9 * 6, title);
                inv.setItem(4, paper);
    
                inv.setItem(41, shift);
                inv.setItem(42, space);
                inv.setItem(43, back);
    
                inv.setItem(52, submit);
                inv.setItem(53, cancel);
    
                ItemStack key = new ItemStack(Material.WOOL, 1, (short) 11);
                for (int i = 1; i <= 26; i++) {
                    ItemMeta km = key.getItemMeta();
                    km.setDisplayName(Alphabet.ALL[i - 1]);
                    key.setItemMeta(km);
                    inv.setItem(8 + i, key);
                }
    
                ItemStack chara = new ItemStack(Material.WOOL, 1, (short) 2);
                ItemMeta km = chara.getItemMeta();
                km.setDisplayName("&");
                chara.setItemMeta(km);
                inv.setItem(35, chara);
    
                km.setDisplayName("@");
                chara.setItemMeta(km);
                inv.setItem(44, chara);
    
                ItemStack basicCyan = new ItemStack(Material.WOOL, 1, (short) 3);
                for (int i = 1; i <= 2; i++) {
                    for (int i2 = 1; i2 <= 5; i2++) {
                        if (i == 1) {
                            ItemMeta bcm = basicCyan.getItemMeta();
                            bcm.setDisplayName(String.valueOf(i2));
                            basicCyan.setItemMeta(bcm);
                            inv.setItem(35 + i2, basicCyan);
                        } else if (i == 2) {
                            ItemMeta bcm = basicCyan.getItemMeta();
                            bcm.setDisplayName(String.valueOf(i2 + 5));
                            if (i2 + 5 == 10) {
                                bcm.setDisplayName("0");
                            }
                            basicCyan.setItemMeta(bcm);
                            inv.setItem(44 + i2, basicCyan);
                        }
                    }
                }
                views.put(p.openInventory(inv), id);


    Code in Listener
    Code (open)

    Code:
                String name = clicked.getItemMeta().getDisplayName();
                Player p = (Player) ev.getWhoClicked();
                UUID id = p.getUniqueId();
                boolean edited = false;
                if (name.equalsIgnoreCase("spacebar")) {
                    edited = true;
                    if (InputGUI.messages.containsKey(id)) {
                        InputGUI.messages.put(id, InputGUI.messages.get(id) + " ");
                    } else {
                        InputGUI.messages.put(id, " ");
                    }
                } else if (name.equalsIgnoreCase("backspace")) {
                    edited = true;
                    if (InputGUI.messages.containsKey(id)) {
                        if (InputGUI.messages.get(id).length() > 0) {
                            InputGUI.messages
                                    .put(id,
                                            InputGUI.messages.get(id).substring(
                                                    0,
                                                    InputGUI.messages.get(id)
                                                            .length() - 1));
                        }
                    }
                } else if (name.equalsIgnoreCase("submit")) {
                    InputGUIEvent event = new InputGUIEvent(p, ev.getView(),
                            InputGUI.views.get(ev.getView()),
                            InputGUI.messages.get(id), InputEventType.SUBMITTED);
                    if (InputGUI.messages.containsKey(p.getUniqueId())) {
                        InputGUI.messages.remove(p.getUniqueId());
                    }
                    if (InputGUI.views.containsKey(ev.getView())) {
                        if (InputGUI.messages.containsKey(p.getUniqueId())) {
                            InputGUI.messages.remove(p.getUniqueId());
                        }
                        InputGUI.views.remove(ev.getView());
                    }
                    Bukkit.getServer().getPluginManager().callEvent(event);
                    p.closeInventory();
                } else if (name.equalsIgnoreCase("cancel")) {
                    InputGUIEvent event = new InputGUIEvent(p, ev.getView(),
                            InputGUI.views.get(ev.getView()), null,
                            InputEventType.CANCELLED);
                    Bukkit.getServer().getPluginManager().callEvent(event);
                    p.closeInventory();
    
                } else if (name.equalsIgnoreCase("shift")) {
                    InputGUI.shift.put(p.getUniqueId(), String.valueOf(true));
                } else {
                    edited = true;
                    if (InputGUI.shift.containsKey(p.getUniqueId())
                            && Boolean.parseBoolean(InputGUI.shift.get(p
                                    .getUniqueId()))) {
                        if (InputGUI.messages.containsKey(id)) {
                            InputGUI.messages.put(id, InputGUI.messages.get(id)
                                    + name.toUpperCase());
                        } else {
                            InputGUI.messages.put(id, name.toUpperCase());
                        }
                    } else {
                        if (InputGUI.messages.containsKey(id)) {
                            InputGUI.messages.put(id, InputGUI.messages.get(id)
                                    + name);
                        } else {
                            InputGUI.messages.put(id, name);
                        }
                    }
                }
                if (edited) {
                    InputGUI.shift.put(p.getUniqueId(), String.valueOf(false));
                    ItemStack paper = new ItemStack(Material.PAPER);
                    ItemMeta pm = paper.getItemMeta();
                    pm.setDisplayName(InputGUI.messages.get(id));
                    paper.setItemMeta(pm);
                    ev.getView().setItem(4, paper);
                }


    Stack trace:
    error.PNG
     
  2. @meguy26 Show the full code and any relevant classes.
     
  3. Offline

    meguy26

    @CodePlaysMinecraft okay... here we go...

    Note: only the type Keyboard is broken/not working:
    InputGUI (open)

    Code:
    package com.gmail.neonblue858.mipa.inventorygui;
    
    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.UUID;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.InventoryView;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.Plugin;
    
    import com.gmail.neonblue858.mipa.auxilary.Alphabet;
    
    public class InputGUI {
        @SuppressWarnings("unused")
        private Plugin p;
        private String id;
        private InputGUIType type;
        static Map<InventoryView, String> views = new HashMap<InventoryView, String>();
        static Map<UUID, String> messages = new HashMap<UUID, String>();
        static Map<UUID, String> shift = new HashMap<UUID, String>();
        private String title;
        private String message;
    
        public InputGUI(Plugin p, InputGUIType type, String id) {
            this.p = p;
            this.type = type;
            this.id = id;
            this.title = "";
        }
    
        public void setTitle(String title) {
            if (title.length() >= 32) {
                this.title = title.substring(0, 32);
            } else {
                this.title = title;
            }
        }
    
        public void create(Player p) {
            ItemStack paper = new ItemStack(Material.PAPER);
            ItemMeta pm = paper.getItemMeta();
            pm.setDisplayName("Start typing!");
            List<String> lore = Arrays.asList("Begin typing!");
            pm.setLore(lore);
            paper.setItemMeta(pm);
            ItemStack space = new ItemStack(Material.WOOL, 1, (short) 9);
            ItemMeta spaceMeta = space.getItemMeta();
            spaceMeta.setDisplayName("spacebar");
            space.setItemMeta(spaceMeta);
            ItemStack back = new ItemStack(Material.WOOL, 1, (short) 9);
            ItemMeta backMeta = back.getItemMeta();
            backMeta.setDisplayName("backspace");
            back.setItemMeta(backMeta);
            ItemStack submit = new ItemStack(Material.WOOL, 1, (short) 5);
            ItemMeta submitMeta = submit.getItemMeta();
            submitMeta.setDisplayName("submit");
            submit.setItemMeta(submitMeta);
            ItemStack cancel = new ItemStack(Material.WOOL, 1, (short) 14);
            ItemMeta cancelMeta = cancel.getItemMeta();
            cancelMeta.setDisplayName("cancel");
            cancel.setItemMeta(cancelMeta);
            ItemStack shift = new ItemStack(Material.WOOL, 1, (short) 9);
            ItemMeta shiftMeta = shift.getItemMeta();
            shiftMeta.setDisplayName("shift");
            shift.setItemMeta(shiftMeta);
            if (type == InputGUIType.NUMBER_PAD) {
                Inventory inv = Bukkit.createInventory(null, 9 * 3, title);
                inv.setItem(4, paper);
                inv.setItem(16, space);
                inv.setItem(17, back);
                inv.setItem(25, submit);
                inv.setItem(26, cancel);
                ItemStack basicCyan = new ItemStack(Material.WOOL, 1, (short) 3);
                for (int i = 1; i <= 2; i++) {
                    for (int i2 = 1; i2 <= 5; i2++) {
                        if (i == 1) {
                            ItemMeta bcm = basicCyan.getItemMeta();
                            bcm.setDisplayName(String.valueOf(i2));
                            basicCyan.setItemMeta(bcm);
                            inv.setItem(9 + i2, basicCyan);
                        } else if (i == 2) {
                            ItemMeta bcm = basicCyan.getItemMeta();
                            bcm.setDisplayName(String.valueOf(i2 + 5));
                            if (i2 + 5 == 10) {
                                bcm.setDisplayName("0");
                            }
                            basicCyan.setItemMeta(bcm);
                            inv.setItem(18 + i2, basicCyan);
                        }
                    }
                }
                views.put(p.openInventory(inv), id);
            } else if (type == InputGUIType.LETTER_PAD) {
                Inventory inv = Bukkit.createInventory(null, 9 * 5, title);
                inv.setItem(4, paper);
                inv.setItem(40, space);
                inv.setItem(41, back);
                inv.setItem(39, shift);
                inv.setItem(43, submit);
                inv.setItem(44, cancel);
                ItemStack key = new ItemStack(Material.WOOL, 1, (short) 11);
                for (int i = 1; i <= 26; i++) {
                    ItemMeta km = key.getItemMeta();
                    km.setDisplayName(Alphabet.ALL[i - 1]);
                    key.setItemMeta(km);
                    inv.setItem(8 + i, key);
                }
    
                ItemStack chara = new ItemStack(Material.WOOL, 1, (short) 2);
                ItemMeta km = chara.getItemMeta();
                km.setDisplayName("&");
                chara.setItemMeta(km);
                inv.setItem(36, chara);
    
                km.setDisplayName("@");
                chara.setItemMeta(km);
                inv.setItem(37, chara);
                views.put(p.openInventory(inv), id);
            } else if (type == InputGUIType.KEYBOARD) {
                Inventory inv = Bukkit.createInventory(null, 9 * 6, title);
                inv.setItem(4, paper);
    
                inv.setItem(41, shift);
                inv.setItem(42, space);
                inv.setItem(43, back);
    
                inv.setItem(52, submit);
                inv.setItem(53, cancel);
    
                ItemStack key = new ItemStack(Material.WOOL, 1, (short) 11);
                for (int i = 1; i <= 26; i++) {
                    ItemMeta km = key.getItemMeta();
                    km.setDisplayName(Alphabet.ALL[i - 1]);
                    key.setItemMeta(km);
                    inv.setItem(8 + i, key);
                }
    
                ItemStack chara = new ItemStack(Material.WOOL, 1, (short) 2);
                ItemMeta km = chara.getItemMeta();
                km.setDisplayName("&");
                chara.setItemMeta(km);
                inv.setItem(35, chara);
    
                km.setDisplayName("@");
                chara.setItemMeta(km);
                inv.setItem(44, chara);
    
                ItemStack basicCyan = new ItemStack(Material.WOOL, 1, (short) 3);
                for (int i = 1; i <= 2; i++) {
                    for (int i2 = 1; i2 <= 5; i2++) {
                        if (i == 1) {
                            ItemMeta bcm = basicCyan.getItemMeta();
                            bcm.setDisplayName(String.valueOf(i2));
                            basicCyan.setItemMeta(bcm);
                            inv.setItem(35 + i2, basicCyan);
                        } else if (i == 2) {
                            ItemMeta bcm = basicCyan.getItemMeta();
                            bcm.setDisplayName(String.valueOf(i2 + 5));
                            if (i2 + 5 == 10) {
                                bcm.setDisplayName("0");
                            }
                            basicCyan.setItemMeta(bcm);
                            inv.setItem(44 + i2, basicCyan);
                        }
                    }
                }
                views.put(p.openInventory(inv), id);
            }
        }
    
        public void setMessage(String newMessage) {
            message = newMessage;
        }
    
        public String getMessage() {
            return message;
        }
    
    }


    Note: not broken, just relevant:
    InventoryGUI (open)

    Code:
    package com.gmail.neonblue858.mipa.inventorygui;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.InventoryView;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.Plugin;
    
    public class InventoryGUI {
        @SuppressWarnings("unused")
        private Plugin p;
        private int rows;
        private String title;
        private List<ItemStack> items;
        static Map<InventoryView, String> views = new HashMap<InventoryView, String>();;
        String id;
      
        public InventoryGUI(Plugin p, String id){
            this.p = p;
            this.rows = 1;
            items = new ArrayList<ItemStack>();
            this.id = id;
        }
      
        public void setRowAmount(int amount){
            rows = amount;
        }
      
        public void addItem(ItemStack i){
            ItemMeta im = i.getItemMeta();
            List<String> lore = im.getLore();
            if(lore != null){
                im.setLore(lore);
            }
            im.setLore(lore);
            i.setItemMeta(im);
            items.add(i);
        }
      
        public void addItem(ItemStack i, String name){
            ItemMeta im = i.getItemMeta();
            im.setDisplayName(name);
            List<String> lore = im.getLore();
            if(lore != null){
                im.setLore(lore);
            }
            i.setItemMeta(im);
            items.add(i);
        }
      
        public void setTitle(String title){
            if(title.length() >= 32){
                this.title = title.substring(0, 32);
            } else {
                this.title = title;
            }
        }
      
        public void create(Player target){
            Inventory inv = Bukkit.createInventory(null, rows * 9, title);
            for(int i = 0; i < items.size(); i++){
                int actI = i;
                int loc = (actI * 2) + 1;
                inv.setItem(loc, items.get(i));
            }
            ItemStack cancel = new ItemStack(Material.WOOL, 1, (short) 14);
            ItemMeta cancelMeta = cancel.getItemMeta();
            cancelMeta.setDisplayName("cancel");
            cancel.setItemMeta(cancelMeta);
            inv.setItem(inv.getSize() - 1, cancel);
            views.put(target.openInventory(inv), id);
        }
    }


    InventoryGUIListener (open)

    Code:
    package com.gmail.neonblue858.mipa.inventorygui;
    
    import java.util.UUID;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.inventory.InventoryCloseEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class InventoryGUIListener implements Listener {
    
        @EventHandler(priority = EventPriority.HIGHEST)
        void onClick(InventoryClickEvent ev) {
            ItemStack clicked = ev.getCurrentItem();
            if (clicked != null && clicked.getType() != Material.AIR
                    && InventoryGUI.views.containsKey(ev.getView())) {
                if (clicked.hasItemMeta()
                        && clicked.getItemMeta().hasDisplayName()
                        && clicked.getItemMeta().getDisplayName()
                                .equalsIgnoreCase("cancel")) {
                    ev.getWhoClicked().closeInventory();
                } else {
                    String id = "";
                    if (InventoryGUI.views.containsKey(ev.getView())) {
                        id = InventoryGUI.views.get(ev.getView());
                        InventoryGUI.views.remove(ev.getView());
                    }
                    GUIClickEvent event = new GUIClickEvent(
                            (Player) ev.getWhoClicked(), clicked, ev.getView(),
                            id);
                    Bukkit.getServer().getPluginManager().callEvent(event);
                    ev.getWhoClicked().closeInventory();
                }
            }
    
            if (clicked != null && clicked.getType() != Material.AIR
                    && InputGUI.views.containsKey(ev.getView())
                    && clicked.hasItemMeta()
                    && clicked.getItemMeta().hasDisplayName()
                    && clicked.getType() != Material.PAPER) {
                String name = clicked.getItemMeta().getDisplayName();
                Player p = (Player) ev.getWhoClicked();
                UUID id = p.getUniqueId();
                boolean edited = false;
                if (name.equalsIgnoreCase("spacebar")) {
                    edited = true;
                    if (InputGUI.messages.containsKey(id)) {
                        InputGUI.messages.put(id, InputGUI.messages.get(id) + " ");
                    } else {
                        InputGUI.messages.put(id, " ");
                    }
                } else if (name.equalsIgnoreCase("backspace")) {
                    edited = true;
                    if (InputGUI.messages.containsKey(id)) {
                        if (InputGUI.messages.get(id).length() > 0) {
                            InputGUI.messages
                                    .put(id,
                                            InputGUI.messages.get(id).substring(
                                                    0,
                                                    InputGUI.messages.get(id)
                                                            .length() - 1));
                        }
                    }
                } else if (name.equalsIgnoreCase("submit")) {
                    InputGUIEvent event = new InputGUIEvent(p, ev.getView(),
                            InputGUI.views.get(ev.getView()),
                            InputGUI.messages.get(id), InputEventType.SUBMITTED);
                    if (InputGUI.messages.containsKey(p.getUniqueId())) {
                        InputGUI.messages.remove(p.getUniqueId());
                    }
                    if (InputGUI.views.containsKey(ev.getView())) {
                        if (InputGUI.messages.containsKey(p.getUniqueId())) {
                            InputGUI.messages.remove(p.getUniqueId());
                        }
                        InputGUI.views.remove(ev.getView());
                    }
                    Bukkit.getServer().getPluginManager().callEvent(event);
                    p.closeInventory();
                } else if (name.equalsIgnoreCase("cancel")) {
                    InputGUIEvent event = new InputGUIEvent(p, ev.getView(),
                            InputGUI.views.get(ev.getView()), null,
                            InputEventType.CANCELLED);
                    Bukkit.getServer().getPluginManager().callEvent(event);
                    p.closeInventory();
    
                } else if (name.equalsIgnoreCase("shift")) {
                    InputGUI.shift.put(p.getUniqueId(), String.valueOf(true));
                } else {
                    edited = true;
                    if (InputGUI.shift.containsKey(p.getUniqueId())
                            && Boolean.parseBoolean(InputGUI.shift.get(p
                                    .getUniqueId()))) {
                        if (InputGUI.messages.containsKey(id)) {
                            InputGUI.messages.put(id, InputGUI.messages.get(id)
                                    + name.toUpperCase());
                        } else {
                            InputGUI.messages.put(id, name.toUpperCase());
                        }
                    } else {
                        if (InputGUI.messages.containsKey(id)) {
                            InputGUI.messages.put(id, InputGUI.messages.get(id)
                                    + name);
                        } else {
                            InputGUI.messages.put(id, name);
                        }
                    }
                }
                if (edited) {
                    InputGUI.shift.put(p.getUniqueId(), String.valueOf(false));
                    ItemStack paper = new ItemStack(Material.PAPER);
                    ItemMeta pm = paper.getItemMeta();
                    pm.setDisplayName(InputGUI.messages.get(id));
                    paper.setItemMeta(pm);
                    ev.getView().setItem(4, paper);
                }
    
            }
    
            if (InventoryGUI.views.containsKey(ev.getView())
                    || InputGUI.views.containsKey(ev.getView())) {
                ev.setCancelled(true);
            }
    
        }
    
        @EventHandler
        void onClose(InventoryCloseEvent ev) {
                if (InventoryGUI.views.containsKey(ev.getView())) {
                    InventoryGUI.views.remove(ev.getView());
                }
                if (InputGUI.views.containsKey(ev.getView())) {
                    InputGUIEvent event = new InputGUIEvent(
                            (Player) ev.getPlayer(), ev.getView(),
                            InputGUI.views.get(ev.getView()), null,
                            InputEventType.CANCELLED);
                    Player p = (Player) ev.getPlayer();
                    if (InputGUI.messages.containsKey(p.getUniqueId())) {
                        InputGUI.messages.remove(p.getUniqueId());
                    }
                    Bukkit.getServer().getPluginManager().callEvent(event);
                    InputGUI.views.remove(ev.getView());
                }
    
        }
    
    }


    Note: not broken, just relevant:
    GUIClickEvent (open)

    Code:
    package com.gmail.neonblue858.mipa.inventorygui;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.event.HandlerList;
    import org.bukkit.inventory.InventoryView;
    import org.bukkit.inventory.ItemStack;
    
    public class GUIClickEvent extends Event {
        private static final HandlerList handlers = new HandlerList();
        private boolean cancelled = false;
        private Player p;
        private ItemStack clicked;
        InventoryView inv;
        String id;
      
        public GUIClickEvent(Player p, ItemStack clicked, InventoryView inv, String id){
            this.p = p;
            this.clicked = clicked;
            this.inv = inv;
            this.id = id;
        }
          
      
        /**
         * Checks if the event is cancelled.
         * @return isCancelled
         */
        public boolean isCancelled() {
            return cancelled;
        }
      
        public String getID(){
            return id;
        }
      
        public InventoryView getInventory(){
            return inv;
        }
    
        /**
         * Sets if the event is cancelled.
         * @param setCancelled
         */
        public void setCancelled(boolean setCancelled) {
            cancelled = setCancelled;
        }
    
        /**
         * Gets the handlers list
         * @return handlers
         */
        public HandlerList getHandlers() {
            return handlers;
          
        }
      
        /**
         * Gets the handlers list
         * @return handlers
         */
        public static HandlerList getHandlerList() {
            return handlers;
          
        }
    
        public ItemStack getClicked(){
            return clicked;
        }
      
        public String getClickedName(){
            if(clicked.hasItemMeta() && clicked.getItemMeta().hasDisplayName()){
                return clicked.getItemMeta().getDisplayName();
            } else {
                return clicked.getType().toString();
            }
        }
      
        public Player getPlayer(){
            return p;
        }
    
    }
    


    InputGUIEvent (open)

    Code:
    package com.gmail.neonblue858.mipa.inventorygui;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.event.HandlerList;
    import org.bukkit.inventory.InventoryView;
    
    public class InputGUIEvent extends Event {
        private static final HandlerList handlers = new HandlerList();
        private boolean cancelled = false;
        private Player p;
        private InventoryView inv;
        private String id;
        private String message;
        private InputEventType type;
      
        public InputGUIEvent(Player p, InventoryView inv, String id, String message, InputEventType type){
            this.p = p;
            this.inv = inv;
            this.id = id;
            this.message = message;
            this.type = type;
        }
          
      
        /**
         * Checks if the event is cancelled.
         * @return isCancelled
         */
        public boolean isCancelled() {
            return cancelled;
        }
      
        public InputEventType getType(){
            return type;
        }
      
        public String getID(){
            return id;
        }
      
        public String getMessage(){
            return message;
        }
      
        public InventoryView getInventory(){
            return inv;
        }
    
        /**
         * Sets if the event is cancelled.
         * @param setCancelled
         */
        public void setCancelled(boolean setCancelled) {
            cancelled = setCancelled;
        }
    
        /**
         * Gets the handlers list
         * @return handlers
         */
        public HandlerList getHandlers() {
            return handlers;
          
        }
      
        /**
         * Gets the handlers list
         * @return handlers
         */
        public static HandlerList getHandlerList() {
            return handlers;
          
        }
      
        public Player getPlayer(){
            return p;
        }
    
    }
    


    InputEventType (open)

    Code:
    package com.gmail.neonblue858.mipa.inventorygui;
    
    public enum InputEventType {
        CANCELLED,
        SUBMITTED,
        CLOSED
    }


    InputGUIType (open)

    Code:
    package com.gmail.neonblue858.mipa.inventorygui;
    
    public enum InputGUIType {
        KEYBOARD,
        NUMBER_PAD,
        LETTER_PAD
    }
    


    FunListener (open)

    Code:
    package com.gmail.neonblue858.rpgsuite.fun;
    
    import org.bukkit.ChatColor;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    
    import com.gmail.neonblue858.mipa.inventorygui.InputEventType;
    import com.gmail.neonblue858.mipa.inventorygui.InputGUIEvent;
    
    public class FunListener implements Listener {
    
        @EventHandler
        void invSub(InputGUIEvent ev) {
            if (ev.getID().equals("tpup")) {
                if (ev.getType().equals(InputEventType.SUBMITTED) && ev.getMessage() != null) {
                    String message = ev.getMessage();
                    message = message.replaceAll(" ", "");
                    int y = (int) Double.parseDouble(message);
                    ev.getPlayer().teleport(ev.getPlayer().getLocation().add(0, y, 0));
                    ev.getPlayer().sendMessage("Shplam!");
                } else if (ev.getType().equals(InputEventType.CANCELLED)) {
                    ev.getPlayer().sendMessage("You cancelled the teleport!");
                }
            } else if (ev.getID().equals("tellme")){
                if (ev.getType().equals(InputEventType.SUBMITTED) && ev.getMessage() != null) {
                    String message = ev.getMessage();
                    ev.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', message));
                } else if (ev.getType().equals(InputEventType.CANCELLED)) {
                    ev.getPlayer().sendMessage("You cancelled the message!");
                }
            } else if (ev.getID().equals("broadcast")){
                if (ev.getType().equals(InputEventType.SUBMITTED) && ev.getMessage() != null) {
                    String message = ev.getMessage();
                    ev.getPlayer().getServer().broadcastMessage(ChatColor.GOLD + "[RPGSuite Fun Broadcast (" + ev.getPlayer().getName() + ")]: " + ChatColor.WHITE  + ChatColor.translateAlternateColorCodes('&', message));
                } else if (ev.getType().equals(InputEventType.CANCELLED)) {
                    ev.getPlayer().sendMessage("You cancelled the broacast!");
                }
            }
        }
      
    }
    


    FunCommands (open)

    Code:
    package com.gmail.neonblue858.rpgsuite.fun;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.gmail.neonblue858.mipa.inventorygui.InputGUI;
    import com.gmail.neonblue858.mipa.inventorygui.InputGUIType;
    import com.gmail.neonblue858.mipa.pluginutil.CommandUtil;
    import com.gmail.neonblue858.rpgsuite.main.Main;
    
    public class FunCommands implements CommandExecutor {
        private CommandUtil ut;
        @SuppressWarnings("unused")
        private Plugin call;
    
        public FunCommands(JavaPlugin p) {
            ut = new CommandUtil(p);
            call = p;
          
            ut.registerMainCommand("fun");
    
            ut.registerSubCommand("tpup", "Teleports you up.");
            ut.registerSubCommand("tellme", "Send yourself a message!");
            ut.registerSubCommand("broadcast", "Broadcasts a message!");
          
            ut.registerHelp("tpup", "/fun tpup", "Teleports you up.");
            ut.registerHelp("tellme", "/fun tellme", "Send yourself a message!");
            ut.registerHelp("broadcast", "/fun broadcast", "Broadcasts a message!");
        }
    
        @Override
        public boolean onCommand(CommandSender sender, Command command,
                String label, String[] args) {
            ut.processCommand(sender, command, label, args);
            if (args.length != 0) {
                if(args[0].equalsIgnoreCase("broadcast")){
                    if(args.length == 1){
                        if (sender instanceof Player) {
                            InputGUI inv = new InputGUI(Main.plugin,
                                    InputGUIType.KEYBOARD, "broadcast");
                            inv.setTitle("Input broadcast.");
                            inv.create((Player) sender);
                        } else {
                            sender.sendMessage("This command must be executed by a player!");
                        }
                    } else {
                        sender.sendMessage("Improper amounf of arguments!");
                    }
                }
                if (args[0].equalsIgnoreCase("tpup")) {
                    if (args.length == 1) {
                        if (sender instanceof Player) {
                            InputGUI inv = new InputGUI(Main.plugin,
                                    InputGUIType.NUMBER_PAD, "tpup");
                            inv.setTitle("How high?");
                            inv.create((Player) sender);
                        } else {
                            sender.sendMessage("This command must be executed by a player!");
                        }
                    } else {
                        sender.sendMessage("Improper amount of arguments!");
                    }
                }
                if (args[0].equalsIgnoreCase("tellme")) {
                    if (args.length == 1) {
                        if (sender instanceof Player) {
                            InputGUI inv = new InputGUI(Main.plugin,
                                    InputGUIType.LETTER_PAD, "tellme");
                            inv.setTitle("Insert message.");
                            inv.create((Player) sender);
                        } else {
                            sender.sendMessage("This command must be executed by a player!");
                        }
                    } else {
                        sender.sendMessage("Improper amount of arguments!");
                    }
                }
            }
            return true;
        }
    
    }
    
     
  4. Youre trying to set something at index 52 in an ArrayList, but the size is only 45.
     
    ChipDev likes this.
  5. Offline

    meguy26

    @FisheyLP
    No, -->I<-- am not, did you read my post or the stacktrace, the stacktrace does not show my classes anywere (all of my packages start with com.gmail.neonblue858). It has something to do with bukkit/spigot internally.
     
  6. Offline

    ChipDev

    Errors are there for a reason. It doesn't show a class because it shows the java's error.
     
  7. Online

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives.
     
  8. Offline

    meguy26

    @ChipDev
    I know errors are there for a reason! But the error shown does not indicate that it is my code that is at fault.
     
    ChipDev likes this.
  9. Online

    timtower Administrator Administrator Moderator

    @meguy26 Are you able to reproduce the errors? Tried adding printlines to your code to see where the error is happening?
     
    ChipDev likes this.
  10. Offline

    meguy26

    @timtower
    @timtower @ChipDev @FisheyLP @CodePlaysMinecraft
    So i decompiled my server and found were the error is occuring

    The line the error is occuring on:
    Code:
    //Line 140 in the above method
    //Edit i meant line 140...
    Slot slot2 = (Slot)this.c.get(i);
    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Apr 19, 2015
  11. Online

    timtower Administrator Administrator Moderator

    @meguy26 And where is the error located in your code? Because you call it somewhere.
     
  12. Offline

    meguy26

    @timtower
    I am pretty sure the error is in the InputGUI class:
    Code (open)

    Code:
    package com.gmail.neonblue858.mipa.inventorygui;
    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.UUID;
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.InventoryView;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.Plugin;
    import com.gmail.neonblue858.mipa.auxilary.Alphabet;
    public class InputGUI {
        @SuppressWarnings("unused")
        private Plugin p;
        private String id;
        private InputGUIType type;
        static Map<InventoryView, String> views = new HashMap<InventoryView, String>();
        static Map<UUID, String> messages = new HashMap<UUID, String>();
        static Map<UUID, String> shift = new HashMap<UUID, String>();
        private String title;
        private String message;
        public InputGUI(Plugin p, InputGUIType type, String id) {
            this.p = p;
            this.type = type;
            this.id = id;
            this.title = "";
        }
        public void setTitle(String title) {
            if (title.length() >= 32) {
                this.title = title.substring(0, 32);
            } else {
                this.title = title;
            }
        }
        public void create(Player p) {
            ItemStack paper = new ItemStack(Material.PAPER);
            ItemMeta pm = paper.getItemMeta();
            pm.setDisplayName("Start typing!");
            List<String> lore = Arrays.asList("Begin typing!");
            pm.setLore(lore);
            paper.setItemMeta(pm);
            ItemStack space = new ItemStack(Material.WOOL, 1, (short) 9);
            ItemMeta spaceMeta = space.getItemMeta();
            spaceMeta.setDisplayName("spacebar");
            space.setItemMeta(spaceMeta);
            ItemStack back = new ItemStack(Material.WOOL, 1, (short) 9);
            ItemMeta backMeta = back.getItemMeta();
            backMeta.setDisplayName("backspace");
            back.setItemMeta(backMeta);
            ItemStack submit = new ItemStack(Material.WOOL, 1, (short) 5);
            ItemMeta submitMeta = submit.getItemMeta();
            submitMeta.setDisplayName("submit");
            submit.setItemMeta(submitMeta);
            ItemStack cancel = new ItemStack(Material.WOOL, 1, (short) 14);
            ItemMeta cancelMeta = cancel.getItemMeta();
            cancelMeta.setDisplayName("cancel");
            cancel.setItemMeta(cancelMeta);
            ItemStack shift = new ItemStack(Material.WOOL, 1, (short) 9);
            ItemMeta shiftMeta = shift.getItemMeta();
            shiftMeta.setDisplayName("shift");
            shift.setItemMeta(shiftMeta);
            if (type == InputGUIType.NUMBER_PAD) {
                Inventory inv = Bukkit.createInventory(null, 9 * 3, title);
                inv.setItem(4, paper);
                inv.setItem(16, space);
                inv.setItem(17, back);
                inv.setItem(25, submit);
                inv.setItem(26, cancel);
                ItemStack basicCyan = new ItemStack(Material.WOOL, 1, (short) 3);
                for (int i = 1; i <= 2; i++) {
                    for (int i2 = 1; i2 <= 5; i2++) {
                        if (i == 1) {
                            ItemMeta bcm = basicCyan.getItemMeta();
                            bcm.setDisplayName(String.valueOf(i2));
                            basicCyan.setItemMeta(bcm);
                            inv.setItem(9 + i2, basicCyan);
                        } else if (i == 2) {
                            ItemMeta bcm = basicCyan.getItemMeta();
                            bcm.setDisplayName(String.valueOf(i2 + 5));
                            if (i2 + 5 == 10) {
                                bcm.setDisplayName("0");
                            }
                            basicCyan.setItemMeta(bcm);
                            inv.setItem(18 + i2, basicCyan);
                        }
                    }
                }
                views.put(p.openInventory(inv), id);
            } else if (type == InputGUIType.LETTER_PAD) {
                Inventory inv = Bukkit.createInventory(null, 9 * 5, title);
                inv.setItem(4, paper);
                inv.setItem(40, space);
                inv.setItem(41, back);
                inv.setItem(39, shift);
                inv.setItem(43, submit);
                inv.setItem(44, cancel);
                ItemStack key = new ItemStack(Material.WOOL, 1, (short) 11);
                for (int i = 1; i <= 26; i++) {
                    ItemMeta km = key.getItemMeta();
                    km.setDisplayName(Alphabet.ALL[i - 1]);
                    key.setItemMeta(km);
                    inv.setItem(8 + i, key);
                }
                ItemStack chara = new ItemStack(Material.WOOL, 1, (short) 2);
                ItemMeta km = chara.getItemMeta();
                km.setDisplayName("&");
                chara.setItemMeta(km);
                inv.setItem(36, chara);
                km.setDisplayName("@");
                chara.setItemMeta(km);
                inv.setItem(37, chara);
                views.put(p.openInventory(inv), id);
            } else if (type == InputGUIType.KEYBOARD) {
                Inventory inv = Bukkit.createInventory(null, 9 * 6, title);
                inv.setItem(4, paper);
                inv.setItem(41, shift);
                inv.setItem(42, space);
                inv.setItem(43, back);
                inv.setItem(52, submit);
                inv.setItem(53, cancel);
                ItemStack key = new ItemStack(Material.WOOL, 1, (short) 11);
                for (int i = 1; i <= 26; i++) {
                    ItemMeta km = key.getItemMeta();
                    km.setDisplayName(Alphabet.ALL[i - 1]);
                    key.setItemMeta(km);
                    inv.setItem(8 + i, key);
                }
                ItemStack chara = new ItemStack(Material.WOOL, 1, (short) 2);
                ItemMeta km = chara.getItemMeta();
                km.setDisplayName("&");
                chara.setItemMeta(km);
                inv.setItem(35, chara);
                km.setDisplayName("@");
                chara.setItemMeta(km);
                inv.setItem(44, chara);
                ItemStack basicCyan = new ItemStack(Material.WOOL, 1, (short) 3);
                for (int i = 1; i <= 2; i++) {
                    for (int i2 = 1; i2 <= 5; i2++) {
                        if (i == 1) {
                            ItemMeta bcm = basicCyan.getItemMeta();
                            bcm.setDisplayName(String.valueOf(i2));
                            basicCyan.setItemMeta(bcm);
                            inv.setItem(35 + i2, basicCyan);
                        } else if (i == 2) {
                            ItemMeta bcm = basicCyan.getItemMeta();
                            bcm.setDisplayName(String.valueOf(i2 + 5));
                            if (i2 + 5 == 10) {
                                bcm.setDisplayName("0");
                            }
                            basicCyan.setItemMeta(bcm);
                            inv.setItem(44 + i2, basicCyan);
                        }
                    }
                }
                views.put(p.openInventory(inv), id);
            }
        }
        public void setMessage(String newMessage) {
            message = newMessage;
        }
        public String getMessage() {
            return message;
        }
    }


    Because the error seems to be caused by the size of the inventory firing wrong, however in the above code I am creating an inventory the size of a double chest under the type keyboard. However, I suppose what I should be mentioning is that my code fully works as intended the inventory opens properly, etc. HOWEVER something internally in bukkit does not accept my inventory...
     
  13. Offline

    meguy26

Thread Status:
Not open for further replies.

Share This Page