From 41fd23122b0522ad483e3640a697d8055278e5d3 Mon Sep 17 00:00:00 2001 From: Fabrizio La Rosa Date: Fri, 10 Jul 2020 10:48:53 +0200 Subject: [PATCH] Hotfix for repeaters not being recognized in 1.8.8 --- .../songoda/skyblock/island/IslandLevel.java | 37 +++++++++++++++ .../levelling/IslandLevelManager.java | 13 +++++- .../skyblock/limit/impl/BlockLimitation.java | 33 +++++++++++-- .../com/songoda/skyblock/listeners/Block.java | 46 ++++++++++++++++--- 4 files changed, 116 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/songoda/skyblock/island/IslandLevel.java b/src/main/java/com/songoda/skyblock/island/IslandLevel.java index 2d73d9f3..a054f6af 100644 --- a/src/main/java/com/songoda/skyblock/island/IslandLevel.java +++ b/src/main/java/com/songoda/skyblock/island/IslandLevel.java @@ -1,6 +1,8 @@ package com.songoda.skyblock.island; import com.google.common.base.Strings; +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.ServerVersion; import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.reward.LevelReward; @@ -94,6 +96,15 @@ public class IslandLevel { } public long getMaterialPoints(String material) { + if(ServerVersion.isServerVersion(ServerVersion.V1_8)) { + switch (material.toUpperCase()) { + case "DIODE_BLOCK_OFF": + case "DIODE_BLOCK_ON": + material = CompatibleMaterial.REPEATER.name(); + break; + } + } + Config config = plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "levelling.yml")); FileConfiguration configLoad = config.getFileConfiguration(); @@ -186,6 +197,15 @@ public class IslandLevel { } public void setMaterialAmount(String material, long amount) { + if(ServerVersion.isServerVersion(ServerVersion.V1_8)) { + switch (material.toUpperCase()) { + case "DIODE_BLOCK_OFF": + case "DIODE_BLOCK_ON": + material = CompatibleMaterial.REPEATER.name(); + break; + } + } + plugin.getFileManager().getConfig(new File(new File(plugin.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml")).getFileConfiguration() .set("Levelling.Materials." + material + ".Amount", amount); @@ -193,10 +213,27 @@ public class IslandLevel { } public long getMaterialAmount(String material) { + if(ServerVersion.isServerVersion(ServerVersion.V1_8)) { + switch (material.toUpperCase()) { + case "DIODE_BLOCK_OFF": + case "DIODE_BLOCK_ON": + material = CompatibleMaterial.REPEATER.name(); + break; + } + } return this.materials.getOrDefault(material, 0l); } public void removeMaterial(String material) { + if(ServerVersion.isServerVersion(ServerVersion.V1_8)) { + switch (material.toUpperCase()) { + case "DIODE_BLOCK_OFF": + case "DIODE_BLOCK_ON": + material = CompatibleMaterial.REPEATER.name(); + break; + } + } + plugin.getFileManager().getConfig(new File(new File(plugin.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml")).getFileConfiguration() .set("Levelling.Materials." + material, null); diff --git a/src/main/java/com/songoda/skyblock/levelling/IslandLevelManager.java b/src/main/java/com/songoda/skyblock/levelling/IslandLevelManager.java index d0faa300..ba5b2d42 100644 --- a/src/main/java/com/songoda/skyblock/levelling/IslandLevelManager.java +++ b/src/main/java/com/songoda/skyblock/levelling/IslandLevelManager.java @@ -231,7 +231,18 @@ public final class IslandLevelManager { private void updateLevelLocation(Island island, Location location) { Block block = location.getBlock(); - CompatibleMaterial material = CompatibleMaterial.getMaterial(block); + CompatibleMaterial material = null; + if(ServerVersion.isServerVersion(ServerVersion.V1_8)) { + switch (block.getType().toString().toUpperCase()) { + case "DIODE_BLOCK_OFF": + case "DIODE_BLOCK_ON": + material = CompatibleMaterial.REPEATER; + break; + } + } + if(material == null) { + material = CompatibleMaterial.getMaterial(block); + } if (material == null || material == CompatibleMaterial.AIR) return; diff --git a/src/main/java/com/songoda/skyblock/limit/impl/BlockLimitation.java b/src/main/java/com/songoda/skyblock/limit/impl/BlockLimitation.java index 6ec563a6..58d63665 100644 --- a/src/main/java/com/songoda/skyblock/limit/impl/BlockLimitation.java +++ b/src/main/java/com/songoda/skyblock/limit/impl/BlockLimitation.java @@ -1,6 +1,7 @@ package com.songoda.skyblock.limit.impl; import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.ServerVersion; import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; @@ -45,11 +46,11 @@ public final class BlockLimitation extends EnumLimitation { for (String key : keys) { final String enumName = key.toUpperCase(Locale.ENGLISH); - final CompatibleMaterial type = CompatibleMaterial.getMaterial(enumName); + CompatibleMaterial type = CompatibleMaterial.getMaterial(enumName); if (type == null) throw new IllegalArgumentException("Unable to parse Materials from '" + enumName + "' in the Section '" + loadFrom.getCurrentPath() + "'"); - + getMap().put(type, loadFrom.getLong(key)); } @@ -64,7 +65,18 @@ public final class BlockLimitation extends EnumLimitation { if (player.hasPermission("fabledskyblock.limit.block.*")) return -1; - final CompatibleMaterial material = CompatibleMaterial.getMaterial(type); + CompatibleMaterial material = null; + if(ServerVersion.isServerVersion(ServerVersion.V1_8)) { + switch (type.toString().toUpperCase()) { + case "DIODE_BLOCK_OFF": + case "DIODE_BLOCK_ON": + material = CompatibleMaterial.REPEATER; + break; + } + } + if(material == null) { + material = CompatibleMaterial.getMaterial(type); + } if (material == null) return -1; @@ -78,7 +90,6 @@ public final class BlockLimitation extends EnumLimitation { } public boolean isBlockLimitExceeded(Material type, Location loc, long limit) { - if (limit == -1) return false; final IslandManager islandManager = SkyBlock.getInstance().getIslandManager(); @@ -88,7 +99,19 @@ public final class BlockLimitation extends EnumLimitation { if (type == CompatibleMaterial.SPAWNER.getBlockMaterial()) { totalPlaced = island.getLevel().getMaterials().entrySet().stream().filter(x -> x.getKey().contains("SPAWNER")).mapToLong(Map.Entry::getValue).sum(); } else { - totalPlaced = island.getLevel().getMaterialAmount(CompatibleMaterial.getMaterial(type).name()); + CompatibleMaterial material = null; + if(ServerVersion.isServerVersion(ServerVersion.V1_8)) { + switch (type.toString().toUpperCase()) { + case "DIODE_BLOCK_OFF": + case "DIODE_BLOCK_ON": + material = CompatibleMaterial.REPEATER; + break; + } + } + if(material == null) { + material = CompatibleMaterial.getMaterial(type); + } + totalPlaced = island.getLevel().getMaterialAmount(material.name()); } return limit <= totalPlaced; diff --git a/src/main/java/com/songoda/skyblock/listeners/Block.java b/src/main/java/com/songoda/skyblock/listeners/Block.java index 9ac94cb5..bf9eb1b9 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Block.java +++ b/src/main/java/com/songoda/skyblock/listeners/Block.java @@ -44,8 +44,7 @@ public class Block implements Listener { public Block(SkyBlock plugin) { this.plugin = plugin; } - - @SuppressWarnings("deprecation") + @EventHandler(priority = EventPriority.LOW) public void onBlockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); @@ -74,7 +73,18 @@ public class Block implements Listener { if (stackableManager != null && stackableManager.isStacked(blockLocation)) { Stackable stackable = stackableManager.getStack(block.getLocation(), CompatibleMaterial.getMaterial(block)); if (stackable != null) { - CompatibleMaterial material = CompatibleMaterial.getMaterial(block); + CompatibleMaterial material = null; + if(ServerVersion.isServerVersion(ServerVersion.V1_8)) { + switch (block.getType().toString().toUpperCase()) { + case "DIODE_BLOCK_OFF": + case "DIODE_BLOCK_ON": + material = CompatibleMaterial.REPEATER; + break; + } + } + if(material == null) { + material = CompatibleMaterial.getMaterial(block); + } byte data = block.getData(); int droppedAmount; @@ -141,8 +151,19 @@ public class Block implements Listener { } if (event.isCancelled() || !configLoad.getBoolean("Island.Block.Level.Enable")) return; - - CompatibleMaterial material = CompatibleMaterial.getMaterial(block); + + CompatibleMaterial material = null; + if(ServerVersion.isServerVersion(ServerVersion.V1_8)) { + switch (block.getType().toString().toUpperCase()) { + case "DIODE_BLOCK_OFF": + case "DIODE_BLOCK_ON": + material = CompatibleMaterial.REPEATER; + break; + } + } + if(material == null) { + material = CompatibleMaterial.getMaterial(block); + } if (material == null) return; @@ -273,7 +294,18 @@ public class Block implements Listener { long limit = limits.getBlockLimit(player, block); if (limits.isBlockLimitExceeded(block, limit)) { - CompatibleMaterial material = CompatibleMaterial.getMaterial(block.getType()); + CompatibleMaterial material = null; + if(ServerVersion.isServerVersion(ServerVersion.V1_8)) { + switch (block.getType().toString().toUpperCase()) { + case "DIODE_BLOCK_OFF": + case "DIODE_BLOCK_ON": + material = CompatibleMaterial.REPEATER; + break; + } + } + if(material == null) { + material = CompatibleMaterial.getMaterial(block); + } plugin.getMessageManager().sendMessage(player, plugin.getFileManager().getConfig(new File(plugin.getDataFolder(), "language.yml")).getFileConfiguration().getString("Island.Limit.Block.Exceeded.Message") .replace("%type", WordUtils.capitalizeFully(material.name().replace("_", " "))).replace("%limit", NumberUtil.formatNumber(limit))); @@ -287,7 +319,7 @@ public class Block implements Listener { if (event.getBlock().getType() == CompatibleMaterial.END_PORTAL_FRAME.getMaterial() && event.getPlayer().getItemInHand().getType() == CompatibleMaterial.ENDER_EYE.getMaterial()) return; - + islandLevelManager.updateLevel(island, blockLoc); }