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-09-05 18:26:13 +02:00
|
|
|
package de.steamwar.fightsystem.winconditions;
|
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
import de.steamwar.fightsystem.Config;
|
2019-09-05 18:26:13 +02:00
|
|
|
import de.steamwar.fightsystem.FightSystem;
|
|
|
|
import de.steamwar.fightsystem.countdown.TechKOCountdown;
|
|
|
|
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;
|
2019-09-05 18:26:13 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.TNTPrimed;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
2020-01-11 15:44:40 +01:00
|
|
|
import org.bukkit.scheduler.BukkitTask;
|
2019-09-05 18:26:13 +02:00
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
import java.util.EnumSet;
|
2019-09-05 18:26:13 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
public class WinconditionTechKO extends ListenerWincondition {
|
2019-09-05 18:26:13 +02:00
|
|
|
|
|
|
|
private static final int TECH_KO_TIME_IN_S = 90;
|
|
|
|
private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S*10;
|
|
|
|
public static final int TECH_KO_COUNTDOWN_TIME = TECH_KO_HALF_TIME/20;
|
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
private World world = Bukkit.getWorlds().get(0);
|
2019-09-05 18:26:13 +02:00
|
|
|
private Map<Integer, Boolean> map = new HashMap<>(400);
|
2020-01-11 15:44:40 +01:00
|
|
|
private double toggle = Config.SpecSpawn.getZ();
|
|
|
|
private int smallerZtime = TECH_KO_HALF_TIME;
|
|
|
|
private int biggerZtime = TECH_KO_HALF_TIME;
|
2019-09-05 18:26:13 +02:00
|
|
|
private TechKOCountdown smallerZcountdown = null;
|
|
|
|
private TechKOCountdown biggerZcountdown = null;
|
2020-01-11 15:44:40 +01:00
|
|
|
private BukkitTask task;
|
2020-07-26 12:13:36 +02:00
|
|
|
private boolean running = false;
|
2019-09-05 18:26:13 +02:00
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
/**
|
|
|
|
* Works only for z-Axis fight direction for performance reasons
|
|
|
|
*/
|
2019-09-05 18:26:13 +02:00
|
|
|
public WinconditionTechKO(){
|
2020-07-25 09:58:09 +02:00
|
|
|
super(Config.TechKO, EnumSet.of(FightState.RUNNING));
|
2020-01-11 15:44:40 +01:00
|
|
|
}
|
2019-09-05 18:26:13 +02:00
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
@Override
|
|
|
|
public void enable() {
|
|
|
|
super.enable();
|
|
|
|
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 1);
|
|
|
|
}
|
2019-09-05 18:26:13 +02:00
|
|
|
|
2020-01-11 15:44:40 +01:00
|
|
|
@Override
|
|
|
|
public void disable() {
|
|
|
|
super.disable();
|
2020-12-09 18:43:50 +01:00
|
|
|
if(smallerZcountdown != null){
|
|
|
|
smallerZcountdown.disable();
|
|
|
|
smallerZcountdown = null;
|
|
|
|
}
|
|
|
|
if(biggerZcountdown != null){
|
|
|
|
biggerZcountdown.disable();
|
|
|
|
biggerZcountdown = null;
|
|
|
|
}
|
2020-01-11 15:44:40 +01:00
|
|
|
task.cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onEntityDead(EntityExplodeEvent event){
|
|
|
|
map.remove(event.getEntity().getEntityId());
|
2019-09-05 18:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void run(){
|
2020-07-26 12:13:36 +02:00
|
|
|
if(running)
|
|
|
|
return;
|
|
|
|
running = true;
|
|
|
|
|
2019-09-05 18:26:13 +02:00
|
|
|
for(TNTPrimed tnt : world.getEntitiesByClass(TNTPrimed.class)){
|
|
|
|
int id = tnt.getEntityId();
|
|
|
|
boolean smallerZ = tnt.getLocation().getZ() < toggle;
|
|
|
|
Boolean old = map.put(id, smallerZ);
|
|
|
|
if(old != null && old != smallerZ){
|
|
|
|
if(old)
|
|
|
|
smallerZtime = TECH_KO_HALF_TIME;
|
|
|
|
else
|
|
|
|
biggerZtime = TECH_KO_HALF_TIME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(smallerZtime == TECH_KO_HALF_TIME && smallerZcountdown != null){
|
2020-01-11 15:44:40 +01:00
|
|
|
smallerZcountdown.disable();
|
2019-09-05 18:26:13 +02:00
|
|
|
smallerZcountdown = null;
|
|
|
|
}else if(smallerZtime == 0){
|
|
|
|
smallerZcountdown = new TechKOCountdown(smallerTeam());
|
|
|
|
}
|
|
|
|
|
|
|
|
if(biggerZtime == TECH_KO_HALF_TIME && biggerZcountdown != null){
|
2020-01-11 15:44:40 +01:00
|
|
|
biggerZcountdown.disable();
|
2019-09-05 18:26:13 +02:00
|
|
|
biggerZcountdown = null;
|
|
|
|
}else if(biggerZtime == 0){
|
|
|
|
biggerZcountdown = new TechKOCountdown(biggerTeam());
|
|
|
|
}
|
|
|
|
|
|
|
|
smallerZtime--;
|
|
|
|
biggerZtime--;
|
2020-07-26 12:13:36 +02:00
|
|
|
running = false;
|
2019-09-05 18:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private FightTeam smallerTeam(){
|
|
|
|
if(Config.TeamBluetoReddistanceZ > 0)
|
|
|
|
return Fight.getBlueTeam();
|
|
|
|
else
|
|
|
|
return Fight.getRedTeam();
|
|
|
|
}
|
|
|
|
|
|
|
|
private FightTeam biggerTeam(){
|
|
|
|
if(Config.TeamBluetoReddistanceZ < 0)
|
|
|
|
return Fight.getBlueTeam();
|
|
|
|
else
|
|
|
|
return Fight.getRedTeam();
|
|
|
|
}
|
|
|
|
}
|