From 2b436a23fa31170beabb2d2c7feeb88aed9e64dc Mon Sep 17 00:00:00 2001 From: alazeprt <92018941+alazeprt@users.noreply.github.com> Date: Sat, 11 May 2024 20:13:39 +0800 Subject: [PATCH] feat: Make /rtp in other worlds use world-specific command (#626) * Update RtpCommand.java * Fix bug about suggestion filtering * Fix bug about suggestion filtering * Fix bug about suggestion filtering * Fix bug about suggestion filtering * Filter restricted world --- .../huskhomes/command/RtpCommand.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 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..3bbe6494 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,18 @@ import net.william278.huskhomes.util.TransactionResolver; 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().stream() + .filter(world -> !plugin.getSettings().getRtp().isWorldRtpRestricted(world)) + .map(World::getName).toList().forEach(world -> map.put(world, true)); + addAdditionalPermissions(map); } @Override @@ -69,11 +69,12 @@ public class RtpCommand extends Command implements UserListTabProvider { @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 -> 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(world -> user.hasPermission(getPermission(world))).toList(); default -> null; }; } @@ -112,7 +113,7 @@ public class RtpCommand extends Command implements UserListTabProvider { // 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();