mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
Fix wrong permissions getting registered
This commit is contained in:
6 files changed
+21
-12
No files matched your search
@@ -60,18 +60,18 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
// Register permissions
|
||||
addPermission(command.getPermission(), command.getUsage(), command.isOperatorCommand());
|
||||
addPermission(command.getPermission(), command.getUsage(), getPermissionDefault(command.isOperatorCommand()));
|
||||
final List<Permission> childNodes = command.getAdditionalPermissions()
|
||||
.entrySet().stream()
|
||||
.map((entry) -> addPermission(entry.getKey(), "", entry.getValue()))
|
||||
.map((entry) -> addPermission(entry.getKey(), "", getPermissionDefault(entry.getValue())))
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
addPermission(command.getPermission("*"), command.getUsage(), command.isOperatorCommand(),
|
||||
addPermission(command.getPermission("*"), command.getUsage(), PermissionDefault.FALSE,
|
||||
childNodes.toArray(new Permission[0]));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Permission addPermission(@NotNull String node, @NotNull String description, boolean operatorCommand, @NotNull Permission... children) {
|
||||
private Permission addPermission(@NotNull String node, @NotNull String description, @NotNull PermissionDefault permissionDefault, @NotNull Permission... children) {
|
||||
final Map<String, Boolean> childNodes = Arrays.stream(children)
|
||||
.map(Permission::getName)
|
||||
.collect(HashMap::new, (map, child) -> map.put(child, true), HashMap::putAll);
|
||||
@@ -83,15 +83,20 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
Permission permission;
|
||||
if (description.isEmpty()) {
|
||||
permission = new Permission(node, operatorCommand ? PermissionDefault.OP : PermissionDefault.TRUE, childNodes);
|
||||
permission = new Permission(node, permissionDefault, childNodes);
|
||||
} else {
|
||||
permission = new Permission(node, description, operatorCommand ? PermissionDefault.OP : PermissionDefault.TRUE, childNodes);
|
||||
permission = new Permission(node, description, permissionDefault, childNodes);
|
||||
}
|
||||
manager.addPermission(permission);
|
||||
|
||||
return permission;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static PermissionDefault getPermissionDefault(boolean isOperatorCommand) {
|
||||
return isOperatorCommand ? PermissionDefault.OP : PermissionDefault.FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Commands available on the Bukkit HuskHomes implementation
|
||||
*/
|
||||
|
||||
@@ -78,4 +78,4 @@ commands:
|
||||
back:
|
||||
usage: /back
|
||||
huskhomes:
|
||||
usage: /huskhomes [about|help|reload|update|migrate]
|
||||
usage: /huskhomes [about|help|reload|update]
|
||||
@@ -9,12 +9,14 @@ import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class BackCommand extends InGameCommand {
|
||||
|
||||
protected BackCommand(@NotNull HuskHomes plugin) {
|
||||
super("back", List.of(), "", plugin);
|
||||
addAdditionalPermissions(Map.of("death", false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,7 @@ public class EditWarpCommand extends SavedPositionCommand<Warp> {
|
||||
|
||||
public EditWarpCommand(@NotNull HuskHomes plugin) {
|
||||
super("editwarp", List.of(), Warp.class, List.of("rename", "description", "relocate"), plugin);
|
||||
setOperatorCommand(true);
|
||||
addAdditionalPermissions(arguments.stream()
|
||||
.collect(HashMap::new, (m, e) -> m.put(getPermission(e), false), HashMap::putAll));
|
||||
}
|
||||
|
||||
@@ -43,11 +43,13 @@ public abstract class Node implements Executable {
|
||||
|
||||
@NotNull
|
||||
public String getPermission(@NotNull String... child) {
|
||||
return new StringJoiner(".")
|
||||
final StringJoiner joiner = new StringJoiner(".")
|
||||
.add(PERMISSION_PREFIX)
|
||||
.add(getName())
|
||||
.add(String.join(".", child))
|
||||
.toString();
|
||||
.add(getName());
|
||||
for (final String node : child) {
|
||||
joiner.add(node);
|
||||
}
|
||||
return joiner.toString().trim();
|
||||
}
|
||||
|
||||
public boolean isOperatorCommand() {
|
||||
|
||||
@@ -13,7 +13,6 @@ public class WarpCommand extends SavedPositionCommand<Warp> {
|
||||
|
||||
protected WarpCommand(@NotNull HuskHomes plugin) {
|
||||
super("warp", List.of(), Warp.class, List.of(), plugin);
|
||||
setOperatorCommand(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user