Search in sources :

Example 36 with CommandSender

use of org.bukkit.command.CommandSender in project Essentials by EssentialsX.

the class EconomyTest method runConsoleCommand.

private void runConsoleCommand(String command, String[] args) throws Exception {
    IEssentialsCommand cmd;
    CommandSender sender = server.getConsoleSender();
    try {
        cmd = (IEssentialsCommand) Essentials.class.getClassLoader().loadClass("com.earth2me.essentials.commands.Command" + command).newInstance();
        cmd.setEssentials(ess);
        cmd.run(server, new CommandSource(sender), command, null, args);
    } catch (NoChargeException ex) {
    }
}
Also used : NoChargeException(com.earth2me.essentials.commands.NoChargeException) IEssentialsCommand(com.earth2me.essentials.commands.IEssentialsCommand) CommandSender(org.bukkit.command.CommandSender)

Example 37 with CommandSender

use of org.bukkit.command.CommandSender in project VoxelGamesLibv2 by VoxelGamesLib.

the class VoxelGamesLib method registerCommandContexts.

private void registerCommandContexts() {
    CommandContexts<BukkitCommandExecutionContext> con = commandManager.getCommandContexts();
    con.registerIssuerAwareContext(User.class, c -> {
        boolean isOptional = c.hasAnnotation(Optional.class);
        CommandSender sender = c.getSender();
        boolean isPlayerSender = sender instanceof Player;
        if (!c.hasFlag("other")) {
            Player player = isPlayerSender ? (Player) sender : null;
            if (player == null) {
                if (!isOptional) {
                    throw new InvalidCommandArgument(MessageKeys.NOT_ALLOWED_ON_CONSOLE, false);
                } else {
                    return null;
                }
            }
            return userHandler.getUser(player.getUniqueId()).orElseThrow(() -> new VoxelGameLibException("Unknown user " + player.getDisplayName()));
        } else {
            String arg = c.popFirstArg();
            if (arg == null) {
                if (isOptional) {
                    if (c.hasFlag("defaultself")) {
                        if (isPlayerSender) {
                            return userHandler.getUser(((Player) sender).getUniqueId()).orElseThrow(() -> new VoxelGameLibException("Unknown user " + ((Player) sender).getDisplayName()));
                        } else {
                            throw new InvalidCommandArgument(MessageKeys.NOT_ALLOWED_ON_CONSOLE, false);
                        }
                    }
                }
                return null;
            } else {
                return userHandler.getUser(arg).orElseThrow(() -> new VoxelGameLibException("Unknown user " + arg));
            }
        }
    });
    con.registerContext(int.class, c -> Integer.parseInt(c.popFirstArg()));
    con.registerContext(GameMode.class, c -> {
        GameMode mode = gameHandler.getGameModes().stream().filter(gameMode -> gameMode.getName().equalsIgnoreCase(c.getFirstArg())).findAny().orElseThrow(() -> new InvalidCommandArgument("Unknown gamemode " + c.getFirstArg()));
        // pop later so that we can get a nice error message
        c.popLastArg();
        return mode;
    });
    con.registerContext(Locale.class, c -> {
        Locale locale = Locale.fromName(c.getFirstArg()).orElse(Locale.fromTag(c.getFirstArg()).orElseThrow(() -> new InvalidCommandArgument("Unknown locale " + c.getFirstArg())));
        // pop later so that we can get a nice error message
        c.popFirstArg();
        return locale;
    });
    con.registerContext(Role.class, c -> Role.fromName(c.popFirstArg()));
    con.registerContext(UUID.class, c -> UUID.fromString(c.popFirstArg()));
    con.registerContext(Trackable.class, c -> {
        Trackable s = StatsHandler.fromName(c.getFirstArg()).orElseThrow(() -> new InvalidCommandArgument("Unknown stats type " + c.getFirstArg()));
        // pop later so that we can get a nice error message
        c.popFirstArg();
        return s;
    });
}
Also used : Locale(com.voxelgameslib.voxelgameslib.lang.Locale) GameMode(com.voxelgameslib.voxelgameslib.game.GameMode) Player(org.bukkit.entity.Player) InvalidCommandArgument(co.aikar.commands.InvalidCommandArgument) VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) CommandSender(org.bukkit.command.CommandSender) Trackable(com.voxelgameslib.voxelgameslib.stats.Trackable) BukkitCommandExecutionContext(co.aikar.commands.BukkitCommandExecutionContext)

Example 38 with CommandSender

use of org.bukkit.command.CommandSender in project LuckPerms by lucko.

the class BukkitCommandExecutor method onTabComplete.

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
    Sender lpSender = this.plugin.getSenderFactory().wrap(sender);
    List<String> arguments = stripQuotes(TAB_COMPLETE_ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
    return onTabComplete(lpSender, arguments);
}
Also used : CommandSender(org.bukkit.command.CommandSender) Sender(me.lucko.luckperms.common.sender.Sender)

Example 39 with CommandSender

use of org.bukkit.command.CommandSender in project LuckPerms by lucko.

the class BukkitCommandExecutor method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    Sender lpSender = this.plugin.getSenderFactory().wrap(sender);
    List<String> arguments = stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args)));
    onCommand(lpSender, label, arguments);
    return true;
}
Also used : CommandSender(org.bukkit.command.CommandSender) Sender(me.lucko.luckperms.common.sender.Sender)

Example 40 with CommandSender

use of org.bukkit.command.CommandSender in project solinia3-core by mixxit.

the class CommandEditLootTable method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp() && !player.hasPermission("solinia.editloottable")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length < 1) {
        sender.sendMessage("Insufficient arguments: LootTableid");
        return false;
    }
    if (args.length == 0) {
        return false;
    }
    int LootTableid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaLootTable LootTable = StateManager.getInstance().getConfigurationManager().getLootTable(LootTableid);
            if (LootTable != null) {
                LootTable.sendLootTableSettingsToSender(sender);
            } else {
                sender.sendMessage("LootTable ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: LootTableid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    if (LootTableid < 1) {
        sender.sendMessage("Invalid LootTable id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getLootTable(LootTableid) == null) {
            sender.sendMessage("Cannot locate LootTable id: " + LootTableid);
            return false;
        }
        if (StateManager.getInstance().getConfigurationManager().getLootTable(LootTableid).isOperatorCreated() && !sender.isOp()) {
            sender.sendMessage("This loottable was op created and you are not an op. Only ops can edit op loottable items");
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editLootTable(LootTableid, setting, value);
        sender.sendMessage("Updating setting on LootTable");
    } catch (InvalidLootTableSettingException ne) {
        sender.sendMessage("Invalid LootTable setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) InvalidLootTableSettingException(com.solinia.solinia.Exceptions.InvalidLootTableSettingException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ISoliniaLootTable(com.solinia.solinia.Interfaces.ISoliniaLootTable)

Aggregations

CommandSender (org.bukkit.command.CommandSender)295 Test (org.junit.Test)171 Player (org.bukkit.entity.Player)94 Matchers.containsString (org.hamcrest.Matchers.containsString)68 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)50 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)43 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)30 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)29 PermissionNode (fr.xephi.authme.permission.PermissionNode)17 BlockCommandSender (org.bukkit.command.BlockCommandSender)16 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)12 Location (org.bukkit.Location)10 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)9 ArrayList (java.util.ArrayList)9 List (java.util.List)9 FoundCommandResult (fr.xephi.authme.command.FoundCommandResult)8 IOException (java.io.IOException)7 Entity (org.bukkit.entity.Entity)7 IEssentialsCommand (com.earth2me.essentials.commands.IEssentialsCommand)6 NoChargeException (com.earth2me.essentials.commands.NoChargeException)6