mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2026-07-29 22:48:53 +00:00
Merge branch 'mc-1.16.x' into mc-1.18.x
This commit is contained in:
@@ -61,12 +61,36 @@ public enum UserLevel implements Predicate<CommandSourceStack>
|
||||
return source.hasPermission( toLevel() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the union of two {@link UserLevel}s.
|
||||
* <p>
|
||||
* This satisfies the property that for all sources {@code s}, {@code a.test(s) || b.test(s) == (a ∪ b).test(s)}.
|
||||
*
|
||||
* @param left The first user level to take the union of.
|
||||
* @param right The second user level to take the union of.
|
||||
* @return The union of two levels.
|
||||
*/
|
||||
public static UserLevel union( UserLevel left, UserLevel right )
|
||||
{
|
||||
if( left == right ) return left;
|
||||
|
||||
// x ∪ ANYONE = ANYONE
|
||||
if( left == ANYONE || right == ANYONE ) return ANYONE;
|
||||
|
||||
// x ∪ OWNER = OWNER
|
||||
if( left == OWNER ) return right;
|
||||
if( right == OWNER ) return left;
|
||||
|
||||
// At this point, we have x != y and x, y ∈ { OP, OWNER_OP }.
|
||||
return OWNER_OP;
|
||||
}
|
||||
|
||||
private static boolean isOwner( CommandSourceStack source )
|
||||
{
|
||||
MinecraftServer server = source.getServer();
|
||||
Entity sender = source.getEntity();
|
||||
return server.isDedicatedServer()
|
||||
? source.getEntity() == null && source.hasPermission( 4 ) && source.getTextName().equals( "Server" )
|
||||
: sender instanceof Player player && player.getGameProfile().getName().equalsIgnoreCase( server.getServerModName() );
|
||||
: sender instanceof Player player && server.isSingleplayerOwner( player.getGameProfile() );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user