Update PercentWincondition and other
Dieser Commit ist enthalten in:
Ursprung
fcf75a12ba
Commit
0b78786bc2
@ -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;
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
}, teamPercent -> {
|
}, teamPercent -> {});
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 @@
|
|||||||
|
/*
|
||||||
|
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 -> {
|
||||||
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!");
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren