2020-08-26 18:24:44 +02:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2019-12-27 12:32:15 +01:00
|
|
|
package de.steamwar.fightsystem.winconditions;
|
|
|
|
|
|
|
|
import de.steamwar.fightsystem.Config;
|
|
|
|
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;
|
2021-03-12 15:43:32 +01:00
|
|
|
import de.steamwar.fightsystem.states.StateDependentTask;
|
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;
|
|
|
|
|
2021-03-10 22:45:17 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2020-01-11 15:44:40 +01:00
|
|
|
|
2021-03-10 22:45:17 +01:00
|
|
|
public class WinconditionPumpkinTechKO extends Wincondition implements PrintableWincondition {
|
2019-12-27 12:32:15 +01:00
|
|
|
|
2021-03-10 22:45:17 +01:00
|
|
|
private static final World world = Bukkit.getWorlds().get(0);
|
2019-12-27 12:32:15 +01:00
|
|
|
private static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN");
|
2021-03-10 22:45:17 +01:00
|
|
|
|
|
|
|
private final Map<FightTeam, TeamPumpkin> teamMap = new HashMap<>();
|
2019-12-27 12:32:15 +01:00
|
|
|
|
|
|
|
public WinconditionPumpkinTechKO(){
|
2021-03-12 15:43:32 +01:00
|
|
|
super("PumpkinTechKO", "§cDas Team ", " §cist Tech K.O.!");
|
|
|
|
new StateDependentTask(Winconditions.PUMPKIN_TECH_KO, FightState.Ingame, this::check, 0, 200);
|
2021-03-10 22:45:17 +01:00
|
|
|
teamMap.put(Fight.getRedTeam(), new TeamPumpkin(Fight.getRedTeam()));
|
|
|
|
teamMap.put(Fight.getBlueTeam(), new TeamPumpkin(Fight.getBlueTeam()));
|
2019-12-27 12:32:15 +01:00
|
|
|
}
|
|
|
|
|
2021-03-10 22:45:17 +01:00
|
|
|
private void check(){
|
|
|
|
teamMap.values().forEach(TeamPumpkin::check);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDisplay(FightTeam team) {
|
|
|
|
return team.getPrefix() + "Kanonen: " + teamMap.get(team).pumpkins;
|
2019-12-27 12:32:15 +01:00
|
|
|
}
|
|
|
|
|
2021-03-10 22:45:17 +01:00
|
|
|
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++;
|
|
|
|
}
|
2019-12-27 12:32:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-10 22:45:17 +01:00
|
|
|
if(pumpkins == 0) {
|
2021-03-12 15:43:32 +01:00
|
|
|
win(Fight.getOpposite(team));
|
2021-03-10 22:45:17 +01:00
|
|
|
}
|
2019-12-27 12:32:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|