From 7a94b57ca5161a004296616a51c08996f9ff6aee Mon Sep 17 00:00:00 2001 From: alazeprt Date: Tue, 7 May 2024 19:05:32 +0800 Subject: [PATCH 1/6] Update RtpCommand.java --- .../huskhomes/command/RtpCommand.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java index 20c54f1a..3e18aed1 100644 --- a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java @@ -29,18 +29,16 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; public class RtpCommand extends Command implements UserListTabProvider { protected RtpCommand(@NotNull HuskHomes plugin) { super("rtp", List.of(), "[player] [world]", plugin); - addAdditionalPermissions(Map.of( - "other", true, - "world", true - )); + Map map = new HashMap<>(); + map.put("other", true); + plugin.getWorlds().forEach(world -> map.put(world.getName(), true)); + addAdditionalPermissions(map); } @Override @@ -71,9 +69,10 @@ public List suggest(@NotNull CommandUser user, @NotNull String[] args) { return switch (args.length) { case 0, 1 -> user.hasPermission("other") ? UserListTabProvider.super.suggestLocal(args) : user instanceof OnlineUser online ? List.of(online.getUsername()) : List.of(); - case 2 -> user.hasPermission("world") ? plugin.getWorlds().stream() + case 2 -> plugin.getWorlds().stream() .filter(world -> !plugin.getSettings().getRtp().isWorldRtpRestricted(world)) - .map(World::getName).toList() : List.of(); + .map(World::getName) + .filter(user::hasPermission).toList(); default -> null; }; } @@ -112,7 +111,7 @@ private Optional validateRtp(@NotNull OnlineUser teleporter, @NotNull Com // Ensure the user has permission to randomly teleport in the world final World world = optionalWorld.get(); - if (!world.equals(teleporterWorld) && !executor.hasPermission(getPermission("world"))) { + if (!world.equals(teleporterWorld) && !executor.hasPermission(getPermission(world.getName()))) { plugin.getLocales().getLocale("error_no_permission") .ifPresent(executor::sendMessage); return Optional.empty(); From f205a3b954f033b8917b60bc10141a0b49f5e2bf Mon Sep 17 00:00:00 2001 From: alazeprt Date: Tue, 7 May 2024 19:17:18 +0800 Subject: [PATCH 2/6] Fix bug about suggestion filtering --- .../main/java/net/william278/huskhomes/command/RtpCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java index 3e18aed1..41f1de9c 100644 --- a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java @@ -72,7 +72,7 @@ public List suggest(@NotNull CommandUser user, @NotNull String[] args) { case 2 -> plugin.getWorlds().stream() .filter(world -> !plugin.getSettings().getRtp().isWorldRtpRestricted(world)) .map(World::getName) - .filter(user::hasPermission).toList(); + .filter(world -> !user.hasPermission(world)).toList(); default -> null; }; } From 7bfabe004ffb00876a8be246ee5cfb2312337903 Mon Sep 17 00:00:00 2001 From: alazeprt Date: Tue, 7 May 2024 19:23:31 +0800 Subject: [PATCH 3/6] Fix bug about suggestion filtering --- .../java/net/william278/huskhomes/command/RtpCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java index 41f1de9c..455e0b7d 100644 --- a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java @@ -67,12 +67,12 @@ public void execute(@NotNull CommandUser executor, @NotNull String[] args) { @Override public List suggest(@NotNull CommandUser user, @NotNull String[] args) { return switch (args.length) { - case 0, 1 -> user.hasPermission("other") ? UserListTabProvider.super.suggestLocal(args) + case 0, 1 -> user.hasPermission(getPermission("other")) ? UserListTabProvider.super.suggestLocal(args) : user instanceof OnlineUser online ? List.of(online.getUsername()) : List.of(); case 2 -> plugin.getWorlds().stream() .filter(world -> !plugin.getSettings().getRtp().isWorldRtpRestricted(world)) .map(World::getName) - .filter(world -> !user.hasPermission(world)).toList(); + .filter(world -> !user.hasPermission(getPermission("world"))).toList(); default -> null; }; } From 06a8d4606aa588b959a410168f92cee9fc2ed72a Mon Sep 17 00:00:00 2001 From: alazeprt Date: Tue, 7 May 2024 19:26:40 +0800 Subject: [PATCH 4/6] Fix bug about suggestion filtering --- .../main/java/net/william278/huskhomes/command/RtpCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java index 455e0b7d..dd1064c8 100644 --- a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java @@ -72,7 +72,7 @@ public List suggest(@NotNull CommandUser user, @NotNull String[] args) { case 2 -> plugin.getWorlds().stream() .filter(world -> !plugin.getSettings().getRtp().isWorldRtpRestricted(world)) .map(World::getName) - .filter(world -> !user.hasPermission(getPermission("world"))).toList(); + .filter(world -> !user.hasPermission(getPermission(world))).toList(); default -> null; }; } From 46371d46cad5c75db49ebf61e3a4d6118f4efd16 Mon Sep 17 00:00:00 2001 From: alazeprt Date: Tue, 7 May 2024 19:33:23 +0800 Subject: [PATCH 5/6] Fix bug about suggestion filtering --- .../main/java/net/william278/huskhomes/command/RtpCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java index dd1064c8..0ac52b40 100644 --- a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java @@ -72,7 +72,7 @@ public List suggest(@NotNull CommandUser user, @NotNull String[] args) { case 2 -> plugin.getWorlds().stream() .filter(world -> !plugin.getSettings().getRtp().isWorldRtpRestricted(world)) .map(World::getName) - .filter(world -> !user.hasPermission(getPermission(world))).toList(); + .filter(world -> user.hasPermission(getPermission(world))).toList(); default -> null; }; } From 2bcc0c85c94daa2dba05aeff16cbd82265528b46 Mon Sep 17 00:00:00 2001 From: alazeprt Date: Sat, 11 May 2024 19:43:25 +0800 Subject: [PATCH 6/6] Filter restricted world --- .../java/net/william278/huskhomes/command/RtpCommand.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java index 0ac52b40..3bbe6494 100644 --- a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java @@ -37,7 +37,9 @@ protected RtpCommand(@NotNull HuskHomes plugin) { super("rtp", List.of(), "[player] [world]", plugin); Map map = new HashMap<>(); map.put("other", true); - plugin.getWorlds().forEach(world -> map.put(world.getName(), true)); + plugin.getWorlds().stream() + .filter(world -> !plugin.getSettings().getRtp().isWorldRtpRestricted(world)) + .map(World::getName).toList().forEach(world -> map.put(world, true)); addAdditionalPermissions(map); }