RedstoneWincondition #274
@ -20,6 +20,8 @@
|
|||||||
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.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;
|
||||||
@ -33,11 +35,11 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
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 {
|
||||||
|
|
||||||
|
private static final World world = Bukkit.getWorlds().get(0);
|
||||||
|
|
||||||
protected final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
protected final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
||||||
|
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
|
|||||||
protected PercentWincondition(String windescription, Winconditions winconditions) {
|
protected PercentWincondition(String windescription, Winconditions winconditions) {
|
||||||
@ -57,63 +59,65 @@ public abstract class PercentWincondition extends Wincondition implements Printa
|
|||||||
return teamMap.get(team).getPercent();
|
return teamMap.get(team).getPercent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TeamPercent implements Listener {
|
protected class TeamPercent implements Listener {
|
||||||
|
protected final FightTeam fightTeam;
|
||||||
|
|
||||||
private static final World world = Bukkit.getWorlds().get(0);
|
protected int totalBlocks = 0;
|
||||||
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.
|
|||||||
|
|
||||||
public final FightTeam fightTeam;
|
|
||||||
private final Predicate<Material> testType;
|
|
||||||
|
|
||||||
public int totalBlocks = 0;
|
|
||||||
private int currentBlocks = 0;
|
private int currentBlocks = 0;
|
||||||
|
|
||||||
private final Consumer<TeamPercent> explodeConsumer;
|
protected TeamPercent(FightTeam fightTeam, Winconditions wincondition) {
|
||||||
|
|
||||||
public TeamPercent(PercentWincondition percentWincondition, FightTeam fightTeam, Winconditions wincondition, Predicate<Material> testType, Consumer<TeamPercent> explodeConsumer) {
|
|
||||||
this(percentWincondition, fightTeam, wincondition, testType, explodeConsumer, () -> {});
|
|
||||||
}
|
|
||||||
|
|
||||||
public TeamPercent(PercentWincondition percentWincondition, FightTeam fightTeam, Winconditions wincondition, Predicate<Material> testType, Consumer<TeamPercent> explodeConsumer, Runnable afterEnable) {
|
|
||||||
this.fightTeam = fightTeam;
|
this.fightTeam = fightTeam;
|
||||||
this.testType = testType;
|
|
||||||
this.explodeConsumer = explodeConsumer;
|
|
||||||
|
|
||||||
new OneShotStateDependent(wincondition, FightState.Running, () -> {
|
|
||||||
fightTeam.getSchemRegion().forEach((x, y, z) -> {
|
|
||||||
if (testType.test(world.getBlockAt(x, y, z).getType())) {
|
|
||||||
totalBlocks++;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
currentBlocks = totalBlocks;
|
|
||||||
afterEnable.run();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
new OneShotStateDependent(wincondition, FightState.Running, this::enable);
|
||||||
new StateDependentListener(wincondition, FightState.Running, this).register();
|
new StateDependentListener(wincondition, FightState.Running, this).register();
|
||||||
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)
|
|||||||
if (percentWincondition != null) {
|
teamMap.put(fightTeam, this);
|
||||||
percentWincondition.teamMap.put(fightTeam, this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
// Entern active
|
if (checkEntern() || !fightTeam.getExtendRegion().inRegion(event.getEntity().getLocation())) {
|
||||||
if (!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fightTeam.getExtendRegion().inRegion(event.getEntity().getLocation())) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.blockList().forEach(block -> {
|
event.blockList().forEach(block -> {
|
||||||
if (testType.test(block.getType())) {
|
if (test(block.getType())) {
|
||||||
currentBlocks--;
|
currentBlocks--;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
explodeConsumer.accept(this);
|
|
||||||
|
checkWin();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPercent() {
|
protected void enable(){
|
||||||
|
countTotal();
|
||||||
|
currentBlocks = totalBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void countTotal(){
|
||||||
|
totalBlocks = 0;
|
||||||
|
fightTeam.getSchemRegion().forEach((x, y, z) -> {
|
||||||
|
if (test(world.getBlockAt(x, y, z).getType())) {
|
||||||
|
totalBlocks++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean checkEntern(){
|
||||||
|
return !Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean test(Material type){
|
||||||
|
return !Config.Blocks.contains(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void checkWin(){
|
||||||
|
if (getPercent() >= Config.PercentWin) {
|
||||||
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");
|
||||||
|
win(Fight.getOpposite(fightTeam));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected double getPercent() {
|
||||||
if (currentBlocks >= totalBlocks) {
|
if (currentBlocks >= totalBlocks) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
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.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
public class WinconditionPercentSystem extends PercentWincondition {
|
public class WinconditionPercentSystem extends PercentWincondition {
|
||||||
|
|
||||||
@ -34,11 +31,16 @@ public class WinconditionPercentSystem extends PercentWincondition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Ist kein Listener mehr. Ist kein Listener mehr.
|
|||||||
private void create(FightTeam fightTeam) {
|
private void create(FightTeam fightTeam) {
|
||||||
new TeamPercent(this, fightTeam, Winconditions.PERCENT_SYSTEM, material -> true, teamPercent -> {
|
new TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM){
|
||||||
if (teamPercent.getPercent() >= Config.PercentWin) {
|
@Override
|
||||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");
|
protected boolean checkEntern() {
|
||||||
win(Fight.getOpposite(teamPercent.fightTeam));
|
return false;
|
||||||
}
|
}
|
||||||
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.
|
|||||||
});
|
|
||||||
|
@Override
|
||||||
|
protected void countTotal() {
|
||||||
|
totalBlocks = fightTeam.getSchemRegion().volume();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,20 +37,18 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class WinconditionPoints extends Wincondition implements PrintableWincondition, Listener {
|
public class WinconditionPoints extends PercentWincondition implements Listener {
|
||||||
|
|
||||||
private final Map<FightTeam, TeamPoints> teamMap = new HashMap<>();
|
private final Map<FightTeam, TeamPoints> teamMap = new HashMap<>();
|
||||||
|
|
||||||
public WinconditionPoints(){
|
public WinconditionPoints(){
|
||||||
super("Points");
|
super("Points", Winconditions.POINTS);
|
||||||
|
|
||||||
teamMap.put(Fight.getBlueTeam(), new TeamPoints(Fight.getBlueTeam()));
|
teamMap.put(Fight.getBlueTeam(), new TeamPoints(Fight.getBlueTeam()));
|
||||||
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);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,27 +100,30 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond
|
|||||||
return team.getPrefix() + "Punkte: " + teamMap.get(team).getPoints();
|
return team.getPrefix() + "Punkte: " + teamMap.get(team).getPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean run = false;
|
private class TeamPoints extends TeamPercent {
|
||||||
private class TeamPoints {
|
|
||||||
private static final int MAX_POINTS = 2000;
|
private static final int MAX_POINTS = 2000;
|
||||||
|
|
||||||
private final FightTeam team;
|
|
||||||
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;
|
super(team, Winconditions.POINTS);
|
||||||
this.percent = new PercentWincondition.TeamPercent(null, team, Winconditions.POINTS, material -> true, teamPercent -> {}, () -> {
|
|
||||||
if (run) teamMap.values().forEach(TeamPoints::enable);
|
|
||||||
run = !run;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enable() {
|
@Override
|
||||||
int ownBlocks = percent.totalBlocks;
|
protected void checkWin() {
|
||||||
int enemyBlocks = teamMap.get(Fight.getOpposite(team)).percent.totalBlocks;
|
//ignored
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void enable() {
|
||||||
|
super.enable();
|
||||||
|
points = 0;
|
||||||
|
int ownBlocks = totalBlocks;
|
||||||
|
int enemyBlocks = teamMap.get(Fight.getOpposite(fightTeam)).totalBlocks;
|
||||||
|
|
||||||
|
if(enemyBlocks == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
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
|
||||||
@ -139,7 +140,7 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getPoints(){
|
public int getPoints(){
|
||||||
int damagePoints = (int)(teamMap.get(Fight.getOpposite(team)).percent.getPercent() * factor);
|
int damagePoints = (int)(teamMap.get(Fight.getOpposite(fightTeam)).getPercent() * factor);
|
||||||
if(damagePoints > MAX_POINTS)
|
if(damagePoints > MAX_POINTS)
|
||||||
damagePoints = MAX_POINTS;
|
damagePoints = MAX_POINTS;
|
||||||
return points + damagePoints;
|
return points + damagePoints;
|
||||||
|
@ -19,11 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
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.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
public class WinconditionRelativePercent extends PercentWincondition {
|
public class WinconditionRelativePercent extends PercentWincondition {
|
||||||
|
|
||||||
@ -34,13 +31,6 @@ public class WinconditionRelativePercent extends PercentWincondition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void create(FightTeam fightTeam) {
|
private void create(FightTeam fightTeam) {
|
||||||
new TeamPercent(this, fightTeam, Winconditions.RELATIVE_WHITELIST_PERCENT, material -> {
|
new TeamPercent(fightTeam, Winconditions.RELATIVE_PERCENT);
|
||||||
return !Config.Blocks.contains(material);
|
|
||||||
}, 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
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 :)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,9 @@
|
|||||||
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 org.bukkit.Bukkit;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
public class WinconditionRelativeWhitelistPercent extends PercentWincondition implements Listener {
|
public class WinconditionRelativeWhitelistPercent extends PercentWincondition implements Listener {
|
||||||
@ -35,14 +34,12 @@ public class WinconditionRelativeWhitelistPercent extends PercentWincondition im
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void create(FightTeam fightTeam) {
|
private void create(FightTeam fightTeam) {
|
||||||
new PercentWincondition.TeamPercent(this, fightTeam, Winconditions.RELATIVE_WHITELIST_PERCENT, material -> {
|
new PercentWincondition.TeamPercent(fightTeam, Winconditions.RELATIVE_WHITELIST_PERCENT){
|
||||||
return Config.Blocks.contains(material);
|
@Override
|
||||||
}, teamPercent -> {
|
protected boolean test(Material type) {
|
||||||
if (teamPercent.getPercent() >= Config.PercentWin) {
|
return Config.Blocks.contains(type);
|
||||||
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
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