mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2026-02-02 17:00:16 +00:00
A whole bunch of refomatting
- Remove redundant constructors and super calls - Standardise naming of texture fields - Always use postfix notations for loops - Cleanup several peripheral classes
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.command;
|
||||
|
||||
import dan200.computercraft.shared.command.framework.CommandContext;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
/**
|
||||
* The level a user must be at in order to execute a command.
|
||||
*/
|
||||
public enum UserLevel
|
||||
{
|
||||
/**
|
||||
* Only can be used by the owner of the server: namely the server console or the player in SSP.
|
||||
*/
|
||||
OWNER,
|
||||
|
||||
/**
|
||||
* Can only be used by ops.
|
||||
*/
|
||||
OP,
|
||||
|
||||
/**
|
||||
* Can be used by any op, or the player in SSP.
|
||||
*/
|
||||
OWNER_OP,
|
||||
|
||||
/**
|
||||
* Can be used by anyone.
|
||||
*/
|
||||
ANYONE;
|
||||
|
||||
public int toLevel()
|
||||
{
|
||||
switch( this )
|
||||
{
|
||||
case OWNER:
|
||||
return 4;
|
||||
case OP:
|
||||
case OWNER_OP:
|
||||
return 2;
|
||||
case ANYONE:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canExecute( CommandContext context )
|
||||
{
|
||||
if( this == ANYONE ) return true;
|
||||
|
||||
// We *always* allow level 0 stuff, even if the
|
||||
MinecraftServer server = context.getServer();
|
||||
ICommandSender sender = context.getSender();
|
||||
|
||||
if( server.isSinglePlayer() && sender instanceof EntityPlayerMP &&
|
||||
((EntityPlayerMP) sender).getGameProfile().getName().equalsIgnoreCase( server.getServerOwner() ) )
|
||||
{
|
||||
if( this == OWNER || this == OWNER_OP ) return true;
|
||||
}
|
||||
|
||||
return sender.canUseCommand( toLevel(), context.getRootCommand() );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user