diff options
-rw-r--r-- | spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java | 11 | ||||
-rw-r--r-- | spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java | 17 |
2 files changed, 23 insertions, 5 deletions
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java index c528e5b..1606d57 100644 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java @@ -119,8 +119,15 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman @Override public boolean hasPermission(CommandOutput sender, String permission) { - if (sender instanceof PlayerEntity) { - return Permissions.check(((PlayerEntity) sender), permission, 4); + if (sender instanceof PlayerEntity player) { + return Permissions.getPermissionValue(player, permission).orElseGet(() -> { + MinecraftServer server = player.getServer(); + if (server != null && server.isHost(player.getGameProfile())) { + return true; + } + + return player.hasPermissionLevel(4); + }); } else { return true; } 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 8ac0c7c..8737057 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 @@ -78,6 +78,19 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< plugin.enable(); } + private static final PermissionResolver<Boolean> DEFAULT_PERMISSION_VALUE = (player, playerUUID, context) -> { + if (player == null) { + return false; + } + + MinecraftServer server = player.getServer(); + if (server != null && server.isSingleplayerOwner(player.getGameProfile())) { + return true; + } + + return player.hasPermissions(4); + }; + private final MinecraftServer server; private final ThreadDumper gameThreadDumper; private Map<String, PermissionNode<Boolean>> registeredPermissions = Collections.emptyMap(); @@ -116,8 +129,6 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< @SubscribeEvent public void onPermissionGather(PermissionGatherEvent.Nodes e) { - PermissionResolver<Boolean> defaultValue = (player, playerUUID, context) -> player != null && player.hasPermissions(4); - // collect all possible permissions List<String> permissions = this.platform.getCommands().stream() .map(me.lucko.spark.common.command.Command::primaryAlias) @@ -143,7 +154,7 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< continue; } - PermissionNode<Boolean> node = new PermissionNode<>("spark", permission, PermissionTypes.BOOLEAN, defaultValue); + PermissionNode<Boolean> node = new PermissionNode<>("spark", permission, PermissionTypes.BOOLEAN, DEFAULT_PERMISSION_VALUE); e.addNodes(node); builder.put(permissionString, node); } |