Guest User

Listener Class

a guest
May 21st, 2020
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package classes.classes.ClassInterfaces;
  2.  
  3. import classes.classes.Commands.Menu;
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Location;
  7. import org.bukkit.Material;
  8. import org.bukkit.configuration.file.FileConfiguration;
  9. import org.bukkit.configuration.file.YamlConfiguration;
  10. import org.bukkit.enchantments.Enchantment;
  11. import org.bukkit.event.EventHandler;
  12. import org.bukkit.event.Listener;
  13. import org.bukkit.event.block.Action;
  14. import org.bukkit.event.block.BlockBreakEvent;
  15. import org.bukkit.event.block.BlockPlaceEvent;
  16. import org.bukkit.event.inventory.InventoryClickEvent;
  17. import org.bukkit.event.inventory.InventoryOpenEvent;
  18. import org.bukkit.event.inventory.InventoryType;
  19. import org.bukkit.event.player.PlayerInteractEvent;
  20. import org.bukkit.inventory.Inventory;
  21. import org.bukkit.inventory.ItemFlag;
  22. import org.bukkit.inventory.ItemStack;
  23. import org.bukkit.inventory.meta.ItemMeta;
  24. import org.yaml.snakeyaml.Yaml;
  25.  
  26. import java.io.File;
  27. import java.io.IOException;
  28. import java.util.ArrayList;
  29. import java.util.List;
  30.  
  31. import static org.bukkit.Bukkit.createInventory;
  32.  
  33. public class BlackSmith implements Listener {
  34. File specialcraftingfile = new File("plugins/Classes/" + File.separator + "specialcraftingtables.yml");
  35. FileConfiguration cryptic = YamlConfiguration.loadConfiguration(specialcraftingfile);
  36. ItemStack specialcrafting = Menu.createItem(ChatColor.AQUA + "Cryptic Crafter", "Using much power, it can craft what the others can't", Material.BEACON);
  37. public static ItemStack excalibur = new ItemStack(Material.GOLD_SWORD);
  38. public static ItemMeta em = excalibur.getItemMeta();
  39.  
  40. @EventHandler
  41. public void onSpecialCrafting(PlayerInteractEvent e){
  42. if(e.getPlayer() != null){
  43. if(e.getClickedBlock() != null){
  44. if(e.getClickedBlock().getType().equals(Material.BEACON)){
  45. Location loc = e.getClickedBlock().getLocation();
  46. if(cryptic.getStringList("PlacedCraftings").contains(loc.getX() + "," + loc.getY() + "," + loc.getZ())){
  47. if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
  48. em.setDisplayName(ChatColor.GOLD + "Excalibur");
  49. em.spigot().setUnbreakable(true);
  50. em.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
  51. em.addItemFlags(ItemFlag.HIDE_ENCHANTS);
  52. em.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
  53. em.addEnchant(Enchantment.DAMAGE_ALL, 45, true);
  54. List<String> lore = new ArrayList<>();
  55. lore.add(ChatColor.RED + "> Warrior Rage");
  56. lore.add(ChatColor.GREEN + "> Boss Killer 2");
  57. lore.add(ChatColor.WHITE + "> Sharpness 45");
  58. lore.add(ChatColor.WHITE + "> Unbreakable");
  59. lore.add("Strong, but is it the strongest?");
  60. em.setLore(lore);
  61. excalibur.setItemMeta(em);
  62. Inventory inv = createInventory(null, 9, "Cryptic Crafter");
  63. inv.addItem(excalibur);
  64. e.getPlayer().openInventory(inv);
  65. }
  66.  
  67. }
  68. }
  69. }
  70.  
  71. }
  72. }
  73. @EventHandler
  74. public void onBlock(BlockPlaceEvent e) throws IOException {
  75. if(e.getPlayer() != null){
  76. if(e.getBlock().getType().equals(Material.BEACON)){
  77. if(e.getPlayer().getInventory().getItemInHand().getItemMeta().equals(specialcrafting.getItemMeta())){
  78. Location loc = e.getBlock().getLocation();
  79. List<String> list = cryptic.getStringList("PlacedCraftings");
  80. list.add(loc.getX() + "," + loc.getY() + "," + loc.getZ());
  81. cryptic.set("PlacedCraftings", list);
  82. cryptic.save(specialcraftingfile);
  83. }
  84. }
  85. }
  86. }
  87. @EventHandler
  88. public void onBreak(BlockBreakEvent e) throws IOException {
  89. if(e.getPlayer() != null){
  90. if(e.getBlock().getType().equals(Material.BEACON)){
  91. Location loc = e.getBlock().getLocation();
  92. if(cryptic.getStringList("PlacedCraftings").contains(loc.getX() + "," + loc.getY() + "," + loc.getZ())){
  93. List<String> list = cryptic.getStringList("PlacedCraftings");
  94. list.remove(loc.getX() + "," + loc.getY() + "," + loc.getZ());
  95. cryptic.set("PlacedCraftings", list);
  96. cryptic.save(specialcraftingfile);
  97. e.getBlock().getDrops().clear();
  98. e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), specialcrafting);
  99. }
  100.  
  101. }
  102. }
  103. }
  104. @EventHandler
  105. public void onOpenInv(InventoryOpenEvent e){
  106. if(e.getPlayer() != null){
  107. if(e.getInventory().getType().equals(InventoryType.BEACON)){
  108. e.setCancelled(true);
  109. }
  110. }
  111. }
  112. public static Inventory addItemInMenu(ItemStack item1, ItemStack item2, ItemStack item3, ItemStack item4, ItemStack item5, ItemStack item6, ItemStack item7, ItemStack item8, ItemStack item9, ItemStack result, String itemname){
  113. Inventory inv = createInventory(null, 45, "Recipe for " + itemname);
  114. ItemStack no = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7);
  115. ItemMeta nom = no.getItemMeta();
  116. nom.setDisplayName(" ");
  117. no.setItemMeta(nom);
  118. ItemStack back = new ItemStack(Material.BARRIER);
  119. ItemMeta bm = back.getItemMeta();
  120. bm.setDisplayName(ChatColor.RED + "Back");
  121. ArrayList<String> lor = new ArrayList<>();
  122. lor.add("Go back to recipes");
  123. bm.setLore(lor);
  124. back.setItemMeta(bm);
  125. ItemStack crafted = new ItemStack(Material.ARROW);
  126. ItemMeta cm = crafted.getItemMeta();
  127. cm.setDisplayName(ChatColor.GOLD + "Crafted Item");
  128. crafted.setItemMeta(cm);
  129. ItemStack craft = new ItemStack(Material.ANVIL);
  130. ItemMeta crm = craft.getItemMeta();
  131. crm.setDisplayName(ChatColor.GRAY + "Craft This Item");
  132. craft.setItemMeta(crm);
  133. ItemStack[] contens = {no,no,no,no,no,no,no,no,no,no,item1,item2,item3,no,no,no,no,no,no,item4,item5,item6,no,crafted,no,result,no,no,item7,item8,item9,no,no,no,no,no,no,no,no,back,no,craft,no,no,no};
  134. inv.setContents(contens);
  135. return inv;
  136. }
  137.  
  138. @EventHandler
  139. public void onRecipe(InventoryClickEvent e){
  140. if(e.getWhoClicked().hasPermission("yabadabado")) System.out.println(e.getInventory());
  141. if(e.getInventory() != null){
  142. if(e.getInventory().getName().equals("Cryptic Crafter")){
  143. if(e.getCurrentItem().getType().equals(Material.GOLD_SWORD)){
  144. if(e.getCurrentItem().getItemMeta() != null){
  145. if(e.getCurrentItem().getItemMeta().equals(em)){
  146. ItemStack air = new ItemStack(Material.AIR);
  147. ItemStack bigblade = new ItemStack(Material.GOLD_INGOT);
  148. ItemMeta bm = bigblade.getItemMeta();
  149. bm.setDisplayName(ChatColor.GOLD + "Big Blade");
  150. ArrayList<String> lo = new ArrayList<>();
  151. lo.add("This sure is big!");
  152. bm.setLore(lo);
  153. bigblade.setItemMeta(bm);
  154. ItemStack branch = new ItemStack(Material.BLAZE_ROD);
  155. ItemMeta bbb = branch.getItemMeta();
  156. bbb.setDisplayName(ChatColor.DARK_GREEN + "Branch");
  157. ArrayList<String> lore = new ArrayList<>();
  158. lore.add("Who knows why this branch is so thick");
  159. bbb.setLore(lore);
  160. branch.setItemMeta(bbb);
  161. e.getWhoClicked().openInventory(addItemInMenu(air,air,bigblade,air,bigblade,air,branch,air,air, excalibur, "Excalibur"));
  162. }
  163. }
  164. }
  165. e.setCancelled(true);
  166. }
  167. }
  168. }
  169.  
  170.  
  171. }
RAW Paste Data