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

View File

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

View File

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