Help with Custom Inventory

Discussion in 'Plugin Development' started by Jalau, Nov 26, 2013.

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

    Jalau

    So basicly, i open a inventory for a player and i want to check at the clickevent if he clicked in the upper (custom inv) or in his inv... I can't check for slot ids because they are the same in both, so if i check if the slot is 1 it will accept if i click the second slot in my inv or in the top inv... So how can i check if the clicked item was in his inv?
     
  2. Offline

    zDylann

    Code:java
    1. if (inventory.getName().equals(InsertCustomInventory.getName())){
    2. // Do Stuff
    3. }



    This is what I do, you will need to make an inventory variable, and this should be in the InventoryClickEvent. Also if you plan to do something when someone clicks it and you don't want them to grab the item, use event.setCancelled(true). I hope I can help.
     
  3. Offline

    Jalau

    Yeah already did this check, so the name is Auctionhall and it does work, but if i click in my inv it works too... (It doesn't works when the other inv is closed so there aren't any wrong checks)...
     
  4. Offline

    zDylann

    Can I see your code?
     
  5. Offline

    Jalau

    Yeah sure:

    Code:java
    1. package me.Jalau.Auction;
    2.  
    3. import me.Jalau.MysticRunes.MysticRunes;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.inventory.InventoryClickEvent;
    10. import org.bukkit.inventory.ItemStack;
    11.  
    12. public class AuctionClickListener implements Listener {
    13. private static MysticRunes plugin;
    14.  
    15. public AuctionClickListener(MysticRunes plugin) {
    16. this.plugin = plugin;
    17. }
    18.  
    19. public MysticRunes getPlugin() {
    20. return plugin;
    21. }
    22.  
    23. @EventHandler
    24. public void standartClick(InventoryClickEvent e) {
    25. final Player p = (Player) e.getWhoClicked();
    26. if(ChatColor.stripColor(e.getInventory().getName()).equalsIgnoreCase("Auctionhall")) {
    27. e.setCancelled(true);
    28. if(e.getInventory().getHolder() != p) {
    29.  
    30. //My Items
    31. if(e.getSlot() == 45) {
    32. p.closeInventory();
    33. AuctionGui.openMyAuctions(p);
    34. }
    35.  
    36. //Buy
    37. if(e.getSlot() <= 35) {
    38. if(e.getCurrentItem() != null && AuctionHandler.getAuction(e.getCurrentItem()) != 0 || e.getCurrentItem() != null && !p.getInventory().contains(e.getCurrentItem())) { <--- Here in the other inv! I just tried a few things there that doesnt worked :D
    39. ItemStack is = e.getCurrentItem();
    40. AuctionHandler.auctionbuying.put(p, is);
    41. p.sendMessage(ChatColor.GREEN + "Enter the quantity: ");
    42. p.closeInventory();
    43. }
    44. }
    45. }
    46. }
    47. if(ChatColor.stripColor(e.getInventory().getName()).equalsIgnoreCase("My Items")) {
    48. e.setCancelled(true);
    49. //Add Auction
    50. if(AuctionHandler.getPrice(e.getCurrentItem()) == 0) { <--- Here needs the item to be in the playerinv
    51. if(e.getSlot() <= 35) {
    52.  
    53. ItemStack tosell = e.getCurrentItem();
    54. AuctionHandler.auctioncreating.put(p, tosell);
    55. p.getInventory().remove(e.getCurrentItem());
    56. p.sendMessage(ChatColor.GREEN + "Enter a price: ");
    57. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable()
    58. {
    59. public void run() {
    60. p.closeInventory();
    61. }
    62. }, 1L);
    63. }
    64. }
    65.  
    66. }
    67. }
    68. }
    69.  


    Bump :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page