SteamWar/FightSystem
Archiviert
13
1

Update PercentWincondition and other

Dieser Commit ist enthalten in:
yoyosource 2021-05-23 16:59:56 +02:00
Ursprung 0b78786bc2
Commit 21ff7fddaf
5 geänderte Dateien mit 41 neuen und 64 gelöschten Zeilen

Datei anzeigen

@ -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);
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;
@ -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) {
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;
} }

Datei anzeigen

@ -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());
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) {
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));

Datei anzeigen

@ -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() {

Datei anzeigen

@ -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) {
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!");

Datei anzeigen

@ -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!");