From 88802db702331cd05116880df9ca4a3f0f87820b Mon Sep 17 00:00:00 2001 From: William Date: Wed, 26 Oct 2022 21:25:26 +0100 Subject: [PATCH] Fix permission issues and erroneous messages with homes and warps, close #252 --- .../huskhomes/command/HomeCommand.java | 7 ++++--- .../huskhomes/command/PublicHomeCommand.java | 7 ++++--- .../huskhomes/command/WarpCommand.java | 20 ++++++++++++++----- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java index ca51b011..e2635865 100644 --- a/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/HomeCommand.java @@ -57,7 +57,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE } private void teleportToNamedHome(@NotNull OnlineUser teleporter, @NotNull User owner, @NotNull String homeName) { - final boolean otherHome = owner.uuid.equals(teleporter.uuid); + final boolean otherHome = !owner.uuid.equals(teleporter.uuid); plugin.getDatabase() .getHome(owner, homeName) .thenAccept(homeResult -> homeResult.ifPresentOrElse(home -> { @@ -65,6 +65,7 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE if (!teleporter.hasPermission(Permission.COMMAND_HOME_OTHER.node)) { plugin.getLocales().getLocale("error_no_permission") .ifPresent(teleporter::sendMessage); + return; } } Teleport.builder(plugin, teleporter) @@ -73,10 +74,10 @@ public class HomeCommand extends CommandBase implements TabCompletable, ConsoleE .thenAccept(TimedTeleport::execute); }, () -> { if (otherHome) { - plugin.getLocales().getLocale("error_home_invalid", homeName) + plugin.getLocales().getLocale("error_home_invalid_other", owner.username, homeName) .ifPresent(teleporter::sendMessage); } else { - plugin.getLocales().getLocale("error_home_invalid_other", owner.username, homeName) + plugin.getLocales().getLocale("error_home_invalid", homeName) .ifPresent(teleporter::sendMessage); } })); diff --git a/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java index aa1a301f..2d4263b8 100644 --- a/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/PublicHomeCommand.java @@ -69,7 +69,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co } private void teleportToNamedHome(@NotNull OnlineUser teleporter, @NotNull User owner, @NotNull String homeName) { - final boolean otherHome = owner.uuid.equals(teleporter.uuid); + final boolean otherHome = !owner.uuid.equals(teleporter.uuid); plugin.getDatabase() .getHome(owner, homeName) .thenAccept(homeResult -> homeResult.ifPresentOrElse(home -> { @@ -77,6 +77,7 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co if (!teleporter.hasPermission(Permission.COMMAND_HOME_OTHER.node)) { plugin.getLocales().getLocale("error_no_permission") .ifPresent(teleporter::sendMessage); + return; } } Teleport.builder(plugin, teleporter) @@ -85,10 +86,10 @@ public class PublicHomeCommand extends CommandBase implements TabCompletable, Co .thenAccept(TimedTeleport::execute); }, () -> { if (otherHome) { - plugin.getLocales().getLocale("error_home_invalid", homeName) + plugin.getLocales().getLocale("error_home_invalid_other", owner.username, homeName) .ifPresent(teleporter::sendMessage); } else { - plugin.getLocales().getLocale("error_home_invalid_other", owner.username, homeName) + plugin.getLocales().getLocale("error_home_invalid", homeName) .ifPresent(teleporter::sendMessage); } })); diff --git a/common/src/main/java/net/william278/huskhomes/command/WarpCommand.java b/common/src/main/java/net/william278/huskhomes/command/WarpCommand.java index d9e15635..e621c07b 100644 --- a/common/src/main/java/net/william278/huskhomes/command/WarpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/WarpCommand.java @@ -6,6 +6,7 @@ import net.william278.huskhomes.position.Warp; import net.william278.huskhomes.teleport.Teleport; import net.william278.huskhomes.teleport.TimedTeleport; import net.william278.huskhomes.util.Permission; +import org.intellij.lang.annotations.Subst; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,11 +37,20 @@ public class WarpCommand extends CommandBase implements TabCompletable, ConsoleE final String warpName = args[0]; plugin.getDatabase() .getWarp(warpName) - .thenAccept(warpResult -> warpResult.ifPresentOrElse(warp -> - Teleport.builder(plugin, onlineUser) - .setTarget(warp) - .toTimedTeleport() - .thenAccept(TimedTeleport::execute), + .thenAccept(warpResult -> warpResult.ifPresentOrElse(warp -> { + if (plugin.getSettings().permissionRestrictWarps) { + @Subst("huskhomes.command.warp") final String warpPermission = Permission.COMMAND_WARP + "." + warp.meta.name; + if (!onlineUser.hasPermission(Permission.COMMAND_SET_WARP.node) && !onlineUser.hasPermission(warpPermission)) { + plugin.getLocales().getLocale("error_no_permission") + .ifPresent(onlineUser::sendMessage); + return; + } + } + Teleport.builder(plugin, onlineUser) + .setTarget(warp) + .toTimedTeleport() + .thenAccept(TimedTeleport::execute); + }, () -> plugin.getLocales().getLocale("error_warp_invalid", warpName) .ifPresent(onlineUser::sendMessage))); }