Kit GUI help

Discussion in 'Plugin Development' started by diamondcodes, Sep 18, 2014.

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

    diamondcodes

    Alright so I am making a kit GUI, all the kits show up as a Coal item in the GUI but when a player clicks on the Item I have 2 question. 1: How can I change the Coal item to a emerald (If a player clicks the "Kit: 1" Item it will remove the kit: 1 Coal and change it to a emerald) and also 2: How would I make it do different things when they click the different kit items? (I know how to do it if they click a Material in the inventory, But both kits will be coal so can I do different actions if they click a Item with a certain name?)

    Thanks!

    Heres my code so you can see the kits

    Code:java
    1. package me.dc.kits;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.*;
    11. import org.bukkit.inventory.Inventory;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.ItemMeta;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. import java.util.Arrays;
    17.  
    18. public class Main extends JavaPlugin implements Listener {
    19.  
    20. @Override
    21. public void onEnable() {
    22. getServer().getPluginManager().registerEvents(this, this);
    23. }
    24.  
    25. @EventHandler
    26. public void onPlayerInteract(PlayerInteractEvent e) {
    27. Player player = e.getPlayer();
    28.  
    29. Inventory inv = Bukkit.createInventory(null, 27, ChatColor.GOLD + "" + ChatColor.BOLD + "Select your kit!");
    30.  
    31. ItemStack kit1 = new ItemStack(Material.COAL);
    32. ItemMeta kit1meta = kit1.getItemMeta();
    33. kit1meta.setDisplayName(ChatColor.RED + "Kit: 1");
    34. kit1meta.setLore(Arrays.asList(ChatColor.AQUA + "Price coming soon!"));
    35.  
    36. kit1.setItemMeta(kit1meta);
    37.  
    38. ItemStack kit2 = new ItemStack(Material.COAL);
    39. ItemMeta kit2meta = kit2.getItemMeta();
    40. kit2meta.setDisplayName(ChatColor.RED + "Kit: 2");
    41. kit2meta.setLore(Arrays.asList(ChatColor.AQUA + "Price coming soon!"));
    42.  
    43. kit2.setItemMeta(kit2meta);
    44.  
    45. inv.setItem(0, kit1);
    46. inv.setItem(1, kit2);
    47.  
    48. if (player.getInventory().getItemInHand().getType() != Material.PAPER) return;
    49.  
    50. if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK && player.getItemInHand().getType() == Material.PAPER) {
    51.  
    52. player.openInventory(inv);
    53. }
    54. }
    55.  
    56. }
    57.  
     
  2. Offline

    mine-care

    For seting to emerald listen on inventory click event and when they click it if it is choral, get its slot and set item in this slot emerald. Preferably have a specific name for each item e ause if they click their inventory coal it will turn it to emerald...

    And to do the second thing as I said above, name the item like &7kit 1 and then check if the name is kit1 to do stuff :)
     
  3. Offline

    diamondcodes

    mine-care What do you mean by "name the item"
    Edit: Never mind I got it, Thanks!
     
Thread Status:
Not open for further replies.

Share This Page