SteamWar/FightSystem
Archiviert
13
1

Hotfix watertechko + simplify and speedup

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2020-06-03 10:38:14 +02:00
Ursprung 10c461f317
Commit 2ee2d74432

Datei anzeigen

@ -7,51 +7,35 @@ import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.WaterRemover;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.scheduler.BukkitTask;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
public class WinconditionWaterTechKO extends Wincondition {
private static final Set<Location> teamRedWater = new HashSet<>();
private static final Set<Location> teamBlueWater = new HashSet<>();
private static int teamRedWater;
private static int teamBlueWater;
private static final World WORLD = Bukkit.getWorlds().get(0);
private BukkitTask task;
public WinconditionWaterTechKO() {
super(Config.WaterTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING, FightState.SPECTATE));
super(Config.WaterTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
}
public static int getTeamBlueWater() {
return teamBlueWater.size();
return teamBlueWater;
}
public static int getTeamRedWater() {
return teamRedWater.size();
return teamRedWater;
}
@Override
public void enable() {
checkForWater(teamRedWater,
Config.TeamRedCornerX,
Config.TeamRedCornerY,
Config.TeamRedCornerZ,
Config.TeamRedCornerX + Config.SchemsizeX,
Config.TeamRedCornerY + Config.SchemsizeY,
Config.TeamRedCornerZ + Config.SchemsizeZ);
checkForWater(teamBlueWater,
Config.TeamBlueCornerX,
Config.TeamBlueCornerY,
Config.TeamBlueCornerZ,
Config.TeamBlueCornerX + Config.SchemsizeX,
Config.TeamBlueCornerY + Config.SchemsizeY,
Config.TeamBlueCornerZ + Config.SchemsizeZ);
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::addWater, 200, 200);
checkTask();
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::checkTask, 200, 200);
}
@Override
@ -59,25 +43,22 @@ public class WinconditionWaterTechKO extends Wincondition {
task.cancel();
}
private void checkEmpty(FightTeam team, Set<Location> teamWater){
if(teamWater.isEmpty()){
private void checkEmpty(FightTeam team, int teamWater){
if(teamWater == 0){
Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!");
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "WaterTechKO"));
}
}
private void addWater() {
if(FightSystem.getFightState() != FightState.PRE_RUNNING && FightSystem.getFightState() != FightState.RUNNING)
return;
checkForWater(teamRedWater,
private void checkTask() {
teamRedWater = calcWater(
Config.TeamRedCornerX,
Config.TeamRedCornerY,
Config.TeamRedCornerZ,
Config.TeamRedCornerX + Config.SchemsizeX,
Config.TeamRedCornerY + Config.SchemsizeY,
Config.TeamRedCornerZ + Config.SchemsizeZ);
checkForWater(teamBlueWater,
teamBlueWater = calcWater(
Config.TeamBlueCornerX,
Config.TeamBlueCornerY,
Config.TeamBlueCornerZ,
@ -89,16 +70,16 @@ public class WinconditionWaterTechKO extends Wincondition {
checkEmpty(Fight.getBlueTeam(), teamBlueWater);
}
private void checkForWater(Set<Location> teamWater, int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
teamWater.clear();
private int calcWater(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
int teamWater = 0;
for(int x = minX; x <= maxX; x++) {
for(int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
if (WaterRemover.isWater(WORLD.getBlockAt(x, y, z)))
teamWater.add(new Location(WORLD, x, y, z));
teamWater++;
}
}
}
return teamWater;
}
}