96 Zeilen
3.1 KiB
Java
96 Zeilen
3.1 KiB
Java
|
package de.steamwar.fightsystem.winconditions;
|
||
|
|
||
|
import de.steamwar.fightsystem.FightSystem;
|
||
|
import de.steamwar.fightsystem.countdown.TechKOCountdown;
|
||
|
import de.steamwar.fightsystem.fight.Fight;
|
||
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||
|
import de.steamwar.fightsystem.utils.Config;
|
||
|
import org.bukkit.Bukkit;
|
||
|
import org.bukkit.World;
|
||
|
import org.bukkit.entity.TNTPrimed;
|
||
|
import org.bukkit.event.EventHandler;
|
||
|
import org.bukkit.event.Listener;
|
||
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||
|
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
public class WinconditionTechKO implements Listener {
|
||
|
|
||
|
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;
|
||
|
|
||
|
private World world;
|
||
|
private Map<Integer, Boolean> map = new HashMap<>(400);
|
||
|
private double toggle;
|
||
|
private int smallerZtime;
|
||
|
private int biggerZtime;
|
||
|
private TechKOCountdown smallerZcountdown = null;
|
||
|
private TechKOCountdown biggerZcountdown = null;
|
||
|
|
||
|
//Works only for z-Axis fight direction for performance reasons
|
||
|
public WinconditionTechKO(){
|
||
|
if(!Config.TechKO)
|
||
|
return;
|
||
|
|
||
|
world = Bukkit.getWorlds().get(0);
|
||
|
toggle = Config.SpecSpawn.getZ();
|
||
|
smallerZtime=TECH_KO_HALF_TIME;
|
||
|
biggerZtime=TECH_KO_HALF_TIME;
|
||
|
|
||
|
Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 1);
|
||
|
Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
|
||
|
}
|
||
|
|
||
|
private void run(){
|
||
|
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){
|
||
|
smallerZcountdown.cancelTimer();
|
||
|
smallerZcountdown = null;
|
||
|
}else if(smallerZtime == 0){
|
||
|
smallerZcountdown = new TechKOCountdown(smallerTeam());
|
||
|
}
|
||
|
|
||
|
if(biggerZtime == TECH_KO_HALF_TIME && biggerZcountdown != null){
|
||
|
biggerZcountdown.cancelTimer();
|
||
|
biggerZcountdown = null;
|
||
|
}else if(biggerZtime == 0){
|
||
|
biggerZcountdown = new TechKOCountdown(biggerTeam());
|
||
|
}
|
||
|
|
||
|
smallerZtime--;
|
||
|
biggerZtime--;
|
||
|
}
|
||
|
|
||
|
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();
|
||
|
}
|
||
|
|
||
|
@EventHandler
|
||
|
public void onEntityDead(EntityExplodeEvent event){
|
||
|
map.remove(event.getEntity().getEntityId());
|
||
|
}
|
||
|
}
|