use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.
the class CondHasItem method check.
@Override
public boolean check(final Event e) {
return entities.check(e, new Checker<Entity>() {
@Override
public boolean check(final Entity entity) {
final MageController controller = MagicPlugin.getAPI().getController();
final Mage mage = controller.getRegisteredMage(entity);
if (mage == null) {
return false;
}
final Wand wand = offhand ? mage.getOffhandWand() : mage.getActiveWand();
if (itemKeys == null) {
return (wand != null) != isNegated();
}
final LivingEntity living = mage.getLivingEntity();
final ItemStack item = wand == null && living != null ? (offhand ? living.getEquipment().getItemInOffHand() : living.getEquipment().getItemInMainHand()) : null;
return itemKeys.check(e, new Checker<String>() {
@Override
public boolean check(final String targetKey) {
if (armor) {
if (living == null)
return false;
for (ItemStack armorItem : living.getEquipment().getArmorContents()) {
if (armorItem == null)
continue;
String key = controller.getWandKey(armorItem);
if (key != null && key.equalsIgnoreCase(targetKey))
return true;
key = controller.getItemKey(armorItem);
if (key != null && key.equalsIgnoreCase(targetKey))
return true;
}
return false;
}
if (wand != null && wand.getTemplateKey().equalsIgnoreCase(targetKey)) {
return true;
}
if (item != null) {
String itemKey = controller.getItemKey(item);
if (itemKey != null && itemKey.equalsIgnoreCase(targetKey)) {
return true;
}
}
return false;
}
}, isNegated());
}
});
}
use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.
the class CondHasSpell method check.
@Override
public boolean check(final Event e) {
return entities.check(e, new Checker<Entity>() {
@Override
public boolean check(final Entity entity) {
final Mage mage = MagicPlugin.getAPI().getController().getRegisteredMage(entity);
if (mage == null) {
return false;
}
return spells.check(e, new Checker<String>() {
@Override
public boolean check(final String spellKey) {
Wand wand = mage.getActiveWand();
if (wand != null && wand.hasSpell(spellKey)) {
return true;
}
MageClass activeClass = mage.getActiveClass();
if (activeClass != null && activeClass.hasSpell(spellKey)) {
return true;
}
return false;
}
}, isNegated());
}
});
}
use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.
the class StashSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Target target = getTarget();
if (!target.hasEntity())
return SpellResult.NO_TARGET;
Entity targetEntity = target.getEntity();
if (!(targetEntity instanceof HumanEntity))
return SpellResult.NO_TARGET;
Player showPlayer = mage.getPlayer();
if (showPlayer == null)
return SpellResult.PLAYER_REQUIRED;
String typeString = parameters.getString("type", "ender");
// Special case for wands
if (targetEntity instanceof Player && targetEntity != showPlayer) {
Player targetPlayer = (Player) targetEntity;
Mage targetMage = controller.getMage(targetPlayer);
if (!mage.isSuperPowered() && isSuperProtected(targetMage)) {
return SpellResult.NO_TARGET;
}
if (targetMage.getActiveWand() != null && typeString.equalsIgnoreCase("inventory")) {
targetMage.getActiveWand().closeInventory();
}
}
// Make sure to close the player's wand
Wand activeWand = mage.getActiveWand();
if (activeWand != null) {
activeWand.closeInventory();
}
HumanEntity humanTarget = (HumanEntity) targetEntity;
if (typeString.equalsIgnoreCase("inventory")) {
Inventory inventory = humanTarget.getInventory();
showPlayer.openInventory(inventory);
} else {
Inventory enderInventory = humanTarget.getEnderChest();
showPlayer.openInventory(enderInventory);
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.
the class MountArmorStandAction method mount.
@Override
protected SpellResult mount(CastContext context) {
Mage mage = context.getMage();
Player player = mage.getPlayer();
if (player == null && mountWand) {
return SpellResult.PLAYER_REQUIRED;
}
item = null;
if (mountWand) {
Wand wand = context.getWand();
if (wand == null) {
return SpellResult.NO_TARGET;
}
wand.deactivate();
item = wand.getItem();
if (item == null || item.getType() == Material.AIR) {
return SpellResult.FAIL;
}
slotNumber = wand.getHeldSlot();
}
if (!mountTarget && !mountNewArmorStand(context)) {
return SpellResult.FAIL;
}
if (mountWand) {
player.getInventory().setItem(slotNumber, new ItemStack(Material.AIR));
}
SpellResult result = super.mount(context);
;
if (mount == null || !(mount instanceof ArmorStand)) {
result = SpellResult.FAIL;
}
return result;
}
use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.
the class EnchantWandAction method perform.
@Override
public SpellResult perform(CastContext context) {
Mage mage = context.getMage();
Wand wand = context.getWand();
Player player = mage.getPlayer();
if (player == null) {
return SpellResult.PLAYER_REQUIRED;
}
if (levels <= 0) {
return SpellResult.FAIL;
}
if (wand == null) {
context.showMessage("no_wand", "You must be holding a wand!");
return SpellResult.FAIL;
}
if (requiredPath != null || exactPath != null) {
WandUpgradePath path = wand.getPath();
if (path == null) {
context.showMessage(context.getMessage("no_upgrade", "You may not learn with that $wand.").replace("$wand", wand.getName()));
return SpellResult.FAIL;
}
if ((requiredPath != null && !path.hasPath(requiredPath)) || (exactPath != null && !exactPath.equals(path.getKey()))) {
WandUpgradePath requiresPath = com.elmakers.mine.bukkit.wand.WandUpgradePath.getPath(requiredPath);
if (requiresPath != null) {
context.showMessage(context.getMessage("no_path", "You may not learn with that $wand.").replace("$path", requiresPath.getName()));
} else {
context.getLogger().warning("Invalid path specified in EnchantWand action: " + requiredPath);
}
return SpellResult.FAIL;
}
}
if (requireItem != null) {
MageController controller = context.getController();
boolean foundItem = false;
ItemStack[] contents = player.getInventory().getContents();
for (int i = 0; i < contents.length; i++) {
ItemStack item = contents[i];
if (controller.itemsAreEqual(item, requireItem)) {
player.getInventory().setItem(i, null);
foundItem = true;
break;
}
}
if (!foundItem) {
context.showMessage("insufficient_resources", "You must have a $requires");
return SpellResult.INSUFFICIENT_RESOURCES;
}
}
int xpLevels = levels;
if (useXp) {
xpLevels = mage.getLevel();
}
int levelsUsed = wand.enchant(xpLevels, mage);
if (levelsUsed == 0) {
return SpellResult.FAIL;
}
if (useXp) {
mage.setLevel(Math.max(0, mage.getLevel() - levelsUsed));
}
return SpellResult.CAST;
}
Aggregations