Advertisement
Lisenochek

Untitled

Oct 22nd, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.45 KB | None | 0 0
  1. package ru.lisenochek.mcrust.listeners;
  2.  
  3. import com.comphenix.protocol.wrappers.EnumWrappers;
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.Location;
  6. import org.bukkit.Material;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.Listener;
  10. import org.bukkit.event.inventory.InventoryClickEvent;
  11. import ru.lisenochek.mcrust.events.player.PlayerUpgradeConstructionEvent;
  12. import ru.lisenochek.mcrust.events.player.interact.PlayerInteractMalletEvent;
  13. import ru.lisenochek.mcrust.objects.blockMechanic.Buildings;
  14. import ru.lisenochek.mcrust.objects.blockMechanic.Constructions;
  15. import ru.lisenochek.mcrust.objects.blockMechanic.Cupboard;
  16. import ru.lisenochek.mcrust.objects.misc.CustomBlock;
  17. import ru.lisenochek.mcrust.objects.misc.Durability;
  18. import ru.lisenochek.mcrust.objects.misc.Radtown;
  19. import ru.lisenochek.mcrust.objects.misc.Sounds;
  20. import ru.lisenochek.mcrust.sql.SQLManager;
  21. import ru.lisenochek.mcrust.utils.ISBuilder;
  22. import ru.lisenochek.mcrust.utils.Utils;
  23.  
  24. import java.util.Arrays;
  25.  
  26. public class BuildingListener implements Listener {
  27.  
  28. @EventHandler
  29. public void onClickOnBuildings(PlayerInteractMalletEvent e) {
  30.  
  31. Player player = e.getPlayer();
  32.  
  33. if (Radtown.locationsMap.get(e.getClickedBlock().getLocation()) != null && !player.hasPermission("mcrust.admin")) {
  34. Utils.sendBarMessage(player, "&7Здесь &cнельзя &7работать киянкой");
  35. return;
  36. }
  37.  
  38. if (player.isSneaking()) {
  39. Utils.sendTitleMessage(player, "", Utils.generateLine(30, e.getBuildings().getHealth(), e.getBuildings().getType().getMaxHealth(), "&a", "&7") + " &7(&a" + e.getBuildings().getHealth() + "&7/&a" + e.getBuildings().getType().getMaxHealth() + "&7)");
  40. return;
  41. }
  42.  
  43. Cupboard cupboard = Cupboard.locationsMap.get(e.getClickedBlock().getLocation());
  44.  
  45. if (cupboard != null && !cupboard.getOwnersList().contains(player.getUniqueId()) && !player.hasPermission("mcrust.admin")) {
  46. Utils.sendBarMessage(player, "&7Только &cавторизованные &7в шкафу &cигроки &7могут работать киянкой");
  47. return;
  48. }
  49.  
  50. if (Arrays.asList(CustomBlock.Type.HAY_CONSTRUCTION, CustomBlock.Type.WOODEN_CONSTRUCTION, CustomBlock.Type.STONE_CONSTRUCTION, CustomBlock.Type.METAL_CONSTRUCTION).contains(e.getBuildings().getType())) {
  51. Constructions.getConstuction(e.getBuildings()).openUpgradeGUI(player);
  52. return;
  53. }
  54.  
  55. Buildings.openGUI(player, e.getBuildings());
  56. }
  57.  
  58. @EventHandler
  59. public void onUpgradeConstructionsGUIClick(InventoryClickEvent e) {
  60.  
  61. Player player = (Player) e.getWhoClicked();
  62.  
  63. if (!e.getInventory().getName().equals(Utils.stripColor("&2&lУлучшение конструкции"))) return;
  64. if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR) return;
  65.  
  66. e.setCancelled(true);
  67. player.playSound(player.getLocation(), org.bukkit.Sound.UI_BUTTON_CLICK, 1, 1);
  68.  
  69. if (!e.getClickedInventory().getName().equals(Utils.stripColor("&2&lУлучшение конструкции"))) return;
  70.  
  71. ISBuilder builder = ISBuilder.getBuilder(e.getCurrentItem());
  72.  
  73. if (!builder.hasTag("location")) return;
  74.  
  75. Location location = Utils.deserialiseLocation(builder.getStringTag("location"));
  76. CustomBlock customBlock = CustomBlock.getBlock(location.getBlock());
  77. Buildings buildings = Buildings.buildingsMap.get(location);
  78.  
  79. player.closeInventory();
  80.  
  81. if (buildings.getType() != customBlock.getType()) return;
  82.  
  83. Durability.getDurability(player.getInventory().getItemInMainHand()).damage(player);
  84.  
  85. if (e.getCurrentItem().getItemMeta().getDisplayName().equals(Utils.stripColor("&a&l» &e&lОтремонтировать"))) {
  86. buildings.setHealth(buildings.getType().getMaxHealth());
  87. SQLManager.getManager().updateBuildingData(buildings);
  88. player.getWorld().playSound(location, Sounds.REPAIR.getSoundName(), 1, 1);
  89. Utils.playEffect(location.clone().add(0.5D, 0, 0.5D), false, false, 0.5f, 0.5f, 0.5f, 0, EnumWrappers.Particle.CLOUD, Material.AIR, 25);
  90. Utils.removeItems(player, ISBuilder.getBuilder(buildings.getType().getResourceStack()).setAmount(builder.getIntTag("repairCost")).getStack());
  91. Utils.sendBarMessage(player, "&7Я &aпочинил &7конструкцию");
  92. return;
  93. }
  94.  
  95. if (e.getCurrentItem().getItemMeta().getDisplayName().equals(Utils.stripColor("&a&l» &c&lСломать"))) {
  96. buildings.remove(player);
  97. player.getWorld().playSound(location, Sounds.BREAK.getSoundName(), 1, 1);
  98. Utils.sendBarMessage(player, "&7Я &aразрушил &7конструкцию");
  99. return;
  100. }
  101.  
  102. if (!builder.hasTag("upgradeType")) return;
  103.  
  104. Constructions.Type type = Constructions.Type.valueOf(builder.getStringTag("upgradeType"));
  105.  
  106. buildings.setType(type.getBlockType());
  107. buildings.setHealth(type.getBlockType().getMaxHealth());
  108. buildings.setDecayTime(type.getBlockType().getDecayTime());
  109. buildings.setBlockDecayTime(type.getBlockType().getBlockDecayTime());
  110. SQLManager.getManager().updateBuildingData(buildings);
  111. CustomBlock.setMaterialData(location.getBlock(), type.getBlockType().getMaterialData());
  112. player.getWorld().playSound(player.getLocation(), Arrays.asList(type.getSoundUpgrade()).get(Utils.getRandom().nextInt(type.getSoundUpgrade().length)), 1, 1);
  113. Bukkit.getPluginManager().callEvent(new PlayerUpgradeConstructionEvent(player, location, type));
  114. Utils.playEffect(location.clone().add(0.5D, 0, 0.5D), false, false, 0.5f, 0.5f, 0.5f, 0, EnumWrappers.Particle.CLOUD, Material.AIR, 25);
  115. Utils.removeItems(player, ISBuilder.getBuilder(buildings.getType().getResourceStack()).setAmount(2).getStack());
  116. Utils.sendBarMessage(player, "&7Я &aулучшил &7конструкцию");
  117. }
  118.  
  119. @EventHandler
  120. public void onBuildingsGUIClick(InventoryClickEvent e) {
  121.  
  122. Player player = (Player) e.getWhoClicked();
  123.  
  124. if (!e.getInventory().getName().equals(Utils.stripColor("&2&lКонструкция"))) return;
  125. if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR) return;
  126.  
  127. e.setCancelled(true);
  128. player.playSound(player.getLocation(), org.bukkit.Sound.UI_BUTTON_CLICK, 1, 1);
  129.  
  130. if (!e.getClickedInventory().getName().equals(Utils.stripColor("&2&lКонструкция"))) return;
  131.  
  132. ISBuilder builder = ISBuilder.getBuilder(e.getCurrentItem());
  133.  
  134. if (!builder.hasTag("location")) return;
  135.  
  136. Location location = Utils.deserialiseLocation(builder.getStringTag("location"));
  137. Buildings buildings = Buildings.buildingsMap.get(location);
  138. CustomBlock customBlock = CustomBlock.getBlock(location.getBlock());
  139.  
  140. player.closeInventory();
  141.  
  142. if (buildings == null) return;
  143. if (buildings.getType() != customBlock.getType()) return;
  144.  
  145. Durability.getDurability(player.getInventory().getItemInMainHand()).damage(player);
  146. Utils.playEffect(location.clone().add(0.5D, 0, 0.5D), false, false, 0.5f, 0.5f, 0.5f, 0, EnumWrappers.Particle.CLOUD, Material.AIR, 25);
  147.  
  148. if (e.getCurrentItem().getItemMeta().getDisplayName().equals(Utils.stripColor("&a&l» &e&lОтремонтировать"))) {
  149. buildings.setHealth(buildings.getType().getMaxHealth());
  150. SQLManager.getManager().updateBuildingData(buildings);
  151. player.getWorld().playSound(location, Sounds.REPAIR.getSoundName(), 1, 1);
  152. Utils.removeItems(player, ISBuilder.getBuilder(buildings.getType().getResourceStack()).setAmount(builder.getIntTag("repairCost")).getStack());
  153. Utils.sendBarMessage(player, "&7Я &aпочинил &7конструкцию");
  154. return;
  155. }
  156.  
  157. if (!e.getCurrentItem().getItemMeta().getDisplayName().equals(Utils.stripColor("&a&l» &c&lСломать"))) return;
  158.  
  159. if (buildings.getType().getDrop() != null) customBlock.dropItem(player);
  160.  
  161. buildings.remove(player);
  162. player.getWorld().playSound(location, Sounds.BREAK.getSoundName(), 1, 1);
  163. Utils.sendBarMessage(player, "&7Я &aразрушил &7конструкцию");
  164. }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement