1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-25 23:12:18 +00:00

Fix NPE when loading mcfunctions

CommandSourceStack.getServer can be null, despite being marked as
non-nullable. Mojang!!! *shakes fist*

Fixes #2235.
This commit is contained in:
Jonathan Coates 2025-07-10 00:46:07 +01:00
parent 180156ff1c
commit 3cf914cb4c
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06

View File

@ -50,6 +50,12 @@ public enum UserLevel implements Predicate<CommandSourceStack> {
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")