diff --git a/projects/common/src/main/java/dan200/computercraft/shared/command/UserLevel.java b/projects/common/src/main/java/dan200/computercraft/shared/command/UserLevel.java index ab7709b90..66e239146 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/command/UserLevel.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/command/UserLevel.java @@ -50,6 +50,12 @@ public enum UserLevel implements Predicate { public static boolean isOwner(CommandSourceStack source) { var server = source.getServer(); + + // While CommandSourceStack.getServer is non-nullable, that's a lie for permission checks. When loading + // .mcfunction files, ServerFunctionLibrary constructs an instance with an empty server. In that case, return + // false — we don't want to treat functions as an owner! + if (server == null) return false; + var player = source.getPlayer(); return server.isDedicatedServer() ? source.getEntity() == null && source.hasPermission(4) && source.getTextName().equals("Server")