Solved Help in inventoryClickEvent. (solved)

Discussion in 'Spigot Plugin Development' started by jarnevan, Jun 9, 2016.

  1. Hello,

    I want to do when i click a oak wood in my gui that i get that item like this:
    Code (Text):
    if (e.getCurrentItem().getType() == Material.LOG){
                    if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', "&a&lOak Wood"))) {
                        if(e.getClick() == ClickType.LEFT){
                            EconomyResponse r = Clans.getEcon().withdrawPlayer((Player) e.getWhoClicked(), Clans.CGS.getConfig().getInt("Building-Gui.Oak-Wood.cost"));
                            if (r.transactionSuccess()) {
                                p.getInventory().addItem(new ItemStack(Material.LOG, 1));
                                p.sendMessage(ChatColor.translateAlternateColorCodes('&', Clans.messages.getConfig().getString("Shop-bought")));
                                p.sendMessage(ChatColor.translateAlternateColorCodes('&', Clans.messages.getConfig().getString("Shop-cannot-afford")));
    But when i buy a Spruce wood i want to sell the spruce wood i want only sell the spruce wood but when i click on the oak wood it sells it but it does not have the item in there inventory.
    how can is solve it

    Best gerards,
  2. I am having a little bit of trouble trying to fully understand your issue. Tell if I'm wrong. Your problem is, when a player clicks on the Oak Wood, and they can buy it, it does not put the item in their inventory? Is that correct or is that not quite your issue?
  3. I mean When they have a spruce wood in there inventory.
    and when they want to sell there Spruce wood i want that it only sell's the spruce wood section in my gui not a oak wood section because when i click with my spruce wood on a oak wood it sell's but i don't want that it sell's
  4. Check the data of the block to determine of it is oak, spruce, birch, etc? I'm still not exactly sure what you are trying to accomplish. It's a little hard to understand what you are saying. Could you retype, step by step, what you want and what the problem is. Make sure to proofread and maybe add pictures. Whenever you bring something new up, make sure to explain what it is; you said you only want it to sell the spruce wood section, but we have no idea what that is. I should be able to help you then?
  5. i have did that already like this you mean or not?
    Code (Text):
                            if(e.getCurrentItem().getTypeId() == 1){
  6. What you did is only to get the material of the item. Items that can have multiple versions of itself like wood, logs, wool, etc, store another bit of data that hold which type it is. What you did was get the material ID for the item. You should never need to use material type IDs unless you need to work around compatibility with older plugins; always use the material ENUM that is provided. What you'll need to do is get the data of the itemstack and that will tell you what the ID is for different types of wool, stone, or in your case wood.
  7. Thanks this helped me allot :)
    It has been solved Thanks YOU!!