/*
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 .
*/
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.HashMap;
import java.util.Map;
public class WinconditionPumpkinTechKO extends Wincondition implements PrintableWincondition {
private static final World world = Bukkit.getWorlds().get(0);
private static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN");
private final Map teamMap = new HashMap<>();
private BukkitTask task;
public WinconditionPumpkinTechKO(){
super(Winconditions.PUMPKIN_TECH_KO, FightState.INGAME, "PumpkinTechKO");
teamMap.put(Fight.getRedTeam(), new TeamPumpkin(Fight.getRedTeam()));
teamMap.put(Fight.getBlueTeam(), new TeamPumpkin(Fight.getBlueTeam()));
}
@Override
public void enable() {
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 0, 200);
}
@Override
public void disable() {
task.cancel();
}
private void check(){
teamMap.values().forEach(TeamPumpkin::check);
}
@Override
public String getDisplay(FightTeam team) {
return team.getPrefix() + "Kanonen: " + teamMap.get(team).pumpkins;
}
private class TeamPumpkin {
private final FightTeam team;
private int pumpkins;
private TeamPumpkin (FightTeam team) {
this.team = team;
}
private void check(){
pumpkins = 0;
for(int x = team.getCornerX(); x <= team.getCornerX() + Config.SchemsizeX; x++) {
for(int y = team.getCornerY(); y <= team.getCornerY() + Config.SchemsizeY; y++) {
for (int z = team.getCornerZ(); z <= team.getCornerZ() + Config.SchemsizeZ; z++) {
if (world.getBlockAt(x, y, z).getType() == PUMPKIN_LANTERN)
pumpkins++;
}
}
}
if(pumpkins == 0) {
win(Fight.getOpposite(team), "§cDas Team ", " §cist Tech K.O.!");
}
}
}
}