use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.
the class WandCommandExecutor method onWandAlphabetize.
public boolean onWandAlphabetize(CommandSender sender, Player player) {
Wand wand = checkWand(sender, player, true);
if (wand == null) {
return true;
}
Mage mage = controller.getMage(player);
wand.alphabetizeInventory();
wand.saveState();
mage.sendMessage(api.getMessages().get("wand.alphabetized").replace("$wand", wand.getName()));
if (sender != player) {
sender.sendMessage(api.getMessages().getParameterized("wand.player_alphabetized", "$name", player.getName()).replace("$wand", wand.getName()));
}
return true;
}
use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.
the class WandCommandExecutor method checkWand.
@Nullable
protected Wand checkWand(CommandSender sender, Player player, boolean skipModifiable, boolean skipBound, boolean quiet) {
Mage mage = controller.getMage(player);
Wand wand = mage.getActiveWand();
boolean bypassLocked = (sender instanceof Player) && api.hasPermission(sender, "Magic.wand.override_locked");
if (wand == null) {
ItemStack item = player.getInventory().getItemInMainHand();
if (api.isUpgrade(item)) {
wand = api.getWand(item);
} else if (bypassLocked && api.isWand(item)) {
wand = api.getWand(item);
}
}
if (wand == null) {
if (!quiet)
mage.sendMessage(api.getMessages().get("wand.no_wand"));
if (sender != player) {
sender.sendMessage(api.getMessages().getParameterized("wand.player_no_wand", "$name", player.getName()));
}
return null;
}
if (!skipModifiable && wand.isLocked() && !bypassLocked) {
if (!quiet)
mage.sendMessage(api.getMessages().get("wand.unmodifiable"));
if (sender != player) {
sender.sendMessage(api.getMessages().getParameterized("wand.player_unmodifiable", "$name", player.getName()));
}
return null;
}
if (!skipBound && !wand.canUse(mage.getPlayer())) {
if (!quiet)
mage.sendMessage(api.getMessages().get("wand.bound_to_other"));
if (sender != player) {
sender.sendMessage(api.getMessages().getParameterized("wand.player_unmodifiable", "$name", player.getName()));
}
return null;
}
return wand;
}
use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.
the class WandCommandExecutor method onWandBind.
public boolean onWandBind(CommandSender sender, Player player) {
Wand wand = checkWand(sender, player);
if (wand == null) {
return true;
}
Mage mage = controller.getMage(player);
wand.bind();
mage.sendMessage(api.getMessages().get("wand.setbound"));
if (sender != player) {
sender.sendMessage(api.getMessages().getParameterized("wand.player_setbound", "$name", player.getName()));
}
return true;
}
use of com.elmakers.mine.bukkit.api.wand.Wand 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.wand.Wand in project MagicPlugin by elBukkit.
the class WandCommandExecutor method onWandUnbind.
public boolean onWandUnbind(CommandSender sender, Player player) {
Wand wand = checkWand(sender, player);
if (wand == null) {
return true;
}
Mage mage = controller.getMage(player);
wand.unbind();
mage.sendMessage(api.getMessages().get("wand.unbound"));
if (sender != player) {
sender.sendMessage(api.getMessages().getParameterized("wand.player_unbound", "$name", player.getName()));
}
return true;
}
Aggregations