RedstoneWincondition #274
@ -19,11 +19,14 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.Config;
|
||||||
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.OneShotStateDependent;
|
import de.steamwar.fightsystem.states.OneShotStateDependent;
|
||||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
@ -37,8 +40,13 @@ public abstract class PercentWincondition extends Wincondition implements Printa
|
|||||||
|
|
||||||
protected final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
protected final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
||||||
|
|
||||||
protected PercentWincondition(String windescription) {
|
protected PercentWincondition(String windescription, Winconditions winconditions) {
|
||||||
super(windescription);
|
super(windescription);
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
|
|||||||
|
|
||||||
|
if (Config.ActiveWinconditions.contains(winconditions)) {
|
||||||
|
printableWinconditions.add(this);
|
||||||
|
percentWincondition = this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDisplay(FightTeam team) {
|
public String getDisplay(FightTeam team) {
|
||||||
@ -51,6 +59,8 @@ public abstract class PercentWincondition extends Wincondition implements Printa
|
|||||||
|
|
||||||
public static class TeamPercent implements Listener {
|
public static class TeamPercent implements Listener {
|
||||||
|
|
||||||
|
private static final World world = Bukkit.getWorlds().get(0);
|
||||||
|
|
||||||
public final FightTeam fightTeam;
|
public final FightTeam fightTeam;
|
||||||
private final Predicate<Material> testType;
|
private final Predicate<Material> testType;
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
OneShotStateDependents werden schon im Konstruktor registered, bitte nicht dopplet registern. OneShotStateDependents werden schon im Konstruktor registered, bitte nicht dopplet registern.
|
|||||||
|
|
||||||
@ -59,21 +69,33 @@ public abstract class PercentWincondition extends Wincondition implements Printa
|
|||||||
|
|
||||||
private final Consumer<TeamPercent> explodeConsumer;
|
private final Consumer<TeamPercent> explodeConsumer;
|
||||||
|
|
||||||
public TeamPercent(FightTeam fightTeam, Winconditions wincondition, Predicate<Material> testType, Consumer<TeamPercent> enableConsumer, Consumer<TeamPercent> explodeConsumer) {
|
public TeamPercent(PercentWincondition percentWincondition, FightTeam fightTeam, Winconditions wincondition, Predicate<Material> testType, Consumer<TeamPercent> explodeConsumer) {
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Hier am Ende des Konstruktors würde ich gleich dieses TeamPercent in die teamMap einfügen, dann musst du das nicht an den ganzen anderen Stellen machen (und kannst es nicht vergessen) Hier am Ende des Konstruktors würde ich gleich dieses TeamPercent in die teamMap einfügen, dann musst du das nicht an den ganzen anderen Stellen machen (und kannst es nicht vergessen)
|
|||||||
this.fightTeam = fightTeam;
|
this.fightTeam = fightTeam;
|
||||||
this.testType = testType;
|
this.testType = testType;
|
||||||
this.explodeConsumer = explodeConsumer;
|
this.explodeConsumer = explodeConsumer;
|
||||||
|
|
||||||
new OneShotStateDependent(wincondition, FightState.Running, () -> {
|
new OneShotStateDependent(wincondition, FightState.Running, () -> {
|
||||||
enableConsumer.accept(TeamPercent.this);
|
fightTeam.getSchemRegion().forEach((x, y, z) -> {
|
||||||
|
if (testType.test(world.getBlockAt(x, y, z).getType())) {
|
||||||
|
totalBlocks++;
|
||||||
|
}
|
||||||
|
});
|
||||||
currentBlocks = totalBlocks;
|
currentBlocks = totalBlocks;
|
||||||
});
|
});
|
||||||
|
|
||||||
new StateDependentListener(wincondition, FightState.Running, this).register();
|
new StateDependentListener(wincondition, FightState.Running, this).register();
|
||||||
|
if (percentWincondition != null) {
|
||||||
|
percentWincondition.teamMap.put(fightTeam, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
|
// Entern active
|
||||||
|
if (!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!fightTeam.getExtendRegion().inRegion(event.getEntity().getLocation())) {
|
if (!fightTeam.getExtendRegion().inRegion(event.getEntity().getLocation())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -28,20 +28,13 @@ import org.bukkit.Bukkit;
|
|||||||
public class WinconditionPercentSystem extends PercentWincondition {
|
public class WinconditionPercentSystem extends PercentWincondition {
|
||||||
|
|
||||||
public WinconditionPercentSystem() {
|
public WinconditionPercentSystem() {
|
||||||
super("Percent");
|
super("Percent", Winconditions.PERCENT_SYSTEM);
|
||||||
teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam()));
|
create(Fight.getBlueTeam());
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Ist kein Listener mehr. Ist kein Listener mehr.
|
|||||||
teamMap.put(Fight.getRedTeam(), create(Fight.getRedTeam()));
|
create(Fight.getRedTeam());
|
||||||
|
|
||||||
if (Config.ActiveWinconditions.contains(Winconditions.PERCENT_SYSTEM)) {
|
|
||||||
printableWinconditions.add(this);
|
|
||||||
percentWincondition = this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private TeamPercent create(FightTeam fightTeam) {
|
private void create(FightTeam fightTeam) {
|
||||||
return new TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> true, teamPercent -> {
|
new TeamPercent(this, fightTeam, Winconditions.PERCENT_SYSTEM, material -> true, teamPercent -> {
|
||||||
teamPercent.totalBlocks = teamPercent.fightTeam.getSchemRegion().volume();
|
|
||||||
}, teamPercent -> {
|
|
||||||
if (teamPercent.getPercent() >= Config.PercentWin) {
|
if (teamPercent.getPercent() >= Config.PercentWin) {
|
||||||
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.
|
|||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||||
win(Fight.getOpposite(teamPercent.fightTeam));
|
win(Fight.getOpposite(teamPercent.fightTeam));
|
||||||
|
@ -38,7 +38,6 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
public class WinconditionPoints extends Wincondition implements PrintableWincondition, Listener {
|
public class WinconditionPoints extends Wincondition implements PrintableWincondition, Listener {
|
||||||
|
|
||||||
@ -121,16 +120,7 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond
|
|||||||
|
|
||||||
TeamPoints(FightTeam team){
|
TeamPoints(FightTeam team){
|
||||||
this.team = team;
|
this.team = team;
|
||||||
this.percent = new PercentWincondition.TeamPercent(team, Winconditions.POINTS, material -> true, teamPercent -> {
|
this.percent = new PercentWincondition.TeamPercent(null, team, Winconditions.POINTS, material -> true, teamPercent -> {});
|
||||||
this.points = 0;
|
|
||||||
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 = currentBlocks.get();
|
|
||||||
}, teamPercent -> {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enable() {
|
public void enable() {
|
||||||
|
@ -24,32 +24,18 @@ import de.steamwar.fightsystem.FightSystem;
|
|||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
|
||||||
|
|
||||||
public class WinconditionRelativePercent extends PercentWincondition {
|
public class WinconditionRelativePercent extends PercentWincondition {
|
||||||
|
|
||||||
private static final World world = Bukkit.getWorlds().get(0);
|
|
||||||
|
|
||||||
public WinconditionRelativePercent() {
|
public WinconditionRelativePercent() {
|
||||||
super("RelativePercent");
|
super("RelativePercent", Winconditions.RELATIVE_PERCENT);
|
||||||
teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam()));
|
create(Fight.getBlueTeam());
|
||||||
teamMap.put(Fight.getRedTeam(), create(Fight.getRedTeam()));
|
create(Fight.getRedTeam());
|
||||||
|
|
||||||
if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT)) {
|
|
||||||
printableWinconditions.add(this);
|
|
||||||
percentWincondition = this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private PercentWincondition.TeamPercent create(FightTeam fightTeam) {
|
private void create(FightTeam fightTeam) {
|
||||||
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 :)
|
|||||||
return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> {
|
new TeamPercent(this, fightTeam, Winconditions.RELATIVE_WHITELIST_PERCENT, material -> {
|
||||||
return !Config.Blocks.contains(material);
|
return !Config.Blocks.contains(material);
|
||||||
}, teamPercent -> {
|
|
||||||
teamPercent.fightTeam.getSchemRegion().forEach((x, y, z) -> {
|
|
||||||
if (!Config.Blocks.contains(world.getBlockAt(x, y, z).getType())) {
|
|
||||||
teamPercent.totalBlocks++;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, teamPercent -> {
|
}, teamPercent -> {
|
||||||
if (teamPercent.getPercent() >= Config.PercentWin) {
|
if (teamPercent.getPercent() >= Config.PercentWin) {
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||||
|
@ -24,33 +24,19 @@ import de.steamwar.fightsystem.FightSystem;
|
|||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
public class WinconditionRelativeWhitelistPercent extends PercentWincondition implements Listener {
|
public class WinconditionRelativeWhitelistPercent extends PercentWincondition implements Listener {
|
||||||
|
|
||||||
private static final World world = Bukkit.getWorlds().get(0);
|
|
||||||
|
|
||||||
public WinconditionRelativeWhitelistPercent() {
|
public WinconditionRelativeWhitelistPercent() {
|
||||||
super("RelativeWhitelistPercent");
|
super("RelativeWhitelistPercent", Winconditions.RELATIVE_WHITELIST_PERCENT);
|
||||||
teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam()));
|
create(Fight.getBlueTeam());
|
||||||
teamMap.put(Fight.getRedTeam(), create(Fight.getRedTeam()));
|
create(Fight.getRedTeam());
|
||||||
|
|
||||||
if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_WHITELIST_PERCENT)) {
|
|
||||||
printableWinconditions.add(this);
|
|
||||||
percentWincondition = this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private PercentWincondition.TeamPercent create(FightTeam fightTeam) {
|
private void create(FightTeam fightTeam) {
|
||||||
return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> {
|
new PercentWincondition.TeamPercent(this, fightTeam, Winconditions.RELATIVE_WHITELIST_PERCENT, material -> {
|
||||||
return Config.Blocks.contains(material);
|
return Config.Blocks.contains(material);
|
||||||
}, teamPercent -> {
|
|
||||||
teamPercent.fightTeam.getSchemRegion().forEach((x, y, z) -> {
|
|
||||||
if (Config.Blocks.contains(world.getBlockAt(x, y, z).getType())) {
|
|
||||||
teamPercent.totalBlocks++;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, teamPercent -> {
|
}, teamPercent -> {
|
||||||
if (teamPercent.getPercent() >= Config.PercentWin) {
|
if (teamPercent.getPercent() >= Config.PercentWin) {
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Jeder Prozentmodus braucht irgendwo beide Teams, die Map FightTeam -> TeamPercent müsste daher hierher abstrahierbar sein.
Aka: Die Teammap schon hier in PercentWincondition zur Verfügung stellen und füllen (parameter im Konstruktor übergeben lassen), getPercent gleich hier implementieren.
In der PointWincondition hast du dann einfach noch eine zweite Map