Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.lisenochek.mcrust.listeners;
- import com.comphenix.protocol.wrappers.EnumWrappers;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import ru.lisenochek.mcrust.events.player.PlayerUpgradeConstructionEvent;
- import ru.lisenochek.mcrust.events.player.interact.PlayerInteractMalletEvent;
- import ru.lisenochek.mcrust.objects.blockMechanic.Buildings;
- import ru.lisenochek.mcrust.objects.blockMechanic.Constructions;
- import ru.lisenochek.mcrust.objects.blockMechanic.Cupboard;
- import ru.lisenochek.mcrust.objects.misc.CustomBlock;
- import ru.lisenochek.mcrust.objects.misc.Durability;
- import ru.lisenochek.mcrust.objects.misc.Radtown;
- import ru.lisenochek.mcrust.objects.misc.Sounds;
- import ru.lisenochek.mcrust.sql.SQLManager;
- import ru.lisenochek.mcrust.utils.ISBuilder;
- import ru.lisenochek.mcrust.utils.Utils;
- import java.util.Arrays;
- public class BuildingListener implements Listener {
- @EventHandler
- public void onClickOnBuildings(PlayerInteractMalletEvent e) {
- Player player = e.getPlayer();
- if (Radtown.locationsMap.get(e.getClickedBlock().getLocation()) != null && !player.hasPermission("mcrust.admin")) {
- Utils.sendBarMessage(player, "&7Здесь &cнельзя &7работать киянкой");
- return;
- }
- if (player.isSneaking()) {
- 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)");
- return;
- }
- Cupboard cupboard = Cupboard.locationsMap.get(e.getClickedBlock().getLocation());
- if (cupboard != null && !cupboard.getOwnersList().contains(player.getUniqueId()) && !player.hasPermission("mcrust.admin")) {
- Utils.sendBarMessage(player, "&7Только &cавторизованные &7в шкафу &cигроки &7могут работать киянкой");
- return;
- }
- if (Arrays.asList(CustomBlock.Type.HAY_CONSTRUCTION, CustomBlock.Type.WOODEN_CONSTRUCTION, CustomBlock.Type.STONE_CONSTRUCTION, CustomBlock.Type.METAL_CONSTRUCTION).contains(e.getBuildings().getType())) {
- Constructions.getConstuction(e.getBuildings()).openUpgradeGUI(player);
- return;
- }
- Buildings.openGUI(player, e.getBuildings());
- }
- @EventHandler
- public void onUpgradeConstructionsGUIClick(InventoryClickEvent e) {
- Player player = (Player) e.getWhoClicked();
- if (!e.getInventory().getName().equals(Utils.stripColor("&2&lУлучшение конструкции"))) return;
- if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR) return;
- e.setCancelled(true);
- player.playSound(player.getLocation(), org.bukkit.Sound.UI_BUTTON_CLICK, 1, 1);
- if (!e.getClickedInventory().getName().equals(Utils.stripColor("&2&lУлучшение конструкции"))) return;
- ISBuilder builder = ISBuilder.getBuilder(e.getCurrentItem());
- if (!builder.hasTag("location")) return;
- Location location = Utils.deserialiseLocation(builder.getStringTag("location"));
- CustomBlock customBlock = CustomBlock.getBlock(location.getBlock());
- Buildings buildings = Buildings.buildingsMap.get(location);
- player.closeInventory();
- if (buildings.getType() != customBlock.getType()) return;
- Durability.getDurability(player.getInventory().getItemInMainHand()).damage(player);
- if (e.getCurrentItem().getItemMeta().getDisplayName().equals(Utils.stripColor("&a&l» &e&lОтремонтировать"))) {
- buildings.setHealth(buildings.getType().getMaxHealth());
- SQLManager.getManager().updateBuildingData(buildings);
- player.getWorld().playSound(location, Sounds.REPAIR.getSoundName(), 1, 1);
- 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);
- Utils.removeItems(player, ISBuilder.getBuilder(buildings.getType().getResourceStack()).setAmount(builder.getIntTag("repairCost")).getStack());
- Utils.sendBarMessage(player, "&7Я &aпочинил &7конструкцию");
- return;
- }
- if (e.getCurrentItem().getItemMeta().getDisplayName().equals(Utils.stripColor("&a&l» &c&lСломать"))) {
- buildings.remove(player);
- player.getWorld().playSound(location, Sounds.BREAK.getSoundName(), 1, 1);
- Utils.sendBarMessage(player, "&7Я &aразрушил &7конструкцию");
- return;
- }
- if (!builder.hasTag("upgradeType")) return;
- Constructions.Type type = Constructions.Type.valueOf(builder.getStringTag("upgradeType"));
- buildings.setType(type.getBlockType());
- buildings.setHealth(type.getBlockType().getMaxHealth());
- buildings.setDecayTime(type.getBlockType().getDecayTime());
- buildings.setBlockDecayTime(type.getBlockType().getBlockDecayTime());
- SQLManager.getManager().updateBuildingData(buildings);
- CustomBlock.setMaterialData(location.getBlock(), type.getBlockType().getMaterialData());
- player.getWorld().playSound(player.getLocation(), Arrays.asList(type.getSoundUpgrade()).get(Utils.getRandom().nextInt(type.getSoundUpgrade().length)), 1, 1);
- Bukkit.getPluginManager().callEvent(new PlayerUpgradeConstructionEvent(player, location, type));
- 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);
- Utils.removeItems(player, ISBuilder.getBuilder(buildings.getType().getResourceStack()).setAmount(2).getStack());
- Utils.sendBarMessage(player, "&7Я &aулучшил &7конструкцию");
- }
- @EventHandler
- public void onBuildingsGUIClick(InventoryClickEvent e) {
- Player player = (Player) e.getWhoClicked();
- if (!e.getInventory().getName().equals(Utils.stripColor("&2&lКонструкция"))) return;
- if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR) return;
- e.setCancelled(true);
- player.playSound(player.getLocation(), org.bukkit.Sound.UI_BUTTON_CLICK, 1, 1);
- if (!e.getClickedInventory().getName().equals(Utils.stripColor("&2&lКонструкция"))) return;
- ISBuilder builder = ISBuilder.getBuilder(e.getCurrentItem());
- if (!builder.hasTag("location")) return;
- Location location = Utils.deserialiseLocation(builder.getStringTag("location"));
- Buildings buildings = Buildings.buildingsMap.get(location);
- CustomBlock customBlock = CustomBlock.getBlock(location.getBlock());
- player.closeInventory();
- if (buildings == null) return;
- if (buildings.getType() != customBlock.getType()) return;
- Durability.getDurability(player.getInventory().getItemInMainHand()).damage(player);
- 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);
- if (e.getCurrentItem().getItemMeta().getDisplayName().equals(Utils.stripColor("&a&l» &e&lОтремонтировать"))) {
- buildings.setHealth(buildings.getType().getMaxHealth());
- SQLManager.getManager().updateBuildingData(buildings);
- player.getWorld().playSound(location, Sounds.REPAIR.getSoundName(), 1, 1);
- Utils.removeItems(player, ISBuilder.getBuilder(buildings.getType().getResourceStack()).setAmount(builder.getIntTag("repairCost")).getStack());
- Utils.sendBarMessage(player, "&7Я &aпочинил &7конструкцию");
- return;
- }
- if (!e.getCurrentItem().getItemMeta().getDisplayName().equals(Utils.stripColor("&a&l» &c&lСломать"))) return;
- if (buildings.getType().getDrop() != null) customBlock.dropItem(player);
- buildings.remove(player);
- player.getWorld().playSound(location, Sounds.BREAK.getSoundName(), 1, 1);
- Utils.sendBarMessage(player, "&7Я &aразрушил &7конструкцию");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement