SteamWar/FightSystem
Archiviert
13
1
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
FightSystem/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java

83 Zeilen
2.9 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.fightsystem.states.FightState;
import de.steamwar.inventory.SWItem;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.scheduler.BukkitTask;
import java.util.EnumSet;
public class WinconditionPumpkinTechKO extends Wincondition {
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");
private BukkitTask task;
public WinconditionPumpkinTechKO(){
super(Config.PumpkinTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING, FightState.ENTERN));
}
public static int getTeamBluePumpkins() {
return teamBluePumpkins;
}
public static int getTeamRedPumpkins() {
return teamRedPumpkins;
}
@Override
public void enable() {
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), WinconditionPumpkinTechKO::recursiveCheck, 0, 200);
}
@Override
public void disable() {
task.cancel();
}
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)));
}
}
}