Skip to content

Conversation

@Hunh0w
Copy link
Contributor

@Hunh0w Hunh0w commented Dec 11, 2024

Information

This PR fixes #5963.

Details

Proposed fix:
If the player uses "/home bed" when he doesn't have the "essentials.home.bed" permission, he's getting a no permission error for it

Environments tested:

OS: Ubuntu 24.04.1 LTS

Java version: 21

  • Most recent Paper version (1.XX.Y, git-Paper-BUILD)
  • CraftBukkit/Spigot/Paper 1.12.2
  • CraftBukkit 1.8.8

Demonstration:

Copy link
Member

@pop4959 pop4959 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for making your first PR to Essentials! We appreciate it.

I left a few comments for you to look at. Please also share proof of testing (show before/after screenshot is probably the easiest) in the demonstration section which you left blank.

Also, in the original issue, essentials.sethome.bed is mentioned. Have you checked if there is a problem with /sethome or is this working as intended?

@Hunh0w
Copy link
Contributor Author

Hunh0w commented Dec 12, 2024

Hey, thanks you too for your feedback ! ^^
I updated this PR according to your comments.

I added a fix for the essentials.sethome.bed there was a problem, we couldn't prevent player from setting his bed position even with this permission to false

Screenshots of the before behaviour:
Capture d’écran du 2024-12-12 09-03-19
Capture d’écran du 2024-12-12 10-11-26

Screenshots of the after behaviour:
Capture d’écran du 2024-12-12 10-09-24
no_bed_perm_result

For the bed sethome, if we don't have the permission it doesn't produce anything, maybe i should add an error message in this case ?

@Hunh0w Hunh0w changed the title fix: essentials.home.bed permission fix: essentials.home.bed & essentials.sethome.bed permissions Dec 12, 2024
@Hunh0w Hunh0w requested a review from pop4959 December 12, 2024 09:33
@mdcfe mdcfe added this to the 2.21.2 milestone Apr 19, 2025
@JRoy JRoy requested a review from Copilot May 25, 2025 02:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures players need the correct permissions for bed-related home commands, preventing misleading errors and unauthorized actions.

  • Adds a permission check for /home bed to show a no-permission message instead of a generic no-home error.
  • Cancels bed spawn setting in the world when a player lacks the essentials.sethome.bed permission.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java Wrapped the teleport event and spawn logic in a bed-permission check and shows a no-perm error.
Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java Introduced an isAuthorized flag and cancels bed-click interactions when permission is missing.
Comments suppressed due to low confidence (2)

Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java:76

  • [nitpick] Consider moving the permission check before creating the UserTeleportHomeEvent to avoid instantiating and scheduling events for users who aren’t authorized.
final UserTeleportHomeEvent event = new UserTeleportHomeEvent(user, null, bed != null ? bed : finalPlayer.getWorld().getSpawnLocation(), bed != null ? UserTeleportHomeEvent.HomeType.BED : UserTeleportHomeEvent.HomeType.SPAWN);

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

  • [nitpick] The variable name isAuthorized is generic; consider renaming to hasSethomeBedPermission for clarity about which permission is being checked.
final boolean isAuthorized = player.isAuthorized("essentials.sethome.bed");

@JRoy
Copy link
Member

JRoy commented May 25, 2025

thanks!

@JRoy JRoy dismissed pop4959’s stale review May 25, 2025 03:01

addressed

@JRoy JRoy merged commit 3fe1495 into EssentialsX:2.x May 25, 2025
1 check passed
@Potothingi
Copy link

Since this commit I can't sleep at night and can't set respawn point. Previous build (2.21.1-dev+18-3b0c229) was fine.

essentials.home: true
essentials.home.bed: true

@mdcfe mdcfe modified the milestones: 2.21.2, 2.21.1 May 25, 2025
player.sendTl("bedSet", player.getLocation().getWorld().getName(), player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
}
} else if (!isAuthorized) {
event.setCancelled(true);
Copy link
Member

@mdcfe mdcfe May 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents people interacting with the bed. Why was this changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was because if someone interact with a bed, they automatically set the bed home even if they don't have the permission

@mdcfe mdcfe removed this from the 2.21.1 milestone May 25, 2025
mdcfe added a commit that referenced this pull request May 25, 2025
mdcfe added a commit that referenced this pull request May 25, 2025
Euphillya added a commit to Euphillya/Essentials-Folia that referenced this pull request Jun 27, 2025
EssentialsX@40540eb Expose IUser#getLastActivityTime to API (EssentialsX#6101)
EssentialsX@50b696b Adds social spy message type for in EssentialsDiscord (EssentialsX#5620)
EssentialsX@dabe687 Add SignTransactionEvent for buy and sell signs (EssentialsX#6071)
EssentialsX@0cb387f Fix NPE when unlinking offline players (EssentialsX#6111)
EssentialsX@f09541c Update to Minecraft 1.21.5 (EssentialsX#6109)
EssentialsX@c7ff994 Fire GlobalChatEvent even when local chat is disabled (EssentialsX#6113)
EssentialsX@06c886c Fix /baltop on 1.15.2 and below (EssentialsX#6115)
EssentialsX@2bb4438 Fix further trade sign validation mismatches (EssentialsX#6116)
EssentialsX@8455212 Fix /spawnmob on < 1.21.5 (EssentialsX#6121)
EssentialsX@be3e641 New Crowdin updates (EssentialsX#6089)
EssentialsX@3f5b122 Use legacy text for TranslatableException#getMessage (EssentialsX#6134)
EssentialsX@fe43017 Fix heer typo in messages_en.properties (EssentialsX#6135)
EssentialsX@a58db23 Update English source strings with fixes from Crowdin (EssentialsX#6140)
EssentialsX@d137031 Improve config comments & ordering (EssentialsX#6108)
EssentialsX@3b0c229 New Crowdin updates (EssentialsX#6131)
EssentialsX@3fe1495 Fix unexpected behavior with essentials.home.bed & essentials.sethome.bed permissions (EssentialsX#5991)
EssentialsX@aebe851 Fix double messages when deleting a non-existent home (EssentialsX#6150)
EssentialsX@3a5c7c4 Revert changes to /home and /sethome that break bed interactions (EssentialsX#6151)
EssentialsX@3d28d82 Release 2.21.1
EssentialsX@e836747 Prepare for 2.21.2 dev builds (EssentialsX#6128)
EssentialsX@d42347f Fix sending message during /editsign paste if SignChangeEvent is cancelled (EssentialsX#6136)
EssentialsX@997f600 Update adventure dependencies (EssentialsX#6163)
EssentialsX@4057326 Update to Minecraft 1.21.6
EssentialsX@2796399 Add 1.21.6 Mobs
EssentialsX@31ea903 Move tests to MockBukkit
EssentialsX@ff1b8b8 Add 1.21.6 Aliases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The "essentials.home.bed" permission is ignored

5 participants