From 6bbe6ff5b3fcf6c991c88382597d3a1e199628cb Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Sun, 14 Apr 2019 01:07:38 +0200 Subject: [PATCH] hotfixes Signed-off-by: Yaruma3341 --- src/me/yaruma/fightsystem/FightSystem.java | 3 ++ .../yaruma/fightsystem/fight/FightTeam.java | 2 + .../fightsystem/fight/WaterRemover.java | 1 - .../winconditions/WinconditionTechKO.java | 42 +++++++++++++++---- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/me/yaruma/fightsystem/FightSystem.java b/src/me/yaruma/fightsystem/FightSystem.java index 1c5790c..574ec79 100644 --- a/src/me/yaruma/fightsystem/FightSystem.java +++ b/src/me/yaruma/fightsystem/FightSystem.java @@ -179,6 +179,8 @@ public class FightSystem extends JavaPlugin { WinconditionTimeout.timeout(); WinconditionEntern.entern(); + WinconditionTechKO.startAutoChecker(); + Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!"); } @@ -187,6 +189,7 @@ public class FightSystem extends JavaPlugin { return; this.fightState = FightState.SPECTATE; Countdown.cancelAllTimers(); + Bukkit.getScheduler().cancelTask(WinconditionTechKO.taskID); setAllPlayersGM(GameMode.SPECTATOR); Bukkit.broadcastMessage(" "); diff --git a/src/me/yaruma/fightsystem/fight/FightTeam.java b/src/me/yaruma/fightsystem/fight/FightTeam.java index cda7fde..c0d62e8 100644 --- a/src/me/yaruma/fightsystem/fight/FightTeam.java +++ b/src/me/yaruma/fightsystem/fight/FightTeam.java @@ -12,6 +12,7 @@ import me.yaruma.fightsystem.FightSystem; import me.yaruma.fightsystem.kit.KitManager; import me.yaruma.fightsystem.utils.Config; import me.yaruma.fightsystem.utils.ItemBuilder; +import me.yaruma.fightsystem.winconditions.WinconditionTechKO; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; @@ -151,6 +152,7 @@ public class FightTeam { } schem.paste(w, v, false, true, aT).flushQueue(); teleportToSpawn(); + WinconditionTechKO.addWater(); } public void setSchematic(Schematic schematic){ diff --git a/src/me/yaruma/fightsystem/fight/WaterRemover.java b/src/me/yaruma/fightsystem/fight/WaterRemover.java index 37e59f9..9aeffef 100644 --- a/src/me/yaruma/fightsystem/fight/WaterRemover.java +++ b/src/me/yaruma/fightsystem/fight/WaterRemover.java @@ -70,7 +70,6 @@ public class WaterRemover { Bukkit.getScheduler().runTask((Plugin)FightSystem.getPlugin(), () -> { for (Block block : blocksToRemove) { block.setType(Material.AIR); - WinconditionTechKO.removeWater(block.getLocation()); } }); } diff --git a/src/me/yaruma/fightsystem/winconditions/WinconditionTechKO.java b/src/me/yaruma/fightsystem/winconditions/WinconditionTechKO.java index 8fa8249..46dbdab 100644 --- a/src/me/yaruma/fightsystem/winconditions/WinconditionTechKO.java +++ b/src/me/yaruma/fightsystem/winconditions/WinconditionTechKO.java @@ -1,18 +1,23 @@ package me.yaruma.fightsystem.winconditions; +import me.yaruma.fightsystem.FightSystem; +import me.yaruma.fightsystem.fight.Fight; import me.yaruma.fightsystem.utils.Config; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import java.util.HashSet; +import java.util.Iterator; public class WinconditionTechKO { public static HashSet teamRedWater = new HashSet<>(); public static HashSet teamBlueWater = new HashSet<>(); + public static int taskID; public static void addWater() { + if(!Config.TechKO) return; //Team Red for(int x = Config.TeamRedCornerX; x <= (x + Config.SchemsizeX); x++) { @@ -39,14 +44,37 @@ public class WinconditionTechKO { } } - public static void removeWater(Location location) { - if(!Config.TechKO) - return; + public static void startAutoChecker() { + if(!Config.TechKO) return; + taskID = Bukkit.getScheduler().scheduleAsyncRepeatingTask(FightSystem.getPlugin(), new Runnable() { + @Override + public void run() { - if(teamRedWater.contains(location)) - teamRedWater.remove(location); - if(teamBlueWater.contains(location)) - teamBlueWater.remove(location); + //Team Red + Iterator itrRed = teamRedWater.iterator(); + while (itrRed.hasNext()) { + Location location = (Location) itrRed.next(); + if(location.getBlock().getType() != Material.WATER && location.getBlock().getType() != Material.STATIONARY_WATER) + itrRed.remove(); + } + if(teamRedWater.isEmpty()) { + Bukkit.broadcastMessage(FightSystem.PREFIX + "6Das Team " + Config.TeamRedPrefix + Config.TeamRedName + " §6ist Tech K.O. !"); + FightSystem.getPlugin().setSpectateState(Fight.getBlueTeam()); + } + + //Team Blue + Iterator itrBlue = teamRedWater.iterator(); + while (itrRed.hasNext()) { + Location location = (Location) itrRed.next(); + if(location.getBlock().getType() != Material.WATER && location.getBlock().getType() != Material.STATIONARY_WATER) + itrRed.remove(); + } + if(teamBlueWater.isEmpty()) { + Bukkit.broadcastMessage(FightSystem.PREFIX + "6Das Team " + Config.TeamBluePrefix + Config.TeamBlueName + " §6ist Tech K.O. !"); + FightSystem.getPlugin().setSpectateState(Fight.getRedTeam()); + } + } + }, 0, 20*20); } }