From 424c80ec81201f7dc1bbe5059d79bca1ee90361b Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Thu, 17 Apr 2025 16:09:29 +0200 Subject: [PATCH] Add general Melting of Blocks --- .../de/steamwar/towerrun/config/WorldConfig.java | 16 ++++------------ .../towerrun/listener/IngameListener.java | 13 +++++++------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/TowerRun/src/de/steamwar/towerrun/config/WorldConfig.java b/TowerRun/src/de/steamwar/towerrun/config/WorldConfig.java index fafdd453..56e90034 100644 --- a/TowerRun/src/de/steamwar/towerrun/config/WorldConfig.java +++ b/TowerRun/src/de/steamwar/towerrun/config/WorldConfig.java @@ -35,7 +35,8 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.util.Vector; import java.io.File; -import java.util.*; +import java.util.ArrayList; +import java.util.List; @UtilityClass public class WorldConfig { @@ -54,7 +55,7 @@ public class WorldConfig { public static final int MAP_MIN_Z; public static final int MAP_MAX_X; public static final int MAP_MAX_Z; - public static final Map MELTING_TIMES; + public static final boolean MELTING; public static final TowerGeneratorConfig TOWER_GENERATOR_CONFIG; public static final List WINCONDITIONS = new ArrayList<>(); @@ -161,16 +162,7 @@ public class WorldConfig { MAP_MAX_X = config.getInt("maxX"); MAP_MAX_Z = config.getInt("maxZ"); - ConfigurationSection meltingBlocksSection = tower.getConfigurationSection("meltingBlocks"); - if (meltingBlocksSection != null) { - Map meltingTimes = new HashMap<>(); - meltingBlocksSection.getKeys(false).forEach(s -> { - meltingTimes.put(Material.valueOf(s), meltingBlocksSection.getInt(s)); - }); - MELTING_TIMES = Collections.unmodifiableMap(meltingTimes); - } else { - MELTING_TIMES = Collections.emptyMap(); - } + MELTING = tower.getBoolean("melting") || tower.contains("meltingBlocks"); // Backwards compatibility with meltingBlocks key! ACTIVE_WINCONDITIONS = config.getStringList("winconditions"); WINCONDITIONS.stream().filter(winCondition -> ACTIVE_WINCONDITIONS.contains(winCondition.getName())).forEach(winCondition -> winCondition.setActive(true)); diff --git a/TowerRun/src/de/steamwar/towerrun/listener/IngameListener.java b/TowerRun/src/de/steamwar/towerrun/listener/IngameListener.java index befc7d47..f3170215 100644 --- a/TowerRun/src/de/steamwar/towerrun/listener/IngameListener.java +++ b/TowerRun/src/de/steamwar/towerrun/listener/IngameListener.java @@ -68,7 +68,7 @@ public class IngameListener extends GameStateBukkitListener { return; } blocks.forEach(block -> { - if (!WorldConfig.MELTING_TIMES.containsKey(block.getType())) return; + if (block.getType() == Material.AIR || block.getType() == Material.LAVA) return; block.setType(Material.AIR); block.getWorld().playSound(block.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 0.1F, 1); }); @@ -189,6 +189,9 @@ public class IngameListener extends GameStateBukkitListener { @EventHandler public void onBlockPhysics(BlockPhysicsEvent event) { + if (!WorldConfig.MELTING) { + return; + } if (event.getSourceBlock().getType() != Material.LAVA) { return; } @@ -202,11 +205,9 @@ public class IngameListener extends GameStateBukkitListener { } private void shouldMelt(Block block) { - int meltingTime = WorldConfig.MELTING_TIMES.getOrDefault(block.getType(), -1); - if (meltingTime == -1) { - return; - } - blocksToMelt.computeIfAbsent(time + meltingTime * 20, integer -> new ArrayList<>()).add(block); + if (block.getType().isBurnable()) return; + int meltingTime = (int) (block.getType().getHardness() * 48 * 20); + blocksToMelt.computeIfAbsent(time + meltingTime, integer -> new ArrayList<>()).add(block); } @EventHandler