use of com.elmakers.mine.bukkit.api.magic.Mage 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.magic.Mage 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.magic.Mage 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;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class BlockController method onBlockBreak.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
Player player = event.getPlayer();
if (creativeBreakFrequency > 0 && player.getGameMode() == GameMode.CREATIVE) {
com.elmakers.mine.bukkit.magic.Mage mage = controller.getMage(event.getPlayer());
if (mage.checkLastClick(creativeBreakFrequency)) {
event.setCancelled(true);
return;
}
}
if (controller.areLocksProtected() && controller.isContainer(block) && !event.getPlayer().hasPermission("Magic.bypass")) {
String lockKey = CompatibilityUtils.getLock(block);
if (lockKey != null && !lockKey.isEmpty()) {
Inventory inventory = player.getInventory();
Mage mage = controller.getRegisteredMage(event.getPlayer());
if (mage != null) {
inventory = mage.getInventory();
}
if (!InventoryUtils.hasItem(inventory, lockKey)) {
String message = controller.getMessages().get("general.locked_chest");
if (mage != null) {
mage.sendMessage(message);
} else {
player.sendMessage(message);
}
event.setCancelled(true);
return;
}
}
}
com.elmakers.mine.bukkit.api.block.BlockData modifiedBlock = com.elmakers.mine.bukkit.block.UndoList.getBlockData(block.getLocation());
if (modifiedBlock != null) {
UndoList undoList = modifiedBlock.getUndoList();
if (undoList != null) {
if (!undoList.isConsumed()) {
event.setCancelled(true);
block.setType(Material.AIR);
}
com.elmakers.mine.bukkit.block.UndoList.commit(modifiedBlock);
}
}
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class BlockController method onWorldSaveEvent.
@EventHandler
public void onWorldSaveEvent(WorldSaveEvent event) {
World world = event.getWorld();
Collection<Player> players = world.getPlayers();
for (Player player : players) {
Mage mage = controller.getRegisteredMage(player);
if (mage != null) {
controller.saveMage(mage, true);
if (undoOnWorldSave) {
com.elmakers.mine.bukkit.api.block.UndoQueue queue = mage.getUndoQueue();
if (queue != null) {
int undone = queue.undoScheduled();
if (undone > 0) {
controller.info("Undid " + undone + " spells for " + player.getName() + " prior to save of world " + world.getName());
}
}
}
}
}
}
Aggregations