fix: deep nesting on permissions causing stack overflow errors
This commit is contained in:
parent
4eb3df1f57
commit
8ea7d59736
3 changed files with 22 additions and 6 deletions
|
|
@ -50,7 +50,15 @@ public final class AndPermission implements CommandPermission {
|
|||
* @return Constructed permission
|
||||
*/
|
||||
public static @NonNull CommandPermission of(final @NonNull Collection<CommandPermission> permissions) {
|
||||
return new AndPermission(new HashSet<>(permissions));
|
||||
final Set<CommandPermission> objects = new HashSet<>();
|
||||
for (final CommandPermission permission : permissions) {
|
||||
if (permission instanceof AndPermission) {
|
||||
objects.addAll(permission.getPermissions());
|
||||
} else {
|
||||
objects.add(permission);
|
||||
}
|
||||
}
|
||||
return new AndPermission(objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public interface CommandPermission {
|
|||
final Set<CommandPermission> permission = new HashSet<>(2);
|
||||
permission.add(this);
|
||||
permission.add(other);
|
||||
return new OrPermission(permission);
|
||||
return OrPermission.of(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -79,7 +79,7 @@ public interface CommandPermission {
|
|||
final Set<CommandPermission> permission = new HashSet<>(other.length + 1);
|
||||
permission.add(this);
|
||||
permission.addAll(Arrays.asList(other));
|
||||
return new OrPermission(permission);
|
||||
return OrPermission.of(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -94,7 +94,7 @@ public interface CommandPermission {
|
|||
final Set<CommandPermission> permission = new HashSet<>(2);
|
||||
permission.add(this);
|
||||
permission.add(other);
|
||||
return new AndPermission(permission);
|
||||
return AndPermission.of(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -109,7 +109,7 @@ public interface CommandPermission {
|
|||
final Set<CommandPermission> permission = new HashSet<>(other.length + 1);
|
||||
permission.add(this);
|
||||
permission.addAll(Arrays.asList(other));
|
||||
return new AndPermission(permission);
|
||||
return AndPermission.of(permission);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,15 @@ public final class OrPermission implements CommandPermission {
|
|||
* @return Constructed permission
|
||||
*/
|
||||
public static @NonNull CommandPermission of(final @NonNull Collection<CommandPermission> permissions) {
|
||||
return new OrPermission(new HashSet<>(permissions));
|
||||
final Set<CommandPermission> objects = new HashSet<>();
|
||||
for (final CommandPermission permission : permissions) {
|
||||
if (permission instanceof OrPermission) {
|
||||
objects.addAll(permission.getPermissions());
|
||||
} else {
|
||||
objects.add(permission);
|
||||
}
|
||||
}
|
||||
return new OrPermission(objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue