From 0a45b161a2c2abf945775718393d642289603827 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 12 Dec 2023 00:10:05 +0100 Subject: [PATCH] Simplify percent system by adding entern percent and whitelist config toggles Signed-off-by: Lixfel --- FightSystem_Core/src/config.yml | 6 ++-- .../src/de/steamwar/fightsystem/Config.java | 4 +++ .../de/steamwar/fightsystem/FightSystem.java | 4 +-- .../winconditions/Wincondition.java | 4 +-- .../WinconditionBlacklistPercent.java | 27 --------------- ...ondition.java => WinconditionPercent.java} | 34 +++++++------------ .../WinconditionPercentSystem.java | 30 ---------------- .../winconditions/WinconditionPoints.java | 4 +-- .../WinconditionPointsAirShip.java | 4 +-- .../WinconditionWhitelistPercent.java | 31 ----------------- .../winconditions/Winconditions.java | 2 -- 11 files changed, 28 insertions(+), 122 deletions(-) delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlacklistPercent.java rename FightSystem_Core/src/de/steamwar/fightsystem/winconditions/{PercentWincondition.java => WinconditionPercent.java} (74%) delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWhitelistPercent.java diff --git a/FightSystem_Core/src/config.yml b/FightSystem_Core/src/config.yml index 408c546..ca3645d 100644 --- a/FightSystem_Core/src/config.yml +++ b/FightSystem_Core/src/config.yml @@ -114,8 +114,6 @@ WinConditions: # defaults to none if missing # - CAPTAIN_DEAD # - PERCENT_SYSTEM - # - WHITELIST_PERCENT - # - RELATIVE_PERCENT # - POINTS # - POINTS_AIRSHIP @@ -133,6 +131,10 @@ WinConditionParams: TimeoutTime: 1200 # defaults to 1200 if missing # The percentage when any of the percent win conditions limits or triggers a win PercentWin: 7.0 # defaults to 7.0 if missing + # Does the percentage still change after the start of the enter phase + PercentEntern: true # defaults to true if missing + # Is Blocks a whitelist (true) or blacklist (false) + BlocksWhitelist: false # defaults to false if missing # Special Blocks (Valid spigot material values) used by the percent win conditions Blocks: [] # defaults to none if missing diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 656c994..331491f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -107,6 +107,8 @@ public class Config { //win condition parameters public static final int TimeoutTime; public static final double PercentWin; + public static final boolean PercentEntern; + public static final boolean PercentBlocksWhitelist; public static final Set PercentBlocks; //default kits @@ -197,6 +199,8 @@ public class Config { TimeoutTime = config.getInt("WinConditionParams.TimeoutTime", 1200); PercentWin = config.getDouble("WinConditionParams.PercentWin", 7.0); + PercentEntern = config.getBoolean("WinConditionParams.PercentEntern", true); + PercentBlocksWhitelist = config.getBoolean("WinConditionParams.BlocksWhitelist", false); PercentBlocks = Collections.unmodifiableSet(config.getStringList("WinConditionParams.Blocks").stream().map(Material::valueOf).collect(Collectors.toSet())); EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages")); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 3c10d4f..d56d7d9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -118,9 +118,7 @@ public class FightSystem extends JavaPlugin { new WinconditionCaptainDead(); new WinconditionBlocks(Winconditions.WATER_TECH_KO, "WaterTechKO", "BAR_WATER", FlatteningWrapper.impl::isWater); new WinconditionBlocks(Winconditions.PUMPKIN_TECH_KO, "PumpkinTechKO", "BAR_CANNONS", block -> block.getType() == WinconditionBlocks.PUMPKIN_LANTERN); - new WinconditionPercentSystem(); - new WinconditionBlacklistPercent(); - new WinconditionWhitelistPercent(); + new WinconditionPercent(Winconditions.PERCENT_SYSTEM, "Percent"); new WinconditionPoints(); new WinconditionPointsAirShip(); new WinconditionTimeout(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java index 8e6e283..3f0f58e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java @@ -34,7 +34,7 @@ import java.util.stream.Collectors; public abstract class Wincondition { - protected static PercentWincondition percentWincondition = null; + protected static WinconditionPercent percentWincondition = null; protected static StateDependentCountdown timeOverCountdown = null; protected static final List printableWinconditions = new ArrayList<>(); @@ -65,7 +65,7 @@ public abstract class Wincondition { return printableWinconditions; } - public static PercentWincondition getPercentWincondition() { + public static WinconditionPercent getPercentWincondition() { return percentWincondition; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlacklistPercent.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlacklistPercent.java deleted file mode 100644 index a823079..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlacklistPercent.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.fightsystem.winconditions; - -public class WinconditionBlacklistPercent extends PercentWincondition { - - public WinconditionBlacklistPercent(){ - super("RelativePercent", Winconditions.RELATIVE_PERCENT); - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercent.java similarity index 74% rename from FightSystem_Core/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercent.java index 40b227f..4b7839a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercent.java @@ -26,7 +26,6 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.Message; -import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -34,27 +33,12 @@ import org.bukkit.event.entity.EntityExplodeEvent; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.BooleanSupplier; import java.util.function.Consumer; -import java.util.function.Predicate; -import java.util.function.ToIntFunction; -public class PercentWincondition extends Wincondition implements PrintableWincondition { +public class WinconditionPercent extends Wincondition implements PrintableWincondition { private final Map teamMap = new HashMap<>(); - protected BooleanSupplier explosionFilter = () -> !Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft(); - protected Predicate testBlock = type -> !Config.PercentBlocks.contains(type); - protected ToIntFunction totalBlockCalc = team -> { - AtomicInteger blocks = new AtomicInteger(); - team.getSchemRegion().forEach((x, y, z) -> { - if (testBlock.test(Config.world.getBlockAt(x, y, z).getType())) { - blocks.getAndIncrement(); - } - }); - return blocks.get(); - }; protected Consumer checkWin = team -> { if (getPercent(team) >= Config.PercentWin) { win(Fight.getOpposite(team), "WIN_PERCENT", team.getColoredName()); @@ -62,7 +46,7 @@ public class PercentWincondition extends Wincondition implements PrintableWincon }; protected Consumer postEnable = team -> {}; - public PercentWincondition(String windescription, Winconditions wincondition) { + public WinconditionPercent(Winconditions wincondition, String windescription) { super(windescription); if (Config.ActiveWinconditions.contains(wincondition)) { @@ -105,12 +89,16 @@ public class PercentWincondition extends Wincondition implements PrintableWincon @EventHandler public void onEntityExplode(EntityExplodeEvent event) { - if (event.getEntityType() == EntityType.FIREBALL || explosionFilter.getAsBoolean() || !team.getExtendRegion().inRegion(event.getEntity().getLocation())) { + if ( + event.getEntityType() == EntityType.FIREBALL || + !team.getExtendRegion().inRegion(event.getEntity().getLocation()) || + (!Config.PercentEntern && !Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft()) + ) { return; } event.blockList().forEach(block -> { - if (testBlock.test(block.getType())) { + if (Config.PercentBlocks.contains(block.getType()) == Config.PercentBlocksWhitelist) { currentBlocks--; } }); @@ -119,7 +107,11 @@ public class PercentWincondition extends Wincondition implements PrintableWincon } private void enable() { - totalBlocks = totalBlockCalc.applyAsInt(team); + totalBlocks = 0; + team.getSchemRegion().forEach((x, y, z) -> { + if (Config.PercentBlocks.contains(Config.world.getBlockAt(x, y, z).getType()) == Config.PercentBlocksWhitelist) + totalBlocks++; + }); currentBlocks = totalBlocks; postEnable.accept(team); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java deleted file mode 100644 index 6be7476..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.fightsystem.winconditions; - -public class WinconditionPercentSystem extends PercentWincondition { - - public WinconditionPercentSystem() { - super("Percent", Winconditions.PERCENT_SYSTEM); - - totalBlockCalc = team -> team.getSchemRegion().volume(); - explosionFilter = () -> false; - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index 2d0396d..028e893 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -36,12 +36,12 @@ import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashMap; import java.util.Map; -public class WinconditionPoints extends PercentWincondition implements Listener { +public class WinconditionPoints extends WinconditionPercent implements Listener { private final Map teamMap = new HashMap<>(); public WinconditionPoints(){ - super("Points", Winconditions.POINTS); + super(Winconditions.POINTS, "Points"); checkWin = team -> {}; postEnable = this::pointInit; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPointsAirShip.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPointsAirShip.java index 124ed14..4f166a6 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPointsAirShip.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPointsAirShip.java @@ -35,7 +35,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; -public class WinconditionPointsAirShip extends PercentWincondition implements Listener { +public class WinconditionPointsAirShip extends WinconditionPercent implements Listener { private double[] as = new double[] { 0.5, @@ -56,7 +56,7 @@ public class WinconditionPointsAirShip extends PercentWincondition implements Li private final Map teamMap = new HashMap<>(); public WinconditionPointsAirShip(){ - super("Points", Winconditions.POINTS_AIRSHIP); + super(Winconditions.POINTS_AIRSHIP, "Points"); checkWin = team -> { if (teamMap.get(team).getPoints() > TeamPoints.WIN_POINTS) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWhitelistPercent.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWhitelistPercent.java deleted file mode 100644 index 6607173..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWhitelistPercent.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - */ - -package de.steamwar.fightsystem.winconditions; - -import de.steamwar.fightsystem.Config; - -public class WinconditionWhitelistPercent extends PercentWincondition { - - public WinconditionWhitelistPercent() { - super("WhitelistPercent", Winconditions.WHITELIST_PERCENT); - - testBlock = Config.PercentBlocks::contains; - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java index fa91d9c..296cf97 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Winconditions.java @@ -28,8 +28,6 @@ public enum Winconditions { CAPTAIN_DEAD, PERCENT_SYSTEM, - WHITELIST_PERCENT, - RELATIVE_PERCENT, POINTS, POINTS_AIRSHIP,