use of com.elmakers.mine.bukkit.api.wand.Wand 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.wand.Wand in project MagicPlugin by elBukkit.
the class BrushSelectAction method clicked.
@Override
public void clicked(InventoryClickEvent event) {
event.setCancelled(true);
InventoryAction action = event.getAction();
if (context != null) {
Mage mage = context.getMage();
if (action == InventoryAction.NOTHING) {
int direction = event.getClick() == ClickType.LEFT ? 1 : -1;
page = page + direction;
mage.deactivateGUI();
perform(context);
event.setCancelled(true);
return;
}
ItemStack item = event.getCurrentItem();
String set = InventoryUtils.getMetaString(item, "brush_set", null);
if (set != null) {
if (set.equals("schematics")) {
String inventoryTitle = context.getMessage("schematics_title", "Schematics");
int invSize = ((schematics.size() + 9) / 9) * 9;
Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
for (ItemStack schematicItem : schematics) {
displayInventory.addItem(schematicItem);
}
mage.deactivateGUI();
mage.activateGUI(this, displayInventory);
return;
} else if (set.equals("variants")) {
MaterialAndData baseMaterial = new MaterialAndData(item);
String baseName = baseMaterial.getBaseName();
String inventoryTitle = context.getMessage("variants_title", "$variant Types").replace("$variant", baseName);
String brushKey = com.elmakers.mine.bukkit.wand.Wand.getBrush(item);
MaterialAndData brushMaterial = new MaterialAndData(brushKey);
List<ItemStack> variantList = variants.get(brushMaterial.getMaterial());
int invSize = ((variantList.size() + 9) / 9) * 9;
Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
for (ItemStack variantItem : variantList) {
displayInventory.addItem(variantItem);
}
mage.deactivateGUI();
mage.activateGUI(this, displayInventory);
return;
}
}
mage.deactivateGUI();
Wand wand = context.getWand();
if (wand != null && com.elmakers.mine.bukkit.wand.Wand.isBrush(item)) {
String brushKey = com.elmakers.mine.bukkit.wand.Wand.getBrush(item);
wand.setActiveBrush(brushKey);
}
}
}
use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.
the class AddSpellAction 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 (permissionNode != null && !player.hasPermission(permissionNode)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
if (wand == null || spellKey == null || spellKey.isEmpty()) {
context.showMessage("no_wand", "You must be holding a wand!");
return SpellResult.FAIL;
}
if (wand.hasSpell(spellKey)) {
return SpellResult.NO_TARGET;
}
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;
}
MageController controller = context.getController();
if (requiredPath != null && !path.hasPath(requiredPath)) {
WandUpgradePath requiresPath = controller.getPath(requiredPath);
if (requiresPath != null) {
context.showMessage(context.getMessage("no_required_path", "You must be at least $path!").replace("$path", requiresPath.getName()));
} else {
context.getLogger().warning("Invalid path specified in AddSpell 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", "You must be at $path!").replace("$path", requiresPath.getName()));
} else {
context.getLogger().warning("Invalid path specified in AddSpell action: " + exactPath);
}
return SpellResult.FAIL;
}
if (requiresCompletedPath != null) {
WandUpgradePath pathUpgrade = path.getUpgrade();
if (pathUpgrade == null) {
context.showMessage(context.getMessage("no_upgrade", "There is nothing more for you here.").replace("$wand", wand.getName()));
return SpellResult.FAIL;
}
if (path.canEnchant(wand)) {
context.showMessage(context.getMessage("no_path_end", "You must be ready to advance to $path!").replace("$path", pathUpgrade.getName()));
return SpellResult.FAIL;
}
}
}
if (!wand.addSpell(spellKey)) {
return SpellResult.NO_TARGET;
}
wand.setActiveSpell(spellKey);
if (autoUpgrade) {
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);
}
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.
the class MagicRecipe method load.
public boolean load(ConfigurationSection configuration) {
outputKey = configuration.getString("output");
if (outputKey == null) {
return false;
}
substitue = ConfigurationUtils.getMaterial(configuration, "substitue", null);
disableDefaultRecipe = configuration.getBoolean("disable_default", false);
if (disableDefaultRecipe) {
controller.getLogger().warning("Recipe " + key + " has disable_default: true, ignoring because trying to remove a recipe now throws an error.");
disableDefaultRecipe = false;
}
outputItemType = configuration.getString("output_type", "item");
ItemStack item = null;
if (outputItemType.equalsIgnoreCase("wand")) {
Wand wand = !outputKey.isEmpty() ? controller.createWand(outputKey) : null;
if (wand != null) {
item = wand.getItem();
} else {
controller.getLogger().warning("Unable to load recipe output wand: " + outputKey);
}
} else if (outputItemType.equalsIgnoreCase("spell")) {
item = controller.createSpellItem(outputKey);
} else if (outputItemType.equalsIgnoreCase("brush")) {
item = controller.createBrushItem(outputKey);
} else if (outputItemType.equalsIgnoreCase("item")) {
item = controller.createItem(outputKey);
} else {
return false;
}
if (item != null) {
outputType = item.getType();
ShapedRecipe shaped = new ShapedRecipe(item);
List<String> rows = new ArrayList<>();
for (int i = 1; i <= 3; i++) {
String recipeRow = configuration.getString("row_" + i, "");
if (recipeRow.length() > 0) {
rows.add(recipeRow);
}
}
if (rows.size() > 0) {
shaped = shaped.shape(rows.toArray(new String[0]));
ConfigurationSection materials = configuration.getConfigurationSection("ingredients");
if (materials == null) {
materials = configuration.getConfigurationSection("materials");
}
Set<String> keys = materials.getKeys(false);
for (String key : keys) {
String materialKey = materials.getString(key);
ItemData ingredient = controller.getOrCreateItem(materialKey);
MaterialData material = ingredient == null ? null : ingredient.getMaterialData();
if (material == null) {
outputType = null;
controller.getLogger().warning("Unable to load recipe ingredient " + materialKey);
return false;
}
shaped.setIngredient(key.charAt(0), material);
ingredients.put(key.charAt(0), ingredient);
}
recipe = shaped;
}
}
return outputType != null;
}
use of com.elmakers.mine.bukkit.api.wand.Wand in project MagicPlugin by elBukkit.
the class PlaceholderAPIManager method onPlaceholderRequest.
@Override
public String onPlaceholderRequest(Player player, String placeholder) {
Mage mage = controller.getMage(player);
MageClass activeClass = mage.getActiveClass();
Wand wand = mage.getActiveWand();
Spell spell = wand == null ? null : wand.getActiveSpell();
if (spell == null) {
ItemStack item = player.getInventory().getItemInMainHand();
String spellKey = controller.getSpell(item);
if (spellKey != null) {
spell = mage.getSpell(spellKey);
}
}
if (spell == null) {
ItemStack item = player.getInventory().getItemInOffHand();
String spellKey = controller.getSpell(item);
if (spellKey != null) {
spell = mage.getSpell(spellKey);
}
}
CasterProperties casterProperties = mage.getActiveProperties();
switch(placeholder) {
case "path":
ProgressionPath path = casterProperties.getPath();
return path == null ? "" : path.getName();
case "class":
return activeClass == null ? "" : activeClass.getName();
case "wand":
return wand == null ? "" : wand.getName();
case "spell":
return spell == null ? "" : spell.getName();
}
return "";
}
Aggregations