RedstoneWincondition #274
@ -192,7 +192,7 @@ public class Config {
|
|||||||
|
|
||||||
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime");
|
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime");
|
||||||
PercentWin = config.getDouble("WinConditionParams.PercentWin");
|
PercentWin = config.getDouble("WinConditionParams.PercentWin");
|
||||||
Blocks = config.getStringList("WinConditionParams.IgnoredBlocks").stream().map(Material::valueOf).collect(Collectors.toSet());
|
Blocks = Collections.unmodifiableSet(config.getStringList("WinConditionParams.IgnoredBlocks").stream().map(Material::valueOf).collect(Collectors.toSet()));
|
||||||
|
|
||||||
EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages"));
|
EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages"));
|
||||||
|
|
||||||
|
@ -28,11 +28,15 @@ 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;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public abstract class PercentWincondition extends Wincondition implements PrintableWincondition {
|
public abstract class PercentWincondition extends Wincondition implements PrintableWincondition {
|
||||||
|
|
||||||
|
protected final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
||||||
|
|
||||||
protected PercentWincondition(String windescription) {
|
protected PercentWincondition(String windescription) {
|
||||||
super(windescription);
|
super(windescription);
|
||||||
}
|
}
|
||||||
@ -41,18 +45,19 @@ public abstract class PercentWincondition extends Wincondition implements Printa
|
|||||||
return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%";
|
return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%";
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract double getPercent(FightTeam team);
|
public double getPercent(FightTeam team) {
|
||||||
|
return teamMap.get(team).getPercent();
|
||||||
|
}
|
||||||
|
|
||||||
public static class TeamPercent implements Listener {
|
public static class TeamPercent implements Listener {
|
||||||
|
|
||||||
public FightTeam fightTeam;
|
public final FightTeam fightTeam;
|
||||||
private Predicate<Material> testType;
|
private final Predicate<Material> testType;
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
|
|||||||
|
|
||||||
public int totalBlocks = 0;
|
public int totalBlocks = 0;
|
||||||
private int currentBlocks = 0;
|
private int currentBlocks = 0;
|
||||||
|
|
||||||
private 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(FightTeam fightTeam, Winconditions wincondition, Predicate<Material> testType, Consumer<TeamPercent> enableConsumer, Consumer<TeamPercent> explodeConsumer) {
|
||||||
this.fightTeam = fightTeam;
|
this.fightTeam = fightTeam;
|
||||||
@ -62,7 +67,7 @@ public abstract class PercentWincondition extends Wincondition implements Printa
|
|||||||
new OneShotStateDependent(wincondition, FightState.Running, () -> {
|
new OneShotStateDependent(wincondition, FightState.Running, () -> {
|
||||||
enableConsumer.accept(TeamPercent.this);
|
enableConsumer.accept(TeamPercent.this);
|
||||||
currentBlocks = totalBlocks;
|
currentBlocks = totalBlocks;
|
||||||
}).register();
|
});
|
||||||
|
|
||||||
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)
|
|||||||
}
|
}
|
||||||
|
@ -24,14 +24,8 @@ 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.event.Listener;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
public class WinconditionPercentSystem extends PercentWincondition {
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class WinconditionPercentSystem extends PercentWincondition implements Listener {
|
|
||||||
|
|
||||||
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
|
||||||
|
|
||||||
public WinconditionPercentSystem() {
|
public WinconditionPercentSystem() {
|
||||||
super("Percent");
|
super("Percent");
|
||||||
@ -54,9 +48,4 @@ public class WinconditionPercentSystem extends PercentWincondition implements Li
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getPercent(FightTeam team) {
|
|
||||||
return teamMap.get(team).getPercent();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -130,9 +130,7 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
teamPercent.totalBlocks = currentBlocks.get();
|
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 -> {
|
}, 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() {
|
public void enable() {
|
||||||
|
@ -26,16 +26,10 @@ import de.steamwar.fightsystem.fight.FightTeam;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
public class WinconditionRelativePercent extends PercentWincondition {
|
public class WinconditionRelativePercent extends PercentWincondition {
|
||||||
|
|
||||||
private static final World world = Bukkit.getWorlds().get(0);
|
private static final World world = Bukkit.getWorlds().get(0);
|
||||||
|
|
||||||
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
|
||||||
|
|
||||||
public WinconditionRelativePercent() {
|
public WinconditionRelativePercent() {
|
||||||
super("RelativePercent");
|
super("RelativePercent");
|
||||||
teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam()));
|
teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam()));
|
||||||
@ -47,22 +41,15 @@ public class WinconditionRelativePercent extends PercentWincondition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getPercent(FightTeam team) {
|
|
||||||
return teamMap.get(team).getPercent();
|
|
||||||
}
|
|
||||||
|
|
||||||
private PercentWincondition.TeamPercent create(FightTeam fightTeam) {
|
private PercentWincondition.TeamPercent create(FightTeam fightTeam) {
|
||||||
return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> {
|
return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> {
|
||||||
return !Config.Blocks.contains(material);
|
return !Config.Blocks.contains(material);
|
||||||
}, teamPercent -> {
|
}, teamPercent -> {
|
||||||
AtomicInteger currentBlocks = new AtomicInteger();
|
|
||||||
teamPercent.fightTeam.getSchemRegion().forEach((x, y, z) -> {
|
teamPercent.fightTeam.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.getAndIncrement();
|
teamPercent.totalBlocks++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
teamPercent.totalBlocks = currentBlocks.get();
|
|
||||||
}, 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!");
|
||||||
|
@ -1,3 +1,22 @@
|
|||||||
|
/*
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Licence fehlt. Licence fehlt.
|
|||||||
|
This file is a part of the SteamWar software.
|
||||||
|
|
||||||
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package de.steamwar.fightsystem.winconditions;
|
package de.steamwar.fightsystem.winconditions;
|
||||||
|
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
@ -8,16 +27,10 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.Listener;
|
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 {
|
public class WinconditionRelativeWhitelistPercent extends PercentWincondition implements Listener {
|
||||||
|
|
||||||
private static final World world = Bukkit.getWorlds().get(0);
|
private static final World world = Bukkit.getWorlds().get(0);
|
||||||
|
|
||||||
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
|
|
||||||
|
|
||||||
public WinconditionRelativeWhitelistPercent() {
|
public WinconditionRelativeWhitelistPercent() {
|
||||||
super("RelativeWhitelistPercent");
|
super("RelativeWhitelistPercent");
|
||||||
teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam()));
|
teamMap.put(Fight.getBlueTeam(), create(Fight.getBlueTeam()));
|
||||||
@ -29,22 +42,15 @@ public class WinconditionRelativeWhitelistPercent extends PercentWincondition im
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getPercent(FightTeam team) {
|
|
||||||
return teamMap.get(team).getPercent();
|
|
||||||
}
|
|
||||||
|
|
||||||
private PercentWincondition.TeamPercent create(FightTeam fightTeam) {
|
private PercentWincondition.TeamPercent create(FightTeam fightTeam) {
|
||||||
return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> {
|
return new PercentWincondition.TeamPercent(fightTeam, Winconditions.PERCENT_SYSTEM, material -> {
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Falsche Wincondition Falsche Wincondition
|
|||||||
return Config.Blocks.contains(material);
|
return Config.Blocks.contains(material);
|
||||||
}, teamPercent -> {
|
}, teamPercent -> {
|
||||||
AtomicInteger currentBlocks = new AtomicInteger();
|
|
||||||
teamPercent.fightTeam.getSchemRegion().forEach((x, y, z) -> {
|
teamPercent.fightTeam.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.getAndIncrement();
|
teamPercent.totalBlocks++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Codedup. Codedup.
|
|||||||
teamPercent.totalBlocks = currentBlocks.get();
|
|
||||||
}, 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!");
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Ich glaube, hier können ein paar Fields final gesetzt werden.