From 3396fe2871eb557cac1af6f3f5d20742ba1ac748 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Wed, 25 Aug 2021 22:09:24 +0100 Subject: [PATCH] Make UserLevel.OWNER a little more strict Closes #904 --- .../shared/command/UserLevel.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/command/UserLevel.java b/src/main/java/dan200/computercraft/shared/command/UserLevel.java index daccef334..2e36afa41 100644 --- a/src/main/java/dan200/computercraft/shared/command/UserLevel.java +++ b/src/main/java/dan200/computercraft/shared/command/UserLevel.java @@ -56,18 +56,17 @@ public enum UserLevel implements Predicate public boolean test( CommandSource source ) { if( this == ANYONE ) return true; - - if( this == OWNER || this == OWNER_OP ) - { - MinecraftServer server = source.getServer(); - Entity sender = source.getEntity(); - if( server.isSingleplayer() && sender instanceof PlayerEntity && - ((PlayerEntity) sender).getGameProfile().getName().equalsIgnoreCase( server.getServerModName() ) ) - { - return true; - } - } - + if( this == OWNER ) return isOwner( source ); + if( this == OWNER_OP && isOwner( source ) ) return true; return source.hasPermission( toLevel() ); } + + private static boolean isOwner( CommandSource source ) + { + MinecraftServer server = source.getServer(); + Entity sender = source.getEntity(); + return server.isDedicatedServer() + ? source.getEntity() == null && source.hasPermission( 4 ) && source.getTextName().equals( "Server" ) + : sender instanceof PlayerEntity && ((PlayerEntity) sender).getGameProfile().getName().equalsIgnoreCase( server.getServerModName() ); + } }