use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class BaseShopAction method checkContext.
public SpellResult checkContext(CastContext context) {
Mage mage = context.getMage();
MageController controller = mage.getController();
Player player = mage.getPlayer();
if (player == null) {
return SpellResult.PLAYER_REQUIRED;
}
if (permissionNode != null && !player.hasPermission(permissionNode)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
if (!requireWand) {
return SpellResult.CAST;
}
Wand wand = mage.getActiveWand();
if (wand == null) {
context.showMessage("no_wand", getDefaultMessage(context, "no_wand"));
return SpellResult.FAIL;
}
WandUpgradePath path = wand.getPath();
if (requiredTemplate != null) {
String template = wand.getTemplateKey();
if (template == null || !template.equals(requiredTemplate)) {
context.showMessage(context.getMessage("no_template", getDefaultMessage(context, "no_template")).replace("$wand", wand.getName()));
return SpellResult.FAIL;
}
}
// Check path requirements
if (requiredPath != null || exactPath != null) {
if (path == null) {
context.showMessage(context.getMessage("no_path", getDefaultMessage(context, "no_path")).replace("$wand", wand.getName()));
return SpellResult.FAIL;
}
if (requiredPath != null && !path.hasPath(requiredPath)) {
WandUpgradePath requiresPath = controller.getPath(requiredPath);
if (requiresPath != null) {
context.showMessage(context.getMessage("no_required_path", getDefaultMessage(context, "no_required_path")).replace("$path", requiresPath.getName()));
} else {
context.getLogger().warning("Invalid path specified in Shop action: " + requiredPath);
}
return SpellResult.FAIL;
}
if (exactPath != null && !exactPath.equals(path.getKey())) {
WandUpgradePath requiresPath = controller.getPath(exactPath);
if (requiresPath != null) {
context.showMessage(context.getMessage("no_path_exact", getDefaultMessage(context, "no_path_exact")).replace("$path", requiresPath.getName()));
} else {
context.getLogger().warning("Invalid path specified in Shop action: " + exactPath);
}
return SpellResult.FAIL;
}
if (requiresCompletedPath != null) {
if (path.canEnchant(wand)) {
context.showMessage(context.getMessage("no_path_end", getDefaultMessage(context, "no_path_end")).replace("$path", path.getName()));
return SpellResult.FAIL;
}
}
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class BaseShopAction method prepare.
@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
super.prepare(context, parameters);
permissionNode = parameters.getString("permission", null);
sell = parameters.getBoolean("sell", false);
showConfirmation = parameters.getBoolean("confirm", true);
confirmFillMaterial = ConfigurationUtils.getMaterialAndData(parameters, "confirm_filler", new MaterialAndData(Material.AIR));
requiredPath = parameters.getString("path", null);
exactPath = parameters.getString("path_exact", null);
requiresCompletedPath = parameters.getString("path_end", null);
requiredTemplate = parameters.getString("require_template", null);
autoUpgrade = parameters.getBoolean("auto_upgrade", false);
upgradeLevels = parameters.getInt("upgrade_levels", 0);
requireWand = parameters.getBoolean("require_wand", false);
autoClose = parameters.getBoolean("auto_close", true);
costScale = parameters.getDouble("scale", 1);
filterBound = parameters.getBoolean("filter_bound", false);
putInHand = parameters.getBoolean("put_in_hand", true);
String worthItemKey = parameters.getString("worth_item", "");
if (!worthItemKey.isEmpty()) {
worthItem = context.getController().createItem(worthItemKey);
} else {
worthItem = null;
}
if (!autoClose) {
showConfirmation = false;
}
if (requiresCompletedPath != null) {
requiredPath = requiresCompletedPath;
exactPath = requiresCompletedPath;
}
if (requiredPath != null || exactPath != null || requiredTemplate != null) {
requireWand = true;
}
applyToWand = parameters.getBoolean("apply_to_wand", requireWand);
MageController controller = context.getController();
isXP = parameters.getBoolean("use_xp", false);
isItems = parameters.getBoolean("use_items", false) && getWorthItem(controller) != null;
isSkillPoints = parameters.getBoolean("use_sp", false) && controller.isSPEnabled();
if (!isSkillPoints && !isXP && !isItems && !VaultController.hasEconomy()) {
if (getWorthItem(controller) != null) {
isItems = true;
} else {
isSkillPoints = true;
}
}
finalResult = null;
isActive = false;
}
use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class BaseShopAction method hasItemCosts.
protected boolean hasItemCosts(CastContext context, ShopItem shopItem) {
Mage mage = context.getMage();
MageController controller = context.getController();
double worth = shopItem.getWorth();
boolean hasCosts = true;
if (worth > 0) {
if (isXP) {
worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthXP());
hasCosts = mage.getExperience() >= (int) worth;
} else if (isItems) {
worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthItemAmount());
int hasAmount = getItemAmount(controller, mage);
hasCosts = hasAmount >= worth;
} else if (isSkillPoints) {
worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthSkillPoints());
hasCosts = mage.getSkillPoints() >= Math.ceil(worth);
} else {
worth = Math.ceil(costScale * worth * controller.getWorthBase());
hasCosts = VaultController.getInstance().has(mage.getPlayer(), worth);
}
}
return hasCosts;
}
use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class BaseShopAction method getBalanceDescription.
protected String getBalanceDescription(CastContext context) {
Mage mage = context.getMage();
MageController controller = context.getController();
Messages messages = controller.getMessages();
String description = "";
if (isXP) {
String xpAmount = Integer.toString(mage.getExperience());
description = messages.get("costs.xp_amount").replace("$amount", xpAmount);
} else if (isItems) {
int itemAmount = getItemAmount(controller, mage);
description = formatItemAmount(controller, itemAmount);
} else if (isSkillPoints) {
String spAmount = Integer.toString(mage.getSkillPoints());
description = messages.get("costs.sp_amount").replace("$amount", spAmount);
} else {
double balance = VaultController.getInstance().getBalance(mage.getPlayer());
description = VaultController.getInstance().format(balance);
}
return description;
}
use of com.elmakers.mine.bukkit.api.magic.MageController in project MagicPlugin by elBukkit.
the class CancelAction method perform.
@Override
public SpellResult perform(CastContext context) {
Entity targetEntity = context.getTargetEntity();
MageController controller = context.getController();
if (targetEntity == null || !controller.isMage(targetEntity)) {
return SpellResult.NO_TARGET;
}
SpellResult result = SpellResult.NO_TARGET;
Mage targetMage = controller.getMage(targetEntity);
if (spellKeys == null) {
Batch batch = targetMage.cancelPending(force);
if (batch != null) {
result = SpellResult.CAST;
undoListName = batch.getName();
}
} else {
for (String spellKey : spellKeys) {
Batch batch = targetMage.cancelPending(spellKey, force);
if (batch != null) {
result = SpellResult.CAST;
undoListName = batch.getName();
}
}
}
return result;
}
Aggregations