RedstoneWincondition #274
@ -26,7 +26,7 @@ public enum Winconditions {
|
||||
ALL_DEAD,
|
||||
CAPTAIN_DEAD,
|
||||
PERCENT_SYSTEM,
|
||||
RELATIVE_REDSTONE_PERCENT,
|
||||
RELATIVE_WHITELIST_PERCENT,
|
||||
RELATIVE_PERCENT,
|
||||
POINTS,
|
||||
TIME_TECH_KO,
|
||||
|
@ -98,7 +98,7 @@ public class FightSystem extends JavaPlugin {
|
||||
new WinconditionWaterTechKO();
|
||||
new WinconditionPercentSystem();
|
||||
new WinconditionRelativePercent();
|
||||
new WinconditionRelativeRedstonePercent();
|
||||
new WinconditionRelativeWhitelistPercent();
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
|
||||
new WinconditionPoints();
|
||||
new WinconditionTimeout();
|
||||
new WinconditionHeartRatioTimeout();
|
||||
|
@ -20,6 +20,8 @@
|
||||
package de.steamwar.fightsystem.states;
|
||||
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.winconditions.Winconditions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@ -27,6 +29,12 @@ public class OneShotStateDependent extends StateDependent{
|
||||
|
||||
private final Runnable runnable;
|
||||
|
||||
public OneShotStateDependent(Winconditions wincondition, Set<FightState> states, Runnable runnable) {
|
||||
super(Config.ActiveWinconditions.contains(wincondition), states);
|
||||
this.runnable = runnable;
|
||||
register();
|
||||
}
|
||||
|
||||
public OneShotStateDependent(Set<ArenaMode> mode, Set<FightState> states, Runnable runnable) {
|
||||
super(mode, states);
|
||||
this.runnable = runnable;
|
||||
|
@ -19,14 +19,17 @@
|
||||
|
||||
package de.steamwar.fightsystem.winconditions;
|
||||
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependent;
|
||||
import org.bukkit.Bukkit;
|
||||
import de.steamwar.fightsystem.states.OneShotStateDependent;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public abstract class PercentWincondition extends Wincondition implements PrintableWincondition {
|
||||
|
||||
@ -40,36 +43,49 @@ public abstract class PercentWincondition extends Wincondition implements Printa
|
||||
|
||||
abstract double getPercent(FightTeam team);
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
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 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
|
||||
|
||||
public class TeamPercent {
|
||||
public final FightTeam team;
|
||||
|
||||
public int totalBlocks;
|
||||
public int currentBlocks;
|
||||
public static class TeamPercent implements Listener {
|
||||
|
||||
protected TeamPercent(FightTeam team) {
|
||||
this.team = team;
|
||||
public FightTeam fightTeam;
|
||||
private Predicate<Material> testType;
|
||||
|
||||
public int totalBlocks = 0;
|
||||
private int currentBlocks = 0;
|
||||
|
||||
private Consumer<TeamPercent> explodeConsumer;
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Ich glaube, hier können ein paar Fields final gesetzt werden. Ich glaube, hier können ein paar Fields final gesetzt werden.
|
||||
|
||||
public TeamPercent(FightTeam fightTeam, Winconditions wincondition, Predicate<Material> testType, Consumer<TeamPercent> enableConsumer, Consumer<TeamPercent> explodeConsumer) {
|
||||
this.fightTeam = fightTeam;
|
||||
this.testType = testType;
|
||||
this.explodeConsumer = explodeConsumer;
|
||||
|
||||
new OneShotStateDependent(wincondition, FightState.Running, () -> {
|
||||
enableConsumer.accept(TeamPercent.this);
|
||||
currentBlocks = totalBlocks;
|
||||
}).register();
|
||||
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.
|
||||
|
||||
new StateDependentListener(wincondition, FightState.Running, this).register();
|
||||
}
|
||||
|
||||
public void lose() {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||
win(Fight.getOpposite(team));
|
||||
}
|
||||
@EventHandler
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (!fightTeam.getExtendRegion().inRegion(event.getEntity().getLocation())) {
|
||||
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)
|
||||
return;
|
||||
}
|
||||
|
||||
public abstract class StateDependentTeamPercent extends StateDependent {
|
||||
public final FightTeam team;
|
||||
|
||||
public int totalBlocks;
|
||||
public int currentBlocks;
|
||||
|
||||
protected StateDependentTeamPercent(FightTeam team, Winconditions winconditions) {
|
||||
super(winconditions, FightState.Running);
|
||||
this.team = team;
|
||||
event.blockList().forEach(block -> {
|
||||
if (testType.test(block.getType())) {
|
||||
currentBlocks--;
|
||||
}
|
||||
});
|
||||
explodeConsumer.accept(this);
|
||||
}
|
||||
|
||||
public void lose() {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||
win(Fight.getOpposite(team));
|
||||
public double getPercent() {
|
||||
if (currentBlocks >= totalBlocks) {
|
||||
return 0;
|
||||
}
|
||||
return (totalBlocks - currentBlocks) * 100 / (double) totalBlocks;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,13 +20,11 @@
|
||||
package de.steamwar.fightsystem.winconditions;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -37,54 +35,28 @@ public class WinconditionPercentSystem extends PercentWincondition implements Li
|
||||
|
||||
public WinconditionPercentSystem() {
|
||||
super("Percent");
|
||||
teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam()));
|
||||
teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam()));
|
||||
teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam()));
|
||||
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.
|
||||
teamMap.put(Fight.getRedTeam(), create(Fight.getRedTeam()));
|
||||
|
||||
new StateDependentListener(Winconditions.PERCENT_SYSTEM, FightState.Running, this) {
|
||||
@Override
|
||||
public void enable() {
|
||||
super.enable();
|
||||
teamMap.forEach((team, percent) -> {
|
||||
percent.currentBlocks = 0;
|
||||
percent.percent = 0;
|
||||
});
|
||||
}
|
||||
};
|
||||
if (Config.ActiveWinconditions.contains(Winconditions.PERCENT_SYSTEM)) {
|
||||
printableWinconditions.add(this);
|
||||
percentWincondition = this;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handleEntityExplode(EntityExplodeEvent event) {
|
||||
teamMap.values().forEach(teamPercent -> teamPercent.check(event));
|
||||
private TeamPercent create(FightTeam fightTeam) {
|
||||
return new TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> true, teamPercent -> {
|
||||
teamPercent.totalBlocks = teamPercent.fightTeam.getSchemRegion().volume();
|
||||
}, teamPercent -> {
|
||||
if (teamPercent.getPercent() >= Config.PercentWin) {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||
win(Fight.getOpposite(teamPercent.fightTeam));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPercent(FightTeam team) {
|
||||
return teamMap.get(team).percent;
|
||||
}
|
||||
|
||||
private class TeamPercent extends PercentWincondition.TeamPercent {
|
||||
|
||||
private double percent;
|
||||
|
||||
private TeamPercent(FightTeam team) {
|
||||
super(team);
|
||||
totalBlocks = team.getSchemRegion().volume();
|
||||
}
|
||||
|
||||
private void check(EntityExplodeEvent event) {
|
||||
if (!team.getExtendRegion().inRegion(event.getEntity().getLocation())) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentBlocks += event.blockList().size();
|
||||
percent = (double) currentBlocks * 100 / totalBlocks;
|
||||
if (percent >= Config.PercentWin) {
|
||||
lose();
|
||||
}
|
||||
}
|
||||
return teamMap.get(team).getPercent();
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +25,11 @@ import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependent;
|
||||
import de.steamwar.fightsystem.states.OneShotStateDependent;
|
||||
import de.steamwar.fightsystem.states.StateDependentCountdown;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -37,9 +38,12 @@ 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 {
|
||||
|
||||
private static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
private final Map<FightTeam, TeamPoints> teamMap = new HashMap<>();
|
||||
|
||||
public WinconditionPoints(){
|
||||
@ -49,17 +53,9 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond
|
||||
teamMap.put(Fight.getRedTeam(), new TeamPoints(Fight.getRedTeam()));
|
||||
|
||||
new StateDependentListener(Winconditions.POINTS, FightState.Ingame, this);
|
||||
new StateDependent(Winconditions.POINTS, FightState.Ingame){
|
||||
@Override
|
||||
public void enable() {
|
||||
new OneShotStateDependent(Winconditions.POINTS, FightState.Ingame, () -> {
|
||||
teamMap.values().forEach(TeamPoints::enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
teamMap.values().forEach(TeamPoints::disable);
|
||||
}
|
||||
}.register();
|
||||
}).register();
|
||||
if(Config.ActiveWinconditions.contains(Winconditions.POINTS)){
|
||||
timeOverCountdown = new StateDependentCountdown(Winconditions.POINTS, FightState.Running, new TimeOverCountdown(this::timeOver));
|
||||
printableWinconditions.add(this);
|
||||
@ -118,21 +114,30 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond
|
||||
private static final int MAX_POINTS = 2000;
|
||||
|
||||
private final FightTeam team;
|
||||
private final WinconditionRelativePercent.TeamPercent percent;
|
||||
private final PercentWincondition.TeamPercent percent;
|
||||
|
||||
private double factor;
|
||||
private int points;
|
||||
|
||||
TeamPoints(FightTeam team){
|
||||
this.team = team;
|
||||
this.percent = new WinconditionRelativePercent.TeamPercent(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();
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Der Codeblock zur Zählung ist in der RelativePercentWincondition "eleganter" gelöst. Evtl. diesen Codeblock in eine Funktion in PercentWincondition.TeamPercent auslagern, die dann hier aufgerufen wird? (Keine Codeduplication) Der Codeblock zur Zählung ist in der RelativePercentWincondition "eleganter" gelöst. Evtl. diesen Codeblock in eine Funktion in PercentWincondition.TeamPercent auslagern, die dann hier aufgerufen wird? (Keine Codeduplication)
|
||||
}, teamPercent -> {
|
||||
|
||||
});
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Zeilenumbrüche für eine leere Methode? teamPercent -> {}); feddich. Zeilenumbrüche für eine leere Methode? teamPercent -> {}); feddich.
|
||||
}
|
||||
|
||||
public void enable() {
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Wie stellst du sicher, dass beim Aufruf dieser Enable-Methode die Enable-Methode des TeamPercents schon aufgerufen wurde, d.h. die Blöcke bereits gezählt wurden? Wie stellst du sicher, dass beim Aufruf dieser Enable-Methode die Enable-Methode des TeamPercents schon aufgerufen wurde, d.h. die Blöcke bereits gezählt wurden?
YoyoNow
hat
Keine Ahnung Ideen? Keine Ahnung Ideen?
Lixfel
hat
Nein, das machst du nicht, daher wird das so nicht funktionieren (aka. verbuggt). Idee 1: Du rufst vorher die enable des TeamPercents auf. Idee 2: (Sauberer) Du übergibst im Konstrutor des TeamPercents eine Methode, welche am Ende der enable von TeamPercent aufgerufen wird... Nein, das machst du nicht, daher wird das so nicht funktionieren (aka. verbuggt).
Idee 1: Du rufst vorher die enable des TeamPercents auf.
Idee 2: (Sauberer) Du übergibst im Konstrutor des TeamPercents eine Methode, welche am Ende der enable von TeamPercent aufgerufen wird...
|
||||
this.points = 0;
|
||||
percent.enable();
|
||||
int ownBlocks = percent.getBlockCount();
|
||||
int enemyBlocks = teamMap.get(Fight.getOpposite(team)).percent.getBlockCount();
|
||||
int ownBlocks = percent.totalBlocks;
|
||||
int enemyBlocks = teamMap.get(Fight.getOpposite(team)).percent.totalBlocks;
|
||||
|
||||
if(enemyBlocks < ownBlocks) {
|
||||
this.factor = 100; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte
|
||||
@ -148,10 +153,6 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond
|
||||
}
|
||||
}
|
||||
|
||||
public void disable(){
|
||||
percent.disable();
|
||||
}
|
||||
|
||||
public int getPoints(){
|
||||
int damagePoints = (int)(teamMap.get(Fight.getOpposite(team)).percent.getPercent() * factor);
|
||||
if(damagePoints > MAX_POINTS)
|
||||
|
@ -25,10 +25,10 @@ import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class WinconditionRelativePercent extends PercentWincondition {
|
||||
|
||||
@ -38,8 +38,8 @@ public class WinconditionRelativePercent extends PercentWincondition {
|
||||
|
||||
public WinconditionRelativePercent() {
|
||||
super("RelativePercent");
|
||||
teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam()));
|
||||
teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam()));
|
||||
teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam()));
|
||||
teamMap.put(Fight.getRedTeam(), create(Fight.getRedTeam()));
|
||||
|
||||
if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT)) {
|
||||
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 :)
|
||||
printableWinconditions.add(this);
|
||||
@ -52,61 +52,22 @@ public class WinconditionRelativePercent extends PercentWincondition {
|
||||
return teamMap.get(team).getPercent();
|
||||
}
|
||||
|
||||
public class TeamPercent extends StateDependentTeamPercent {
|
||||
|
||||
private BukkitTask task;
|
||||
|
||||
public TeamPercent(FightTeam team) {
|
||||
super(team, Winconditions.RELATIVE_PERCENT);
|
||||
currentBlocks = 1;
|
||||
register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
totalBlocks = currentBlocks();
|
||||
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 400, 400);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
private void check() {
|
||||
currentBlocks();
|
||||
|
||||
if (!Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT))
|
||||
return;
|
||||
|
||||
if (getPercent() >= Config.PercentWin) {
|
||||
lose();
|
||||
}
|
||||
}
|
||||
|
||||
public double getPercent() {
|
||||
if (currentBlocks > totalBlocks) {
|
||||
return 0;
|
||||
}
|
||||
return (totalBlocks - currentBlocks) * 100 / (double) totalBlocks;
|
||||
}
|
||||
|
||||
public int getBlockCount() {
|
||||
return totalBlocks;
|
||||
}
|
||||
|
||||
private int currentBlocks() {
|
||||
// Entern active
|
||||
if (!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft())
|
||||
return currentBlocks;
|
||||
|
||||
currentBlocks = 0;
|
||||
team.getSchemRegion().forEach((x, y, z) -> {
|
||||
private PercentWincondition.TeamPercent create(FightTeam fightTeam) {
|
||||
return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> {
|
||||
return !Config.Blocks.contains(material);
|
||||
}, teamPercent -> {
|
||||
AtomicInteger currentBlocks = new AtomicInteger();
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Muss kein AtomicInteger sein, wenn es sich um eine Objektvariable handelt Muss kein AtomicInteger sein, wenn es sich um eine Objektvariable handelt
|
||||
teamPercent.fightTeam.getSchemRegion().forEach((x, y, z) -> {
|
||||
if (!Config.Blocks.contains(world.getBlockAt(x, y, z).getType())) {
|
||||
currentBlocks++;
|
||||
currentBlocks.getAndIncrement();
|
||||
}
|
||||
});
|
||||
teamPercent.totalBlocks = currentBlocks.get();
|
||||
}, teamPercent -> {
|
||||
if (teamPercent.getPercent() >= Config.PercentWin) {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||
win(Fight.getOpposite(teamPercent.fightTeam));
|
||||
}
|
||||
});
|
||||
return currentBlocks;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,111 +0,0 @@
|
||||
package de.steamwar.fightsystem.winconditions;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class WinconditionRelativeRedstonePercent extends PercentWincondition implements Listener {
|
||||
|
||||
private static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
||||
|
||||
public WinconditionRelativeRedstonePercent() {
|
||||
super("RelativeRedstonePercent");
|
||||
teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam()));
|
||||
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.totalBlocks = 0;
|
||||
percent.currentBlocks = 1;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_REDSTONE_PERCENT)) {
|
||||
printableWinconditions.add(this);
|
||||
percentWincondition = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPercent(FightTeam team) {
|
||||
return teamMap.get(team).getPercent();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
teamMap.values().forEach(teamPercent -> teamPercent.check(event));
|
||||
}
|
||||
|
||||
private static boolean validBlock(Block block) {
|
||||
return Config.Blocks.contains(block.getType());
|
||||
}
|
||||
|
||||
public class TeamPercent extends StateDependentTeamPercent {
|
||||
|
||||
public TeamPercent(FightTeam team) {
|
||||
super(team, Winconditions.RELATIVE_REDSTONE_PERCENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
totalBlocks = currentBlocks();
|
||||
currentBlocks = totalBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
|
||||
}
|
||||
|
||||
private void check(EntityExplodeEvent event) {
|
||||
if (!team.getExtendRegion().inRegion(event.getEntity().getLocation())) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.blockList().forEach(block -> {
|
||||
if (validBlock(block)) {
|
||||
currentBlocks--;
|
||||
}
|
||||
});
|
||||
|
||||
if (getPercent() >= Config.PercentWin) {
|
||||
lose();
|
||||
}
|
||||
}
|
||||
|
||||
public double getPercent() {
|
||||
if (currentBlocks > totalBlocks)
|
||||
return 0;
|
||||
return (totalBlocks - currentBlocks) * 100 / (double) totalBlocks;
|
||||
}
|
||||
|
||||
private int currentBlocks() {
|
||||
totalBlocks = 0;
|
||||
team.getSchemRegion().forEach((x, y, z) -> {
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
if (validBlock(block)) {
|
||||
totalBlocks++;
|
||||
}
|
||||
});
|
||||
return totalBlocks;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package de.steamwar.fightsystem.winconditions;
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Licence fehlt. Licence fehlt.
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
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;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class WinconditionRelativeWhitelistPercent extends PercentWincondition implements Listener {
|
||||
|
||||
private static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPercent(FightTeam team) {
|
||||
return teamMap.get(team).getPercent();
|
||||
}
|
||||
|
||||
private PercentWincondition.TeamPercent create(FightTeam fightTeam) {
|
||||
return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> {
|
||||
return Config.Blocks.contains(material);
|
||||
}, teamPercent -> {
|
||||
AtomicInteger currentBlocks = new AtomicInteger();
|
||||
teamPercent.fightTeam.getSchemRegion().forEach((x, y, z) -> {
|
||||
if (Config.Blocks.contains(world.getBlockAt(x, y, z).getType())) {
|
||||
currentBlocks.getAndIncrement();
|
||||
}
|
||||
});
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Falsche Wincondition Falsche Wincondition
|
||||
teamPercent.totalBlocks = currentBlocks.get();
|
||||
}, teamPercent -> {
|
||||
if (teamPercent.getPercent() >= Config.PercentWin) {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||
win(Fight.getOpposite(teamPercent.fightTeam));
|
||||
}
|
||||
});
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Codedup. Codedup.
|
||||
}
|
||||
|
||||
}
|
Der Aufwand, das ganze 1.12-Kompatibel zu machen, ist nicht so groß, bitte machen (da eigentlich alles im Fightsystem für alle Versionen ausgelegt ist). Und nicht den 1.14-Support vergessen.