diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index feb9395..c03ce3c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -176,7 +176,6 @@ public class FightSystem extends JavaPlugin { mainCountdown = new EnternCountdown(); FightStatistics.start(); - WaterRemover.init(); Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!"); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java index c9538c9..728dc91 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java @@ -1,106 +1,57 @@ package de.steamwar.fightsystem.utils; import de.steamwar.core.Core; -import de.steamwar.fightsystem.FightSystem; -import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import java.util.*; +import java.util.List; public class WaterRemover { - private WaterRemover(){} - private static final Map explodedBlocks = Collections.synchronizedMap(new HashMap<>()); - private static Set waterList = new HashSet<>(); - private static boolean isRunning = false; - private static int steps = 1; - - public static void init() { - Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), () -> { - if(isRunning){ - steps++; - return; - } - isRunning = true; - wateredCheck(); - removeWater(); - isRunning = false; - }, 0, 20); - } - public static void add(List l) { - l.forEach((Block b) -> explodedBlocks.put(b.getLocation(), 0)); - } + for(Block b : l){ + //b cannot be water or air due to current explosion - private static void wateredCheck() { - try{ - Iterator> it = explodedBlocks.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry e = it.next(); - Block b = e.getKey().getBlock(); - if (isWater(b)) - waterList.add(b); - - if(b.getType() != Material.AIR){ - it.remove(); - continue; - } - e.setValue(e.getValue() + steps); - - if(e.getValue() > 3) - it.remove(); + int startX = b.getX(); + int startY = b.getY(); + int startZ = b.getZ(); + try{ + checkBlock(b.getRelative(BlockFace.EAST), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.WEST), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.NORTH), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.SOUTH), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.UP), startX, startY, startZ); + }catch(IsAnOcean e){ + //ignore } - steps = 1; - }catch(ConcurrentModificationException e){ - steps++; } } - private static void removeWater() { - List blocksToRemove = new LinkedList<>(); - Iterator it = waterList.iterator(); - while(it.hasNext()){ - Block b = it.next(); - blocksToRemove.addAll(getSourceBlocksOfWater(b)); - if (!isWater(b)) - it.remove(); - } - - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> blocksToRemove.forEach((Block b) -> b.setType(Material.AIR))); - } - - private static Set getSourceBlocksOfWater(Block startBlock) { - Set water = new HashSet<>(); - collectBlocks(startBlock, water, new HashSet<>()); - return water; - } - - private static void collectBlocks(Block anchor, Set collected, Set visitedBlocks) { - if( - !isWater(anchor) || - visitedBlocks.contains(anchor) - ) + private static void checkBlock(Block b, int startX, int startY, int startZ) throws IsAnOcean { + if(!isWater(b)) return; - visitedBlocks.add(anchor); - if (isWater(anchor)) - collected.add(anchor); + // If distance to original block is greater than 20 + if(Math.abs(startX - b.getX()) + Math.abs(startY - b.getY() + Math.abs(startZ - b.getZ())) >= 20) + throw new IsAnOcean(); - if(visitedBlocks.size() > 100) { - collected.clear(); - return; + b.setType(Material.AIR); + try{ + checkBlock(b.getRelative(BlockFace.EAST), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.WEST), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.NORTH), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.SOUTH), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.UP), startX, startY, startZ); + }catch(IsAnOcean e){ + b.setType(Material.WATER); + throw e; } - collectBlocks(anchor.getRelative(BlockFace.UP), collected, visitedBlocks); - collectBlocks(anchor.getRelative(BlockFace.NORTH), collected, visitedBlocks); - collectBlocks(anchor.getRelative(BlockFace.EAST), collected, visitedBlocks); - collectBlocks(anchor.getRelative(BlockFace.SOUTH), collected, visitedBlocks); - collectBlocks(anchor.getRelative(BlockFace.WEST), collected, visitedBlocks); } + private static class IsAnOcean extends Throwable{} + public static boolean isWater(Block block){ switch(Core.getVersion()){ case 15: