Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,40 @@ private void onMove(PlayerMoveEvent e) {
* Checks a player's flight status when they teleport, and disables the trail if necessary.
*/
@EventHandler private void onTP(PlayerTeleportEvent e) {
// Prevent calling on login because another handler takes care of that
// Only check if not login because onJoin handles login
if (e.getCause() != PlayerTeleportEvent.TeleportCause.UNKNOWN) {
Player p = e.getPlayer();

pl.getFlightManager().check(p);
// Only check if same worlds because onWorldChange handles world changes
if (e.getFrom().getWorld().equals(e.getTo().getWorld())) {
pl.getFlightManager().check(p);
}

// Fixes a bug where particles remain when not supposed so
// Fixes a bug where particles remain when not supposed to
if (!p.getAllowFlight()) {
pl.getTrailManager().disableTrail(p);
}
}
}

/**
* Checks a player's flight status when they change worlds, and disables the trail if necessary.
*
* Note: Must use world change event because otherwise the manager checks from the previous
* world and enables flight incorrectly.
*/
@EventHandler private void onWorldChange(PlayerChangedWorldEvent e) {
Player p = e.getPlayer();

pl.getFlightManager().check(p);

// Fixes a bug where particles remain when not supposed to
if (!p.getAllowFlight()) {
pl.getTrailManager().disableTrail(p);
}

}

/**
* Pauses temporary flight timer and removes trail on player disconnect.
*/
Expand Down Expand Up @@ -196,7 +217,8 @@ public void run() {
* Checks tempfly timer when a player interacts
* with a sign because signs may affect tempfly status.
*/
@EventHandler(priority = EventPriority.MONITOR) private void onSignInteract(PlayerInteractEvent e) {
@EventHandler(priority = EventPriority.MONITOR)
private void onSignInteract(PlayerInteractEvent e) {
if (e.hasBlock()) {
// Workaround for multiple versions (I hope)
if (e.getClickedBlock().getState() instanceof Sign) {
Expand Down Expand Up @@ -233,4 +255,4 @@ public void run() {
@EventHandler private void onWorldInit(WorldInitEvent e) {
pl.getPermissionManager().registerDefaultFlyPerms(e.getWorld().getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,23 @@ public void check(Player p, boolean isCommand) {
boolean disable = !disableChecks.isEmpty();
Cause enableCause = enable ? enableChecks.iterator().next().getCause() : null;
Cause disableCause = disable ? disableChecks.iterator().next().getCause() : null;

if (p.getAllowFlight()) {
// If override or not enabled
if (disable || !enable) {
disableFlight(p, disableCause,false);
}
// If all clear to enable

} else if (enable && !disable) {
// If directly enabled or auto-enable is enabled

if (isCommand || (pl.getConfManager().isAutoEnable() && !disabledByPlayer.contains(p))) {
enableFlight(p, enableCause, isCommand);
} else {
canEnable(p, enableCause);
}
// If denied
} else if (isCommand || alreadyCanMsg.contains(p)) {
} else if (isCommand || (alreadyCanMsg.contains(p) && !disabledByPlayer.contains(p))) {
cannotEnable(p, disableCause);
}
// If bypassing checks
Expand Down Expand Up @@ -124,6 +125,9 @@ private void cannotEnable(Player p, Cause cause) {
APIManager.getInstance().callEvent(e);

if (!e.isCancelled()) {
pl.getPlayerManager().getFlightPlayer(p).getTempflyTimer().pause();
p.setAllowFlight(false);
p.setFlying(false);
alreadyCanMsg.remove(p);
Sound.play(p, e.getSound());
msg(p, e.getMessage(), e.isByActionbar());
Expand All @@ -140,6 +144,7 @@ private void enableFlight(Player p, Cause cause, boolean isCommand) {
if (isCommand) {
disabledByPlayer.remove(p);
}
alreadyCanMsg.add(p);
p.setAllowFlight(true);
// Ignore if not double-tapped
if (!Sound.playEveryEnable) {
Expand All @@ -154,16 +159,14 @@ public void disableFlight(Player p, Cause cause, boolean isCommand) {
Sound.disableSound, pl.getLangManager().useActionBar(), isCommand);

APIManager.getInstance().callEvent(e);

if (!e.isCancelled()) {

pl.getPlayerManager().getFlightPlayer(p).getTempflyTimer().pause();

if (isCommand) {
disabledByPlayer.add(p);
alreadyCanMsg.add(p);
} else {
alreadyCanMsg.remove(p);
}
alreadyCanMsg.remove(p);

if (pl.getConfManager().isCancelFall() && p.isFlying()) {
noFallDmg.add(p);
Expand Down