use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class MagicController method createItem.
@Nullable
@Override
public ItemStack createItem(String magicItemKey, boolean brief) {
ItemStack itemStack = null;
if (magicItemKey == null) {
return null;
}
// Check for amounts
int amount = 1;
if (magicItemKey.contains("@")) {
String[] pieces = StringUtils.split(magicItemKey, '@');
magicItemKey = pieces[0];
try {
amount = Integer.parseInt(pieces[1]);
} catch (Exception ignored) {
}
}
// Handle : or | as delimiter
magicItemKey = magicItemKey.replace("|", ":");
try {
if (magicItemKey.contains("skull:") || magicItemKey.contains("skull_item:")) {
magicItemKey = magicItemKey.replace("skull:", "skull_item:");
MaterialAndData skullData = new MaterialAndData(magicItemKey);
itemStack = skullData.getItemStack(amount);
} else if (magicItemKey.contains("book:")) {
String bookCategory = magicItemKey.substring(5);
com.elmakers.mine.bukkit.api.spell.SpellCategory category = null;
if (!bookCategory.isEmpty() && !bookCategory.equalsIgnoreCase("all")) {
category = getCategory(bookCategory);
if (category == null) {
return null;
}
}
itemStack = getSpellBook(category, amount);
} else if (skillPointItemsEnabled && magicItemKey.contains("sp:")) {
String spAmount = magicItemKey.substring(3);
itemStack = InventoryUtils.getURLSkull(skillPointIcon);
ItemMeta meta = itemStack.getItemMeta();
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', messages.get("sp.name")).replace("$amount", spAmount));
String spDescription = messages.get("sp.description");
if (spDescription.length() > 0) {
List<String> lore = new ArrayList<>();
lore.add(ChatColor.translateAlternateColorCodes('&', spDescription));
meta.setLore(lore);
}
itemStack.setItemMeta(meta);
InventoryUtils.setMeta(itemStack, "sp", spAmount);
} else if (magicItemKey.contains("spell:")) {
String spellKey = magicItemKey.substring(6);
itemStack = createSpellItem(spellKey, brief);
} else if (magicItemKey.contains("wand:")) {
String wandKey = magicItemKey.substring(5);
com.elmakers.mine.bukkit.api.wand.Wand wand = createWand(wandKey);
if (wand != null) {
itemStack = wand.getItem();
}
} else if (magicItemKey.contains("upgrade:")) {
String wandKey = magicItemKey.substring(8);
com.elmakers.mine.bukkit.api.wand.Wand wand = createWand(wandKey);
if (wand != null) {
wand.makeUpgrade();
itemStack = wand.getItem();
}
} else if (magicItemKey.contains("brush:")) {
String brushKey = magicItemKey.substring(6);
itemStack = createBrushItem(brushKey);
} else if (magicItemKey.contains("item:")) {
String itemKey = magicItemKey.substring(5);
itemStack = createGenericItem(itemKey);
} else if (items != null) {
ItemData itemData = items.get(magicItemKey);
if (itemData != null) {
return itemData.getItemStack(amount);
}
MaterialAndData item = new MaterialAndData(magicItemKey);
if (item.isValid()) {
return item.getItemStack(amount);
}
com.elmakers.mine.bukkit.api.wand.Wand wand = createWand(magicItemKey);
if (wand != null) {
ItemStack wandItem = wand.getItem();
if (wandItem != null) {
wandItem.setAmount(amount);
}
return wandItem;
}
// Spells may be using the | delimiter for levels
// I am regretting overloading this delimiter!
String spellKey = magicItemKey.replace(":", "|");
itemStack = createSpellItem(spellKey, brief);
if (itemStack != null) {
itemStack.setAmount(amount);
return itemStack;
}
itemStack = createBrushItem(magicItemKey);
if (itemStack != null) {
itemStack.setAmount(amount);
}
}
} catch (Exception ex) {
getLogger().log(Level.WARNING, "Error creating item: " + magicItemKey, ex);
}
return itemStack;
}
use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class MagicController method createGenericItem.
@Nullable
@Override
public ItemStack createGenericItem(String key) {
ConfigurationSection template = getWandTemplateConfiguration(key);
if (template == null || !template.contains("icon")) {
return null;
}
MaterialAndData icon = ConfigurationUtils.toMaterialAndData(template.getString("icon"));
ItemStack item = icon.getItemStack(1);
ItemMeta meta = item.getItemMeta();
if (template.contains("name")) {
meta.setDisplayName(template.getString("name"));
} else {
String name = messages.get("wands." + key + ".name");
if (name != null && !name.isEmpty()) {
meta.setDisplayName(name);
}
}
List<String> lore = new ArrayList<>();
if (template.contains("description")) {
lore.add(template.getString("description"));
} else {
String description = messages.get("wands." + key + ".description");
if (description != null && !description.isEmpty()) {
lore.add(description);
}
}
meta.setLore(lore);
item.setItemMeta(meta);
return item;
}
use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class RecallAction method getWarp.
@Nullable
protected Waypoint getWarp(String warpKey) {
if (warps == null)
return getUnknownWarp(warpKey);
ConfigurationSection config = warps.get(warpKey);
if (config == null)
return getUnknownWarp(warpKey);
MageController controller = context.getController();
String warpName = config.getString("name", warpKey);
String castMessage = context.getMessage("cast_warp").replace("$name", warpName);
String failMessage = context.getMessage("no_target_warp").replace("$name", warpName);
String title = context.getMessage("title_warp").replace("$name", warpName);
String description = config.getString("description");
String iconURL = config.getString("icon_url");
MaterialAndData icon = getIcon(context, config, "icon");
Location warpLocation = controller.getWarp(warpKey);
if (warpLocation == null || warpLocation.getWorld() == null) {
String serverName = config.getString("server", null);
if (serverName != null) {
return new Waypoint(RecallType.WARP, warpKey, serverName, title, castMessage, failMessage, description, icon, iconURL);
}
return null;
}
return new Waypoint(RecallType.WARP, warpLocation, title, castMessage, failMessage, description, icon, iconURL);
}
use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class RecallAction method getCommand.
@Nullable
protected Waypoint getCommand(CastContext context, String commandKey) {
if (commands == null)
return null;
ConfigurationSection config = commands.get(commandKey);
if (config == null)
return null;
String commandName = config.getString("name", commandKey);
String castMessage = context.getMessage("cast_warp").replace("$name", commandName);
String failMessage = context.getMessage("no_target_warp").replace("$name", commandName);
String title = context.getMessage("title_warp").replace("$name", commandName);
String description = config.getString("description");
String iconURL = config.getString("icon_url");
String command = context.parameterize(config.getString("command"));
boolean op = config.getBoolean("op", false);
boolean console = config.getBoolean("console", false);
MaterialAndData icon = getIcon(context, config, "icon");
return new Waypoint(RecallType.COMMAND, command, op, console, title, castMessage, failMessage, description, icon, iconURL);
}
use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class RecurseAction method prepare.
@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
super.prepare(context, parameters);
checker = parameters.getBoolean("checkered", false);
replace = parameters.getBoolean("replace", false);
recursionDepth = parameters.getInt("size", 32);
recursionDepth = parameters.getInt("depth", recursionDepth);
if (replace) {
if (replaceable == null) {
replaceable = new HashSet<>();
}
Block targetBlock = context.getTargetBlock();
replaceable.clear();
if (targetBlock == null) {
return;
}
MaterialAndData targetMaterialAndData = new MaterialAndData(targetBlock);
if (targetMaterialAndData.isValid()) {
replaceable.add(targetMaterialAndData);
}
Material targetMaterial = targetBlock.getType();
if (parameters.getBoolean("auto_water", true)) {
if (targetMaterial == Material.STATIONARY_WATER || targetMaterial == Material.WATER) {
for (byte i = 0; i < 15; i++) {
replaceable.add(new MaterialAndData(Material.STATIONARY_WATER, i));
replaceable.add(new MaterialAndData(Material.WATER, i));
}
}
}
if (parameters.getBoolean("auto_lava", true)) {
if (targetMaterial == Material.STATIONARY_LAVA || targetMaterial == Material.LAVA) {
for (byte i = 0; i < 15; i++) {
replaceable.add(new MaterialAndData(Material.STATIONARY_LAVA, i));
replaceable.add(new MaterialAndData(Material.LAVA, i));
}
}
}
if (parameters.getBoolean("auto_snow", true)) {
if (targetMaterial == Material.SNOW) {
for (byte i = 0; i < 15; i++) {
replaceable.add(new MaterialAndData(Material.SNOW, i));
}
}
}
} else {
replaceable = null;
}
}
Aggregations