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