diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 1fcf4e8..5f3f2ba 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -26,6 +26,7 @@ import de.steamwar.sql.EventFight; import de.steamwar.sql.Team; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -33,7 +34,12 @@ import org.bukkit.util.Vector; import java.io.File; import java.util.*; +import java.util.function.BiConsumer; +import java.util.function.BinaryOperator; +import java.util.function.Function; +import java.util.function.Supplier; import java.util.logging.Level; +import java.util.stream.Collector; import java.util.stream.Collectors; public class Config { @@ -97,7 +103,7 @@ public class Config { //win condition parameters public static final int TimeoutTime; public static final double PercentWin; - public static final List IgnoredBlocks; + public static final Set Blocks; //default kits public static final String MemberDefault; @@ -186,7 +192,35 @@ public class Config { TimeoutTime = config.getInt("WinConditionParams.TimeoutTime"); PercentWin = config.getDouble("WinConditionParams.PercentWin"); - IgnoredBlocks = Collections.unmodifiableList(config.getStringList("WinConditionParams.IgnoredBlocks")); + Blocks = config.getStringList("WinConditionParams.IgnoredBlocks").stream().map(Material::valueOf).collect(new Collector, Set>() { + @Override + public Supplier> supplier() { + return HashSet::new; + } + + @Override + public BiConsumer, Material> accumulator() { + return HashSet::add; + } + + @Override + public BinaryOperator> combiner() { + return (materials, materials2) -> { + materials.addAll(materials2); + return materials; + }; + } + + @Override + public Function, Set> finisher() { + return Collections::unmodifiableSet; + } + + @Override + public Set characteristics() { + return Collections.emptySet(); + } + }); 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 eacac0b..685166d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java @@ -21,6 +21,15 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.fightsystem.fight.FightTeam; -public interface PercentWincondition { - double getPercent(FightTeam team); +public abstract class PercentWincondition extends Wincondition implements PrintableWincondition { + + protected PercentWincondition(String windescription) { + super(windescription); + } + + public String getDisplay(FightTeam team) { + return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%"; + } + + abstract double getPercent(FightTeam team); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java index 4b4dd1d..f726c9a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java @@ -33,7 +33,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; import java.util.HashMap; import java.util.Map; -public class WinconditionPercentSystem extends Wincondition implements Listener, PrintableWincondition, PercentWincondition { +public class WinconditionPercentSystem extends PercentWincondition implements Listener { private final Map teamMap = new HashMap<>(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java index db34dec..420379f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java @@ -26,23 +26,15 @@ import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import org.bukkit.Bukkit; -import org.bukkit.Material; import org.bukkit.World; import org.bukkit.scheduler.BukkitTask; -import java.util.*; +import java.util.HashMap; +import java.util.Map; -public class WinconditionRelativePercent extends Wincondition implements PrintableWincondition, PercentWincondition { +public class WinconditionRelativePercent extends PercentWincondition { private static final World world = Bukkit.getWorlds().get(0); - private static final Set ignoredBlocks; - - static{ - Set ignored = new HashSet<>(); - for(String s : Config.IgnoredBlocks) - ignored.add(Material.valueOf(s)); - ignoredBlocks = Collections.unmodifiableSet(ignored); - } private final Map teamMap = new HashMap<>(); @@ -121,7 +113,7 @@ public class WinconditionRelativePercent extends Wincondition implements Printab currentBlocks = 0; team.getSchemRegion().forEach((x, y, z) -> { - if(!ignoredBlocks.contains(world.getBlockAt(x,y,z).getType())) + if(!Config.Blocks.contains(world.getBlockAt(x,y,z).getType())) currentBlocks++; }); return currentBlocks; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativeRedstonePercent.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativeRedstonePercent.java index a2da0b8..8f02e11 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativeRedstonePercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativeRedstonePercent.java @@ -7,6 +7,7 @@ import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; @@ -21,19 +22,12 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.scheduler.BukkitTask; -import java.util.*; +import java.util.HashMap; +import java.util.Map; -public class WinconditionRelativeRedstonePercent extends Wincondition implements PrintableWincondition, PercentWincondition, Listener { +public class WinconditionRelativeRedstonePercent extends PercentWincondition implements Listener { private static final World world = Bukkit.getWorlds().get(0); - private static final Set ignoredBlocks; - - static { - Set ignored = new HashSet<>(); - for (String s : Config.IgnoredBlocks) - ignored.add(Material.valueOf(s)); - ignoredBlocks = Collections.unmodifiableSet(ignored); - } private final Map teamMap = new HashMap<>(); @@ -42,10 +36,19 @@ public class WinconditionRelativeRedstonePercent extends Wincondition implements teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam())); teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam())); + new StateDependentListener(Winconditions.RELATIVE_REDSTONE_PERCENT, FightState.Running, this){ + @Override + public void enable() { + super.enable(); + teamMap.forEach((team, percent) -> { + percent.currentBlocks = 0; + }); + } + }; + if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_REDSTONE_PERCENT)) { printableWinconditions.add(this); percentWincondition = this; - Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); } } @@ -131,7 +134,7 @@ public class WinconditionRelativeRedstonePercent extends Wincondition implements private static boolean validBlock(Block block) { Material material = block.getType(); - if (ignoredBlocks.contains(material)) { + if (Config.Blocks.contains(material)) { return false; } BlockData blockData = block.getBlockData();