diff --git a/src/de/steamwar/fightsystem/utils/WaterRemover.java b/src/de/steamwar/fightsystem/utils/WaterRemover.java index 2704071..f60b26d 100644 --- a/src/de/steamwar/fightsystem/utils/WaterRemover.java +++ b/src/de/steamwar/fightsystem/utils/WaterRemover.java @@ -1,7 +1,6 @@ package de.steamwar.fightsystem.utils; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.winconditions.WinconditionWaterTechKO; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -61,10 +60,7 @@ public class WaterRemover { it.remove(); } - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> { - blocksToRemove.forEach((Block b) -> b.setType(Material.AIR)); - WinconditionWaterTechKO.removeWater(); - }); + Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> blocksToRemove.forEach((Block b) -> b.setType(Material.AIR))); } private static Set getSourceBlocksOfWater(Block startBlock) { diff --git a/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java index e3cdf91..82eb377 100644 --- a/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java @@ -8,6 +8,7 @@ import de.steamwar.fightsystem.utils.Config; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import java.util.HashSet; import java.util.Set; @@ -16,6 +17,7 @@ public class WinconditionWaterTechKO { private static final Set teamRedWater = new HashSet<>(); private static final Set teamBlueWater = new HashSet<>(); + private static final World WORLD = Bukkit.getWorlds().get(0); public WinconditionWaterTechKO() { if(!Config.WaterTechKO) @@ -61,17 +63,25 @@ public class WinconditionWaterTechKO { checkEmpty(Fight.getBlueTeam(), teamBlueWater); } - public static void removeWater() { - if(!Config.WaterTechKO) - return; - if(FightSystem.getFightState() != FightState.PRE_RUNNING && FightSystem.getFightState() != FightState.RUNNING) - return; + private void checkForWater(Set teamWater, int minX, int minY, int minZ, int maxX, int maxY, int maxZ){ + teamWater.clear(); - checkWaterspots(teamRedWater); - checkWaterspots(teamBlueWater); + for(int x = minX; x <= maxX; x++) { + for(int y = minY; y <= maxY; y++) { + for (int z = minZ; z <= maxZ; z++) { + Material type = WORLD.getBlockAt(x, y, z).getType(); + if (type == Material.STATIONARY_WATER || type == Material.WATER) + teamWater.add(new Location(WORLD, x, y, z)); + } + } + } + } - checkEmpty(Fight.getRedTeam(), teamRedWater); - checkEmpty(Fight.getBlueTeam(), teamBlueWater); + private static void checkEmpty(FightTeam team, Set teamWater){ + if(teamWater.isEmpty()){ + Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getName() + " §eist Tech K.O.!"); + Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team))); + } } public static int getTeamBlueWater() { @@ -81,29 +91,4 @@ public class WinconditionWaterTechKO { public static int getTeamRedWater() { return teamRedWater.size(); } - - private void checkForWater(Set teamWater, int minX, int minY, int minZ, int maxX, int maxY, int maxZ){ - teamWater.clear(); - - for(int x = minX; x <= maxX; x++) { - for(int y = minY; y <= maxY; y++) { - for (int z = minZ; z <= maxZ; z++) { - Location location = new Location(Bukkit.getWorlds().get(0), x, y, z); - if (location.getBlock().getType() == Material.STATIONARY_WATER || location.getBlock().getType() == Material.WATER) - teamWater.add(location); - } - } - } - } - - private static void checkWaterspots(Set teamWater){ - teamWater.removeIf(location -> location.getBlock().getType() != Material.STATIONARY_WATER && location.getBlock().getType() != Material.WATER); - } - - private static void checkEmpty(FightTeam team, Set teamWater){ - if(teamWater.isEmpty()){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + team.getName() + " §6ist Tech K.O.!"); - FightSystem.setSpectateState(Fight.getOpposite(team)); - } - } }