Guest User

Code 2

a guest
Sep 14th, 2015
207
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.YouTubeDanTDM.menuinv;
  2.  
  3. import java.util.Arrays;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.DyeColor;
  7. import org.bukkit.GameMode;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.event.inventory.InventoryClickEvent;
  10. import org.bukkit.inventory.Inventory;
  11. import org.bukkit.inventory.ItemStack;
  12. import org.bukkit.inventory.meta.ItemMeta;
  13. import org.bukkit.material.Wool;
  14.  
  15. public class MenuInv {
  16.  
  17. private Inventory inv;
  18. private ItemStack c, s, a,
  19.  
  20. public Menu(Plugin p) {
  21. inv = Bukkit.getServer().createInventory(null, 9"GameMode Chooser");
  22.  
  23.  
  24. c = createItem(DyeColor.YELLOW, "Creative");
  25. s = createItem(DyeColor.GREEN, "Suvival");
  26. a = createItem(DyeColor.RED "Adventure");
  27.  
  28. inv.setItem(2, c);
  29. inv.setItem(4, s);
  30. inv.setItem(6, a);
  31.  
  32. Bukkit.getServer().getPluginManager().registerEvent(this, p);
  33. }
  34.  
  35. privare ItemStack createItem(DyeColor dc, String name) {
  36. ItemStack i = new Wool(dc).toItemStack(1);
  37. ItemMeta im = i.getItemMeta();
  38. im.setLore(Arrays.asList("Set your gamemode", "to " + name.toLowerCase() + " mode"));
  39. i.setItemMeta(im);
  40. return i;
  41. }
  42.  
  43. public void show(Player p) {
  44. p.openInventory(inv)
  45. }
  46.  
  47. @EventHandler
  48. public void onInventoryClick(InventoryClickEvent e) {
  49. if (!e.getInventory().equals(inv)) return;
  50. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Creative")) {
  51. e.getWhoClicked().setGameMode(GameMode.CREATIVE);
  52.  
  53. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Survival")) {
  54. e.getWhoClicked().setGameMode(GameMode.SURVIVAL);
  55.  
  56. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Adventure")) {
  57. e.getWhoClicked().setGameMode(GameMode.ADVENTURE);
  58. }
  59. }
  60. }
RAW Paste Data