com.sk89q.minecraft.util.commands.CommandPermissionsException Java Examples

The following examples show how to use com.sk89q.minecraft.util.commands.CommandPermissionsException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChannelCommands.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = "t",
        desc = "Sends a message to the team channel (or sets the team channel to your default channel).",
        usage = "[message...]",
        min = 0,
        max = -1,
        anyFlags = true
)
public static void teamChat(CommandContext args, CommandSender sender) throws CommandException {
    MatchPlayer player = CommandUtils.senderToMatchPlayer(sender);

    if (player.getBukkit().hasPermission(ChannelMatchModule.TEAM_SEND_PERMISSION)) {
        ChannelMatchModule cmm = player.getMatch().needMatchModule(ChannelMatchModule.class);

        if (args.argsLength() == 0) {
            cmm.setTeamChat(player, true);
            player.sendMessage(new TranslatableComponent("command.chat.team.switchSuccess"));
        } else {
            Channel channel = cmm.getChannel(player.getParty());
            channel.sendMessage(args.getJoinedStrings(0), player.getBukkit());
            if (!player.getBukkit().hasPermission(channel.getListeningPermission())) {
                sender.sendMessage(ChatColor.YELLOW + PGMTranslations.t("command.chat.team.success", player));
            }
        }
    } else {
        throw new CommandPermissionsException();
    }
}
 
Example #2
Source File: SimpleDispatcher.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object call(String arguments, CommandLocals locals, String[] parentCommands) throws CommandException {
    // We have permission for this command if we have permissions for subcommands
    if (!testPermission(locals)) {
        throw new CommandPermissionsException();
    }

    String[] split = arguments.split(" ", -1);
    Set<String> aliases = getPrimaryAliases();

    if (aliases.isEmpty()) {
        throw new InvalidUsageException("This command has no sub-commands.", this);
    } else if (split.length > 0) {
        String subCommand = split[0];
        String subArguments = Joiner.on(" ").join(Arrays.copyOfRange(split, 1, split.length));
        String[] subParents = Arrays.copyOf(parentCommands, parentCommands.length + 1);
        subParents[parentCommands.length] = subCommand;
        CommandMapping mapping = get(subCommand);

        if (mapping != null) {
            try {
                return mapping.getCallable().call(subArguments, locals, subParents);
            } catch (CommandException e) {
                e.prependStack(subCommand);
                throw e;
            } catch (Throwable t) {
                throw new WrappedCommandException(t);
            }
        }

    }

    throw new InvalidUsageException("Please choose a sub-command.", this, true);
}
 
Example #3
Source File: CardinalCommand.java    From CardinalPGM with MIT License 5 votes vote down vote up
@Command(aliases = "cardinal", flags = "vru", desc = "Various functions related to Cardinal.", min = 0, max = 0)
public static void cardinal(final CommandContext cmd, CommandSender sender) throws CommandPermissionsException {
    if (cmd.hasFlag('v')) {
        sender.sendMessage(ChatColor.GOLD + ChatConstant.UI_VERSION.asMessage(new UnlocalizedChatMessage(Cardinal.getInstance().getDescription().getVersion())).getMessage(ChatUtil.getLocale(sender)));
        sender.sendMessage(ChatColor.GOLD + ChatConstant.UI_JAVA_VERSION.asMessage(new UnlocalizedChatMessage(System.getProperty("java.version"))).getMessage(ChatUtil.getLocale(sender)));
        if (System.getProperty("java.version").startsWith("1.7")) {
            sender.sendMessage(ChatColor.DARK_RED + ChatConstant.UI_JAVA_UPDATE.getMessage(ChatUtil.getLocale(sender)));
        }
        Bukkit.getScheduler().runTaskAsynchronously(Cardinal.getInstance(), UpdateHandler.getUpdateHandler().getNotificationTask(sender));
    }
    if (cmd.hasFlag('r')) {
        if (sender.hasPermission("cardinal.reload")) {
            Cardinal.getInstance().reloadConfig();
            sender.sendMessage(new UnlocalizedChatMessage(ChatColor.GREEN + "{0}", new LocalizedChatMessage(ChatConstant.GENERIC_CONFIG_RELOAD)).getMessage(sender instanceof Player ? ((Player) sender).getLocale() : Locale.getDefault().toString()));
            Cardinal.getInstance().registerRanks();
            sender.sendMessage(new UnlocalizedChatMessage(ChatColor.GREEN + "{0}", new LocalizedChatMessage(ChatConstant.GENERIC_RANKS_RELOAD)).getMessage(sender instanceof Player ? ((Player) sender).getLocale() : Locale.getDefault().toString()));
        } else {
            throw new CommandPermissionsException();
        }
    }
    if (cmd.hasFlag('u')) {
        if (sender.hasPermission("cardinal.update")) {
            Bukkit.getScheduler().runTaskAsynchronously(Cardinal.getInstance(), UpdateHandler.getUpdateHandler().getUpdateTask(sender));
        } else {
            throw new CommandPermissionsException();
        }
    }
}
 
Example #4
Source File: RestartCommands.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Command(
    aliases = {"queuerestart", "qr"},
    desc = "Restart the server at the next safe opportunity",
    usage = "[-l/h (low/high priority)]",
    min = 0,
    max = 0,
    flags = "lh"
)
@CommandPermissions("server.queuerestart")
@Console
public void queueRestart(CommandContext args, final CommandSender sender) throws CommandException {
    final Audience audience = audiences.get(sender);

    final int priority;
    if(args.hasFlag('l')) {
        priority = ServerDoc.Restart.Priority.LOW;
    } else if(args.hasFlag('h')) {
        if(!sender.hasPermission("server.queuerestart.high")) {
            throw new CommandPermissionsException();
        }
        priority = ServerDoc.Restart.Priority.HIGH;
    } else {
        priority = ServerDoc.Restart.Priority.NORMAL;
    }

    if(restartManager.isRestartRequested(priority)) {
        audience.sendMessage(new TranslatableComponent("command.admin.queueRestart.restartQueued"));
        return;
    }

    syncExecutor.callback(
        restartManager.requestRestart("/queuerestart command", priority),
        CommandFutureCallback.onSuccess(sender, args, result -> {
            if(restartManager.isRestartDeferred()) {
                audience.sendMessage(new TranslatableComponent("command.admin.queueRestart.restartQueued"));
            } else {
                audience.sendMessage(new TranslatableComponent("command.admin.queueRestart.restartingNow"));
            }
        })
    );
}
 
Example #5
Source File: CommandUtils.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void assertPermission(Permissible permissible, String permission) throws CommandPermissionsException {
    if(!permissible.hasPermission(permission)) {
        throw new CommandPermissionsException();
    }
}
 
Example #6
Source File: CommandUtils.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void assertPermission(Permissible permissible, Permission permission) throws CommandPermissionsException {
    if(!permissible.hasPermission(permission)) {
        throw new CommandPermissionsException();
    }
}
 
Example #7
Source File: PunishmentCommands.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean permission(CommandSender sender, @Nullable Type type) throws CommandException {
    if(!sender.hasPermission(fromType(type))) {
        throw new CommandPermissionsException();
    }
    return true;
}