Runnable to Lambda

This commit is contained in:
Driftay 2019-03-27 10:54:32 -04:00
parent 173676fa31
commit ec36827378
1 changed files with 78 additions and 87 deletions

View File

@ -44,10 +44,54 @@ public class CmdFly extends FCommand {
return; return;
} }
id = Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, new Runnable() { id = Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, () -> {
@Override for (String name : flyMap.keySet()) {
public void run() { Player player = Bukkit.getPlayer(name);
if (player == null) {
continue;
}
if (!player.isFlying()) {
continue;
}
if (!SavageFactions.plugin.mc17) {
if (player.getGameMode() == GameMode.SPECTATOR) {
continue;
}
}
if (FPlayers.getInstance().getByPlayer(player).isVanished()) {
// Actually, vanished players (such as admins) should not display particles to prevent others from knowing their vanished assistance for moderation.
// But we can keep it as a config.
if (SavageFactions.plugin.getConfig().getBoolean("ffly.Particles.Enable-While-Vanished")) {
return;
}
continue;
}
if (SavageFactions.plugin.useNonPacketParticles) {
// 1.9+ based servers will use the built in particleAPI instead of packet based.
// any particle amount higher than 0 made them go everywhere, and the offset at 0 was not working.
// So setting the amount to 0 spawns 1 in the precise location
player.getWorld().spawnParticle(Particle.CLOUD, player.getLocation().add(0, -0.35, 0), 0);
} else {
ParticleEffect.CLOUD.display((float) 0, (float) 0, (float) 0, (float) 0, 3, player.getLocation().add(0, -0.35, 0), 16);
}
}
if (flyMap.keySet().size() == 0) {
Bukkit.getScheduler().cancelTask(id);
id = -1;
}
}, 10L, 3L);
}
public static void startFlyCheck() {
flyid = Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, () -> { //threw the exception for now, until I recode fly :( Cringe.
checkTaskState();
if (flyMap.keySet().size() != 0) {
for (String name : flyMap.keySet()) { for (String name : flyMap.keySet()) {
if (name == null) {
continue;
}
Player player = Bukkit.getPlayer(name); Player player = Bukkit.getPlayer(name);
if (player == null) { if (player == null) {
continue; continue;
@ -55,88 +99,38 @@ public class CmdFly extends FCommand {
if (!player.isFlying()) { if (!player.isFlying()) {
continue; continue;
} }
if (!SavageFactions.plugin.mc17) { FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
if (player.getGameMode() == GameMode.SPECTATOR) { if (fPlayer == null) {
continue;
}
}
if (FPlayers.getInstance().getByPlayer(player).isVanished()) {
// Actually, vanished players (such as admins) should not display particles to prevent others from knowing their vanished assistance for moderation.
// But we can keep it as a config.
if (SavageFactions.plugin.getConfig().getBoolean("ffly.Particles.Enable-While-Vanished")) {
return;
}
continue; continue;
} }
if (SavageFactions.plugin.useNonPacketParticles) { if (player.getGameMode() == GameMode.CREATIVE) {
// 1.9+ based servers will use the built in particleAPI instead of packet based. continue;
// any particle amount higher than 0 made them go everywhere, and the offset at 0 was not working.
// So setting the amount to 0 spawns 1 in the precise location
player.getWorld().spawnParticle(Particle.CLOUD, player.getLocation().add(0, -0.35, 0), 0);
} else {
ParticleEffect.CLOUD.display((float) 0, (float) 0, (float) 0, (float) 0, 3, player.getLocation().add(0, -0.35, 0), 16);
} }
if (!SavageFactions.plugin.mc17 && player.getGameMode() == GameMode.SPECTATOR) {
} continue;
if (flyMap.keySet().size() == 0) { }
Bukkit.getScheduler().cancelTask(id); Faction myFaction = fPlayer.getFaction();
id = -1; if (myFaction.isWilderness()) {
} fPlayer.setFlying(false);
} flyMap.remove(name);
}, 10L, 3L); continue;
} }
if (fPlayer.checkIfNearbyEnemies()) {
public static void startFlyCheck() { continue;
flyid = Bukkit.getScheduler().scheduleSyncRepeatingTask(SavageFactions.plugin, new Runnable() { }
@Override FLocation myFloc = new FLocation(player.getLocation());
public void run() throws ConcurrentModificationException { //threw the exception for now, until I recode fly :( Cringe. Faction toFac = Board.getInstance().getFactionAt(myFloc);
checkTaskState(); if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
if (flyMap.keySet().size() != 0) { if (!checkBypassPerms(fPlayer, player, toFac)) {
for (String name : flyMap.keySet()) {
if (name == null) {
continue;
}
Player player = Bukkit.getPlayer(name);
if (player == null) {
continue;
}
if (!player.isFlying()) {
continue;
}
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
if (fPlayer == null) {
continue;
}
if (player.getGameMode() == GameMode.CREATIVE) {
continue;
}
if (!SavageFactions.plugin.mc17 && player.getGameMode() == GameMode.SPECTATOR) {
continue;
}
Faction myFaction = fPlayer.getFaction();
if (myFaction.isWilderness()) {
fPlayer.setFlying(false); fPlayer.setFlying(false);
flyMap.remove(name); flyMap.remove(name);
continue; continue;
} }
if (fPlayer.checkIfNearbyEnemies()) {
continue;
}
FLocation myFloc = new FLocation(player.getLocation());
Faction toFac = Board.getInstance().getFactionAt(myFloc);
if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
if (!checkBypassPerms(fPlayer, player, toFac)) {
fPlayer.setFlying(false);
flyMap.remove(name);
continue;
}
}
} }
}
}
} }
}, 20L, 20L); }, 20L, 20L);
} }
@ -226,20 +220,17 @@ public class CmdFly extends FCommand {
if (fme.canFlyAtLocation()) if (fme.canFlyAtLocation())
this.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", new Runnable() { this.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> {
@Override fme.setFlying(true);
public void run() { flyMap.put(player.getName(), true);
fme.setFlying(true); if (id == -1) {
flyMap.put(player.getName(), true); if (SavageFactions.plugin.getConfig().getBoolean("ffly.Particles.Enabled")) {
if (id == -1) { startParticles();
if (SavageFactions.plugin.getConfig().getBoolean("ffly.Particles.Enabled")) {
startParticles();
}
}
if (flyid == -1) {
startFlyCheck();
} }
} }
if (flyid == -1) {
startFlyCheck();
}
}, this.p.getConfig().getLong("warmups.f-fly", 0)); }, this.p.getConfig().getLong("warmups.f-fly", 0));
} }