SteamWar/FightSystem
Archiviert
13
1

Merge pull request 'Improve WaterTechKO performance' (#338) from waterTechKOPerformance into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #338
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2022-03-14 11:12:52 +01:00
Commit ea3261ccfa

Datei anzeigen

@ -28,8 +28,11 @@ import de.steamwar.fightsystem.utils.FlatteningWrapper;
import de.steamwar.fightsystem.utils.Message; import de.steamwar.fightsystem.utils.Message;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public class WinconditionWaterTechKO extends Wincondition implements PrintableWincondition { public class WinconditionWaterTechKO extends Wincondition implements PrintableWincondition {
@ -43,7 +46,13 @@ public class WinconditionWaterTechKO extends Wincondition implements PrintableWi
teamMap.put(Fight.getBlueTeam(), new TeamWater(Fight.getBlueTeam())); teamMap.put(Fight.getBlueTeam(), new TeamWater(Fight.getBlueTeam()));
teamMap.put(Fight.getRedTeam(), new TeamWater(Fight.getRedTeam())); teamMap.put(Fight.getRedTeam(), new TeamWater(Fight.getRedTeam()));
new StateDependentTask(Winconditions.WATER_TECH_KO, FightState.Ingame, this::check, 200, 200); new StateDependentTask(Winconditions.WATER_TECH_KO, FightState.Ingame, this::check, 200, 200){
@Override
public void enable() {
teamMap.values().forEach(TeamWater::find);
super.enable();
}
};
if(Config.ActiveWinconditions.contains(Winconditions.WATER_TECH_KO)){ if(Config.ActiveWinconditions.contains(Winconditions.WATER_TECH_KO)){
printableWinconditions.add(this); printableWinconditions.add(this);
} }
@ -55,25 +64,29 @@ public class WinconditionWaterTechKO extends Wincondition implements PrintableWi
@Override @Override
public Message getDisplay(FightTeam team) { public Message getDisplay(FightTeam team) {
return new Message("BAR_WATER", team.getPrefix() + teamMap.get(team).water); return new Message("BAR_WATER", team.getPrefix() + teamMap.get(team).water.size());
} }
private class TeamWater { private class TeamWater {
private final FightTeam team; private final FightTeam team;
private int water; private final List<Block> water = new ArrayList<>();
private TeamWater(FightTeam team) { private TeamWater(FightTeam team) {
this.team = team; this.team = team;
} }
private void check() { private void find() {
water = 0; water.clear();
team.getExtendRegion().forEach((x, y, z) -> { team.getExtendRegion().forEach((x, y, z) -> {
if (FlatteningWrapper.impl.isWater(WORLD.getBlockAt(x, y, z))) Block block = WORLD.getBlockAt(x, y, z);
water++; if (FlatteningWrapper.impl.isWater(block))
water.add(block);
}); });
}
if(water == 0){ private void check() {
water.removeIf(block -> !FlatteningWrapper.impl.isWater(block));
if(water.isEmpty()){
win(Fight.getOpposite(team), "WIN_TECHKO", team.getColoredName()); win(Fight.getOpposite(team), "WIN_TECHKO", team.getColoredName());
} }
} }