Skip to content

Commit f5fc430

Browse files
Touchie771JRoy
andauthored
fix(fly): persist fly mode and restore on join (#6403)
Persist /fly state in userdata and re-enable allowFlight on login so flight isn’t lost after relogging on ground (upstream #6344). <!-- EssentialsX bug fix submission guide ==================================== NOTE: Failure to fill out this template properly may result in your PR being delayed or ignored without warning. NOTE: Don't type between any arrows in the template, as this text will be hidden. This includes this header block and any other explanation text blocks. Want to discuss your PR before submitting it? Join the EssentialsX Development server: https://discord.gg/CUN7qVb EssentialsX is GPL ------------------ By contributing to EssentialsX, you agree to license your code under the GNU General Public License version 3, which can be found at the link below: https://github.com/EssentialsX/Essentials/blob/2.x/LICENSE Instructions ------------ If you are submitting a bug fix, please follow the following steps: 1. Fill out the template in full. This includes providing screenshots and a link to the original bug report. If there isn't an existing bug report, we recommend opening a new detailed bug report BEFORE opening your PR to fix it, else your PR may be delayed or rejected without warning. You can open a new bug report by following this link: https://github.com/EssentialsX/Essentials/issues/new/choose 2. When linking logs or config files, do not attach them to the post! Copy and paste any logs into https://gist.github.com/, then paste a link to them in the relevant parts of the template. Do not use Hastebin or Pastebin, as this can cause issues with future reviews. DO NOT drag logs directly into this text box, as we cannot read these! 3. If you are fixing a performance issue, please include a link to a Timings and/or profiler report, both before and after your PR. 4. If you are fixing a visual bug, such as in commands, please include screenshots so that we can more easily review the proposed fix. (You can drag screenshots into the bottom of the editor.) --> ### Information <!-- Replace #nnnn with the number of the original issue. If this PR fixes multiple issues, you should repeat the phrase "fixes #nnnn" for each issue. --> This PR fixes #6344 ### Details **Proposed fix:** <!-- Type a description of your proposed fix below this line. --> Persist the /fly state to userdata and restore allowFlight on login so flight isn’t lost after relogging while on the ground. **Environments tested:** <!-- Type the OS you have used below. --> OS: Ubuntu 24.04 <!-- Type the JDK version (from java -version) you have used below. --> Java version: 21 <!-- Put an "x" inside the boxes for the server software you have tested this bug fix on. If this feature does not apply to a server, strike through the server software using ~~strikethrough~~. If you have tested on other environments, add a new line with relevant details. --> - [x] Most recent Paper version (1.XX.Y, git-Paper-BUILD) - [x] Paper 1.21.8 - [ ] CraftBukkit/Spigot/Paper 1.12.2 - [ ] CraftBukkit 1.8.8 --------- Co-authored-by: JRoy <10731363+JRoy@users.noreply.github.com>
1 parent 08b7fe3 commit f5fc430

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,20 @@ private void joinFlow(final User user, final long currentTime, final String mess
503503
});
504504
}
505505

506+
final boolean restoreFly = user.isFlyModeEnabled() && user.isAuthorized("essentials.fly");
507+
if (restoreFly) {
508+
user.getBase().setAllowFlight(true);
509+
if (ess.getSettings().isSendFlyEnableOnJoin()) {
510+
user.sendTl("flyMode", CommonPlaceholders.enableDisable(user.getSource(), true), user.getDisplayName());
511+
}
512+
}
513+
506514
if (user.isAuthorized("essentials.fly.safelogin")) {
507515
user.getBase().setFallDistance(0);
508516
if (LocationUtil.shouldFly(ess, user.getLocation())) {
509517
user.getBase().setAllowFlight(true);
510518
user.getBase().setFlying(true);
511-
if (ess.getSettings().isSendFlyEnableOnJoin()) {
519+
if (!restoreFly && ess.getSettings().isSendFlyEnableOnJoin()) {
512520
user.sendTl("flyMode", CommonPlaceholders.enableDisable(user.getSource(), true), user.getDisplayName());
513521
}
514522
}
@@ -524,6 +532,11 @@ private void joinFlow(final User user, final long currentTime, final String mess
524532
ess.getLogger().log(Level.INFO, "Set socialspy to false for {0} because they had it enabled without permission.", user.getName());
525533
}
526534

535+
if (user.isFlyModeEnabled() && !user.isAuthorized("essentials.fly")) {
536+
user.setFlyModeEnabled(false);
537+
ess.getLogger().log(Level.INFO, "Set fly mode to false for {0} because they had it enabled without permission.", user.getName());
538+
}
539+
527540
if (user.isGodModeEnabled() && !user.isAuthorized("essentials.god")) {
528541
user.setGodModeEnabled(false);
529542
ess.getLogger().log(Level.INFO, "Set god mode to false for {0} because they had it enabled without permission.", user.getName());

Essentials/src/main/java/com/earth2me/essentials/UserData.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,15 @@ public void setGodModeEnabled(final boolean set) {
469469
config.save();
470470
}
471471

472+
public boolean isFlyModeEnabled() {
473+
return holder.flyMode();
474+
}
475+
476+
public void setFlyModeEnabled(final boolean set) {
477+
holder.flyMode(set);
478+
config.save();
479+
}
480+
472481
public boolean getMuted() {
473482
return holder.muted();
474483
}

Essentials/src/main/java/com/earth2me/essentials/commands/Commandfly.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ protected void togglePlayer(final CommandSource sender, final User user, Boolean
3434
user.getBase().setFallDistance(0f);
3535
user.getBase().setAllowFlight(enabled);
3636

37+
user.setFlyModeEnabled(enabled);
38+
3739
if (!user.getBase().getAllowFlight()) {
3840
user.getBase().setFlying(false);
3941
}

Essentials/src/main/java/com/earth2me/essentials/config/holders/UserConfigHolder.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ public void godMode(final boolean value) {
171171
this.godmode = value;
172172
}
173173

174+
private boolean flymode = false;
175+
176+
public boolean flyMode() {
177+
return this.flymode;
178+
}
179+
180+
public void flyMode(final boolean value) {
181+
this.flymode = value;
182+
}
183+
174184
private boolean muted = false;
175185

176186
public boolean muted() {

0 commit comments

Comments
 (0)