Optimize TechKO detection
Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
fd3d6d9911
Commit
b8b8b1b0f5
@ -22,15 +22,14 @@ package de.steamwar.fightsystem.countdown;
|
|||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.winconditions.WinconditionTechKO;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
public class TechKOCountdown extends Countdown {
|
public class TechKOCountdown extends Countdown {
|
||||||
|
|
||||||
private final FightTeam team;
|
private final FightTeam team;
|
||||||
|
|
||||||
public TechKOCountdown(FightTeam team) {
|
public TechKOCountdown(FightTeam team, int countdownTime) {
|
||||||
super(WinconditionTechKO.TECH_KO_COUNTDOWN_TIME, SWSound.BLOCK_NOTE_PLING, false);
|
super(countdownTime, SWSound.BLOCK_NOTE_PLING, false);
|
||||||
this.team = team;
|
this.team = team;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,41 +28,45 @@ import de.steamwar.fightsystem.states.FightState;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class WinconditionTechKO extends ListenerWincondition {
|
public class WinconditionTechKO extends ListenerWincondition {
|
||||||
|
|
||||||
private static final int TECH_KO_TIME_IN_S = 90;
|
private static final int TECH_KO_TIME_IN_S = 90;
|
||||||
private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S*10;
|
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 = Bukkit.getWorlds().get(0);
|
private final World world = Bukkit.getWorlds().get(0);
|
||||||
private Map<Integer, Boolean> map = new HashMap<>(400);
|
private final double toggle = Config.SpecSpawn.getZ();
|
||||||
private double toggle = Config.SpecSpawn.getZ();
|
private final FightTeam smallerZteam;
|
||||||
|
private final FightTeam biggerZteam;
|
||||||
|
|
||||||
private int smallerZtime = TECH_KO_HALF_TIME;
|
private int smallerZtime = TECH_KO_HALF_TIME;
|
||||||
private int biggerZtime = TECH_KO_HALF_TIME;
|
private int biggerZtime = TECH_KO_HALF_TIME;
|
||||||
private TechKOCountdown smallerZcountdown = null;
|
private TechKOCountdown smallerZcountdown = null;
|
||||||
private TechKOCountdown biggerZcountdown = null;
|
private TechKOCountdown biggerZcountdown = null;
|
||||||
private BukkitTask task;
|
private BukkitTask task;
|
||||||
private boolean running = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Works only for z-Axis fight direction for performance reasons
|
* Works only for z-Axis fight direction for performance reasons
|
||||||
*/
|
*/
|
||||||
public WinconditionTechKO(){
|
public WinconditionTechKO(){
|
||||||
super(Config.TechKO, EnumSet.of(FightState.RUNNING));
|
super(Config.TechKO, EnumSet.of(FightState.RUNNING));
|
||||||
|
|
||||||
|
if(Config.TeamBluetoReddistanceZ > 0) {
|
||||||
|
smallerZteam = Fight.getBlueTeam();
|
||||||
|
biggerZteam = Fight.getRedTeam();
|
||||||
|
}else{
|
||||||
|
smallerZteam = Fight.getRedTeam();
|
||||||
|
biggerZteam = Fight.getBlueTeam();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
super.enable();
|
super.enable();
|
||||||
task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::run, 1, 1);
|
task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::run, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -79,58 +83,32 @@ public class WinconditionTechKO extends ListenerWincondition {
|
|||||||
task.cancel();
|
task.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onEntityDead(EntityExplodeEvent event){
|
|
||||||
map.remove(event.getEntity().getEntityId());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void run(){
|
private void run(){
|
||||||
if(running)
|
|
||||||
return;
|
|
||||||
running = true;
|
|
||||||
|
|
||||||
for(TNTPrimed tnt : world.getEntitiesByClass(TNTPrimed.class)){
|
for(TNTPrimed tnt : world.getEntitiesByClass(TNTPrimed.class)){
|
||||||
int id = tnt.getEntityId();
|
double z = tnt.getLocation().getZ();
|
||||||
boolean smallerZ = tnt.getLocation().getZ() < toggle;
|
boolean smallerZ = z < toggle;
|
||||||
Boolean old = map.put(id, smallerZ);
|
boolean wasSmallerZ = z - tnt.getVelocity().getZ() < toggle;
|
||||||
if(old != null && old != smallerZ){
|
if(wasSmallerZ && !smallerZ) {
|
||||||
if(old)
|
|
||||||
smallerZtime = TECH_KO_HALF_TIME;
|
smallerZtime = TECH_KO_HALF_TIME;
|
||||||
else
|
if(smallerZcountdown != null){
|
||||||
biggerZtime = TECH_KO_HALF_TIME;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(smallerZtime == TECH_KO_HALF_TIME && smallerZcountdown != null){
|
|
||||||
smallerZcountdown.disable();
|
smallerZcountdown.disable();
|
||||||
smallerZcountdown = null;
|
smallerZcountdown = null;
|
||||||
}else if(smallerZtime == 0){
|
|
||||||
smallerZcountdown = new TechKOCountdown(smallerTeam());
|
|
||||||
}
|
}
|
||||||
|
}else if(!wasSmallerZ && smallerZ){
|
||||||
if(biggerZtime == TECH_KO_HALF_TIME && biggerZcountdown != null){
|
biggerZtime = TECH_KO_HALF_TIME;
|
||||||
|
if(biggerZcountdown != null){
|
||||||
biggerZcountdown.disable();
|
biggerZcountdown.disable();
|
||||||
biggerZcountdown = null;
|
biggerZcountdown = null;
|
||||||
}else if(biggerZtime == 0){
|
|
||||||
biggerZcountdown = new TechKOCountdown(biggerTeam());
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(smallerZtime == 0)
|
||||||
|
smallerZcountdown = new TechKOCountdown(smallerZteam, TECH_KO_HALF_TIME / 20);
|
||||||
|
if(biggerZtime == 0)
|
||||||
|
biggerZcountdown = new TechKOCountdown(biggerZteam, TECH_KO_HALF_TIME / 20);
|
||||||
|
|
||||||
smallerZtime--;
|
smallerZtime--;
|
||||||
biggerZtime--;
|
biggerZtime--;
|
||||||
running = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren