Hello everbody, at the moment i write a plugin which should allow me to use a inventory as menu, so every itemslot for as menu option! How i can open an inventory and how i can read out from a special slot i can do but i have some questions: - How can i set only the inventory to "read-only"? So nobody can take items of this inventory away - Which Event Listener should i use? At the moment i use the inventoryClickevent... And how can i only read from the opened inventory and not from the normal inventory? I hope somebody have some nice tipps or ideas and sorry for my question and my bad english !
paxi InventoryClickEvent is the event you're most definitely going to want to use, to make it so you can't actually pull or put items in the inventory you just cancel the event. Here is how you can tell which inventory is clicked: Code:java if (event.getRawSlot() == event.getSlot()) { //Click happened in the chest inventory} else { //Click happened in player's inventory}
paxi InventoryClickEvent . Make sure you make a if statement at the start, where it checks the inventory, else if you click any item anywhere, chests, in your own inventory, it will act like it's in the inventory, and perform the event. So be careful
Thanks for your answers but they doens't solve my problem: here my code: Code:java public void oninventoryclick(InventoryClickEvent e){ if(e.getRawSlot()==e.getSlot()){ e.setCancelled(true); //code where i read out the item and do something other I can move the items and the funktion which readout the items starts also in the normal player inventory
paxi I don't understand what you're trying to say. What do you mean by the readout starts in the normal player inventory; as in the slots?
Okay sorry. I mean following: With one command I open a small chest inventory which i want to use as a menu. So when i klick on slot 1 of this menu/inventory for example my plugin prints in the config.yml something. This read out works good! But I also want that i can't take this items of this menu away and this doens't work.... On this position O hope someone of you can help me ! So maybe you can compare it like the "read only" status of a folder in windows....! I hope it is a better explanation ! With this code i try it: Code:java public void oninventoryclick(InventoryClickEvent e){ if(e.getRawSlot()==e.getSlot()){e.setCancelled(true); EDIT by Moderator: merged posts, please use the edit button instead of double posting.
paxi Ok now I understand, what's really happening, or at least should be, is it is giving you a ghost item. The best way I've found to get rid of this error is by updating the inventory.
How do you mean this? :O At the moment it is so: When i take a item of this inventory i replace it thats not the problem but how can i set the item in the "cursor==air"?
This changes the item at the cursor? Okay thank you,I will try it when I am at home Warreo I found the code which shoudl do what i want but why it doens't work? Code: Code:java ItemStack handitem= new ItemStack(Material.AIR); p.setItemOnCursor(handitem); //p is the player I think it should work or? Or need i to reload something ? :O Did someone have an idea how i can change it? It doesn't work... EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Now i have following code: Code:java if (e.getInventory().getName().equalsIgnoreCase("Skills")){Inventory pinv = e.getInventory();Player p = (Player) e.getWhoClicked();ItemStack cursor = e.getCursor();ItemStack itemclicked = e.getCurrentItem();if (e.getRawSlot() < 27 && e.getRawSlot() > -1){cursor = e.getCursor();itemclicked = e.getCurrentItem();p = (Player) e.getWhoClicked();e.setCancelled(true);} ItemStack handitem= new ItemStack(Material.AIR);p.setItemOnCursor(handitem);p.updateInventory(); When i get an item of this special inventory i can't put it in the normal player inventory but when i clicked on the item i see the item on the cursor :/! How can i change it? I hope you understand what i mean... Of course: All code is called.... also the if....