2019-12-27 12:32:15 +01:00
|
|
|
package de.steamwar.fightsystem.winconditions;
|
|
|
|
|
|
|
|
import de.steamwar.fightsystem.Config;
|
|
|
|
import de.steamwar.fightsystem.FightSystem;
|
|
|
|
import de.steamwar.fightsystem.fight.Fight;
|
|
|
|
import de.steamwar.fightsystem.fight.FightTeam;
|
2020-01-11 15:44:40 +01:00
|
|
|
import de.steamwar.fightsystem.states.FightState;
|
2019-12-27 12:32:15 +01:00
|
|
|
import de.steamwar.inventory.SWItem;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.World;
|
2020-01-11 15:44:40 +01:00
|
|
|
import org.bukkit.scheduler.BukkitTask;
|
2019-12-27 12:32:15 +01:00
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
public class WinconditionPumpkinTechKO extends Wincondition {
|
2019-12-27 12:32:15 +01:00
|
|
|
|
|
|
|
private static int teamRedPumpkins = -1;
|
|
|
|
private static int teamBluePumpkins = -1;
|
|
|
|
private static final World WORLD = Bukkit.getWorlds().get(0);
|
|
|
|
private static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN");
|
2020-01-11 15:44:40 +01:00
|
|
|
private BukkitTask task;
|
2019-12-27 12:32:15 +01:00
|
|
|
|
|
|
|
public WinconditionPumpkinTechKO(){
|
2020-01-11 15:44:40 +01:00
|
|
|
super(Config.PumpkinTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING, FightState.ENTERN));
|
2019-12-27 12:32:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int getTeamBluePumpkins() {
|
|
|
|
return teamBluePumpkins;
|
|
|
|
}
|
|
|
|
public static int getTeamRedPumpkins() {
|
|
|
|
return teamRedPumpkins;
|
|
|
|
}
|
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
@Override
|
|
|
|
public void enable() {
|
|
|
|
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), WinconditionPumpkinTechKO::recursiveCheck, 0, 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void disable() {
|
|
|
|
task.cancel();
|
|
|
|
}
|
|
|
|
|
2019-12-27 12:32:15 +01:00
|
|
|
private static void recursiveCheck(){
|
|
|
|
teamRedPumpkins = getPumpkins(Config.TeamRedCornerX,
|
|
|
|
Config.TeamRedCornerY,
|
|
|
|
Config.TeamRedCornerZ,
|
|
|
|
Config.TeamRedCornerX + Config.SchemsizeX,
|
|
|
|
Config.TeamRedCornerY + Config.SchemsizeY,
|
|
|
|
Config.TeamRedCornerZ + Config.SchemsizeZ);
|
|
|
|
teamBluePumpkins = getPumpkins(Config.TeamBlueCornerX,
|
|
|
|
Config.TeamBlueCornerY,
|
|
|
|
Config.TeamBlueCornerZ,
|
|
|
|
Config.TeamBlueCornerX + Config.SchemsizeX,
|
|
|
|
Config.TeamBlueCornerY + Config.SchemsizeY,
|
|
|
|
Config.TeamBlueCornerZ + Config.SchemsizeZ);
|
|
|
|
|
|
|
|
checkKO(Fight.getRedTeam(), teamRedPumpkins);
|
|
|
|
checkKO(Fight.getBlueTeam(), teamBluePumpkins);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int getPumpkins(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){
|
|
|
|
int pumpkins = 0;
|
|
|
|
for(int x = minX; x <= maxX; x++) {
|
|
|
|
for(int y = minY; y <= maxY; y++) {
|
|
|
|
for (int z = minZ; z <= maxZ; z++) {
|
|
|
|
if (WORLD.getBlockAt(x, y, z).getType() == PUMPKIN_LANTERN)
|
|
|
|
pumpkins++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pumpkins;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void checkKO(FightTeam team, int pumpkins){
|
|
|
|
if(pumpkins == 0){
|
|
|
|
Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!");
|
2020-01-23 17:33:29 +01:00
|
|
|
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "PumpkinTechKO"));
|
2019-12-27 12:32:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|