Guest User

Untitled

a guest
May 1st, 2014
14
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package noah.plugins.maxymenu;
  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 c, s, a;
  23.  
  24. public Menu(Plugin p) {
  25. inv = Bukkit.getServer().createInventory(null, 9, "Gamemode Chooser");
  26.  
  27. c = createItem(DyeColor.GREEN, ChatColor.GREEN + "Creative");
  28. s = createItem(DyeColor.YELLOW, ChatColor.YELLOW + "Survival");
  29. a = createItem(DyeColor.RED, ChatColor.RED + "Adventure");
  30.  
  31. inv.setItem(2, c);
  32. inv.setItem(4, s);
  33. inv.setItem(6, a);
  34.  
  35. Bukkit.getServer().getPluginManager().registerEvents(this, p);
  36. }
  37.  
  38. private ItemStack createItem(DyeColor dc, String name) {
  39. ItemStack i = new ItemStack(new Wool(dc).toItemStack(1));
  40. ItemMeta im = i.getItemMeta();
  41.  
  42. im.setDisplayName(name);
  43. im.setLore(Arrays.asList("Set your gamemode", " to " + name.toLowerCase() + "mode"));
  44. i.setItemMeta(im);
  45.  
  46. return i;
  47. }
  48.  
  49. public void show(Player p) {
  50. p.openInventory(inv);
  51. }
  52.  
  53. @EventHandler
  54. public void onInventoryClick(InventoryClickEvent e) {
  55. if (!(e.getInventory().getName().equalsIgnoreCase(inv.getName()))) return;
  56.  
  57. if(e.getCurrentItem().getItemMeta().getDisplayName().contains("Survival")) {
  58. e.setCancelled(true);
  59. e.getWhoClicked().setGameMode(GameMode.SURVIVAL);
  60. e.getWhoClicked().closeInventory();
  61. }
  62.  
  63. if(e.getCurrentItem().getItemMeta().getDisplayName().contains("Creative")) {
  64. e.setCancelled(true);
  65. e.getWhoClicked().setGameMode(GameMode.CREATIVE);
  66. e.getWhoClicked().closeInventory();
  67. }
  68.  
  69. if(e.getCurrentItem().getItemMeta().getDisplayName().contains("Adventure")) {
  70. e.setCancelled(true);
  71. e.getWhoClicked().setGameMode(GameMode.ADVENTURE);
  72. e.getWhoClicked().closeInventory();
  73. }
  74.  
  75.  
  76. }
  77.  
  78. }
RAW Paste Data