Guest User

Menu 2

a guest
Jun 5th, 2018
29
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.10 KB | None
  1. package ts.uba; //The package your class is located it
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import org.bukkit.Bukkit; //Importing types (You already know this)
  6. import org.bukkit.ChatColor;
  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.ItemStack;
  13. import org.bukkit.inventory.meta.ItemMeta;
  14. import org.bukkit.plugin.Plugin;
  15.  
  16. public class Craft implements Listener { //Inventory = the name of this class)
  17.  
  18. private CraftingSelection menu;
  19.  
  20. private org.bukkit.inventory.Inventory cinv; //Settings inventory to inv
  21.  
  22. public Craft(Plugin p) {
  23. cinv = Bukkit.getServer().createInventory(null, 9, "§c§lCrafting Menu"); //settings the inventory name
  24.  
  25. ItemStack Rifle = new ItemStack(Material.RECORD_3);
  26. ItemMeta RifleMeta = Rifle.getItemMeta();
  27. RifleMeta.setDisplayName(ChatColor.AQUA + "Energy Rifle");
  28. ArrayList<String> lore = new ArrayList<String>();
  29. lore.add(ChatColor.GOLD + "Craft Requirements:");
  30. lore.add(ChatColor.GREEN + "x1 Energy Rifle Body, x1 Trigger");
  31. RifleMeta.setLore(lore);
  32. Rifle.setItemMeta(RifleMeta);
  33.  
  34. ItemStack Body = new ItemStack(Material.IRON_INGOT);
  35. ItemMeta meta = Body.getItemMeta();
  36. meta.setDisplayName(ChatColor.GOLD + "Energy Rifle Body");
  37. ArrayList<String> lore2 = new ArrayList<String>();
  38. lore2.add(ChatColor.GOLD + "Craft Requirements:");
  39. lore2.add(ChatColor.GREEN + "x6 Stone, x1 Energy Fuse");
  40. meta.setLore(lore2);
  41. Body.setItemMeta(meta);
  42.  
  43. ItemStack Fuse = new ItemStack(Material.DIAMOND);
  44. ItemMeta meta2 = Fuse.getItemMeta();
  45. meta2.setDisplayName(ChatColor.AQUA + "Energy Fuse");
  46. ArrayList<String> lore3 = new ArrayList<String>();
  47. lore3.add(ChatColor.GOLD + "Craft Requirements:");
  48. lore3.add(ChatColor.GREEN + "x1 Emerald");
  49. meta2.setLore(lore3);
  50. Fuse.setItemMeta(meta2);
  51.  
  52. ItemStack Trigger = new ItemStack(Material.TRIPWIRE_HOOK);
  53. ItemMeta meta3 = Trigger.getItemMeta();
  54. meta3.setDisplayName(ChatColor.GOLD + "Trigger");
  55. ArrayList<String> lore4 = new ArrayList<String>();
  56. lore4.add(ChatColor.GOLD + "Craft Requirements:");
  57. lore4.add(ChatColor.GREEN + "x1 Iron, x1 String");
  58. meta3.setLore(lore4);
  59. Trigger.setItemMeta(meta3);
  60.  
  61. ItemStack Close = new ItemStack(Material.BARRIER);
  62. ItemMeta m = Close.getItemMeta();
  63. m.setDisplayName(ChatColor.RED + "Back To Menu");
  64. Close.setItemMeta(m);
  65.  
  66. cinv.setItem(0, Rifle);
  67. cinv.setItem(1, Body);
  68. cinv.setItem(2, Fuse);
  69. cinv.setItem(3, Trigger);
  70. cinv.setItem(8, Close);
  71.  
  72. Bukkit.getServer().getPluginManager().registerEvents(this, p);
  73.  
  74. }
  75.  
  76. public void showmenu(Player p) {
  77. p.openInventory(cinv);
  78.  
  79. }
  80.  
  81. @EventHandler
  82. public void onInventoryClick1(InventoryClickEvent e) {
  83. if (!e.getInventory().getName().equalsIgnoreCase(cinv.getName())) return;
  84. if (e.getCurrentItem().getItemMeta() == null) return;
  85. if (e.getCurrentItem().getItemMeta().getDisplayName().contains(ChatColor.AQUA + "Energy Rifle")) {
  86. e.setCancelled(true);
  87. Player p = (Player) e.getWhoClicked();
  88.  
  89. ItemStack Rifle = new ItemStack(Material.RECORD_3);
  90. ItemMeta RifleMeta = Rifle.getItemMeta();
  91. RifleMeta.setDisplayName(ChatColor.AQUA + "Energy Rifle");
  92. ArrayList<String> lore = new ArrayList<String>();
  93. lore.add(ChatColor.GREEN + "Manufacter: HERA ARMS");
  94. lore.add(ChatColor.GOLD + "Model Number: 62459");
  95. RifleMeta.setLore(lore);
  96. Rifle.setItemMeta(RifleMeta);
  97.  
  98. ItemStack Body = new ItemStack(Material.IRON_INGOT);
  99. ItemMeta meta = Body.getItemMeta();
  100. meta.setDisplayName(ChatColor.GOLD + "Energy Rifle Body");
  101. ArrayList<String> lore2 = new ArrayList<String>();
  102. lore2.add(ChatColor.GREEN + "Used to craft the Energy Rifle");
  103. meta.setLore(lore2);
  104. Body.setItemMeta(meta);
  105.  
  106. ItemStack Trigger = new ItemStack(Material.TRIPWIRE_HOOK);
  107. ItemMeta meta3 = Trigger.getItemMeta();
  108. meta3.setDisplayName(ChatColor.GOLD + "Trigger");
  109. ArrayList<String> lore4 = new ArrayList<String>();
  110. lore4.add(ChatColor.GREEN + "Used to craft the Energy Rifle");
  111. meta3.setLore(lore4);
  112. Trigger.setItemMeta(meta3);
  113.  
  114. if(p.getInventory().contains(Body) && p.getInventory().contains(Trigger))
  115. {
  116. p.getInventory().addItem(Rifle);
  117. e.setCancelled(true);
  118. e.getWhoClicked().closeInventory();
  119.  
  120. p.getInventory().remove(Body);
  121. p.getInventory().remove(Trigger);
  122. } else
  123. {
  124. e.getWhoClicked().closeInventory();
  125. p.sendMessage(ChatColor.RED + "You need 1 Energy Rifle Body and 1 Trigger to craft this!");
  126. }
  127.  
  128.  
  129. }
  130. }
  131. @EventHandler
  132. public void onInventoryClick2(InventoryClickEvent e) {
  133. if (!e.getInventory().getName().equalsIgnoreCase(cinv.getName())) return;
  134. if (e.getCurrentItem().getItemMeta() == null) return;
  135. if (e.getCurrentItem().getItemMeta().getDisplayName().contains(ChatColor.GOLD + "Energy Rifle Body")) {
  136. e.setCancelled(true);
  137.  
  138. ItemStack Fuse = new ItemStack(Material.DIAMOND);
  139. ItemMeta meta2 = Fuse.getItemMeta();
  140. meta2.setDisplayName(ChatColor.AQUA + "Energy Fuse");
  141. ArrayList<String> lore3 = new ArrayList<String>();
  142. lore3.add(ChatColor.GREEN + "Used to craft the Energy Rifle");
  143. meta2.setLore(lore3);
  144. Fuse.setItemMeta(meta2);
  145.  
  146. ItemStack Body = new ItemStack(Material.IRON_INGOT);
  147. ItemMeta meta = Body.getItemMeta();
  148. meta.setDisplayName(ChatColor.GOLD + "Energy Rifle Body");
  149. ArrayList<String> lore = new ArrayList<String>();
  150. lore.add(ChatColor.GREEN + "Used to craft the Energy Rifle");
  151. meta.setLore(lore);
  152. Body.setItemMeta(meta);
  153.  
  154.  
  155.  
  156. Player p = (Player) e.getWhoClicked();
  157.  
  158. if(p.getInventory().contains(Material.STONE, 6) && p.getInventory().contains(Fuse))
  159. {
  160. p.getInventory().addItem(Body);
  161. e.setCancelled(true);
  162. e.getWhoClicked().closeInventory();
  163.  
  164. p.getInventory().remove(Material.STONE);
  165. p.getInventory().remove(Material.STONE);
  166. p.getInventory().remove(Material.STONE);
  167. p.getInventory().remove(Material.STONE);
  168. p.getInventory().remove(Material.STONE);
  169. p.getInventory().remove(Material.STONE);
  170. p.getInventory().remove(Fuse);
  171. }else {
  172. e.getWhoClicked().closeInventory();
  173. p.sendMessage(ChatColor.RED + "You need 1 Fuse and 6 Iron to craft this!");
  174. }
  175.  
  176. e.getWhoClicked().closeInventory();
  177.  
  178. }
  179. }
  180. @EventHandler
  181. public void onInventoryClick3(InventoryClickEvent e) {
  182. if (!e.getInventory().getName().equalsIgnoreCase(cinv.getName())) return;
  183. if (e.getCurrentItem().getItemMeta() == null) return;
  184. if (e.getCurrentItem().getItemMeta().getDisplayName().contains(ChatColor.AQUA + "Energy Fuse")) {
  185. e.setCancelled(true);
  186.  
  187.  
  188. ItemStack Fuse = new ItemStack(Material.DIAMOND);
  189. ItemMeta meta2 = Fuse.getItemMeta();
  190. meta2.setDisplayName(ChatColor.AQUA + "Energy Fuse");
  191. ArrayList<String> lore3 = new ArrayList<String>();
  192. lore3.add(ChatColor.GREEN + "Used to craft the Energy Rifle");
  193. meta2.setLore(lore3);
  194. Fuse.setItemMeta(meta2);
  195.  
  196. Player p = (Player) e.getWhoClicked();
  197.  
  198. if(p.getInventory().contains(Material.EMERALD))
  199. {
  200. p.getInventory().addItem(Fuse);
  201. e.setCancelled(true);
  202. e.getWhoClicked().closeInventory();
  203.  
  204. p.getInventory().remove(Material.EMERALD);
  205. }else {
  206. e.getWhoClicked().closeInventory();
  207. p.sendMessage(ChatColor.RED + "You need 1 Emerald to craft this!");
  208. }
  209.  
  210. e.getWhoClicked().closeInventory();
  211.  
  212. }
  213. }
  214. @EventHandler
  215. public void onInventoryClick4(InventoryClickEvent e) {
  216. if (!e.getInventory().getName().equalsIgnoreCase(cinv.getName())) return;
  217. if (e.getCurrentItem().getItemMeta() == null) return;
  218. if (e.getCurrentItem().getItemMeta().getDisplayName().contains(ChatColor.GOLD + "Trigger")) {
  219. e.setCancelled(true);
  220.  
  221.  
  222. ItemStack Trigger = new ItemStack(Material.TRIPWIRE_HOOK);
  223. ItemMeta meta3 = Trigger.getItemMeta();
  224. meta3.setDisplayName(ChatColor.GOLD + "Trigger");
  225. ArrayList<String> lore4 = new ArrayList<String>();
  226. lore4.add(ChatColor.GREEN + "Used to craft the Energy Rifle");
  227. meta3.setLore(lore4);
  228. Trigger.setItemMeta(meta3);
  229.  
  230. Player p = (Player) e.getWhoClicked();
  231.  
  232. if(p.getInventory().contains(Material.IRON_INGOT) && p.getInventory().contains(Material.STRING))
  233. {
  234. p.getInventory().addItem(Trigger);
  235. e.setCancelled(true);
  236. e.getWhoClicked().closeInventory();
  237.  
  238. p.getInventory().remove(Material.IRON_INGOT);
  239. p.getInventory().remove(Material.STRING);
  240. }else {
  241. e.getWhoClicked().closeInventory();
  242. p.sendMessage(ChatColor.RED + "You need 1 Iron Ingot and 1 String to craft this!");
  243. }
  244.  
  245. e.getWhoClicked().closeInventory();
  246.  
  247. }
  248. }
  249. @EventHandler
  250. public void onInventoryClick5(InventoryClickEvent e) {
  251. if (!e.getInventory().getName().equalsIgnoreCase(cinv.getName())) return;
  252. if (e.getCurrentItem().getItemMeta() == null) return;
  253. if (e.getCurrentItem().getItemMeta().getDisplayName().contains(ChatColor.RED + "Back To Menu")) {
  254. e.setCancelled(true);
  255.  
  256. Player p = (Player) e.getWhoClicked();
  257. menu.showmenu(p);
  258.  
  259. e.getWhoClicked().closeInventory();
  260.  
  261. }
  262. }
  263. }
RAW Paste Data Copied