Fixed NPE with FlyTask

This commit is contained in:
Driftay 2019-11-16 04:23:43 -05:00
parent ac859db55f
commit f8e22896d5
3 changed files with 13 additions and 13 deletions

View File

@ -20,8 +20,8 @@ import java.util.concurrent.ConcurrentHashMap;
public class CmdFly extends FCommand {
public static ConcurrentHashMap<String, Boolean> flyMap = new ConcurrentHashMap<String, Boolean>();
public static int id = -1;
public static ConcurrentHashMap<String, Boolean> flyMap = new ConcurrentHashMap<>();
public static BukkitTask particleTask = null;
public static BukkitTask flyTask = null;
@ -38,7 +38,7 @@ public class CmdFly extends FCommand {
public static void startParticles() {
id = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> {
particleTask = Bukkit.getScheduler().runTaskTimerAsynchronously(FactionsPlugin.instance, () -> {
for (String name : flyMap.keySet()) {
Player player = Bukkit.getPlayer(name);
if (player == null) continue;
@ -49,11 +49,10 @@ public class CmdFly extends FCommand {
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
fplayer.isVanished();
}
if (flyMap.keySet().size() == 0) {
Bukkit.getScheduler().cancelTask(id);
id = -1;
if (flyMap.isEmpty()) {
particleTask.cancel();
particleTask = null;
}
}, 10L, 3L);
}
@ -192,6 +191,10 @@ public class CmdFly extends FCommand {
context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> {
fme.setFlying(true);
flyMap.put(fme.getPlayer().getName(), true);
if (particleTask == null) {
startParticles();
}
if (flyTask == null) {
startFlyCheck();
}

View File

@ -23,7 +23,7 @@ public class CmdHome extends FCommand {
public CmdHome() {
super();
this.aliases.add("home");
this.optionalArgs.put("home", "faction-name");
this.optionalArgs.put("faction", "yours");
this.requirements = new CommandRequirements.Builder(Permission.HOME)
.playerOnly()

View File

@ -581,15 +581,12 @@ public class FactionsPlayerListener implements Listener {
if (FactionsPlugin.getInstance().getConfig().getBoolean("ffly.AutoEnable")) {
me.setFlying(true);
CmdFly.flyMap.put(me.getName(), true);
if (CmdFly.id == -1) {
if (FactionsPlugin.getInstance().getConfig().getBoolean("ffly.Particles.Enabled")) {
if (CmdFly.particleTask == null)
if (FactionsPlugin.getInstance().getConfig().getBoolean("ffly.Particles.Enabled"))
CmdFly.startParticles();
}
}
if (CmdFly.flyTask == null) CmdFly.startFlyCheck();
CmdFly.startFlyCheck();
}
}
//inspect