Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting the permissions node for the /rtp command #626

Merged
merged 7 commits into from
May 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@
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
Expand Down Expand Up @@ -69,11 +69,12 @@ public void execute(@NotNull CommandUser executor, @NotNull String[] args) {
@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;
};
}
Expand Down Expand Up @@ -112,7 +113,7 @@ private Optional<World> 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();
Expand Down
Loading