Update PercentWincondition and other
Dieser Commit ist enthalten in:
Ursprung
0b78786bc2
Commit
21ff7fddaf
@ -19,11 +19,14 @@
|
||||
|
||||
package de.steamwar.fightsystem.winconditions;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.OneShotStateDependent;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
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 PercentWincondition(String windescription) {
|
||||
protected PercentWincondition(String windescription, Winconditions winconditions) {
|
||||
super(windescription);
|
||||
|
||||
if (Config.ActiveWinconditions.contains(winconditions)) {
|
||||
printableWinconditions.add(this);
|
||||
percentWincondition = this;
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplay(FightTeam team) {
|
||||
@ -51,6 +59,8 @@ public abstract class PercentWincondition extends Wincondition implements Printa
|
||||
|
||||
public static class TeamPercent implements Listener {
|
||||
|
||||
private static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
public final FightTeam fightTeam;
|
||||
private final Predicate<Material> testType;
|
||||
|
||||
@ -59,21 +69,33 @@ public abstract class PercentWincondition extends Wincondition implements Printa
|
||||
|
||||
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.testType = testType;
|
||||
this.explodeConsumer = explodeConsumer;
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
new StateDependentListener(wincondition, FightState.Running, this).register();
|
||||
if (percentWincondition != null) {
|
||||
percentWincondition.teamMap.put(fightTeam, this);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
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())) {
|
||||
return;
|
||||
}
|
||||
|
@ -28,20 +28,13 @@ import org.bukkit.Bukkit;
|
||||
public class WinconditionPercentSystem extends PercentWincondition {
|
||||
|
||||
public WinconditionPercentSystem() {
|
||||
super("Percent");
|
||||
teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam()));
|
||||
teamMap.put(Fight.getRedTeam(), create(Fight.getRedTeam()));
|
||||
|
||||
if (Config.ActiveWinconditions.contains(Winconditions.PERCENT_SYSTEM)) {
|
||||
printableWinconditions.add(this);
|
||||
percentWincondition = this;
|
||||
}
|
||||
super("Percent", Winconditions.PERCENT_SYSTEM);
|
||||
create(Fight.getBlueTeam());
|
||||
create(Fight.getRedTeam());
|
||||
}
|
||||
|
||||
private TeamPercent create(FightTeam fightTeam) {
|
||||
return new TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> true, teamPercent -> {
|
||||
teamPercent.totalBlocks = teamPercent.fightTeam.getSchemRegion().volume();
|
||||
}, teamPercent -> {
|
||||
private void create(FightTeam fightTeam) {
|
||||
new TeamPercent(this, fightTeam, Winconditions.PERCENT_SYSTEM, material -> true, teamPercent -> {
|
||||
if (teamPercent.getPercent() >= Config.PercentWin) {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||
win(Fight.getOpposite(teamPercent.fightTeam));
|
||||
|
@ -38,7 +38,6 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class WinconditionPoints extends Wincondition implements PrintableWincondition, Listener {
|
||||
|
||||
@ -121,16 +120,7 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond
|
||||
|
||||
TeamPoints(FightTeam team){
|
||||
this.team = team;
|
||||
this.percent = new PercentWincondition.TeamPercent(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 -> {});
|
||||
this.percent = new PercentWincondition.TeamPercent(null, team, Winconditions.POINTS, material -> true, teamPercent -> {});
|
||||
}
|
||||
|
||||
public void enable() {
|
||||
|
@ -24,32 +24,18 @@ import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class WinconditionRelativePercent extends PercentWincondition {
|
||||
|
||||
private static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
public WinconditionRelativePercent() {
|
||||
super("RelativePercent");
|
||||
teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam()));
|
||||
teamMap.put(Fight.getRedTeam(), create(Fight.getRedTeam()));
|
||||
|
||||
if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT)) {
|
||||
printableWinconditions.add(this);
|
||||
percentWincondition = this;
|
||||
}
|
||||
super("RelativePercent", Winconditions.RELATIVE_PERCENT);
|
||||
create(Fight.getBlueTeam());
|
||||
create(Fight.getRedTeam());
|
||||
}
|
||||
|
||||
private PercentWincondition.TeamPercent create(FightTeam fightTeam) {
|
||||
return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> {
|
||||
private void create(FightTeam fightTeam) {
|
||||
new TeamPercent(this, fightTeam, Winconditions.RELATIVE_WHITELIST_PERCENT, 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 -> {
|
||||
if (teamPercent.getPercent() >= Config.PercentWin) {
|
||||
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.FightTeam;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class WinconditionRelativeWhitelistPercent extends PercentWincondition implements Listener {
|
||||
|
||||
private static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
public WinconditionRelativeWhitelistPercent() {
|
||||
super("RelativeWhitelistPercent");
|
||||
teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam()));
|
||||
teamMap.put(Fight.getRedTeam(), create(Fight.getRedTeam()));
|
||||
|
||||
if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_WHITELIST_PERCENT)) {
|
||||
printableWinconditions.add(this);
|
||||
percentWincondition = this;
|
||||
}
|
||||
super("RelativeWhitelistPercent", Winconditions.RELATIVE_WHITELIST_PERCENT);
|
||||
create(Fight.getBlueTeam());
|
||||
create(Fight.getRedTeam());
|
||||
}
|
||||
|
||||
private PercentWincondition.TeamPercent create(FightTeam fightTeam) {
|
||||
return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> {
|
||||
private void create(FightTeam fightTeam) {
|
||||
new PercentWincondition.TeamPercent(this, fightTeam, Winconditions.RELATIVE_WHITELIST_PERCENT, 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 -> {
|
||||
if (teamPercent.getPercent() >= Config.PercentWin) {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren