Skip to content

Commit

Permalink
Particles on vanish/gamemode issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Spazzinq authored Apr 20, 2019
1 parent 03106f7 commit e5a48f7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.bukkit.Location;
import org.bukkit.command.*;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
Expand All @@ -72,7 +73,7 @@ public final class FlightControl extends org.bukkit.plugin.java.JavaPlugin {

// Msg when command enabled
private ArrayList<Player> notif = new ArrayList<>();
ArrayList<Player> fall = new ArrayList<>();
ArrayList<Entity> fall = new ArrayList<>();

private Combat combat = new Combat();
private BaseTowny towny = new BaseTowny();
Expand Down Expand Up @@ -188,7 +189,7 @@ private void enableFlight(Player p) {
private void disableFlight(Player p) {
if (Config.command) notif.remove(p);
if (Config.cancelFall && p.isFlying()) { fall.add(p);
new BukkitRunnable() { public void run() { fall.remove(p); } }.runTaskLater(this, 120); }
new BukkitRunnable() { public void run() { fall.remove(p); } }.runTaskLater(this, 300); }
p.setAllowFlight(false);
p.setFlying(false);
Sound.play(p, Config.dSound);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,52 +49,48 @@ final class Listener implements org.bukkit.event.Listener {
Listener(FlightControl i) { pl = i; Bukkit.getPluginManager().registerEvents(this, i); }

private void trailCheck(Player p) {
if (pl.particles != null)
if (pl.particles != null && p.getGameMode() != GameMode.SPECTATOR)
partTasks.put(p, new BukkitRunnable() {
public void run() {
if (Config.trail && !Config.trailPrefs.contains(p.getUniqueId().toString()) && !pl.vanish.vanished(p))
pl.particles.play(p.getLocation());
}
}.runTaskTimerAsynchronously(pl, 0, 4));
}.runTaskTimerAsynchronously(pl, 0, 3));
}
// Fly particles
@EventHandler private void onFly(PlayerToggleFlightEvent e) {
Player p = e.getPlayer();
if (e.isFlying()) {
if (Config.everyEnable) Sound.play(p, Config.eSound);
trailCheck(p);
}
}
else {
BukkitTask task = partTasks.remove(p);
BukkitTask task = partTasks.remove(p);
if (task != null) task.cancel();
}
}
@EventHandler private void onGamemode(PlayerGameModeChangeEvent e) {
if (e.getNewGameMode() == GameMode.SPECTATOR) {
BukkitTask task = partTasks.remove(e.getPlayer());
if (task != null) task.cancel();
}
else if (e.getPlayer().isFlying()) trailCheck(e.getPlayer());
}

// Check fly status
@EventHandler(priority = EventPriority.HIGHEST) private void onMove(PlayerMoveEvent e) {
Player p = e.getPlayer();
pl.check(p, e.getTo());
}
@EventHandler(priority = EventPriority.HIGHEST) private void onMove(PlayerMoveEvent e) { pl.check(e.getPlayer(), e.getTo()); }
@EventHandler private void onLeave(PlayerQuitEvent e) { BukkitTask task = partTasks.remove(e.getPlayer()); if (task != null) task.cancel(); }
@EventHandler private void onJoin(PlayerJoinEvent e) {
Player p = e.getPlayer(); pl.check(p);
if (p.isFlying()) new BukkitRunnable() { public void run() { trailCheck(p); } }.runTaskLater(pl, 2);
if (p.isFlying()) new BukkitRunnable() { public void run() { trailCheck(p); } }.runTask(pl);
}
@EventHandler private void onCommand(PlayerCommandPreprocessEvent e) {
Player p = e.getPlayer();
new BukkitRunnable() { public void run() {
pl.check(p);
// TODO Only check fly commands/Move spectator back to trailCheck
if (p.isFlying() && !partTasks.containsKey(p)) new BukkitRunnable() { public void run() { trailCheck(p); } }.runTask(pl);
else if ((!p.isFlying() || p.getGameMode() == GameMode.SPECTATOR) && partTasks.containsKey(p)) { BukkitTask task = partTasks.remove(e.getPlayer()); if (task != null) task.cancel(); }
} }.runTask(pl);
}
@EventHandler private void onCommand(PlayerCommandPreprocessEvent e) { new BukkitRunnable() { public void run() { pl.check(e.getPlayer()); } }.runTaskLater(pl, 1); }

// Fall damage prevention
@EventHandler private void onFallDamage(EntityDamageEvent e) {
if (e.getEntity() instanceof Player && e.getCause() == DamageCause.FALL) {
Player p = (Player) e.getEntity();
if (pl.fall.contains(p)) { e.setCancelled(true); pl.fall.remove(p); }
}
if (e.getEntity() instanceof Player && e.getCause() == DamageCause.FALL &&
pl.fall.remove(e.getEntity())) e.setCancelled(true);
}

// On-the-fly permission management
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

<modules>
<module>FlightControl</module>
<module>Multiversion</module>
<module>v8</module>
<module>v13</module>
<module>Multiversion</module>
</modules>
</project>
2 changes: 1 addition & 1 deletion v13/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit e5a48f7

Please sign in to comment.