SteamWar/FightSystem
Archiviert
13
1

Improve WaterTechKO performance #338

Zusammengeführt
Lixfel hat 1 Commits von waterTechKOPerformance nach master 2022-03-14 11:12:53 +01:00 zusammengeführt

Datei anzeigen

@ -28,8 +28,11 @@ import de.steamwar.fightsystem.utils.FlatteningWrapper;
import de.steamwar.fightsystem.utils.Message;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.Block;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.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)){
printableWinconditions.add(this);
}
@ -55,25 +64,29 @@ public class WinconditionWaterTechKO extends Wincondition implements PrintableWi
@Override
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 final FightTeam team;
private int water;
private final List<Block> water = new ArrayList<>();
private TeamWater(FightTeam team) {
this.team = team;
}
private void check() {
water = 0;
private void find() {
water.clear();
team.getExtendRegion().forEach((x, y, z) -> {
if (FlatteningWrapper.impl.isWater(WORLD.getBlockAt(x, y, z)))
water++;
Block block = WORLD.getBlockAt(x, y, z);
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());
}
}