SteamWar/FightSystem
Archiviert
13
1

Update PercentWincondition and other

Dieser Commit ist enthalten in:
yoyosource 2021-05-22 15:39:51 +02:00
Ursprung fcf75a12ba
Commit 0b78786bc2
6 geänderte Dateien mit 35 neuen und 50 gelöschten Zeilen

Datei anzeigen

@ -192,7 +192,7 @@ public class Config {
TimeoutTime = config.getInt("WinConditionParams.TimeoutTime");
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"));

Datei anzeigen

@ -28,11 +28,15 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Predicate;
public abstract class PercentWincondition extends Wincondition implements PrintableWincondition {
protected final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
protected PercentWincondition(String 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) + "%";
}
abstract double getPercent(FightTeam team);
public double getPercent(FightTeam team) {
return teamMap.get(team).getPercent();
}
public static class TeamPercent implements Listener {
public FightTeam fightTeam;
private Predicate<Material> testType;
public final FightTeam fightTeam;
private final Predicate<Material> testType;
public int totalBlocks = 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) {
this.fightTeam = fightTeam;
@ -62,7 +67,7 @@ public abstract class PercentWincondition extends Wincondition implements Printa
new OneShotStateDependent(wincondition, FightState.Running, () -> {
enableConsumer.accept(TeamPercent.this);
currentBlocks = totalBlocks;
}).register();
});
new StateDependentListener(wincondition, FightState.Running, this).register();
}

Datei anzeigen

@ -24,14 +24,8 @@ import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import java.util.HashMap;
import java.util.Map;
public class WinconditionPercentSystem extends PercentWincondition implements Listener {
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
public class WinconditionPercentSystem extends PercentWincondition {
public WinconditionPercentSystem() {
super("Percent");
@ -54,9 +48,4 @@ public class WinconditionPercentSystem extends PercentWincondition implements Li
}
});
}
@Override
public double getPercent(FightTeam team) {
return teamMap.get(team).getPercent();
}
}

Datei anzeigen

@ -130,9 +130,7 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond
}
});
teamPercent.totalBlocks = currentBlocks.get();
}, teamPercent -> {
});
}, teamPercent -> {});
}
public void enable() {

Datei anzeigen

@ -26,16 +26,10 @@ import de.steamwar.fightsystem.fight.FightTeam;
import org.bukkit.Bukkit;
import org.bukkit.World;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
public class WinconditionRelativePercent extends PercentWincondition {
private static final World world = Bukkit.getWorlds().get(0);
private final Map<FightTeam, TeamPercent> teamMap = new HashMap<>();
public WinconditionRelativePercent() {
super("RelativePercent");
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) {
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++;
}
});
teamPercent.totalBlocks = currentBlocks.get();
}, teamPercent -> {
if (teamPercent.getPercent() >= Config.PercentWin) {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");

Datei anzeigen

@ -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;
import de.steamwar.fightsystem.Config;
@ -8,16 +27,10 @@ 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()));
@ -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) {
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++;
}
});
teamPercent.totalBlocks = currentBlocks.get();
}, teamPercent -> {
if (teamPercent.getPercent() >= Config.PercentWin) {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cTeam " + teamPercent.fightTeam.getColoredName() + " §chat zu viel Schaden erlitten!");