diff --git a/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java b/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java index 4803d0d7..4e77bb34 100644 --- a/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java +++ b/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java @@ -185,7 +185,7 @@ public class LevellingManager { Location location = new Location(world, chunkSnapshotList.getX() * 16 + x, y, chunkSnapshotList.getZ() * 16 + z); if (stackableManager.isStacked(location)) { Stackable stackable = stackableManager.getStack(location, blockMaterial); - amount += stackable.getSize(); + amount = stackable.getSize(); } } } @@ -322,12 +322,12 @@ public class LevellingManager { private Materials getMaterials() { if (this.spawnerType != null) { - return Materials.fromString("SPAWNER_" + this.spawnerType.name()); + return Materials.getSpawner(this.spawnerType); } if (NMSUtil.getVersionNumber() > 12) { try { - return Materials.fromString(material.name()); + return Materials.fromString(this.material.name()); } catch (Exception ignored) { } } diff --git a/src/main/java/me/goodandevil/skyblock/listeners/Block.java b/src/main/java/me/goodandevil/skyblock/listeners/Block.java index 04a3d39d..97513bea 100644 --- a/src/main/java/me/goodandevil/skyblock/listeners/Block.java +++ b/src/main/java/me/goodandevil/skyblock/listeners/Block.java @@ -17,9 +17,12 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.BlockFace; +import org.bukkit.block.CreatureSpawner; import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.*; import org.bukkit.event.entity.EntityCreatePortalEvent; @@ -157,7 +160,7 @@ public class Block implements Listener { } } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); org.bukkit.block.Block block = event.getBlock(); @@ -223,12 +226,24 @@ public class Block implements Listener { } } - if (event.isCancelled() || !configLoad.getBoolean("Island.Block.Level.Enable")) return; + if (!configLoad.getBoolean("Island.Block.Level.Enable")) + return; @SuppressWarnings("deprecation") Materials materials = Materials.getMaterials(block.getType(), block.getData()); - if (materials == null) return; + if (materials.equals(Materials.SPAWNER)) { + if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners") || Bukkit.getPluginManager().isPluginEnabled("WildStacker")) + return; + + CreatureSpawner creatureSpawner = (CreatureSpawner) block.getState(); + EntityType spawnerType = creatureSpawner.getSpawnedType(); + materials = Materials.getSpawner(spawnerType); + } + + if (materials == null) + return; + long materialAmount = 0; IslandLevel level = island.getLevel(); diff --git a/src/main/java/me/goodandevil/skyblock/listeners/Entity.java b/src/main/java/me/goodandevil/skyblock/listeners/Entity.java index e40a3127..7f7354b8 100644 --- a/src/main/java/me/goodandevil/skyblock/listeners/Entity.java +++ b/src/main/java/me/goodandevil/skyblock/listeners/Entity.java @@ -13,6 +13,7 @@ import me.goodandevil.skyblock.utils.version.NMSUtil; import me.goodandevil.skyblock.utils.version.Sounds; import me.goodandevil.skyblock.utils.world.LocationUtil; import me.goodandevil.skyblock.world.WorldManager; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.configuration.file.FileConfiguration; @@ -31,6 +32,7 @@ import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerShearEntityEvent; +import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; @@ -563,9 +565,10 @@ public class Entity implements Listener { LivingEntity livingEntity = event.getEntity(); // Certain entities shouldn't drop twice the amount - if (livingEntity instanceof Player || - livingEntity instanceof ArmorStand || - livingEntity instanceof Horse) { + if (livingEntity instanceof Player + || livingEntity instanceof ArmorStand + || livingEntity instanceof Horse + || livingEntity instanceof ElderGuardian) { return; } @@ -573,11 +576,20 @@ public class Entity implements Listener { if (livingEntity instanceof Donkey || livingEntity instanceof Mule) return; } - - if (livingEntity.hasMetadata("SkyBlock")) { - return; + + if (NMSUtil.getVersionNumber() > 10) { + if (livingEntity instanceof Evoker) + return; } + if (NMSUtil.getVersionNumber() > 13) { + if (livingEntity instanceof Ravager || livingEntity instanceof Illager) + return; + } + + if (livingEntity.hasMetadata("SkyBlock")) + return; + IslandManager islandManager = skyblock.getIslandManager(); if (skyblock.getWorldManager().isIslandWorld(livingEntity.getWorld())) { @@ -586,15 +598,34 @@ public class Entity implements Listener { if (island != null) { List upgrades = skyblock.getUpgradeManager().getUpgrades(Upgrade.Type.Drops); - if (upgrades != null && upgrades.size() > 0 && upgrades.get(0).isEnabled() - && island.isUpgrade(Upgrade.Type.Drops)) { - List entityDrops = event.getDrops(); + if (upgrades != null && upgrades.size() > 0 && upgrades.get(0).isEnabled() && island.isUpgrade(Upgrade.Type.Drops)) { + Set dontMultiply = new HashSet<>(); - if (entityDrops != null) { - for (ItemStack is : entityDrops) { - is.setAmount(is.getAmount() * 2); + if (NMSUtil.getVersionNumber() > 8) { + EntityEquipment equipment = livingEntity.getEquipment(); + if (equipment != null) { + for (ItemStack item : event.getDrops()) { + if (item.equals(equipment.getHelmet()) + || item.equals(equipment.getChestplate()) + || item.equals(equipment.getLeggings()) + || item.equals(equipment.getBoots()) + || item.equals(equipment.getItemInMainHand()) + || item.equals(equipment.getItemInOffHand())) { + dontMultiply.add(item); + } + } + } + + if (livingEntity instanceof Pig) { + Pig pig = (Pig) livingEntity; + if (pig.hasSaddle()) + dontMultiply.add(new ItemStack(Material.SADDLE, 1)); } } + + for (ItemStack is : event.getDrops()) + if (!dontMultiply.contains(is)) + is.setAmount(is.getAmount() * 2); } } } diff --git a/src/main/java/me/goodandevil/skyblock/listeners/EpicSpawners.java b/src/main/java/me/goodandevil/skyblock/listeners/EpicSpawners.java index 4070183c..bf7774e1 100644 --- a/src/main/java/me/goodandevil/skyblock/listeners/EpicSpawners.java +++ b/src/main/java/me/goodandevil/skyblock/listeners/EpicSpawners.java @@ -1,6 +1,7 @@ package me.goodandevil.skyblock.listeners; import com.songoda.epicspawners.api.events.SpawnerBreakEvent; +import com.songoda.epicspawners.api.events.SpawnerChangeEvent; import com.songoda.epicspawners.api.events.SpawnerPlaceEvent; import me.goodandevil.skyblock.SkyBlock; import me.goodandevil.skyblock.config.FileManager; @@ -9,10 +10,12 @@ import me.goodandevil.skyblock.island.IslandLevel; import me.goodandevil.skyblock.island.IslandManager; import me.goodandevil.skyblock.utils.version.Materials; import me.goodandevil.skyblock.world.WorldManager; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import java.io.File; @@ -25,8 +28,44 @@ public class EpicSpawners implements Listener { this.skyblock = skyblock; } - @EventHandler + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSpawnerPlace(SpawnerPlaceEvent event) { + Bukkit.getScheduler().scheduleSyncDelayedTask(SkyBlock.getInstance(), () -> { + IslandManager islandManager = skyblock.getIslandManager(); + WorldManager worldManager = skyblock.getWorldManager(); + + Location location = event.getSpawner().getLocation(); + if (!worldManager.isIslandWorld(location.getWorld())) return; + + Island island = islandManager.getIslandAtLocation(location); + + int amount = event.getSpawner().getFirstStack().getStackSize(); + EntityType spawnerType = event.getSpawner().getCreatureSpawner().getSpawnedType(); + + FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + if (configLoad.getBoolean("Island.Block.Level.Enable")) { + Materials materials = Materials.getSpawner(spawnerType); + if (materials != null) { + IslandLevel level = island.getLevel(); + + long materialAmount = 0; + if (level.hasMaterial(materials.name())) { + materialAmount = level.getMaterialAmount(materials.name()); + } + + level.setMaterialAmount(materials.name(), materialAmount + amount); + } + } + }); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onSpawnerChange(SpawnerChangeEvent event) { + if (event.getChange() != SpawnerChangeEvent.ChangeType.STACK_SIZE) + return; + IslandManager islandManager = skyblock.getIslandManager(); WorldManager worldManager = skyblock.getWorldManager(); @@ -35,7 +74,7 @@ public class EpicSpawners implements Listener { Island island = islandManager.getIslandAtLocation(location); - int amount = event.getSpawner().getFirstStack().getStackSize(); + int amount = event.getStackSize() - event.getOldStackSize(); EntityType spawnerType = event.getSpawner().getCreatureSpawner().getSpawnedType(); FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")); @@ -51,12 +90,16 @@ public class EpicSpawners implements Listener { materialAmount = level.getMaterialAmount(materials.name()); } - level.setMaterialAmount(materials.name(), materialAmount + amount); + if (materialAmount + amount <= 0) { + level.removeMaterial(materials.name()); + } else { + level.setMaterialAmount(materials.name(), materialAmount + amount); + } } } } - @EventHandler + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSpawnerBreak(SpawnerBreakEvent event) { IslandManager islandManager = skyblock.getIslandManager(); WorldManager worldManager = skyblock.getWorldManager(); diff --git a/src/main/java/me/goodandevil/skyblock/listeners/Interact.java b/src/main/java/me/goodandevil/skyblock/listeners/Interact.java index 3da38d9e..c7862eb8 100644 --- a/src/main/java/me/goodandevil/skyblock/listeners/Interact.java +++ b/src/main/java/me/goodandevil/skyblock/listeners/Interact.java @@ -13,6 +13,7 @@ import org.bukkit.entity.Horse; import org.bukkit.entity.Player; import org.bukkit.entity.minecart.StorageMinecart; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; @@ -47,7 +48,7 @@ public class Interact implements Listener { } @SuppressWarnings("deprecation") - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); org.bukkit.block.Block block = event.getClickedBlock(); @@ -409,7 +410,7 @@ public class Interact implements Listener { } } - if ((event.getItem() != null) && (event.getItem().getType() != Material.AIR)) { + if ((event.getItem() != null) && (event.getItem().getType() != Material.AIR) && !event.isCancelled()) { if (event.getItem().getType() == Material.BUCKET || event.getItem().getType() == Material.WATER_BUCKET || event.getItem().getType() == Material.LAVA_BUCKET) { if (!islandManager.hasPermission(player, block.getLocation(), "Bucket")) { @@ -462,9 +463,7 @@ public class Interact implements Listener { } } } - } else if (event.getAction() == Action.LEFT_CLICK_BLOCK) - - { + } else if (event.getAction() == Action.LEFT_CLICK_BLOCK) { if (player.getTargetBlock((Set) null, 5).getType() == Material.FIRE) { if (!islandManager.hasPermission(player, block.getLocation(), "Fire")) { event.setCancelled(true); @@ -817,7 +816,7 @@ public class Interact implements Listener { @EventHandler(ignoreCancelled = true) - public void PlayerInteractEvent(PlayerArmorStandManipulateEvent event) { + public void onPlayerArmorStandManipulate(PlayerArmorStandManipulateEvent event) { if (skyblock.getStackableManager() != null && skyblock.getStackableManager().isStacked(event.getRightClicked().getLocation().getBlock().getLocation())) { event.setCancelled(true); } diff --git a/src/main/java/me/goodandevil/skyblock/listeners/WildStacker.java b/src/main/java/me/goodandevil/skyblock/listeners/WildStacker.java index 4095bed1..5b460526 100644 --- a/src/main/java/me/goodandevil/skyblock/listeners/WildStacker.java +++ b/src/main/java/me/goodandevil/skyblock/listeners/WildStacker.java @@ -1,6 +1,10 @@ package me.goodandevil.skyblock.listeners; +import com.bgsoftware.wildstacker.api.events.BarrelPlaceEvent; +import com.bgsoftware.wildstacker.api.events.BarrelStackEvent; import com.bgsoftware.wildstacker.api.events.BarrelUnstackEvent; +import com.bgsoftware.wildstacker.api.events.SpawnerPlaceEvent; +import com.bgsoftware.wildstacker.api.events.SpawnerStackEvent; import com.bgsoftware.wildstacker.api.events.SpawnerUnstackEvent; import me.goodandevil.skyblock.SkyBlock; import me.goodandevil.skyblock.config.FileManager; @@ -10,11 +14,13 @@ import me.goodandevil.skyblock.island.IslandManager; import me.goodandevil.skyblock.utils.version.Materials; import me.goodandevil.skyblock.utils.version.NMSUtil; import me.goodandevil.skyblock.world.WorldManager; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import java.io.File; @@ -27,7 +33,79 @@ public class WildStacker implements Listener { this.skyblock = skyblock; } - @EventHandler + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onBarrelPlace(BarrelPlaceEvent event) { + IslandManager islandManager = skyblock.getIslandManager(); + WorldManager worldManager = skyblock.getWorldManager(); + + Location location = event.getBarrel().getLocation(); + if (!worldManager.isIslandWorld(location.getWorld())) return; + + Island island = islandManager.getIslandAtLocation(location); + + Material material = event.getBarrel().getType(); + byte data = (byte) event.getBarrel().getData(); + + if (NMSUtil.getVersionNumber() > 12 && material.name().startsWith("LEGACY_")) { + material = Material.matchMaterial(material.name().replace("LEGACY_", "")); + data = 0; + } + + FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + if (configLoad.getBoolean("Island.Block.Level.Enable")) { + Materials materials = Materials.getMaterials(material, data); + if (materials != null) { + IslandLevel level = island.getLevel(); + + long materialAmount = 0; + if (level.hasMaterial(materials.name())) { + materialAmount = level.getMaterialAmount(materials.name()); + } + + level.setMaterialAmount(materials.name(), materialAmount + event.getBarrel().getStackAmount()); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onBarrelStack(BarrelStackEvent event) { + IslandManager islandManager = skyblock.getIslandManager(); + WorldManager worldManager = skyblock.getWorldManager(); + + Location location = event.getBarrel().getLocation(); + if (!worldManager.isIslandWorld(location.getWorld())) return; + + Island island = islandManager.getIslandAtLocation(location); + + Material material = event.getBarrel().getType(); + byte data = (byte) event.getBarrel().getData(); + + if (NMSUtil.getVersionNumber() > 12 && material.name().startsWith("LEGACY_")) { + material = Material.matchMaterial(material.name().replace("LEGACY_", "")); + data = 0; + } + + FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + if (configLoad.getBoolean("Island.Block.Level.Enable")) { + Materials materials = Materials.getMaterials(material, data); + if (materials != null) { + IslandLevel level = island.getLevel(); + + long materialAmount = 0; + if (level.hasMaterial(materials.name())) { + materialAmount = level.getMaterialAmount(materials.name()); + } + + level.setMaterialAmount(materials.name(), materialAmount + event.getTarget().getStackAmount()); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBarrelUnstack(BarrelUnstackEvent event) { IslandManager islandManager = skyblock.getIslandManager(); WorldManager worldManager = skyblock.getWorldManager(); @@ -66,7 +144,67 @@ public class WildStacker implements Listener { } } - @EventHandler + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onSpawnerPlace(SpawnerPlaceEvent event) { + IslandManager islandManager = skyblock.getIslandManager(); + WorldManager worldManager = skyblock.getWorldManager(); + + Location location = event.getSpawner().getLocation(); + if (!worldManager.isIslandWorld(location.getWorld())) return; + + Island island = islandManager.getIslandAtLocation(location); + + EntityType spawnerType = event.getSpawner().getSpawnedType(); + + FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + if (configLoad.getBoolean("Island.Block.Level.Enable")) { + Materials materials = Materials.getSpawner(spawnerType); + if (materials != null) { + IslandLevel level = island.getLevel(); + + long materialAmount = 0; + if (level.hasMaterial(materials.name())) { + materialAmount = level.getMaterialAmount(materials.name()); + } + + level.setMaterialAmount(materials.name(), materialAmount + event.getSpawner().getStackAmount()); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onSpawnerStack(SpawnerStackEvent event) { + IslandManager islandManager = skyblock.getIslandManager(); + WorldManager worldManager = skyblock.getWorldManager(); + + Location location = event.getSpawner().getLocation(); + if (!worldManager.isIslandWorld(location.getWorld())) return; + + Island island = islandManager.getIslandAtLocation(location); + + EntityType spawnerType = event.getSpawner().getSpawnedType(); + + FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + if (configLoad.getBoolean("Island.Block.Level.Enable")) { + Materials materials = Materials.getSpawner(spawnerType); + if (materials != null) { + IslandLevel level = island.getLevel(); + + long materialAmount = 0; + if (level.hasMaterial(materials.name())) { + materialAmount = level.getMaterialAmount(materials.name()); + } + + level.setMaterialAmount(materials.name(), materialAmount + event.getTarget().getStackAmount()); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSpawnerUnstack(SpawnerUnstackEvent event) { IslandManager islandManager = skyblock.getIslandManager(); WorldManager worldManager = skyblock.getWorldManager(); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a0abcbf6..537b38ca 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ version: @version@ api-version: 1.13 description: A unique SkyBlock plugin author: Songoda -softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, Vault, LeaderHeads, WildStacker] +softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, Vault, LeaderHeads, EpicSpawners, WildStacker] loadbefore: [Multiverse-Core] commands: island: