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);
}
}
Aggregations