From 0b78786bc2be7bb0bc7b964b52f51a4331c5cde9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 22 May 2021 15:39:51 +0200 Subject: [PATCH] Update PercentWincondition and other --- .../src/de/steamwar/fightsystem/Config.java | 2 +- .../winconditions/PercentWincondition.java | 17 ++++++---- .../WinconditionPercentSystem.java | 13 +------ .../winconditions/WinconditionPoints.java | 4 +-- .../WinconditionRelativePercent.java | 15 +------- .../WinconditionRelativeWhitelistPercent.java | 34 +++++++++++-------- 6 files changed, 35 insertions(+), 50 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 55cccf3..9156fba 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -192,7 +192,7 @@ public class Config { TimeoutTime = config.getInt("WinConditionParams.TimeoutTime"); PercentWin = config.getDouble("WinConditionParams.PercentWin"); - Blocks = config.getStringList("WinConditionParams.IgnoredBlocks").stream().map(Material::valueOf).collect(Collectors.toSet()); + Blocks = Collections.unmodifiableSet(config.getStringList("WinConditionParams.IgnoredBlocks").stream().map(Material::valueOf).collect(Collectors.toSet())); EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages")); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java index 43aeef7..8cce497 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java @@ -28,11 +28,15 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; +import java.util.HashMap; +import java.util.Map; import java.util.function.Consumer; import java.util.function.Predicate; public abstract class PercentWincondition extends Wincondition implements PrintableWincondition { + protected final Map teamMap = new HashMap<>(); + protected PercentWincondition(String windescription) { super(windescription); } @@ -41,18 +45,19 @@ public abstract class PercentWincondition extends Wincondition implements Printa return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%"; } - abstract double getPercent(FightTeam team); - + public double getPercent(FightTeam team) { + return teamMap.get(team).getPercent(); + } public static class TeamPercent implements Listener { - public FightTeam fightTeam; - private Predicate testType; + public final FightTeam fightTeam; + private final Predicate testType; public int totalBlocks = 0; private int currentBlocks = 0; - private Consumer explodeConsumer; + private final Consumer explodeConsumer; public TeamPercent(FightTeam fightTeam, Winconditions wincondition, Predicate testType, Consumer enableConsumer, Consumer explodeConsumer) { this.fightTeam = fightTeam; @@ -62,7 +67,7 @@ public abstract class PercentWincondition extends Wincondition implements Printa new OneShotStateDependent(wincondition, FightState.Running, () -> { enableConsumer.accept(TeamPercent.this); currentBlocks = totalBlocks; - }).register(); + }); new StateDependentListener(wincondition, FightState.Running, this).register(); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java index 307bb7d..aee2740 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java @@ -24,14 +24,8 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import org.bukkit.Bukkit; -import org.bukkit.event.Listener; -import java.util.HashMap; -import java.util.Map; - -public class WinconditionPercentSystem extends PercentWincondition implements Listener { - - private final Map teamMap = new HashMap<>(); +public class WinconditionPercentSystem extends PercentWincondition { public WinconditionPercentSystem() { super("Percent"); @@ -54,9 +48,4 @@ public class WinconditionPercentSystem extends PercentWincondition implements Li } }); } - - @Override - public double getPercent(FightTeam team) { - return teamMap.get(team).getPercent(); - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index 548d0b1..11083b3 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -130,9 +130,7 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond } }); teamPercent.totalBlocks = currentBlocks.get(); - }, teamPercent -> { - - }); + }, 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 ddf2e9c..0f833a2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java @@ -26,16 +26,10 @@ import de.steamwar.fightsystem.fight.FightTeam; import org.bukkit.Bukkit; import org.bukkit.World; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; - public class WinconditionRelativePercent extends PercentWincondition { private static final World world = Bukkit.getWorlds().get(0); - private final Map teamMap = new HashMap<>(); - public WinconditionRelativePercent() { super("RelativePercent"); teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam())); @@ -47,22 +41,15 @@ public class WinconditionRelativePercent extends PercentWincondition { } } - @Override - public double getPercent(FightTeam team) { - return teamMap.get(team).getPercent(); - } - private PercentWincondition.TeamPercent create(FightTeam fightTeam) { return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> { return !Config.Blocks.contains(material); }, teamPercent -> { - 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++; } }); - teamPercent.totalBlocks = currentBlocks.get(); }, 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 71f9ea0..fcd9acf 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativeWhitelistPercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativeWhitelistPercent.java @@ -1,3 +1,22 @@ +/* + 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; import de.steamwar.fightsystem.Config; @@ -8,16 +27,10 @@ import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.event.Listener; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; - public class WinconditionRelativeWhitelistPercent extends PercentWincondition implements Listener { private static final World world = Bukkit.getWorlds().get(0); - private final Map teamMap = new HashMap<>(); - public WinconditionRelativeWhitelistPercent() { super("RelativeWhitelistPercent"); teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam())); @@ -29,22 +42,15 @@ public class WinconditionRelativeWhitelistPercent extends PercentWincondition im } } - @Override - public double getPercent(FightTeam team) { - return teamMap.get(team).getPercent(); - } - private PercentWincondition.TeamPercent create(FightTeam fightTeam) { return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> { return Config.Blocks.contains(material); }, teamPercent -> { - 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++; } }); - teamPercent.totalBlocks = currentBlocks.get(); }, teamPercent -> { if (teamPercent.getPercent() >= Config.PercentWin) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");