SteamWar/FightSystem
Archiviert
13
1
Update PercentWincondition
Dieser Commit ist enthalten in:
yoyosource 2021-05-13 12:52:26 +02:00
Ursprung 784bd88e43
Commit c37abd7d54
5 geänderte Dateien mit 67 neuen und 29 gelöschten Zeilen

Datei anzeigen

@ -26,6 +26,7 @@ import de.steamwar.sql.EventFight;
import de.steamwar.sql.Team; import de.steamwar.sql.Team;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -33,7 +34,12 @@ import org.bukkit.util.Vector;
import java.io.File; import java.io.File;
import java.util.*; 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.logging.Level;
import java.util.stream.Collector;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class Config { public class Config {
@ -97,7 +103,7 @@ public class Config {
//win condition parameters //win condition parameters
public static final int TimeoutTime; public static final int TimeoutTime;
public static final double PercentWin; public static final double PercentWin;
public static final List<String> IgnoredBlocks; public static final Set<Material> Blocks;
//default kits //default kits
public static final String MemberDefault; public static final String MemberDefault;
@ -186,7 +192,35 @@ public class Config {
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime"); TimeoutTime = config.getInt("WinConditionParams.TimeoutTime");
PercentWin = config.getDouble("WinConditionParams.PercentWin"); PercentWin = config.getDouble("WinConditionParams.PercentWin");
IgnoredBlocks = Collections.unmodifiableList(config.getStringList("WinConditionParams.IgnoredBlocks")); Blocks = config.getStringList("WinConditionParams.IgnoredBlocks").stream().map(Material::valueOf).collect(new Collector<Material, HashSet<Material>, Set<Material>>() {
@Override
public Supplier<HashSet<Material>> supplier() {
return HashSet::new;
}
@Override
public BiConsumer<HashSet<Material>, Material> accumulator() {
return HashSet::add;
}
@Override
public BinaryOperator<HashSet<Material>> combiner() {
return (materials, materials2) -> {
materials.addAll(materials2);
return materials;
};
}
@Override
public Function<HashSet<Material>, Set<Material>> finisher() {
return Collections::unmodifiableSet;
}
@Override
public Set<Characteristics> characteristics() {
return Collections.emptySet();
}
});
EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages")); EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages"));

Datei anzeigen

@ -21,6 +21,15 @@ package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
public interface PercentWincondition { public abstract class PercentWincondition extends Wincondition implements PrintableWincondition {
double getPercent(FightTeam team);
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);
} }

Datei anzeigen

@ -33,7 +33,7 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class WinconditionPercentSystem extends Wincondition implements Listener, PrintableWincondition, PercentWincondition { public class WinconditionPercentSystem extends PercentWincondition implements Listener {
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>(); private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();

Datei anzeigen

@ -26,23 +26,15 @@ import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.scheduler.BukkitTask; 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 World world = Bukkit.getWorlds().get(0);
private static final Set<Material> ignoredBlocks;
static{
Set<Material> ignored = new HashSet<>();
for(String s : Config.IgnoredBlocks)
ignored.add(Material.valueOf(s));
ignoredBlocks = Collections.unmodifiableSet(ignored);
}
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>(); private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
@ -121,7 +113,7 @@ public class WinconditionRelativePercent extends Wincondition implements Printab
currentBlocks = 0; currentBlocks = 0;
team.getSchemRegion().forEach((x, y, z) -> { 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++; currentBlocks++;
}); });
return currentBlocks; return currentBlocks;

Datei anzeigen

@ -7,6 +7,7 @@ import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependent;
import de.steamwar.fightsystem.states.StateDependentListener;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
@ -21,19 +22,12 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.scheduler.BukkitTask; 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 World world = Bukkit.getWorlds().get(0);
private static final Set<Material> ignoredBlocks;
static {
Set<Material> ignored = new HashSet<>();
for (String s : Config.IgnoredBlocks)
ignored.add(Material.valueOf(s));
ignoredBlocks = Collections.unmodifiableSet(ignored);
}
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>(); private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
@ -42,10 +36,19 @@ public class WinconditionRelativeRedstonePercent extends Wincondition implements
teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam())); teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam()));
teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam())); 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)) { if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_REDSTONE_PERCENT)) {
printableWinconditions.add(this); printableWinconditions.add(this);
percentWincondition = 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) { private static boolean validBlock(Block block) {
Material material = block.getType(); Material material = block.getType();
if (ignoredBlocks.contains(material)) { if (Config.Blocks.contains(material)) {
return false; return false;
} }
BlockData blockData = block.getBlockData(); BlockData blockData = block.getBlockData();