use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class ForceSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
effectColor = mage.getEffectColor();
if (effectColor == null) {
effectColor = Color.fromRGB(Integer.parseInt(parameters.getString("effect_color", "FF0000"), 16));
}
if (targetEntity != null) {
Location location = getLocation();
World targetWorld = targetEntity.getWorld();
if (!targetEntity.isValid() || targetEntity.isDead()) {
releaseTarget();
} else if (targetWorld == null || location == null || !targetWorld.getName().equals(location.getWorld().getName())) {
releaseTarget();
} else if (location.distanceSquared(targetEntity.getLocation()) > getMaxRangeSquared()) {
releaseTarget();
}
// Check for protected Mages
if (targetEntity != null && controller.isMage(targetEntity)) {
Mage targetMage = controller.getMage(targetEntity);
// Check for protected players (admins, generally...)
if (isSuperProtected(targetMage)) {
releaseTarget();
}
}
}
if (targetEntity == null) {
Target target = getTarget();
if (!target.hasEntity() || !(target.getEntity() instanceof LivingEntity)) {
return SpellResult.NO_TARGET;
}
releaseTarget();
LivingEntity checkTarget = (LivingEntity) target.getEntity();
// Check for protected Mages
if (checkTarget != null && controller.isMage(checkTarget)) {
Mage targetMage = controller.getMage(checkTarget);
// Check for protected players
if (isSuperProtected(targetMage)) {
return SpellResult.NO_TARGET;
}
}
selectTarget(checkTarget);
activate();
return SpellResult.TARGET_SELECTED;
}
double multiplier = parameters.getDouble("size", 1);
int magnitude = parameters.getInt("entity_force", DEFAULT_MAGNITUDE);
forceEntity(targetEntity, multiplier, magnitude);
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class Targeting method target.
public Target target(CastContext context, double range) {
if (source == null) {
source = context.getEyeLocation();
}
target = findTarget(context, range);
target = overrideTarget(context, target);
Mage mage = context.getMage();
if (mage != null && mage.getDebugLevel() > 15) {
Location targetLocation = target.getLocation();
String message = ChatColor.GREEN + "Targeted from " + ChatColor.GRAY + source.getBlockX() + ChatColor.DARK_GRAY + "," + ChatColor.GRAY + source.getBlockY() + ChatColor.DARK_GRAY + "," + ChatColor.GRAY + source.getBlockZ() + ChatColor.DARK_GREEN + " with range of " + ChatColor.GREEN + range + ChatColor.DARK_GREEN + ": " + ChatColor.GOLD + result;
Entity targetEntity = target.getEntity();
if (targetEntity != null) {
message = message + ChatColor.DARK_GREEN + " (" + ChatColor.YELLOW + targetEntity.getType() + ChatColor.DARK_GREEN + ")";
}
if (targetLocation != null) {
message = message + ChatColor.DARK_GREEN + " (" + ChatColor.LIGHT_PURPLE + targetLocation.getBlock().getType() + ChatColor.DARK_GREEN + ")";
message = message + ChatColor.DARK_GREEN + " at " + ChatColor.GRAY + targetLocation.getBlockX() + ChatColor.DARK_GRAY + "," + ChatColor.GRAY + targetLocation.getBlockY() + ChatColor.DARK_GRAY + "," + ChatColor.GRAY + targetLocation.getBlockZ();
}
mage.sendDebugMessage(message);
}
return target;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class ActionHandler method perform.
@Override
public SpellResult perform(CastContext context) {
Location targetLocation = context.getTargetLocation();
Entity targetEntity = context.getTargetEntity();
SpellResult result = SpellResult.NO_ACTION;
if (actions == null || actions.size() == 0) {
return result;
}
Mage mage = context.getMage();
boolean showDebug = mage.getDebugLevel() > 2;
if (showDebug) {
debugIndent += " ";
}
boolean isPending = false;
while (currentAction != null) {
ActionContext action = actions.get(currentAction);
if (!started) {
started = true;
action.getAction().reset(context);
}
if (action.getAction().requiresTargetEntity() && targetEntity == null) {
if (showDebug) {
mage.sendDebugMessage(ChatColor.GRAY + debugIndent + "Action " + ChatColor.GOLD + action.getAction().getClass().getSimpleName() + ChatColor.WHITE + ": " + ChatColor.GRAY + "Skipped, requires entity target", 17);
}
result = result.min(SpellResult.NO_TARGET);
advance(context);
continue;
}
if (action.getAction().requiresTarget() && targetLocation == null) {
if (showDebug) {
mage.sendDebugMessage(ChatColor.GRAY + debugIndent + "Action " + ChatColor.GOLD + action.getAction().getClass().getSimpleName() + ChatColor.WHITE + ": " + ChatColor.GRAY + "Skipped, requires target", 17);
}
result = result.min(SpellResult.NO_TARGET);
advance(context);
continue;
}
SpellResult actionResult = action.perform(context);
context.addWork(1);
if (actionResult == SpellResult.PENDING) {
isPending = true;
} else {
result = result.min(actionResult);
}
if (actionResult == SpellResult.STOP) {
if (showDebug) {
mage.sendDebugMessage(ChatColor.RED + debugIndent + "Action " + ChatColor.GOLD + action.getAction().getClass().getSimpleName() + ChatColor.WHITE + ": " + ChatColor.AQUA + actionResult.name().toLowerCase(), 15);
}
cancel(context);
}
if (actionResult.isStop()) {
break;
}
if (showDebug) {
mage.sendDebugMessage(ChatColor.WHITE + debugIndent + "Action " + ChatColor.GOLD + action.getAction().getClass().getSimpleName() + ChatColor.WHITE + ": " + ChatColor.AQUA + actionResult.name().toLowerCase(), 15);
}
advance(context);
if (context.getWorkAllowed() <= 0) {
isPending = true;
break;
}
}
if (showDebug) {
debugIndent = debugIndent.substring(0, debugIndent.length() - 2);
}
SpellResult currentResult = context.getResult();
context.addResult(result);
SpellResult contextResult = context.processHandlers();
if (contextResult == SpellResult.PENDING) {
isPending = true;
} else {
context.addResult(contextResult);
}
SpellResult newResult = context.getResult();
if (showDebug && newResult != currentResult) {
mage.sendDebugMessage(ChatColor.AQUA + debugIndent + "Result changed from " + ChatColor.DARK_AQUA + currentResult.name().toLowerCase() + ChatColor.WHITE + " to " + ChatColor.AQUA + newResult.name().toLowerCase(), 12);
}
return isPending ? SpellResult.PENDING : newResult;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class BaseShopAction method getCaster.
@Nonnull
protected CasterProperties getCaster(CastContext context) {
Mage mage = context.getMage();
Wand wand = mage.getActiveWand();
CasterProperties caster = wand;
if (caster == null) {
caster = mage.getActiveClass();
}
if (caster == null) {
caster = mage.getProperties();
}
return caster;
}
use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.
the class BaseShopAction method clicked.
@Override
public void clicked(InventoryClickEvent event) {
event.setCancelled(true);
ItemStack item = event.getCurrentItem();
Mage mage = context.getMage();
if (item == null || !InventoryUtils.hasMeta(item, "shop")) {
if (!autoClose) {
mage.deactivateGUI();
}
return;
}
int slotIndex = Integer.parseInt(InventoryUtils.getMetaString(item, "shop"));
MageController controller = context.getController();
Wand wand = mage.getActiveWand();
ShopItem shopItem = showingItems.get(slotIndex);
if (shopItem == null) {
return;
}
String unpurchasableMessage = InventoryUtils.getMetaString(shopItem.getItem(), "unpurchasable");
if (unpurchasableMessage != null && !unpurchasableMessage.isEmpty()) {
context.showMessage(unpurchasableMessage);
mage.deactivateGUI();
return;
}
boolean hasCosts = sell ? hasItem(controller, mage, shopItem.getItem()) : hasItemCosts(context, shopItem);
if (!hasCosts) {
String costString = context.getMessage("insufficient", getDefaultMessage(context, "insufficient"));
if (sell) {
costString = costString.replace("$cost", formatItemAmount(controller, item, shopItem.getItem().getAmount()));
} else {
costString = costString.replace("$cost", getItemCost(context, shopItem));
}
context.showMessage(costString);
} else {
String itemName = formatItemAmount(controller, item, item.getAmount());
if (InventoryUtils.hasMeta(item, "confirm")) {
String inventoryTitle = context.getMessage("confirm_title", getDefaultMessage(context, "confirm_title")).replace("$item", itemName);
Inventory confirmInventory = CompatibilityUtils.createInventory(null, 9, inventoryTitle);
InventoryUtils.removeMeta(item, "confirm");
for (int i = 0; i < 9; i++) {
if (i != 4) {
ItemStack filler = confirmFillMaterial.getItemStack(1);
ItemMeta meta = filler.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.DARK_GRAY + (i < 4 ? "-->" : "<--"));
filler.setItemMeta(meta);
}
confirmInventory.setItem(i, filler);
} else {
confirmInventory.setItem(i, item);
}
}
mage.deactivateGUI();
isActive = true;
mage.activateGUI(this, confirmInventory);
return;
}
String costString = context.getMessage("deducted", getDefaultMessage(context, "deducted"));
if (sell) {
costString = costString.replace("$cost", getItemCost(context, shopItem));
removeItems(controller, mage, item, shopItem.getItem().getAmount());
giveCosts(context, shopItem);
} else {
costString = costString.replace("$cost", getItemCost(context, shopItem));
item = shopItem.getItem();
if (requireWand) {
if (wand == null) {
context.showMessage("no_wand", getDefaultMessage(context, "no_wand"));
mage.deactivateGUI();
return;
}
if (applyToWand && !wand.addItem(item)) {
String inapplicable = context.getMessage("not_applicable", getDefaultMessage(context, "not_applicable")).replace("$item", itemName);
context.showMessage(inapplicable);
mage.deactivateGUI();
return;
}
}
CasterProperties caster = getCaster(context);
if (applyToCaster && !caster.addItem(item)) {
String inapplicable = context.getMessage("not_applicable", getDefaultMessage(context, "not_applicable")).replace("$item", itemName);
context.showMessage(inapplicable);
mage.deactivateGUI();
return;
}
if (castsSpells) {
Spell spell = null;
String spellKey = controller.getSpell(item);
String spellArgs = controller.getSpellArgs(item);
spell = mage.getSpell(spellKey);
if (spell != null && (spellArgs != null ? !spell.cast(StringUtils.split(spellArgs, ' ')) : !spell.cast())) {
context.showMessage("cast_fail", getDefaultMessage(context, "cast_fail"));
mage.deactivateGUI();
return;
}
}
if (!takeCosts(context, shopItem)) {
costString = context.getMessage("insufficient", getDefaultMessage(context, "insufficient"));
costString = costString.replace("$cost", getItemCost(context, shopItem));
context.showMessage(costString);
return;
}
if (!castsSpells && !applyToWand && !applyToCaster) {
ItemStack copy = InventoryUtils.getCopy(item);
if (filterBound && com.elmakers.mine.bukkit.wand.Wand.isBound(copy)) {
Wand bindWand = controller.getWand(copy);
mage.tryToOwn(bindWand);
}
if (showActiveIcons && controller.getAPI().isWand(copy)) {
Wand newWand = controller.getWand(copy);
com.elmakers.mine.bukkit.api.block.MaterialAndData inactiveIcon = newWand.getInactiveIcon();
if (inactiveIcon != null) {
inactiveIcon.applyToItem(copy);
}
}
Player player = mage.getPlayer();
if (putInHand) {
context.getController().giveItemToPlayer(player, copy);
} else {
PlayerInventory inventory = player.getInventory();
ItemStack inHand = inventory.getItemInMainHand();
Integer freeSlot = null;
if (InventoryUtils.isEmpty(inHand)) {
for (int i = 0; i < inventory.getSize() && freeSlot == null; i++) {
if (i != inventory.getHeldItemSlot() && InventoryUtils.isEmpty(inventory.getItem(i))) {
freeSlot = i;
}
}
}
if (freeSlot == null) {
context.getController().giveItemToPlayer(player, copy);
} else {
inventory.setItem(freeSlot, copy);
}
}
}
}
costString = costString.replace("$item", itemName);
context.showMessage(costString);
if (!sell && wand != null && autoUpgrade) {
if (upgradeLevels <= 0) {
com.elmakers.mine.bukkit.api.wand.WandUpgradePath path = wand.getPath();
WandUpgradePath nextPath = path != null ? path.getUpgrade() : null;
if (nextPath != null && path.checkUpgradeRequirements(wand, null) && !path.canEnchant(wand)) {
path.upgrade(wand, mage);
}
} else {
wand.enchant(upgradeLevels, mage, false);
}
}
finalResult = SpellResult.CAST;
onPurchase(context, item);
}
if (autoClose) {
mage.deactivateGUI();
} else {
// update title
mage.continueGUI(this, getInventory(context));
}
}
Aggregations