RedstoneWincondition #274
@ -26,7 +26,7 @@ public enum Winconditions {
|
|||||||
ALL_DEAD,
|
ALL_DEAD,
|
||||||
CAPTAIN_DEAD,
|
CAPTAIN_DEAD,
|
||||||
PERCENT_SYSTEM,
|
PERCENT_SYSTEM,
|
||||||
RELATIVE_REDSTONE_PERCENT,
|
RELATIVE_WHITELIST_PERCENT,
|
||||||
RELATIVE_PERCENT,
|
RELATIVE_PERCENT,
|
||||||
POINTS,
|
POINTS,
|
||||||
TIME_TECH_KO,
|
TIME_TECH_KO,
|
||||||
|
@ -98,7 +98,7 @@ public class FightSystem extends JavaPlugin {
|
|||||||
new WinconditionWaterTechKO();
|
new WinconditionWaterTechKO();
|
||||||
new WinconditionPercentSystem();
|
new WinconditionPercentSystem();
|
||||||
new WinconditionRelativePercent();
|
new WinconditionRelativePercent();
|
||||||
new WinconditionRelativeRedstonePercent();
|
new WinconditionRelativeWhitelistPercent();
|
||||||
new WinconditionPoints();
|
new WinconditionPoints();
|
||||||
new WinconditionTimeout();
|
new WinconditionTimeout();
|
||||||
new WinconditionHeartRatioTimeout();
|
new WinconditionHeartRatioTimeout();
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
package de.steamwar.fightsystem.states;
|
package de.steamwar.fightsystem.states;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.ArenaMode;
|
import de.steamwar.fightsystem.ArenaMode;
|
||||||
|
import de.steamwar.fightsystem.Config;
|
||||||
|
import de.steamwar.fightsystem.winconditions.Winconditions;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -27,6 +29,12 @@ public class OneShotStateDependent extends StateDependent{
|
|||||||
|
|
||||||
private final Runnable runnable;
|
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) {
|
public OneShotStateDependent(Set<ArenaMode> mode, Set<FightState> states, Runnable runnable) {
|
||||||
super(mode, states);
|
super(mode, states);
|
||||||
this.runnable = runnable;
|
this.runnable = runnable;
|
||||||
|
@ -19,14 +19,17 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
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.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.OneShotStateDependent;
|
||||||
import org.bukkit.Bukkit;
|
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 {
|
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);
|
abstract double getPercent(FightTeam team);
|
||||||
|
|
||||||
public class TeamPercent {
|
|
||||||
public final FightTeam team;
|
|
||||||
|
|
||||||
public int totalBlocks;
|
public static class TeamPercent implements Listener {
|
||||||
public int currentBlocks;
|
|
||||||
|
|
||||||
protected TeamPercent(FightTeam team) {
|
public FightTeam fightTeam;
|
||||||
this.team = team;
|
private Predicate<Material> testType;
|
||||||
|
|
||||||
|
public int totalBlocks = 0;
|
||||||
|
private int currentBlocks = 0;
|
||||||
|
|
||||||
|
private Consumer<TeamPercent> explodeConsumer;
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
new StateDependentListener(wincondition, FightState.Running, this).register();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void lose() {
|
@EventHandler
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!");
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
win(Fight.getOpposite(team));
|
if (!fightTeam.getExtendRegion().inRegion(event.getEntity().getLocation())) {
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class StateDependentTeamPercent extends StateDependent {
|
event.blockList().forEach(block -> {
|
||||||
public final FightTeam team;
|
if (testType.test(block.getType())) {
|
||||||
|
currentBlocks--;
|
||||||
public int totalBlocks;
|
}
|
||||||
public int currentBlocks;
|
});
|
||||||
|
explodeConsumer.accept(this);
|
||||||
protected StateDependentTeamPercent(FightTeam team, Winconditions winconditions) {
|
|
||||||
super(winconditions, FightState.Running);
|
|
||||||
this.team = team;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void lose() {
|
public double getPercent() {
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + team.getColoredName() + " §chat zu viel Schaden erlitten!");
|
if (currentBlocks >= totalBlocks) {
|
||||||
win(Fight.getOpposite(team));
|
return 0;
|
||||||
|
}
|
||||||
|
return (totalBlocks - currentBlocks) * 100 / (double) totalBlocks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,11 @@
|
|||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
|
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 de.steamwar.fightsystem.states.FightState;
|
import org.bukkit.Bukkit;
|
||||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -37,54 +35,28 @@ public class WinconditionPercentSystem extends PercentWincondition implements Li
|
|||||||
|
|
||||||
public WinconditionPercentSystem() {
|
public WinconditionPercentSystem() {
|
||||||
super("Percent");
|
super("Percent");
|
||||||
teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam()));
|
teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam()));
|
||||||
teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam()));
|
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)) {
|
if (Config.ActiveWinconditions.contains(Winconditions.PERCENT_SYSTEM)) {
|
||||||
printableWinconditions.add(this);
|
printableWinconditions.add(this);
|
||||||
percentWincondition = this;
|
percentWincondition = this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
private TeamPercent create(FightTeam fightTeam) {
|
||||||
public void handleEntityExplode(EntityExplodeEvent event) {
|
return new TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> true, teamPercent -> {
|
||||||
teamMap.values().forEach(teamPercent -> teamPercent.check(event));
|
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
|
@Override
|
||||||
public double getPercent(FightTeam team) {
|
public double getPercent(FightTeam team) {
|
||||||
return teamMap.get(team).percent;
|
return teamMap.get(team).getPercent();
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,11 @@ import de.steamwar.fightsystem.countdown.TimeOverCountdown;
|
|||||||
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 de.steamwar.fightsystem.states.FightState;
|
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.StateDependentCountdown;
|
||||||
import de.steamwar.fightsystem.states.StateDependentListener;
|
import de.steamwar.fightsystem.states.StateDependentListener;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -37,9 +38,12 @@ 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 {
|
||||||
|
|
||||||
|
private static final World world = Bukkit.getWorlds().get(0);
|
||||||
|
|
||||||
private final Map<FightTeam, TeamPoints> teamMap = new HashMap<>();
|
private final Map<FightTeam, TeamPoints> teamMap = new HashMap<>();
|
||||||
|
|
||||||
public WinconditionPoints(){
|
public WinconditionPoints(){
|
||||||
@ -49,17 +53,9 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond
|
|||||||
teamMap.put(Fight.getRedTeam(), new TeamPoints(Fight.getRedTeam()));
|
teamMap.put(Fight.getRedTeam(), new TeamPoints(Fight.getRedTeam()));
|
||||||
|
|
||||||
new StateDependentListener(Winconditions.POINTS, FightState.Ingame, this);
|
new StateDependentListener(Winconditions.POINTS, FightState.Ingame, this);
|
||||||
new StateDependent(Winconditions.POINTS, FightState.Ingame){
|
new OneShotStateDependent(Winconditions.POINTS, FightState.Ingame, () -> {
|
||||||
@Override
|
teamMap.values().forEach(TeamPoints::enable);
|
||||||
public void enable() {
|
}).register();
|
||||||
teamMap.values().forEach(TeamPoints::enable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disable() {
|
|
||||||
teamMap.values().forEach(TeamPoints::disable);
|
|
||||||
}
|
|
||||||
}.register();
|
|
||||||
if(Config.ActiveWinconditions.contains(Winconditions.POINTS)){
|
if(Config.ActiveWinconditions.contains(Winconditions.POINTS)){
|
||||||
timeOverCountdown = new StateDependentCountdown(Winconditions.POINTS, FightState.Running, new TimeOverCountdown(this::timeOver));
|
timeOverCountdown = new StateDependentCountdown(Winconditions.POINTS, FightState.Running, new TimeOverCountdown(this::timeOver));
|
||||||
printableWinconditions.add(this);
|
printableWinconditions.add(this);
|
||||||
@ -118,21 +114,30 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond
|
|||||||
private static final int MAX_POINTS = 2000;
|
private static final int MAX_POINTS = 2000;
|
||||||
|
|
||||||
private final FightTeam team;
|
private final FightTeam team;
|
||||||
private final WinconditionRelativePercent.TeamPercent percent;
|
private final PercentWincondition.TeamPercent percent;
|
||||||
|
|
||||||
private double factor;
|
private double factor;
|
||||||
private int points;
|
private int points;
|
||||||
|
|
||||||
TeamPoints(FightTeam team){
|
TeamPoints(FightTeam team){
|
||||||
this.team = 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();
|
||||||
|
}, teamPercent -> {
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enable() {
|
public void enable() {
|
||||||
this.points = 0;
|
int ownBlocks = percent.totalBlocks;
|
||||||
percent.enable();
|
int enemyBlocks = teamMap.get(Fight.getOpposite(team)).percent.totalBlocks;
|
||||||
int ownBlocks = percent.getBlockCount();
|
|
||||||
int enemyBlocks = teamMap.get(Fight.getOpposite(team)).percent.getBlockCount();
|
|
||||||
|
|
||||||
if(enemyBlocks < ownBlocks) {
|
if(enemyBlocks < ownBlocks) {
|
||||||
this.factor = 100; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte
|
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(){
|
public int getPoints(){
|
||||||
int damagePoints = (int)(teamMap.get(Fight.getOpposite(team)).percent.getPercent() * factor);
|
int damagePoints = (int)(teamMap.get(Fight.getOpposite(team)).percent.getPercent() * factor);
|
||||||
if(damagePoints > MAX_POINTS)
|
if(damagePoints > MAX_POINTS)
|
||||||
|
@ -25,10 +25,10 @@ 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.World;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class WinconditionRelativePercent extends PercentWincondition {
|
public class WinconditionRelativePercent extends PercentWincondition {
|
||||||
|
|
||||||
@ -38,8 +38,8 @@ public class WinconditionRelativePercent extends PercentWincondition {
|
|||||||
|
|
||||||
public WinconditionRelativePercent() {
|
public WinconditionRelativePercent() {
|
||||||
super("RelativePercent");
|
super("RelativePercent");
|
||||||
teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam()));
|
teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam()));
|
||||||
teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam()));
|
teamMap.put(Fight.getRedTeam(), create(Fight.getRedTeam()));
|
||||||
|
|
||||||
if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT)) {
|
if (Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT)) {
|
||||||
printableWinconditions.add(this);
|
printableWinconditions.add(this);
|
||||||
@ -52,61 +52,22 @@ public class WinconditionRelativePercent extends PercentWincondition {
|
|||||||
return teamMap.get(team).getPercent();
|
return teamMap.get(team).getPercent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TeamPercent extends StateDependentTeamPercent {
|
private PercentWincondition.TeamPercent create(FightTeam fightTeam) {
|
||||||
|
return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> {
|
||||||
private BukkitTask task;
|
return !Config.Blocks.contains(material);
|
||||||
|
}, teamPercent -> {
|
||||||
public TeamPercent(FightTeam team) {
|
AtomicInteger currentBlocks = new AtomicInteger();
|
||||||
super(team, Winconditions.RELATIVE_PERCENT);
|
teamPercent.fightTeam.getSchemRegion().forEach((x, y, z) -> {
|
||||||
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) -> {
|
|
||||||
if (!Config.Blocks.contains(world.getBlockAt(x, y, z).getType())) {
|
if (!Config.Blocks.contains(world.getBlockAt(x, y, z).getType())) {
|
||||||
currentBlocks++;
|
currentBlocks.getAndIncrement();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return currentBlocks;
|
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));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren