Guest User

mcamenu class

a guest
May 28th, 2018
87
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.uba;
  2.  
  3. import java.util.ArrayList;
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Location;
  7. import org.bukkit.Material;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.event.EventHandler;
  10. import org.bukkit.event.Listener;
  11. import org.bukkit.event.inventory.InventoryClickEvent;
  12. import org.bukkit.inventory.Inventory;
  13. import org.bukkit.inventory.ItemStack;
  14. import org.bukkit.inventory.meta.ItemMeta;
  15. import org.bukkit.plugin.Plugin;
  16.  
  17.  
  18.  
  19. public class mcamenu implements Listener {
  20.  
  21. main main = me.uba.main.getInstance();
  22.  
  23. private Inventory inv;
  24.  
  25. public mcamenu(Plugin p) {
  26. inv = Bukkit.getServer().createInventory(null, 9, "Level Menu");
  27.  
  28. ItemStack item = new ItemStack(Material.EYE_OF_ENDER);
  29. ItemMeta meta = item.getItemMeta();
  30. meta.setDisplayName(ChatColor.BLUE+ "Spawn location");
  31. ArrayList<String> Lore = new ArrayList<String>();
  32. Lore.add("Teleports you to the spawn location!");
  33. meta.setLore(Lore);
  34. item.setItemMeta(meta);
  35.  
  36. ItemStack item2 = new ItemStack(Material.DIAMOND_HELMET);
  37. ItemMeta meta2 = item2.getItemMeta();
  38. meta2.setDisplayName(ChatColor.GREEN+ "Loadout");
  39. ArrayList<String> Lore2 = new ArrayList<String>();
  40. Lore2.add("Gives you your set loadout!");
  41. meta2.setLore(Lore2);
  42. item2.setItemMeta(meta2);
  43.  
  44. ItemStack item3 = new ItemStack(Material.CHEST);
  45. ItemMeta meta3 = item3.getItemMeta();
  46. meta3.setDisplayName(ChatColor.GOLD+ "Level Check");
  47. ArrayList<String> Lore3 = new ArrayList<String>();
  48. Lore3.add("Veryify's that your level is setup!");
  49. meta3.setLore(Lore3);
  50. item3.setItemMeta(meta3);
  51.  
  52. ItemStack item4 = new ItemStack(Material.EYE_OF_ENDER);
  53. ItemMeta meta4 = item4.getItemMeta();
  54. meta4.setDisplayName(ChatColor.RED+ "Close");
  55. ArrayList<String> Lore4 = new ArrayList<String>();
  56. Lore4.add("Teleports you to the spawn location");
  57. meta4.setLore(Lore4);
  58. item4.setItemMeta(meta4);
  59.  
  60. inv.setItem(4, item);
  61. inv.setItem(5, item2);
  62. inv.setItem(6, item3);
  63. inv.setItem(1, item4);
  64.  
  65. Bukkit.getServer().getPluginManager().registerEvents(this, p);
  66. }
  67.  
  68. public void show(Player p) {
  69. p.openInventory(inv);
  70. }
  71.  
  72. @EventHandler
  73. public void onInventoryClick(InventoryClickEvent e) {
  74. Player p = (Player) e.getWhoClicked();
  75. if (!e.getInventory().getName().equalsIgnoreCase(inv.getName())) return;
  76. if (e.getCurrentItem().getItemMeta() == null) return;
  77. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Spawn Location")) {
  78. e.setCancelled(true);
  79. //Checks if the spawn is set
  80. if(main.getConfig().getString(p.getUniqueId() + "SpawnIsSet").equals("false")) {
  81. p.sendMessage(ChatColor.RED + "You do not have a set spawn!");
  82. } else if (main.getConfig().getString(p.getUniqueId() + "SpawnIsSet").equals("true")) {
  83. Location leveltoplay = new Location(main.getServer().getWorld(p.getName()), main.getServer().getWorld(p.getName()).getSpawnLocation().getX(), main.getServer().getWorld(p.getName()).getSpawnLocation().getY(), main.getServer().getWorld(p.getName()).getSpawnLocation().getZ());
  84. p.teleport(leveltoplay);
  85. e.getWhoClicked().closeInventory();
  86. } else {
  87. p.sendMessage(ChatColor.RED + "You must create a level!");
  88. e.getWhoClicked().closeInventory();
  89. }
  90. e.getWhoClicked().closeInventory();
  91. }
  92. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Loadout")) {
  93. e.setCancelled(true);
  94. //Do loadout stuff here
  95. e.getWhoClicked().closeInventory();
  96. }
  97. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Level Check")) {
  98. e.setCancelled(true);
  99. p.sendMessage(ChatColor.GREEN + "Level Check");
  100. //If the /mcasetup has been reset by deleting a level, do this
  101. if(main.getConfig().getString(p.getUniqueId() + "setupcomplete").equals("false")) {
  102. p.sendMessage(ChatColor.RED + "Setup is not complete!");
  103. e.getWhoClicked().closeInventory();
  104. }else {
  105. //Is there any part in the config about setup being null? If so do this
  106. if(main.getConfig().getString(p.getUniqueId() + "setupcomplete") == null) {
  107. p.sendMessage(ChatColor.RED + "You must create a level first!");
  108. e.getWhoClicked().closeInventory();
  109. //Checking if a spawn is set
  110. if(main.getConfig().getString(p.getUniqueId() + "SpawnIsSet").equals("false")) {
  111. p.sendMessage(ChatColor.RED + "You must set a spawn!");
  112. } else if(main.getConfig().getString(p.getUniqueId() + "SpawnIsSet") == null) {
  113. p.sendMessage(ChatColor.RED + "You must create a level first!");
  114. } else {
  115. //If a spawn and the setup is complete, then do this
  116. p.sendMessage(ChatColor.GREEN + "Level is ready to be played! Type /mcafinish to finish editing!");
  117. e.getWhoClicked().closeInventory();
  118. }
  119. }
  120. e.getWhoClicked().closeInventory();
  121. }
  122. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Close")) {
  123. e.setCancelled(true);
  124. e.getWhoClicked().closeInventory();
  125. }
  126. }
  127. }
  128. }
RAW Paste Data