use of org.bukkit.command.CommandSender in project MagicPlugin by elBukkit.
the class MageCommandExecutor method onTabComplete.
@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
List<String> options = new ArrayList<>();
if (args.length == 1) {
addIfPermissible(sender, options, "Magic.commands.mage.", "add");
addIfPermissible(sender, options, "Magic.commands.mage.", "remove");
addIfPermissible(sender, options, "Magic.commands.mage.", "configure");
addIfPermissible(sender, options, "Magic.commands.mage.", "describe");
addIfPermissible(sender, options, "Magic.commands.mage.", "upgrade");
addIfPermissible(sender, options, "Magic.commands.mage.", "getdata");
addIfPermissible(sender, options, "Magic.commands.mage.", "setdata");
addIfPermissible(sender, options, "Magic.commands.mage.", "check");
addIfPermissible(sender, options, "Magic.commands.mage.", "debug");
addIfPermissible(sender, options, "Magic.commands.mage.", "reset");
addIfPermissible(sender, options, "Magic.commands.mage.", "unbind");
addIfPermissible(sender, options, "Magic.commands.mage.", "activate");
addIfPermissible(sender, options, "Magic.commands.mage.", "unlock");
addIfPermissible(sender, options, "Magic.commands.mage.", "lock");
addIfPermissible(sender, options, "Magic.commands.mage.", "levelspells");
addIfPermissible(sender, options, "Magic.commands.mage.", "attribute");
} else if (args.length == 2 && sender.hasPermission("Magic.commands.mage.others")) {
options.addAll(api.getPlayerNames());
}
if (args.length == 3 || args.length == 2) {
CommandSender target = args.length == 2 ? sender : DeprecatedUtils.getPlayer(args[1]);
String subCommand = args[0];
String subCommandPNode = "Magic.commands.mage." + subCommand;
if (subCommand.equalsIgnoreCase("setdata") || subCommand.equalsIgnoreCase("getdata")) {
if (target != null) {
Mage mage = controller.getMage(target);
ConfigurationSection data = mage.getData();
options.addAll(data.getKeys(false));
}
}
if (subCommand.equalsIgnoreCase("add")) {
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
addIfPermissible(sender, options, subCommandPNode, spell.getKey(), true);
}
addIfPermissible(sender, options, subCommandPNode, "brush", true);
}
if (subCommand.equalsIgnoreCase("remove")) {
if (target != null) {
Mage mage = controller.getMage(target);
MageClass mageClass = mage.getActiveClass();
if (mageClass != null) {
options.addAll(mageClass.getSpells());
}
}
options.add("brush");
}
if (subCommand.equalsIgnoreCase("configure") || subCommand.equalsIgnoreCase("describe") || subCommand.equalsIgnoreCase("upgrade")) {
for (String key : BaseMagicProperties.PROPERTY_KEYS) {
options.add(key);
}
for (String protection : api.getController().getDamageTypes()) {
options.add("protection." + protection);
}
}
if (subCommand.equalsIgnoreCase("attribute")) {
for (String attribute : api.getController().getAttributes()) {
options.add(attribute);
}
}
if (subCommand.equalsIgnoreCase("add")) {
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
addIfPermissible(sender, options, subCommandPNode, spell.getKey(), true);
}
addIfPermissible(sender, options, subCommandPNode, "brush", true);
}
if (args[0].equalsIgnoreCase("lock") || args[0].equalsIgnoreCase("unlock") || args[0].equalsIgnoreCase("activate")) {
options.addAll(api.getController().getMageClassKeys());
}
}
return options;
}
use of org.bukkit.command.CommandSender in project MagicPlugin by elBukkit.
the class HeroesSkillSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
CommandSender sender = mage.getCommandSender();
controller.getPlugin().getServer().dispatchCommand(sender, "skill " + skillKey);
return SpellResult.CAST;
}
use of org.bukkit.command.CommandSender in project MagicPlugin by elBukkit.
the class RecallAction method tryTeleport.
protected boolean tryTeleport(final Player player, final Waypoint waypoint) {
Mage mage = context.getMage();
if (waypoint == null)
return false;
if (waypoint.isCommand()) {
if (waypoint.asConsole) {
try {
player.getServer().dispatchCommand(Bukkit.getConsoleSender(), waypoint.command);
} catch (Exception ex) {
context.getLogger().log(Level.WARNING, "Error running command as console " + waypoint.command, ex);
}
} else {
CommandSender sender = mage.getCommandSender();
boolean isOp = sender.isOp();
if (waypoint.opPlayer && !isOp) {
sender.setOp(true);
}
try {
player.getServer().dispatchCommand(sender, waypoint.command);
} catch (Exception ex) {
context.getLogger().log(Level.WARNING, "Error running command " + waypoint.command, ex);
}
if (waypoint.opPlayer && !isOp) {
sender.setOp(false);
}
}
mage.enableSuperProtection(protectionTime);
return true;
}
Location targetLocation = waypoint.location;
if (targetLocation == null) {
String serverName = waypoint.serverName;
String warpName = waypoint.warpName;
if (warpName != null && serverName != null) {
context.getController().warpPlayerToServer(player, serverName, warpName);
} else {
context.sendMessage(waypoint.failMessage);
}
return false;
}
if (!allowCrossWorld && !mage.getLocation().getWorld().equals(targetLocation.getWorld())) {
context.sendMessageKey("cross_world_disallowed");
return false;
}
if (waypoint.maintainDirection) {
Location playerLocation = player.getLocation();
targetLocation.setYaw(playerLocation.getYaw());
targetLocation.setPitch(playerLocation.getPitch());
}
mage.enableSuperProtection(protectionTime);
if (context.teleport(player, targetLocation, verticalSearchDistance, waypoint.safe, waypoint.safe)) {
context.castMessage(waypoint.message);
} else {
context.castMessage(waypoint.failMessage);
}
return true;
}
use of org.bukkit.command.CommandSender in project MagicPlugin by elBukkit.
the class CommandAction method perform.
@Override
public SpellResult perform(CastContext context) {
Mage mage = context.getMage();
MageController controller = context.getController();
CommandSender sender = asConsole ? Bukkit.getConsoleSender() : mage.getCommandSender();
if (sender == null) {
return SpellResult.FAIL;
}
Queue<String> conversationCommands = new ArrayDeque<>(commands.size());
boolean isOp = sender.isOp();
if (opPlayer && !isOp) {
sender.setOp(true);
}
for (String command : commands) {
try {
String converted = context.parameterize(command);
if (converted.contains("@arg")) {
conversationCommands.add(converted);
} else {
controller.getPlugin().getServer().dispatchCommand(sender, converted);
}
} catch (Exception ex) {
controller.getLogger().log(Level.WARNING, "Error running command: " + command, ex);
}
}
if (opPlayer && !isOp) {
sender.setOp(false);
}
if (!conversationCommands.isEmpty()) {
runConversations(context, conversationCommands, opPlayer);
}
return SpellResult.CAST;
}
use of org.bukkit.command.CommandSender in project MagicPlugin by elBukkit.
the class CountAction method finish.
@Override
public void finish(CastContext context) {
super.finish(context);
CommandSender sender = context.getMage().getCommandSender();
if (sender != null) {
sender.sendMessage(ChatColor.DARK_AQUA + "Found " + ChatColor.AQUA + totalCount + ChatColor.DARK_AQUA + " targets in the area");
for (Map.Entry<String, Integer> entry : counts.entrySet()) {
sender.sendMessage(ChatColor.AQUA + entry.getKey() + ChatColor.WHITE + ": " + ChatColor.GOLD + entry.getValue());
}
}
totalCount = 0;
counts.clear();
}
Aggregations