Fixed NPE with Start flight method

This commit is contained in:
Driftay 2019-05-20 15:25:23 -04:00
parent 2cb2068825
commit c5445e2d17
3 changed files with 20 additions and 3 deletions

@ -58,7 +58,8 @@ public class SavageFactions extends MPlugin {
// a green light to use the api.
public static boolean startupFinished = false;
// Persistence related
public static ArrayList<FPlayer> playersFlying = new ArrayList();
public boolean PlaceholderApi;
// Commands
@ -185,6 +186,11 @@ public class SavageFactions extends MPlugin {
faction.addFPlayer(fPlayer);
}
}
playersFlying.clear();
for (FPlayer fPlayer : FPlayers.getInstance().getAllFPlayers()) {
playersFlying.add(fPlayer);
}
UtilFly.run();
Board.getInstance().load();

@ -14,14 +14,18 @@ import java.util.Iterator;
public class UtilFly {
public static ArrayList<FPlayer> playersFlying = SavageFactions.playersFlying;
public static void run() {
if (!SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight"))
return;
playersFlying.clear();
Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, () -> {
for (FPlayer fp : FPlayers.getInstance().getAllFPlayers()) {
if (fp.isFlying()) fp.checkIfNearbyEnemies();
for (FPlayer fp : playersFlying) {
if (fp != null)
fp.checkIfNearbyEnemies();
}
}, 0, SavageFactions.plugin.getConfig().getInt("fly-task-interval", 10));
}
@ -34,6 +38,11 @@ public class UtilFly {
fp.getPlayer().setFlying(fly);
fp.setFlying(fly);
if (fly) {
playersFlying.add(fp);
} else {
playersFlying.remove(fp);
}
if (!silent) {
if (!damage) {
@ -98,3 +107,4 @@ public class UtilFly {
}

@ -1070,6 +1070,7 @@ public abstract class MemoryFPlayer implements FPlayer {
if (e == null) {
continue;
}
if (e instanceof Player) {
Player eplayer = (((Player) e).getPlayer());
if (eplayer == null) {