Fixed NullPointer With UtilFight

This commit is contained in:
Driftay 2019-03-09 13:40:13 -05:00
parent e4899e4d8d
commit 8697de9e85

View File

@ -12,103 +12,96 @@ import java.util.Iterator;
public class UtilFly { public class UtilFly {
public static ArrayList<FPlayer> playersFlying; public static ArrayList<FPlayer> playersFlying = SavageFactions.playersFlying;
static { public static void call() {
playersFlying = SavageFactions.playersFlying; if (!SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight"))
} return;
public UtilFly() { playersFlying.clear();
}
public static void run() { Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, () -> {
if (SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight")) { for (FPlayer fp : playersFlying) {
playersFlying.clear(); if (fp != null)
Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, new Runnable() { fp.checkIfNearbyEnemies();
public void run() { }
Iterator var2 = UtilFly.playersFlying.iterator(); }, 0, SavageFactions.plugin.getConfig().getInt("fly-task-interval", 10));
while (var2.hasNext()) {
FPlayer fp = (FPlayer) var2.next();
if (fp != null) {
fp.checkIfNearbyEnemies();
}
}
}
}, 0L, (long) SavageFactions.plugin.getConfig().getInt("fly-task-interval", 10));
}
} }
public static void setFly(FPlayer fp, boolean fly, boolean silent, boolean damage) { public static void setFly(FPlayer fp, boolean fly, boolean silent, boolean damage) {
if (SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight")) { if (!SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight"))
fp.getPlayer().setAllowFlight(fly); return;
fp.getPlayer().setFlying(fly);
fp.setFlying(fly);
if (fly) {
playersFlying.add(fp);
} else {
playersFlying.remove(fp);
}
if (!silent) { fp.getPlayer().setAllowFlight(fly);
if (!damage) { fp.getPlayer().setFlying(fly);
fp.msg(TL.COMMAND_FLY_CHANGE, fly ? "enabled" : "disabled"); fp.setFlying(fly);
} else {
fp.msg(TL.COMMAND_FLY_DAMAGE);
}
}
setFallDamage(fp, fly, damage); if (fly) {
playersFlying.add(fp);
} else {
playersFlying.remove(fp);
} }
if (!silent) {
if (!damage) {
fp.msg(TL.COMMAND_FLY_CHANGE, fly ? "enabled" : "disabled");
} else {
fp.msg(TL.COMMAND_FLY_DAMAGE);
}
}
setFallDamage(fp, fly, damage);
} }
public static void checkFly(FPlayer me, Faction factionTo) { public static void checkFly(FPlayer me, Faction factionTo) {
if (SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight")) { if (!SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight"))
if (!me.isAdminBypassing() || !me.isFlying()) { return;
Relation relationTo;
if (!me.isFlying()) {
if (me.isAdminBypassing()) {
setFly(me, true, false, false);
return;
}
if (factionTo == me.getFaction() && me.getPlayer().hasPermission("factions.fly")) { if (me.isAdminBypassing() && me.isFlying())
setFly(me, true, false, false); return;
} else {
relationTo = factionTo.getRelationTo(me); if (!me.isFlying()) {
if (factionTo.isWilderness() && me.canflyinWilderness() || factionTo.isWarZone() && me.canflyinWarzone() || factionTo.isSafeZone() && me.canflyinSafezone() || relationTo == Relation.ENEMY && me.canflyinEnemy() || relationTo == Relation.ALLY && me.canflyinAlly() || relationTo == Relation.TRUCE && me.canflyinTruce() || relationTo == Relation.NEUTRAL && me.canflyinNeutral()) { if (me.isAdminBypassing()) {
setFly(me, true, false, false); UtilFly.setFly(me, true, false, false);
} return;
} }
} else {
relationTo = factionTo.getRelationTo(me); if (factionTo == me.getFaction() && me.getPlayer().hasPermission("factions.fly")) {
if (factionTo.equals(me.getFaction()) && !me.getPlayer().hasPermission("factions.fly") || factionTo.isWilderness() && !me.canflyinWilderness() || factionTo.isWarZone() && !me.canflyinWarzone() || factionTo.isSafeZone() && !me.canflyinSafezone() || relationTo == Relation.ENEMY && !me.canflyinEnemy() || relationTo == Relation.ALLY && !me.canflyinAlly() || relationTo == Relation.TRUCE && !me.canflyinTruce() || relationTo == Relation.NEUTRAL && !me.canflyinNeutral()) { UtilFly.setFly(me, true, false, false);
setFly(me, false, false, false); } else {
} Relation relationTo = factionTo.getRelationTo(me);
if ((factionTo.isWilderness() && me.canflyinWilderness()) || (factionTo.isWarZone() && me.canflyinWarzone())
|| (factionTo.isSafeZone() && me.canflyinSafezone()) || (relationTo == Relation.ENEMY && me.canflyinEnemy())
|| (relationTo == Relation.ALLY && me.canflyinAlly()) || (relationTo == Relation.TRUCE && me.canflyinTruce())
|| (relationTo == Relation.NEUTRAL && me.canflyinNeutral())) {
UtilFly.setFly(me, true, false, false);
} }
}
} else {
Relation relationTo = factionTo.getRelationTo(me);
if ((factionTo.equals(me.getFaction()) && !me.getPlayer().hasPermission("factions.fly"))
|| (factionTo.isWilderness() && !me.canflyinWilderness()) || (factionTo.isWarZone() && !me.canflyinWarzone())
|| (factionTo.isSafeZone() && !me.canflyinSafezone()) || (relationTo == Relation.ENEMY && !me.canflyinEnemy())
|| (relationTo == Relation.ALLY && !me.canflyinAlly()) || (relationTo == Relation.TRUCE && !me.canflyinTruce())
|| (relationTo == Relation.NEUTRAL && !me.canflyinNeutral())) {
UtilFly.setFly(me, false, false, false);
} }
} }
} }
public static void setFallDamage(final FPlayer fp, boolean fly, boolean damage) { public static void setFallDamage(FPlayer fp, boolean fly, boolean damage) {
if (!fly) { if (!fly) {
if (!damage) { if (!damage) {
fp.sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", String.valueOf(SavageFactions.plugin.getConfig().getInt("fly-falldamage-cooldown", 3)))); fp.sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", SavageFactions.plugin.getConfig().getInt("fly-falldamage-cooldown", 3) + ""));
} }
int cooldown = SavageFactions.plugin.getConfig().getInt("fly-falldamage-cooldown", 3); int cooldown = SavageFactions.plugin.getConfig().getInt("fly-falldamage-cooldown", 3);
if (cooldown > 0) { if (cooldown > 0) {
fp.setTakeFallDamage(false); fp.setTakeFallDamage(false);
Bukkit.getScheduler().runTaskLater(SavageFactions.plugin, new Runnable() { Bukkit.getScheduler().runTaskLater(SavageFactions.plugin, () -> fp.setTakeFallDamage(true), 20L * cooldown);
public void run() {
fp.setTakeFallDamage(true);
}
}, 20L * (long) cooldown);
} }
} }
} }
} }