From c90d13836afaf7d096512913f7701d964182bfa0 Mon Sep 17 00:00:00 2001 From: Brianna Date: Fri, 1 May 2020 05:39:24 -0400 Subject: [PATCH] Count ore generation towards island level. --- .../com/songoda/skyblock/listeners/Block.java | 74 ++++++++++--------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/songoda/skyblock/listeners/Block.java b/src/main/java/com/songoda/skyblock/listeners/Block.java index c81b3112..c911cc1c 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Block.java +++ b/src/main/java/com/songoda/skyblock/listeners/Block.java @@ -265,40 +265,7 @@ public class Block implements Listener { if (event.getBlock().getType() == CompatibleMaterial.END_PORTAL_FRAME.getMaterial() && event.getPlayer().getItemInHand().getType() == CompatibleMaterial.ENDER_EYE.getMaterial()) return; - // Fix a bug in Paper 1.8.8 when using ViaVersion on a 1.12.2 client. - // BUG: Player can infinitely increase their level by placing a block at their - // feet. - // It doesn't take the block away but still increments the level. - // This doesn't happen in Spigot, but does happen in PaperSpigot due to a - // BlockPlaceEvent being incorrectly fired. - // The solution is to wait a tick to make sure that the block was actually - // placed. - // This shouldn't cause any issues besides the task number being increased - // insanely fast. - Bukkit.getScheduler().runTask(skyblock, () -> { - CompatibleMaterial material = CompatibleMaterial.getMaterial(block.getType()); - - if (material == null || material == CompatibleMaterial.AIR) return; - - if (material == CompatibleMaterial.SPAWNER) { - if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners") || Bukkit.getPluginManager().isPluginEnabled("WildStacker")) - return; - - CompatibleSpawners spawner = CompatibleSpawners.getSpawner(((CreatureSpawner) block.getState()).getSpawnedType()); - - if (spawner != null) - material = CompatibleMaterial.getBlockMaterial(spawner.getMaterial()); - } - - long materialAmount = 0; - IslandLevel level = island.getLevel(); - - if (level.hasMaterial(material.name())) { - materialAmount = level.getMaterialAmount(material.name()); - } - - level.setMaterialAmount(material.name(), materialAmount + 1); - }); + updateLevel(island, blockLoc); } @EventHandler @@ -363,6 +330,7 @@ public class Block implements Listener { toBlockState.setData(genState.getData()); toBlockState.setType(genState.getType()); toBlockState.update(); + updateLevel(island, genState.getLocation()); return; } } @@ -588,6 +556,7 @@ public class Block implements Listener { state.setType(genState.getType()); if (NMSUtil.getVersionNumber() < 13) state.setData(genState.getData()); + updateLevel(island, genState.getLocation()); return; } } @@ -672,4 +641,41 @@ public class Block implements Listener { event.setCancelled(true); } + private void updateLevel(Island island, Location location) { + // Fix a bug in Paper 1.8.8 when using ViaVersion on a 1.12.2 client. + // BUG: Player can infinitely increase their level by placing a block at their + // feet. + // It doesn't take the block away but still increments the level. + // This doesn't happen in Spigot, but does happen in PaperSpigot due to a + // BlockPlaceEvent being incorrectly fired. + // The solution is to wait a tick to make sure that the block was actually + // placed. + // This shouldn't cause any issues besides the task number being increased + // insanely fast. + Bukkit.getScheduler().runTask(skyblock, () -> { + org.bukkit.block.Block block = location.getBlock(); + CompatibleMaterial material = CompatibleMaterial.getMaterial(block); + + if (material == null || material == CompatibleMaterial.AIR) return; + + if (material == CompatibleMaterial.SPAWNER) { + if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners") || Bukkit.getPluginManager().isPluginEnabled("WildStacker")) + return; + + CompatibleSpawners spawner = CompatibleSpawners.getSpawner(((CreatureSpawner) block.getState()).getSpawnedType()); + + if (spawner != null) + material = CompatibleMaterial.getBlockMaterial(spawner.getMaterial()); + } + + long materialAmount = 0; + IslandLevel level = island.getLevel(); + + if (level.hasMaterial(material.name())) + materialAmount = level.getMaterialAmount(material.name()); + + level.setMaterialAmount(material.name(), materialAmount + 1); + }); + } + }