aboutsummaryrefslogtreecommitdiff
path: root/spark-forge
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2022-10-21 21:59:27 +0100
committerLuck <git@lucko.me>2022-10-21 22:02:39 +0100
commit4545bbffd95d27e4e72aaad1a481af9d91094a64 (patch)
tree7ecbcb62ee34611d967574f482337bed1d5e4f59 /spark-forge
parentd31f3c7bdf03c874ff9518d47d060adc18322d6b (diff)
downloadspark-4545bbffd95d27e4e72aaad1a481af9d91094a64.tar.gz
spark-4545bbffd95d27e4e72aaad1a481af9d91094a64.tar.bz2
spark-4545bbffd95d27e4e72aaad1a481af9d91094a64.zip
Fix exception from Forge permission registration (#255)
Diffstat (limited to 'spark-forge')
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java12
1 files changed, 12 insertions, 0 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 56d30b7..a047538 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,6 +66,7 @@ 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.stream.Collectors;
import java.util.stream.Stream;
@@ -127,7 +128,18 @@ 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());
+
for (String permission : permissions) {
+ // 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)) {
+ continue;
+ }
+
PermissionNode<Boolean> node = new PermissionNode<>("spark", permission, PermissionTypes.BOOLEAN, defaultValue);
e.addNodes(node);
builder.put("spark." + permission, node);