From 5ce1075ec0c6d41d66ecbe14250763573297590f Mon Sep 17 00:00:00 2001 From: Font Vincent Date: Wed, 11 Dec 2024 17:12:22 +0100 Subject: [PATCH 1/4] fix: essentials.home.bed permission --- .../earth2me/essentials/commands/Commandhome.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java index a8017dcbf8a..1c93cd17918 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java @@ -73,10 +73,14 @@ public void run(final Server server, final User user, final String commandLabel, final List homes = finalPlayer.getHomes(); if (homes.isEmpty() && finalPlayer.equals(user)) { if (ess.getSettings().isSpawnIfNoHome()) { - final UserTeleportHomeEvent event = new UserTeleportHomeEvent(user, null, bed != null ? bed : finalPlayer.getWorld().getSpawnLocation(), bed != null ? UserTeleportHomeEvent.HomeType.BED : UserTeleportHomeEvent.HomeType.SPAWN); - server.getPluginManager().callEvent(event); - if (!event.isCancelled()) { - user.getAsyncTeleport().respawn(charge, TeleportCause.COMMAND, getNewExceptionFuture(user.getSource(), commandLabel)); + if(bed == null || finalPlayer.isAuthorized("essentials.home.bed")){ + final UserTeleportHomeEvent event = new UserTeleportHomeEvent(user, null, bed != null ? bed : finalPlayer.getWorld().getSpawnLocation(), bed != null ? UserTeleportHomeEvent.HomeType.BED : UserTeleportHomeEvent.HomeType.SPAWN); + server.getPluginManager().callEvent(event); + if (!event.isCancelled()) { + user.getAsyncTeleport().respawn(charge, TeleportCause.COMMAND, getNewExceptionFuture(user.getSource(), commandLabel)); + } + }else { + showError(user.getBase(), new TranslatableException("noPerm", "essentials.home.bed"), commandLabel); } } else { showError(user.getBase(), new TranslatableException("noHomeSetPlayer"), commandLabel); From 221defe2f0d760e2fc699701d2faad6b9bdbe93b Mon Sep 17 00:00:00 2001 From: Font Vincent Date: Thu, 12 Dec 2024 08:55:15 +0100 Subject: [PATCH 2/4] fix: identation & no null bed check --- .../java/com/earth2me/essentials/commands/Commandhome.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java index 1c93cd17918..8040366bc3a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java @@ -73,13 +73,13 @@ public void run(final Server server, final User user, final String commandLabel, final List homes = finalPlayer.getHomes(); if (homes.isEmpty() && finalPlayer.equals(user)) { if (ess.getSettings().isSpawnIfNoHome()) { - if(bed == null || finalPlayer.isAuthorized("essentials.home.bed")){ - final UserTeleportHomeEvent event = new UserTeleportHomeEvent(user, null, bed != null ? bed : finalPlayer.getWorld().getSpawnLocation(), bed != null ? UserTeleportHomeEvent.HomeType.BED : UserTeleportHomeEvent.HomeType.SPAWN); + final UserTeleportHomeEvent event = new UserTeleportHomeEvent(user, null, bed != null ? bed : finalPlayer.getWorld().getSpawnLocation(), bed != null ? UserTeleportHomeEvent.HomeType.BED : UserTeleportHomeEvent.HomeType.SPAWN); + if (event.getHomeType() != UserTeleportHomeEvent.HomeType.BED || finalPlayer.isAuthorized("essentials.home.bed")) { server.getPluginManager().callEvent(event); if (!event.isCancelled()) { user.getAsyncTeleport().respawn(charge, TeleportCause.COMMAND, getNewExceptionFuture(user.getSource(), commandLabel)); } - }else { + } else { showError(user.getBase(), new TranslatableException("noPerm", "essentials.home.bed"), commandLabel); } } else { From 063eafb5d358345412e0c443f9584ec61b32849c Mon Sep 17 00:00:00 2001 From: Font Vincent Date: Thu, 12 Dec 2024 09:55:18 +0100 Subject: [PATCH 3/4] fix: essentials.sethome.bed permission --- .../com/earth2me/essentials/EssentialsPlayerListener.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java index e6b5043e079..0218ffb17fc 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java @@ -795,12 +795,16 @@ public void onPlayerInteract(final PlayerInteractEvent event) { break; } final User player = ess.getUser(event.getPlayer()); - if (player.isAuthorized("essentials.sethome.bed") && player.getWorld().getEnvironment().equals(World.Environment.NORMAL)) { + final boolean isAuthorized = player.isAuthorized("essentials.sethome.bed"); + if (isAuthorized && player.getWorld().getEnvironment().equals(World.Environment.NORMAL)) { player.getBase().setBedSpawnLocation(event.getClickedBlock().getLocation()); // In 1.15 and above, vanilla sends its own bed spawn message. if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_15_R01)) { player.sendTl("bedSet", player.getLocation().getWorld().getName(), player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()); } + } else if (!isAuthorized) { + player.sendMessage("event canceled"); + event.setCancelled(true); } } break; From 151a5b7f044cb9c8ebf78e242ff017fd34455615 Mon Sep 17 00:00:00 2001 From: Font Vincent Date: Thu, 12 Dec 2024 09:56:07 +0100 Subject: [PATCH 4/4] remove: test message --- .../java/com/earth2me/essentials/EssentialsPlayerListener.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java index 0218ffb17fc..25bf82f6a25 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java @@ -803,7 +803,6 @@ public void onPlayerInteract(final PlayerInteractEvent event) { player.sendTl("bedSet", player.getLocation().getWorld().getName(), player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()); } } else if (!isAuthorized) { - player.sendMessage("event canceled"); event.setCancelled(true); } }