use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class WandCommandExecutor method onTabComplete.
@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
List<String> options = new ArrayList<>();
Player player = (sender instanceof Player) ? (Player) sender : null;
String permissionKey = "wand";
if (commandName.contains("wandp")) {
permissionKey = "wandp";
if (args.length > 0) {
player = DeprecatedUtils.getPlayer(args[0]);
}
if (args.length == 1) {
options.addAll(api.getPlayerNames());
return options;
} else if (args.length > 1) {
args = Arrays.copyOfRange(args, 1, args.length);
}
}
if (args.length == 1) {
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "add");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "remove");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "name");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "fill");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "configure");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "override");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "organize");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "alphabetize");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "combine");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "upgrade");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "describe");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "enchant");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "create");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "destroy");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "duplicate");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "restore");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "unlock");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "bind");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "unbind");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "save");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "delete");
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "levelspells");
Collection<String> allWands = api.getWandKeys();
for (String wandKey : allWands) {
addIfPermissible(sender, options, "Magic.create.", wandKey);
}
}
if (args.length == 2) {
String subCommand = args[0];
String subCommandPNode = "Magic.commands." + permissionKey + "." + subCommand;
if (!api.hasPermission(sender, subCommandPNode)) {
return options;
}
subCommandPNode += ".";
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("configure") || subCommand.equalsIgnoreCase("describe") || subCommand.equalsIgnoreCase("upgrade")) {
for (String key : BaseMagicProperties.PROPERTY_KEYS) {
options.add(key);
}
for (String damageType : api.getController().getDamageTypes()) {
options.add("protection." + damageType);
options.add("strength." + damageType);
options.add("weakness." + damageType);
}
}
if (subCommand.equalsIgnoreCase("override")) {
Collection<SpellTemplate> spellList = api.getController().getSpellTemplates(true);
String partial = args[1];
if (partial.indexOf('.') > 0) {
String[] pieces = StringUtils.split(partial, '.');
String spellKey = pieces[0];
SpellTemplate spell = api.getController().getSpellTemplate(spellKey);
if (spell != null) {
List<String> spellOptions = new ArrayList<>();
spell.getParameters(spellOptions);
for (String option : spellOptions) {
options.add(spellKey + "." + option);
}
}
} else {
for (SpellTemplate spell : spellList) {
String spellKey = spell.getKey();
if (api.hasPermission(sender, subCommandPNode + spellKey)) {
options.add(spellKey + ".");
}
}
}
}
if (subCommand.equalsIgnoreCase("remove")) {
Wand activeWand = null;
if (player != null) {
Mage mage = controller.getMage(player);
activeWand = mage.getActiveWand();
}
if (activeWand != null) {
Collection<String> spellNames = activeWand.getSpells();
for (String spellName : spellNames) {
options.add(spellName);
}
options.add("brush");
}
}
if (subCommand.equalsIgnoreCase("combine")) {
Collection<String> allWands = api.getWandKeys();
for (String wandKey : allWands) {
addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".combine.", wandKey, true);
}
}
if (subCommand.equalsIgnoreCase("delete")) {
File wandFolder = new File(api.getController().getConfigFolder(), "wands");
if (wandFolder.exists()) {
File[] files = wandFolder.listFiles();
for (File file : files) {
if (file.getName().endsWith(".yml")) {
options.add(file.getName().replace(".yml", ""));
}
}
}
}
}
if (args.length == 3) {
String subCommand = args[0];
String subCommand2 = args[1];
String commandPNode = "Magic.commands." + permissionKey + "." + subCommand;
if (!api.hasPermission(sender, commandPNode)) {
return options;
}
if (subCommand.equalsIgnoreCase("override")) {
String[] pieces = StringUtils.split(subCommand2, '.');
if (pieces.length > 1) {
String spellKey = pieces[0];
String argument = pieces[1];
SpellTemplate spell = api.getSpellTemplate(spellKey);
if (spell != null) {
spell.getParameterOptions(options, argument);
}
}
}
if (subCommand.equalsIgnoreCase("configure") || subCommand.equalsIgnoreCase("upgrade")) {
if (subCommand2.equals("effect_sound")) {
Sound[] sounds = Sound.values();
for (Sound sound : sounds) {
options.add(sound.name().toLowerCase());
}
} else if (subCommand2.equals("effect_particle")) {
ParticleEffect[] particleTypes = ParticleEffect.values();
for (ParticleEffect particleType : particleTypes) {
options.add(particleType.name().toLowerCase());
}
} else if (subCommand2.equals("mode")) {
for (WandMode mode : WandMode.values()) {
options.add(mode.name().toLowerCase());
}
} else if (subCommand2.equals("left_click") || subCommand2.equals("right_click") || subCommand2.equals("drop") || subCommand2.equals("swap")) {
for (WandAction action : WandAction.values()) {
options.add(action.name().toLowerCase());
}
}
}
String subCommandPNode = "Magic.commands." + permissionKey + "." + subCommand + "." + subCommand2;
if (!api.hasPermission(sender, subCommandPNode)) {
return options;
}
boolean isBrushCommand = subCommand2.equalsIgnoreCase("material") || subCommand2.equalsIgnoreCase("brush");
if (subCommand.equalsIgnoreCase("remove") && isBrushCommand) {
Wand activeWand = null;
if (player != null) {
Mage mage = controller.getMage(player);
activeWand = mage.getActiveWand();
}
if (activeWand != null) {
Collection<String> materialNames = activeWand.getBrushes();
for (String materialName : materialNames) {
options.add(materialName);
}
}
}
if (subCommand.equalsIgnoreCase("add") && isBrushCommand) {
options.addAll(api.getBrushes());
}
}
return options;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class MagicCommandExecutor 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.magic.", "clean");
addIfPermissible(sender, options, "Magic.commands.magic.", "clearcache");
addIfPermissible(sender, options, "Magic.commands.magic.", "cancel");
addIfPermissible(sender, options, "Magic.commands.magic.", "load");
addIfPermissible(sender, options, "Magic.commands.magic.", "save");
addIfPermissible(sender, options, "Magic.commands.magic.", "commit");
addIfPermissible(sender, options, "Magic.commands.magic.", "give");
addIfPermissible(sender, options, "Magic.commands.magic.", "worth");
addIfPermissible(sender, options, "Magic.commands.magic.", "sell");
addIfPermissible(sender, options, "Magic.commands.magic.", "list");
addIfPermissible(sender, options, "Magic.commands.magic.", "rpcheck");
addIfPermissible(sender, options, "Magic.commands.magic.", "rpsend");
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("list")) {
addIfPermissible(sender, options, "Magic.commands.magic.list", "maps");
addIfPermissible(sender, options, "Magic.commands.magic.list", "wands");
addIfPermissible(sender, options, "Magic.commands.magic.list", "automata");
addIfPermissible(sender, options, "Magic.commands.magic.list", "schematics");
addIfPermissible(sender, options, "Magic.commands.magic.list", "entities");
addIfPermissible(sender, options, "Magic.commands.magic.list", "tasks");
addIfPermissible(sender, options, "Magic.commands.magic.list", "blocks");
addIfPermissible(sender, options, "Magic.commands.magic.list", "mages");
} else if (args[0].equalsIgnoreCase("give") || args[0].equalsIgnoreCase("worth") || args[0].equalsIgnoreCase("sell")) {
options.add("wand");
options.add("material");
options.add("upgrade");
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
options.add(spell.getKey());
}
Collection<String> allWands = api.getWandKeys();
for (String wandKey : allWands) {
options.add(wandKey);
}
options.addAll(api.getBrushes());
}
} else if (args.length == 3) {
if (args[0].equalsIgnoreCase("give") || args[0].equalsIgnoreCase("sell")) {
if (args[1].equalsIgnoreCase("upgrade") || args[1].equalsIgnoreCase("wand")) {
Collection<String> allWands = api.getWandKeys();
for (String wandKey : allWands) {
options.add(wandKey);
}
} else if (args[1].equalsIgnoreCase("material")) {
options.addAll(api.getBrushes());
}
} else if (args[0].equalsIgnoreCase("configure") || args[0].equalsIgnoreCase("describe")) {
Player player = DeprecatedUtils.getPlayer(args[1]);
if (player != null) {
Mage mage = controller.getMage(player);
ConfigurationSection data = mage.getData();
options.addAll(data.getKeys(false));
}
}
}
return options;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class MagicTraitCommandExecutor method onTabComplete.
@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
List<String> options = new ArrayList<>();
if (!sender.hasPermission("Magic.commands.mtrait"))
return options;
String lastParameter = "";
if (args.length > 1) {
lastParameter = args[args.length - 2];
}
if (lastParameter.equalsIgnoreCase("spell")) {
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
addIfPermissible(sender, options, "Magic.cast.", spell.getKey());
}
} else if (lastParameter.equalsIgnoreCase("parameters")) {
options.addAll(Arrays.asList(BaseSpell.COMMON_PARAMETERS));
} else if (lastParameter.equalsIgnoreCase("hat")) {
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
options.add(spell.getKey());
}
Collection<String> allWands = api.getWandKeys();
for (String wandKey : allWands) {
options.add(wandKey);
}
for (Material material : Material.values()) {
options.add(material.name().toLowerCase());
}
Collection<String> allItems = api.getController().getItemKeys();
for (String itemKey : allItems) {
options.add(itemKey);
}
} else if (lastParameter.equalsIgnoreCase("cost")) {
options.addAll(Arrays.asList(BaseSpell.EXAMPLE_SIZES));
} else if (lastParameter.equalsIgnoreCase("caster") || lastParameter.equalsIgnoreCase("invisible") || lastParameter.equalsIgnoreCase("target_player") || lastParameter.equalsIgnoreCase("message_player")) {
options.addAll(Arrays.asList(BaseSpell.EXAMPLE_BOOLEANS));
} else {
options.add("spell");
options.add("parameter");
options.add("caster");
options.add("target_player");
options.add("message_player");
options.add("cost");
options.add("permission");
options.add("invisible");
options.add("hat");
options.add("command");
Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellList) {
addIfPermissible(sender, options, "Magic.cast.", spell.getKey());
}
}
return options;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class SpellsCommandExecutor method listCategories.
public void listCategories(Player player) {
HashMap<String, Integer> spellCounts = new HashMap<>();
List<SpellCategory> spellGroups = new ArrayList<>();
Collection<SpellTemplate> spellVariants = api.getSpellTemplates(player == null || player.hasPermission("Magic.bypass_hidden"));
for (SpellTemplate spell : spellVariants) {
if (player != null && !spell.hasCastPermission(player))
continue;
if (spell.getCategory() == null)
continue;
Integer spellCount = spellCounts.get(spell.getCategory().getKey());
if (spellCount == null || spellCount == 0) {
spellCounts.put(spell.getCategory().getKey(), 1);
spellGroups.add(spell.getCategory());
} else {
spellCounts.put(spell.getCategory().getKey(), spellCount + 1);
}
}
if (spellGroups.size() == 0) {
player.sendMessage(api.getMessages().get("general.no_spells"));
return;
}
Collections.sort(spellGroups);
for (SpellCategory group : spellGroups) {
player.sendMessage(group.getName() + " [" + spellCounts.get(group.getKey()) + "]");
}
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class SpellsCommandExecutor method listSpells.
public void listSpells(CommandSender sender, int pageNumber, String category) {
if (category != null) {
listSpellsByCategory(sender, category);
return;
}
Player player = sender instanceof Player ? (Player) sender : null;
Collection<SpellTemplate> spellVariants = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
int spellCount = 0;
for (SpellTemplate spell : spellVariants) {
if (player != null && !spell.hasCastPermission(player)) {
continue;
}
if (spell.getCategory() == null)
continue;
spellCount++;
}
// Kinda hacky internals-reaching
Collection<SpellCategory> allCategories = api.getController().getCategories();
List<SpellCategory> sortedGroups = new ArrayList<>(allCategories);
Collections.sort(sortedGroups);
int maxLines = -1;
if (pageNumber >= 0) {
maxLines = 5;
int maxPages = spellCount / maxLines + 1;
if (pageNumber > maxPages) {
pageNumber = maxPages;
}
String message = api.getMessages().get("general.spell_list_page");
message = message.replace("$count", Integer.toString(spellCount));
message = message.replace("$pages", Integer.toString(maxPages));
message = message.replace("$page", Integer.toString(pageNumber));
sender.sendMessage(message);
} else {
String message = api.getMessages().get("general.spell_list");
message = message.replace("$count", Integer.toString(spellCount));
sender.sendMessage(message);
}
int currentPage = 1;
int lineCount = 0;
int printedCount = 0;
for (SpellCategory group : sortedGroups) {
if (printedCount > maxLines && maxLines > 0)
break;
boolean isFirst = true;
Collection<SpellTemplate> spells = group.getSpells();
for (SpellTemplate spell : spells) {
if (printedCount > maxLines && maxLines > 0)
break;
if (!spell.hasCastPermission(sender))
continue;
if (currentPage == pageNumber || maxLines < 0) {
if (isFirst) {
sender.sendMessage(group.getName() + ":");
isFirst = false;
}
String name = spell.getName();
String description = spell.getDescription();
if (!name.equals(spell.getKey())) {
description = name + " : " + description;
}
MaterialAndData spellIcon = spell.getIcon();
Material material = spellIcon == null ? null : spellIcon.getMaterial();
String icon = material == null ? "None" : material.name().toLowerCase();
sender.sendMessage(ChatColor.AQUA + spell.getKey() + ChatColor.BLUE + " [" + icon + "] : " + ChatColor.YELLOW + description);
printedCount++;
}
lineCount++;
if (lineCount == maxLines) {
lineCount = 0;
currentPage++;
}
}
}
}
Aggregations