107 Zeilen
3.8 KiB
Java
107 Zeilen
3.8 KiB
Java
/*
|
|
This file is a part of the SteamWar software.
|
|
|
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
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;
|
|
private static boolean running = false;
|
|
|
|
public WinconditionPumpkinTechKO(){
|
|
super(Config.PumpkinTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING));
|
|
}
|
|
|
|
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(){
|
|
if(running)
|
|
return;
|
|
running = true;
|
|
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);
|
|
running = false;
|
|
}
|
|
|
|
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), "PumpkinTechKO"));
|
|
}
|
|
}
|
|
}
|