From 21c6baf40fe33b4ec4027bc39e95a1c08fda1ac0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 23 May 2021 19:23:55 +0200 Subject: [PATCH] Update PercentWincondition Update WinconditionPoints --- .../winconditions/PercentWincondition.java | 5 +++++ .../winconditions/WinconditionPoints.java | 13 +++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java index 5508dae..30a28ca 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java @@ -70,6 +70,10 @@ public abstract class PercentWincondition extends Wincondition implements Printa private final Consumer explodeConsumer; public TeamPercent(PercentWincondition percentWincondition, FightTeam fightTeam, Winconditions wincondition, Predicate testType, Consumer explodeConsumer) { + this(percentWincondition, fightTeam, wincondition, testType, explodeConsumer, () -> {}); + } + + public TeamPercent(PercentWincondition percentWincondition, FightTeam fightTeam, Winconditions wincondition, Predicate testType, Consumer explodeConsumer, Runnable afterEnable) { this.fightTeam = fightTeam; this.testType = testType; this.explodeConsumer = explodeConsumer; @@ -81,6 +85,7 @@ public abstract class PercentWincondition extends Wincondition implements Printa } }); currentBlocks = totalBlocks; + afterEnable.run(); }); new StateDependentListener(wincondition, FightState.Running, this).register(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index c4a3af2..59390ab 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -25,11 +25,9 @@ import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.states.StateDependentCountdown; import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.Bukkit; -import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -41,8 +39,6 @@ import java.util.Map; public class WinconditionPoints extends Wincondition implements PrintableWincondition, Listener { - private static final World world = Bukkit.getWorlds().get(0); - private final Map teamMap = new HashMap<>(); public WinconditionPoints(){ @@ -52,9 +48,6 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond teamMap.put(Fight.getRedTeam(), new TeamPoints(Fight.getRedTeam())); new StateDependentListener(Winconditions.POINTS, FightState.Ingame, this); - new OneShotStateDependent(Winconditions.POINTS, FightState.Ingame, () -> { - teamMap.values().forEach(TeamPoints::enable); - }).register(); if(Config.ActiveWinconditions.contains(Winconditions.POINTS)){ timeOverCountdown = new StateDependentCountdown(Winconditions.POINTS, FightState.Running, new TimeOverCountdown(this::timeOver)); printableWinconditions.add(this); @@ -109,6 +102,7 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond return team.getPrefix() + "Punkte: " + teamMap.get(team).getPoints(); } + private static boolean run = false; private class TeamPoints { private static final int MAX_POINTS = 2000; @@ -120,7 +114,10 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond TeamPoints(FightTeam team){ this.team = team; - this.percent = new PercentWincondition.TeamPercent(null, team, Winconditions.POINTS, material -> true, teamPercent -> {}); + this.percent = new PercentWincondition.TeamPercent(null, team, Winconditions.POINTS, material -> true, teamPercent -> {}, () -> { + if (run) teamMap.values().forEach(TeamPoints::enable); + run = !run; + }); } public void enable() {