71 Zeilen
2.6 KiB
Java
71 Zeilen
2.6 KiB
Java
|
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;
|
||
|
import de.steamwar.inventory.SWItem;
|
||
|
import org.bukkit.Bukkit;
|
||
|
import org.bukkit.Material;
|
||
|
import org.bukkit.World;
|
||
|
|
||
|
public class WinconditionPumpkinTechKO {
|
||
|
|
||
|
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");
|
||
|
|
||
|
public WinconditionPumpkinTechKO(){
|
||
|
if(!Config.PumpkinTechKO)
|
||
|
return;
|
||
|
|
||
|
Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), WinconditionPumpkinTechKO::recursiveCheck, 0, 200);
|
||
|
}
|
||
|
|
||
|
public static int getTeamBluePumpkins() {
|
||
|
return teamBluePumpkins;
|
||
|
}
|
||
|
public static int getTeamRedPumpkins() {
|
||
|
return teamRedPumpkins;
|
||
|
}
|
||
|
|
||
|
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.!");
|
||
|
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team)));
|
||
|
}
|
||
|
}
|
||
|
}
|