aboutsummaryrefslogtreecommitdiff
path: root/spark-forge/src
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2022-10-29 21:53:50 +0100
committerLuck <git@lucko.me>2022-10-29 21:53:50 +0100
commit4314cdf23be38f75297c406ca48900c3dd80eec5 (patch)
treeb1ddb230064c0c0482e82c116df1ff3a64ff4e48 /spark-forge/src
parentfafc14712fa78001b431241bd961ca429d6f74bc (diff)
downloadspark-4314cdf23be38f75297c406ca48900c3dd80eec5.tar.gz
spark-4314cdf23be38f75297c406ca48900c3dd80eec5.tar.bz2
spark-4314cdf23be38f75297c406ca48900c3dd80eec5.zip
Fix Forge permission checks
Diffstat (limited to 'spark-forge/src')
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java15
1 files changed, 9 insertions, 6 deletions
diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java
index a047538..8ac0c7c 100644
--- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java
+++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java
@@ -66,8 +66,8 @@ import net.minecraftforge.server.permission.nodes.PermissionTypes;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -129,20 +129,23 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command<
// register permissions with forge & keep a copy for lookup
ImmutableMap.Builder<String, PermissionNode<Boolean>> builder = ImmutableMap.builder();
- Set<String> alreadyRegistered = e.getNodes().stream()
- .map(PermissionNode::getNodeName)
- .collect(Collectors.toSet());
+ Map<String, PermissionNode<?>> alreadyRegistered = e.getNodes().stream().collect(Collectors.toMap(PermissionNode::getNodeName, Function.identity()));
for (String permission : permissions) {
+ String permissionString = "spark." + permission;
+
// there's a weird bug where it seems that this listener can be called twice, causing an
// IllegalArgumentException to be thrown the second time e.addNodes is called.
- if (alreadyRegistered.contains("spark." + permission)) {
+ PermissionNode<?> existing = alreadyRegistered.get(permissionString);
+ if (existing != null) {
+ //noinspection unchecked
+ builder.put(permissionString, (PermissionNode<Boolean>) existing);
continue;
}
PermissionNode<Boolean> node = new PermissionNode<>("spark", permission, PermissionTypes.BOOLEAN, defaultValue);
e.addNodes(node);
- builder.put("spark." + permission, node);
+ builder.put(permissionString, node);
}
this.registeredPermissions = builder.build();
}