Even more fly changes

This commit is contained in:
DroppingAnvil 2020-04-26 12:53:48 -05:00 committed by droppinganvil
parent b89db7b082
commit f2c6d0b9da
4 changed files with 20 additions and 24 deletions

View File

@ -424,6 +424,8 @@ public class Conf {
public static HashMap<String, DefaultPermissions> defaultFactionPermissions = new HashMap<>(); public static HashMap<String, DefaultPermissions> defaultFactionPermissions = new HashMap<>();
public static HashSet<PermissableAction> lockedPermissions = new HashSet<>(); public static HashSet<PermissableAction> lockedPermissions = new HashSet<>();
public static boolean useComplexFly = true;
public static boolean wildLoadChunkBeforeTeleport = true; public static boolean wildLoadChunkBeforeTeleport = true;
private static transient Conf i = new Conf(); private static transient Conf i = new Conf();

View File

@ -24,7 +24,7 @@ public class CmdFly extends FCommand {
*/ */
public static ConcurrentHashMap<String, Boolean> flyMap = new ConcurrentHashMap<>(); public static ConcurrentHashMap<FPlayer, Boolean> flyMap = new ConcurrentHashMap<>();
public static BukkitTask particleTask = null; public static BukkitTask particleTask = null;
public static BukkitTask flyTask = null; public static BukkitTask flyTask = null;
public static boolean autoenable = FactionsPlugin.instance.getConfig().getBoolean("ffly.AutoEnable"); public static boolean autoenable = FactionsPlugin.instance.getConfig().getBoolean("ffly.AutoEnable");
@ -44,16 +44,13 @@ public class CmdFly extends FCommand {
public static void startParticles() { public static void startParticles() {
particleTask = Bukkit.getScheduler().runTaskTimerAsynchronously(FactionsPlugin.instance, () -> { particleTask = Bukkit.getScheduler().runTaskTimerAsynchronously(FactionsPlugin.instance, () -> {
for (String name : flyMap.keySet()) { for (FPlayer fPlayer : flyMap.keySet()) {
Player player = Bukkit.getPlayer(name); Player player = fPlayer.getPlayer();
if (player == null) continue; if (!player.isOnline() || !player.isFlying()) continue;
if (!player.isFlying()) continue;
if (!FactionsPlugin.getInstance().mc17) { if (!FactionsPlugin.getInstance().mc17) {
if (player.getGameMode() == GameMode.SPECTATOR) continue; if (player.getGameMode() == GameMode.SPECTATOR) continue;
} }
fPlayer.isVanished();
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
fplayer.isVanished();
} }
if (flyMap.isEmpty()) { if (flyMap.isEmpty()) {
particleTask.cancel(); particleTask.cancel();
@ -66,18 +63,14 @@ public class CmdFly extends FCommand {
flyTask = Bukkit.getScheduler().runTaskTimerAsynchronously(FactionsPlugin.instance, () -> { flyTask = Bukkit.getScheduler().runTaskTimerAsynchronously(FactionsPlugin.instance, () -> {
checkTaskState(); checkTaskState();
if (flyMap.keySet().size() != 0) { if (flyMap.keySet().size() != 0) {
for (String name : flyMap.keySet()) { for (FPlayer fPlayer : flyMap.keySet()) {
if (name == null) { Player player = fPlayer.getPlayer();
continue;
}
Player player = Bukkit.getPlayer(name);
if (player == null if (player == null
|| !player.isFlying() || !player.isFlying()
|| player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.CREATIVE
|| !FactionsPlugin.getInstance().mc17 && player.getGameMode() == GameMode.SPECTATOR) { || !FactionsPlugin.getInstance().mc17 && player.getGameMode() == GameMode.SPECTATOR) {
continue; continue;
} }
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
if (fPlayer.isAdminBypassing()) continue; if (fPlayer.isAdminBypassing()) continue;
if (!player.hasPermission("factions.fly.bypassnearbyenemycheck")) { if (!player.hasPermission("factions.fly.bypassnearbyenemycheck")) {
if (fPlayer.hasEnemiesNearby()) { if (fPlayer.hasEnemiesNearby()) {
@ -101,7 +94,7 @@ public class CmdFly extends FCommand {
if ((Conf.denyFlightIfInNoClaimingWorld && !Conf.worldsNoClaiming.isEmpty() && Conf.worldsNoClaiming.stream().anyMatch(me.getWorld().getName()::equalsIgnoreCase)) || !me.hasPermission(Permission.FLY_FLY.node)) if ((Conf.denyFlightIfInNoClaimingWorld && !Conf.worldsNoClaiming.isEmpty() && Conf.worldsNoClaiming.stream().anyMatch(me.getWorld().getName()::equalsIgnoreCase)) || !me.hasPermission(Permission.FLY_FLY.node))
return false; return false;
if (toFac.getAccess(fme, PermissableAction.FLY) == Access.ALLOW) return true; if (toFac.getAccess(fme, PermissableAction.FLY) == Access.ALLOW) return true;
if (fme.getFaction().isWilderness()) return false; if (fme.getFaction().isWilderness() || !Conf.useComplexFly) return false;
if (toFac.isSystemFaction()) if (toFac.isSystemFaction())
return me.hasPermission(toFac.isWilderness() ? Permission.FLY_WILDERNESS.node : toFac.isSafeZone() ? Permission.FLY_SAFEZONE.node : Permission.FLY_WARZONE.node); return me.hasPermission(toFac.isWilderness() ? Permission.FLY_WILDERNESS.node : toFac.isSafeZone() ? Permission.FLY_SAFEZONE.node : Permission.FLY_WARZONE.node);
Relation relationTo = toFac.getRelationTo(fme.getFaction()); Relation relationTo = toFac.getRelationTo(fme.getFaction());
@ -120,20 +113,20 @@ public class CmdFly extends FCommand {
public static void disableFlight(final FPlayer fme) { public static void disableFlight(final FPlayer fme) {
fme.setFlying(false); fme.setFlying(false);
flyMap.remove(fme.getPlayer().getName()); flyMap.remove(fme);
} }
private static void disableFlightSync(FPlayer fme) { private static void disableFlightSync(FPlayer fme) {
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> fme.setFFlying(false, false)); Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> fme.setFFlying(false, false));
flyMap.remove(fme.getName()); flyMap.remove(fme);
} }
private static void checkEnemiesSync(FPlayer fp) { private static void checkEnemiesSync(FPlayer fp) {
Bukkit.getScheduler().runTask(FactionsPlugin.instance, fp::checkIfNearbyEnemies); Bukkit.getScheduler().runTask(FactionsPlugin.instance, fp::checkIfNearbyEnemies);
} }
public boolean isInFlightChecker(Player player) { public boolean isInFlightChecker(FPlayer fPlayer) {
return flyMap.containsKey(player.getName()); return flyMap.containsKey(fPlayer);
} }
@Override @Override
@ -171,13 +164,13 @@ public class CmdFly extends FCommand {
private void toggleFlight(final boolean toggle, final FPlayer fme, CommandContext context) { private void toggleFlight(final boolean toggle, final FPlayer fme, CommandContext context) {
if (toggle) { if (toggle) {
fme.setFlying(false); fme.setFlying(false);
flyMap.remove(fme.getPlayer().getName()); flyMap.remove(fme);
return; return;
} }
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, true);
if (particleTask == null) { if (particleTask == null) {
startParticles(); startParticles();
} }

View File

@ -60,7 +60,8 @@ public class WildGUI implements FactionGUI {
inv.setItem(fill, fillItem); inv.setItem(fill, fillItem);
} }
for (String key : Objects.requireNonNull(FactionsPlugin.getInstance().getConfig().getConfigurationSection("Wild.Zones")).getKeys(false)) { for (String key : Objects.requireNonNull(FactionsPlugin.getInstance().getConfig().getConfigurationSection("Wild.Zones")).getKeys(false)) {
ItemStack zoneItem = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getConfig().getString("Wild.Zones." + key + ".Material")).get().parseItem(); ItemStack zoneItem = XMaterial.matchXMaterial(Objects.requireNonNull(FactionsPlugin.getInstance().getConfig().getString("Wild.Zones." + key + ".Material"))).get().parseItem();
assert zoneItem != null;
ItemMeta zoneMeta = zoneItem.getItemMeta(); ItemMeta zoneMeta = zoneItem.getItemMeta();
if (zoneMeta == null) return; if (zoneMeta == null) return;
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();

View File

@ -582,7 +582,7 @@ public class FactionsPlayerListener implements Listener {
if (me.isFlying()) return; if (me.isFlying()) return;
if (me.getPlayer().hasPermission(Permission.FLY_FLY.node)) { if (me.getPlayer().hasPermission(Permission.FLY_FLY.node)) {
me.setFFlying(true, false); me.setFFlying(true, false);
CmdFly.flyMap.put(me.getName(), true); CmdFly.flyMap.put(me, true);
if (CmdFly.particleTask == null) if (CmdFly.particleTask == null)
CmdFly.startParticles(); CmdFly.startParticles();
} }
@ -726,7 +726,7 @@ public class FactionsPlayerListener implements Listener {
} }
if (FCmdRoot.instance.fFlyEnabled && CmdFly.autoenable && CmdFly.checkFly(me, me.getPlayer(), factionTo)) { if (FCmdRoot.instance.fFlyEnabled && CmdFly.autoenable && CmdFly.checkFly(me, me.getPlayer(), factionTo)) {
me.setFFlying(true, false); me.setFFlying(true, false);
CmdFly.flyMap.put(me.getName(), true); CmdFly.flyMap.put(me, true);
if (CmdFly.particleTask == null) if (CmdFly.particleTask == null)
CmdFly.startParticles(); CmdFly.startParticles();
} }