mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 14:38:53 +00:00
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
This commit is contained in:
1 parent
4d86f580ae
commit
2b436a23fa
1 file changed
+12
-11
@@ -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<String, Boolean> 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<String> 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();
|
||||
|
||||
Reference in new issue
Block a user