Dye item?

Discussion in 'Plugin Development' started by Sean0402, Aug 30, 2014.

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

    Sean0402

    Hi guys! How do I get the dye item? To go inside my inventory such as green dye for when the players is on. And the red dye when the players are turnt off. Thanks!

    My code so far:
    Code:java
    1. package me.Sean0402.MagicClock;
    2.  
    3. import java.util.Arrays;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.DyeColor;
    8. import org.bukkit.GameMode;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.inventory.InventoryClickEvent;
    13. import org.bukkit.inventory.Inventory;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16. import org.bukkit.material.Wool;
    17. import org.bukkit.plugin.Plugin;
    18.  
    19. public class Menu implements Listener {
    20.  
    21. private Inventory inv;
    22. private ItemStack HideAll, Hide50, Hide150;
    23.  
    24. public Menu(Plugin p) {
    25. inv = Bukkit.getServer().createInventory(null, 9, "Player Visibility");
    26.  
    27. HideAll = createItem(DyeColor.GREEN, ChatColor.GREEN + "Hide All Players");
    28. Hide50 = createItem(DyeColor.GRAY, ChatColor.YELLOW + "Hide 50 Players");
    29. Hide150 = createItem(DyeColor.GRAY, ChatColor.RED + "Hide 150 Players");
    30.  
    31. inv.setItem(0, HideAll);
    32. inv.setItem(4, Hide50);
    33. inv.setItem(8, Hide150);
    34.  
    35. Bukkit.getServer().getPluginManager().registerEvents(this, p);
    36. }
    37.  
    38. private ItemStack createItem(DyeColor dc, String name) {
    39. ItemStack i = new Wool(dc).toItemStack(1);
    40. ItemMeta im = i.getItemMeta();
    41. im.setDisplayName(name);
    42. i.setItemMeta(im);
    43. return i;
    44. }
    45.  
    46. public void show(Player p) {
    47. p.openInventory(inv);
    48. }
    49.  
    50. @EventHandler
    51. public void onInventoryClick(InventoryClickEvent e) {
    52. if (!e.getInventory().getName().equalsIgnoreCase(inv.getName())) return;
    53. if (e.getCurrentItem().getItemMeta() == null) return;
    54. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Hide All Players")) {
    55. e.setCancelled(true);
    56. e.getWhoClicked().setGameMode(GameMode.CREATIVE);
    57. e.getWhoClicked().closeInventory();
    58. }
    59. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Hide 50 Players")) {
    60. e.setCancelled(true);
    61. e.getWhoClicked().setGameMode(GameMode.SURVIVAL);
    62. e.getWhoClicked().closeInventory();
    63. }
    64. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Hide 150 Players")) {
    65. e.setCancelled(true);
    66. e.getWhoClicked().setGameMode(GameMode.ADVENTURE);
    67. e.getWhoClicked().closeInventory();
    68. }
    69. }
    70. }
     
  2. Offline

    lrdemolition

    Code:
    e.getWhoClicked()
    is that valid?
    idk
    i thought it would be e.getPlayer().aMethod()

    Sean0402

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  3. Offline

    Sean0402

    @Irdemolition yes it is.
     
  4. Offline

    wptcraft

    Are you doing something like you right click with say greenwool in your hand and it turns red and players disapear or soemthing?
     
  5. Offline

    Sean0402

    wptcraft I currently have it so when you right click a redstone torch on is opens a gui like hppixels clock. And then you select one to choose. When you open the GUI I need all of them to be green dye. Then turn to grey dye and turn players off when you click it.
     
  6. Offline

    wptcraft

    On my iPod, so I can't explain in code but it will be some kind of Boolean when set to true changes the id to GREEN_WOOL il get some code written up tommorow for you if its still not sorted
     
  7. Offline

    Sean0402

  8. Offline

    wptcraft

    Sean0402 has it been solved or do you still need the code?
     
  9. Offline

    Sean0402

Thread Status:
Not open for further replies.

Share This Page