RedstoneWincondition #274
@ -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();
|
||||||
|
}
|
||||||
|
});
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
|
|||||||
|
|
||||||
EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages"));
|
EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages"));
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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<>();
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Dieser Codeblock sollte in die PercentWincondition verschoben werden (und dann aus den Subklassen entfernt werden). Points braucht ja nur ein @Override getDisplay Dieser Codeblock sollte in die PercentWincondition verschoben werden (und dann aus den Subklassen entfernt werden). Points braucht ja nur ein @Override getDisplay
YoyoNow
hat
Kannst du mir das nochmal genauer erklären? Kannst du mir das nochmal genauer erklären?
Lixfel
hat
Diesen if-Block kannst du so in den Konstruktor der PercentWincondition verschieben. Diesen if-Block kannst du so in den Konstruktor der PercentWincondition verschieben.
|
|||||||
|
|
||||||
|
@ -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);
|
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
WÜrde empfehlen, in der COnfig diesen Codeblock zu verwenden, 4 Zeilen sind da etwas kürzer :) WÜrde empfehlen, in der COnfig diesen Codeblock zu verwenden, 4 Zeilen sind da etwas kürzer :)
|
|||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
|
@ -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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Bitte einen StateDependentListener verwenden. Bitte einen StateDependentListener verwenden.
YoyoNow
hat
Kann ich aber nicht hier in der Klasse machen, weil 2 mal Extend wird wohl nichts! Kann ich aber nicht hier in der Klasse machen, weil 2 mal Extend wird wohl nichts!
|
|||||||
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
|
|||||||
|
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Es wird nur eine Auswahl an Blöcken erfasst, aber dann gibt es nochmal extra ignorierte Blöcke?!? Bitte was? Es wäre evtl. am besten (und konfiurabelsten) die ignoredBlocks-Liste als die Liste der Blöcke, die gewertet wird, zu verwenden. Es wird nur eine Auswahl an Blöcken erfasst, aber dann gibt es nochmal extra ignorierte Blöcke?!? Bitte was?
Es wäre evtl. am besten (und konfiurabelsten) die ignoredBlocks-Liste als die Liste der Blöcke, die gewertet wird, zu verwenden.
|
|||||||
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();
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
30+ Zeilen sind definitiv zu viel für so eine simple Sache. Bitte den Code kürzer/präziser machen.