From 21ff7fddaf906c45022165f13d5c993e5b843326 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 23 May 2021 16:59:56 +0200 Subject: [PATCH] Update PercentWincondition and other --- .../winconditions/PercentWincondition.java | 28 +++++++++++++++++-- .../WinconditionPercentSystem.java | 17 ++++------- .../winconditions/WinconditionPoints.java | 12 +------- .../WinconditionRelativePercent.java | 24 ++++------------ .../WinconditionRelativeWhitelistPercent.java | 24 ++++------------ 5 files changed, 41 insertions(+), 64 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java index 8cce497..5508dae 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java @@ -19,11 +19,14 @@ package de.steamwar.fightsystem.winconditions; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.states.StateDependentListener; +import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; @@ -37,8 +40,13 @@ public abstract class PercentWincondition extends Wincondition implements Printa protected final Map teamMap = new HashMap<>(); - protected PercentWincondition(String windescription) { + protected PercentWincondition(String windescription, Winconditions winconditions) { super(windescription); + + if (Config.ActiveWinconditions.contains(winconditions)) { + printableWinconditions.add(this); + percentWincondition = this; + } } public String getDisplay(FightTeam team) { @@ -51,6 +59,8 @@ public abstract class PercentWincondition extends Wincondition implements Printa public static class TeamPercent implements Listener { + private static final World world = Bukkit.getWorlds().get(0); + public final FightTeam fightTeam; private final Predicate testType; @@ -59,21 +69,33 @@ public abstract class PercentWincondition extends Wincondition implements Printa private final Consumer explodeConsumer; - public TeamPercent(FightTeam fightTeam, Winconditions wincondition, Predicate testType, Consumer enableConsumer, Consumer explodeConsumer) { + public TeamPercent(PercentWincondition percentWincondition, FightTeam fightTeam, Winconditions wincondition, Predicate testType, Consumer explodeConsumer) { this.fightTeam = fightTeam; this.testType = testType; this.explodeConsumer = explodeConsumer; new OneShotStateDependent(wincondition, FightState.Running, () -> { - enableConsumer.accept(TeamPercent.this); + fightTeam.getSchemRegion().forEach((x, y, z) -> { + if (testType.test(world.getBlockAt(x, y, z).getType())) { + totalBlocks++; + } + }); currentBlocks = totalBlocks; }); new StateDependentListener(wincondition, FightState.Running, this).register(); + if (percentWincondition != null) { + percentWincondition.teamMap.put(fightTeam, this); + } } @EventHandler public void onEntityExplode(EntityExplodeEvent event) { + // Entern active + if (!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft()) { + return; + } + if (!fightTeam.getExtendRegion().inRegion(event.getEntity().getLocation())) { return; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java index aee2740..f58ba42 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java @@ -28,20 +28,13 @@ import org.bukkit.Bukkit; public class WinconditionPercentSystem extends PercentWincondition { public WinconditionPercentSystem() { - super("Percent"); - teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam())); - teamMap.put(Fight.getRedTeam(), create(Fight.getRedTeam())); - - if (Config.ActiveWinconditions.contains(Winconditions.PERCENT_SYSTEM)) { - printableWinconditions.add(this); - percentWincondition = this; - } + super("Percent", Winconditions.PERCENT_SYSTEM); + create(Fight.getBlueTeam()); + create(Fight.getRedTeam()); } - private TeamPercent create(FightTeam fightTeam) { - return new TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> true, teamPercent -> { - teamPercent.totalBlocks = teamPercent.fightTeam.getSchemRegion().volume(); - }, teamPercent -> { + private void create(FightTeam fightTeam) { + new TeamPercent(this, fightTeam, Winconditions.PERCENT_SYSTEM, material -> true, teamPercent -> { if (teamPercent.getPercent() >= Config.PercentWin) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!"); win(Fight.getOpposite(teamPercent.fightTeam)); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index 11083b3..c4a3af2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -38,7 +38,6 @@ import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; public class WinconditionPoints extends Wincondition implements PrintableWincondition, Listener { @@ -121,16 +120,7 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond TeamPoints(FightTeam team){ this.team = team; - this.percent = new PercentWincondition.TeamPercent(team, Winconditions.POINTS, material -> true, teamPercent -> { - this.points = 0; - AtomicInteger currentBlocks = new AtomicInteger(); - teamPercent.fightTeam.getSchemRegion().forEach((x, y, z) -> { - if (!Config.Blocks.contains(world.getBlockAt(x, y, z).getType())) { - currentBlocks.getAndIncrement(); - } - }); - teamPercent.totalBlocks = currentBlocks.get(); - }, teamPercent -> {}); + this.percent = new PercentWincondition.TeamPercent(null, team, Winconditions.POINTS, material -> true, teamPercent -> {}); } public void enable() { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java index 0f833a2..69fd28a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java @@ -24,32 +24,18 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import org.bukkit.Bukkit; -import org.bukkit.World; public class WinconditionRelativePercent extends PercentWincondition { - private static final World world = Bukkit.getWorlds().get(0); - public WinconditionRelativePercent() { - super("RelativePercent"); - teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam())); - teamMap.put(Fight.getRedTeam(), create(Fight.getRedTeam())); - - if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT)) { - printableWinconditions.add(this); - percentWincondition = this; - } + super("RelativePercent", Winconditions.RELATIVE_PERCENT); + create(Fight.getBlueTeam()); + create(Fight.getRedTeam()); } - private PercentWincondition.TeamPercent create(FightTeam fightTeam) { - return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> { + private void create(FightTeam fightTeam) { + new TeamPercent(this, fightTeam, Winconditions.RELATIVE_WHITELIST_PERCENT, material -> { return !Config.Blocks.contains(material); - }, teamPercent -> { - teamPercent.fightTeam.getSchemRegion().forEach((x, y, z) -> { - if (!Config.Blocks.contains(world.getBlockAt(x, y, z).getType())) { - teamPercent.totalBlocks++; - } - }); }, teamPercent -> { if (teamPercent.getPercent() >= Config.PercentWin) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!"); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativeWhitelistPercent.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativeWhitelistPercent.java index fcd9acf..ce1ef28 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativeWhitelistPercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativeWhitelistPercent.java @@ -24,33 +24,19 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import org.bukkit.Bukkit; -import org.bukkit.World; import org.bukkit.event.Listener; public class WinconditionRelativeWhitelistPercent extends PercentWincondition implements Listener { - private static final World world = Bukkit.getWorlds().get(0); - public WinconditionRelativeWhitelistPercent() { - super("RelativeWhitelistPercent"); - teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam())); - teamMap.put(Fight.getRedTeam(), create(Fight.getRedTeam())); - - if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_WHITELIST_PERCENT)) { - printableWinconditions.add(this); - percentWincondition = this; - } + super("RelativeWhitelistPercent", Winconditions.RELATIVE_WHITELIST_PERCENT); + create(Fight.getBlueTeam()); + create(Fight.getRedTeam()); } - private PercentWincondition.TeamPercent create(FightTeam fightTeam) { - return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> { + private void create(FightTeam fightTeam) { + new PercentWincondition.TeamPercent(this, fightTeam, Winconditions.RELATIVE_WHITELIST_PERCENT, material -> { return Config.Blocks.contains(material); - }, teamPercent -> { - teamPercent.fightTeam.getSchemRegion().forEach((x, y, z) -> { - if (Config.Blocks.contains(world.getBlockAt(x, y, z).getType())) { - teamPercent.totalBlocks++; - } - }); }, teamPercent -> { if (teamPercent.getPercent() >= Config.PercentWin) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");