use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class GiveItemAction method prepare.
@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
super.prepare(context, parameters);
MageController controller = context.getController();
permissionNode = parameters.getString("permission", null);
String itemKey = parameters.getString("item");
item = controller.createItem(itemKey);
if (item == null) {
context.getLogger().warning("Invalid item: " + itemKey);
} else {
String name = parameters.getString("name", null);
List<String> lore = ConfigurationUtils.getStringList(parameters, "lore");
if ((name != null && !name.isEmpty()) || (lore != null && !lore.isEmpty())) {
ItemMeta meta = item.getItemMeta();
if (name != null && !name.isEmpty()) {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
}
if (lore != null && !lore.isEmpty()) {
for (int i = 0; i < lore.size(); i++) {
lore.set(i, ChatColor.translateAlternateColorCodes('&', lore.get(i)));
}
meta.setLore(lore);
}
item.setItemMeta(meta);
}
}
String costKey = parameters.getString("requires");
if (costKey != null && !costKey.isEmpty()) {
requireItem = controller.createItem(costKey);
if (requireItem == null) {
context.getLogger().warning("Invalid required item: " + costKey);
}
}
}
use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class GrowEntityAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity targetEntity = context.getTargetEntity();
MageController controller = context.getController();
if (controller.isElemental(targetEntity)) {
double elementalSize = controller.getElementalScale(targetEntity);
elementalSize *= 1.2;
controller.setElementalScale(targetEntity, elementalSize);
return SpellResult.CAST;
}
if (!(targetEntity instanceof LivingEntity))
return SpellResult.NO_TARGET;
LivingEntity li = (LivingEntity) targetEntity;
if (li instanceof Ageable && !((Ageable) li).isAdult() && !(li instanceof Player)) {
context.registerModified(li);
((Ageable) li).setAdult();
} else if (li instanceof Zombie) {
context.registerModified(li);
Zombie zombie = (Zombie) li;
if (!zombie.isBaby()) {
UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
Location targetLocation = li.getLocation();
li.remove();
Entity giant = targetLocation.getWorld().spawnEntity(targetLocation, EntityType.GIANT);
context.registerForUndo(giant);
if (spawnedList != null) {
spawnedList.add(giant);
}
} else {
((Zombie) li).setBaby(false);
}
} else if (li instanceof PigZombie && ((PigZombie) li).isBaby()) {
context.registerModified(li);
((PigZombie) li).setBaby(false);
} else if (li instanceof Slime) {
context.registerModified(li);
Slime slime = (Slime) li;
slime.setSize(slime.getSize() + 1);
} else if (li instanceof Skeleton && skeletons && ((Skeleton) li).getSkeletonType() == Skeleton.SkeletonType.NORMAL) {
context.registerModified(li);
Skeleton skeleton = (Skeleton) li;
skeleton.setSkeletonType(Skeleton.SkeletonType.WITHER);
} else {
return SpellResult.NO_TARGET;
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.MageController 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 com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class CreateFieldAction method perform.
@Override
public SpellResult perform(CastContext context) {
SpellResult result = super.perform(context);
if (!result.isSuccess() || fieldType != context.getTargetBlock().getType()) {
return result;
}
MageController apiController = context.getController();
if (!(apiController instanceof MagicController)) {
return SpellResult.FAIL;
}
MagicController controller = (MagicController) apiController;
PreciousStonesManager preciousStones = controller.getPreciousStones();
context.getMage().sendDebugMessage(ChatColor.GRAY + "Placing field", 7);
if (!preciousStones.createField(context.getTargetLocation(), context.getMage().getPlayer())) {
context.getMage().sendDebugMessage(ChatColor.RED + "Could not place field", 2);
return SpellResult.NO_TARGET;
}
if (!rent.isEmpty() && !rentPeriod.isEmpty()) {
if (!preciousStones.rentField(context.getTargetLocation().getBlock().getRelative(BlockFace.UP).getLocation(), context.getMage().getPlayer(), rent, rentPeriod, rentSignDirection)) {
context.getMage().sendDebugMessage(ChatColor.RED + "Could not rent field", 2);
}
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class CreatePlotAction method perform.
@Override
public SpellResult perform(CastContext context) {
MageController apiController = context.getController();
if (!(apiController instanceof MagicController)) {
return SpellResult.FAIL;
}
MagicController controller = (MagicController) apiController;
TownyManager towny = controller.getTowny();
if (!towny.createPlot(context.getTargetLocation(), price)) {
return SpellResult.NO_TARGET;
}
return SpellResult.CAST;
}
Aggregations