Search in sources :

Example 1 with PlayerContext

use of net.minecraftforge.server.permission.context.PlayerContext in project minecolonies by Minecolonies.

the class CommandEntryPointNew method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String[] args) throws CommandException {
    final BlockPos pos = null;
    final ParsingResult parsingResult = getTabCompletionsAndParsingHolders(root, server, sender, args, pos);
    final TreeNode<IMenu> executionTreeNode = parsingResult.getExecutionTreeNode();
    if (null == executionTreeNode) {
        throw new CommandException(getCommandUsage(sender, root));
    }
    final IMenu executionMenu = executionTreeNode.getData();
    if (executionMenu.getMenuType().isNavigationMenu()) {
        throw new CommandException(getCommandUsage(sender, executionTreeNode));
    }
    final ActionMenu actionMenu = (ActionMenu) executionMenu;
    final List<ActionArgument> executionActionArgumentList = parsingResult.getExecutionActionArgumentList();
    final String badArgument = parsingResult.getBadArgument();
    throwCommandUsageExceptionIfRequiredArgumentsAreNotProvided(executionTreeNode, actionMenu, executionActionArgumentList, badArgument, sender);
    if (sender instanceof EntityPlayer) {
        final ForgePermissionNodes forgePermissionNode = actionMenu.getForgePermissionNode();
        final EntityPlayer player = (EntityPlayer) sender;
        if (!PermissionAPI.hasPermission(player.getGameProfile(), forgePermissionNode.getNodeName(), new PlayerContext(player))) {
        // TODO: Do something if permission check fails.
        // But we don't have permissions set up yet.
        }
    }
    for (final ActionArgument executionActionArgument : executionActionArgumentList) {
        if (!executionActionArgument.isValueSet()) {
            throw new CommandException(getCommandUsage(sender, executionTreeNode));
        }
    }
    final Class<? extends IActionCommand> clazz = actionMenu.getActionCommandClass();
    try {
        createInstanceAndExecute(server, sender, actionMenu, clazz);
    } catch (final InstantiationException | IllegalAccessException e) {
        final Logger log = LogManager.getLogger();
        log.error("Unable to instantiate class %s for command %s ", clazz.getName(), actionMenu.getDescription(), e);
        throw new CommandException("Unable to instantiate class " + clazz.getName() + " for command " + actionMenu.getDescription(), e);
    }
}
Also used : CommandException(net.minecraft.command.CommandException) Logger(org.apache.logging.log4j.Logger) ForgePermissionNodes(com.minecolonies.coremod.colony.permissions.ForgePermissionNodes) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PlayerContext(net.minecraftforge.server.permission.context.PlayerContext) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

ForgePermissionNodes (com.minecolonies.coremod.colony.permissions.ForgePermissionNodes)1 CommandException (net.minecraft.command.CommandException)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 BlockPos (net.minecraft.util.math.BlockPos)1 PlayerContext (net.minecraftforge.server.permission.context.PlayerContext)1 Logger (org.apache.logging.log4j.Logger)1