From 8697de9e85d22b8c0c722801477fc13247921157 Mon Sep 17 00:00:00 2001 From: Driftay Date: Sat, 9 Mar 2019 13:40:13 -0500 Subject: [PATCH 1/2] Fixed NullPointer With UtilFight --- .../massivecraft/factions/util/UtilFly.java | 133 +++++++++--------- 1 file changed, 63 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/util/UtilFly.java b/src/main/java/com/massivecraft/factions/util/UtilFly.java index c8acf539..e931a398 100644 --- a/src/main/java/com/massivecraft/factions/util/UtilFly.java +++ b/src/main/java/com/massivecraft/factions/util/UtilFly.java @@ -12,103 +12,96 @@ import java.util.Iterator; public class UtilFly { - public static ArrayList playersFlying; + public static ArrayList playersFlying = SavageFactions.playersFlying; - static { - playersFlying = SavageFactions.playersFlying; - } + public static void call() { + if (!SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight")) + return; - public UtilFly() { - } + playersFlying.clear(); - public static void run() { - if (SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight")) { - playersFlying.clear(); - Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, new Runnable() { - public void run() { - Iterator var2 = UtilFly.playersFlying.iterator(); - - while (var2.hasNext()) { - FPlayer fp = (FPlayer) var2.next(); - if (fp != null) { - fp.checkIfNearbyEnemies(); - } - } - - } - }, 0L, (long) SavageFactions.plugin.getConfig().getInt("fly-task-interval", 10)); - } + Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, () -> { + for (FPlayer fp : playersFlying) { + if (fp != null) + fp.checkIfNearbyEnemies(); + } + }, 0, SavageFactions.plugin.getConfig().getInt("fly-task-interval", 10)); } public static void setFly(FPlayer fp, boolean fly, boolean silent, boolean damage) { - if (SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight")) { - fp.getPlayer().setAllowFlight(fly); - fp.getPlayer().setFlying(fly); - fp.setFlying(fly); - if (fly) { - playersFlying.add(fp); - } else { - playersFlying.remove(fp); - } + if (!SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight")) + return; - if (!silent) { - if (!damage) { - fp.msg(TL.COMMAND_FLY_CHANGE, fly ? "enabled" : "disabled"); - } else { - fp.msg(TL.COMMAND_FLY_DAMAGE); - } - } + fp.getPlayer().setAllowFlight(fly); + fp.getPlayer().setFlying(fly); + fp.setFlying(fly); - 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) { - if (SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight")) { - if (!me.isAdminBypassing() || !me.isFlying()) { - Relation relationTo; - if (!me.isFlying()) { - if (me.isAdminBypassing()) { - setFly(me, true, false, false); - return; - } + if (!SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight")) + return; - if (factionTo == me.getFaction() && me.getPlayer().hasPermission("factions.fly")) { - setFly(me, true, false, false); - } else { - 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()) { - setFly(me, true, false, false); - } - } - } else { - 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()) { - setFly(me, false, false, false); - } + if (me.isAdminBypassing() && me.isFlying()) + return; + + if (!me.isFlying()) { + if (me.isAdminBypassing()) { + UtilFly.setFly(me, true, false, false); + return; + } + + if (factionTo == me.getFaction() && me.getPlayer().hasPermission("factions.fly")) { + UtilFly.setFly(me, true, 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 (!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); if (cooldown > 0) { fp.setTakeFallDamage(false); - Bukkit.getScheduler().runTaskLater(SavageFactions.plugin, new Runnable() { - public void run() { - fp.setTakeFallDamage(true); - } - }, 20L * (long) cooldown); + Bukkit.getScheduler().runTaskLater(SavageFactions.plugin, () -> fp.setTakeFallDamage(true), 20L * cooldown); } } - } } + From cbf4467f8421be1ab741674e06253470a67f698a Mon Sep 17 00:00:00 2001 From: Driftay Date: Sat, 9 Mar 2019 13:51:06 -0500 Subject: [PATCH 2/2] Fixed OutPut Error Code By Renaming Run Method --- src/main/java/com/massivecraft/factions/util/UtilFly.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/massivecraft/factions/util/UtilFly.java b/src/main/java/com/massivecraft/factions/util/UtilFly.java index e931a398..954fc9ff 100644 --- a/src/main/java/com/massivecraft/factions/util/UtilFly.java +++ b/src/main/java/com/massivecraft/factions/util/UtilFly.java @@ -14,7 +14,7 @@ public class UtilFly { public static ArrayList playersFlying = SavageFactions.playersFlying; - public static void call() { + public static void run() { if (!SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight")) return;