use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class HatSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Player player = mage.getPlayer();
if (player == null) {
return SpellResult.PLAYER_REQUIRED;
}
Block target = getTargetBlock();
if (target == null) {
return SpellResult.NO_TARGET;
}
MaterialAndData material = new MaterialAndData(target);
if (material.getMaterial() == Material.AIR) {
return SpellResult.NO_TARGET;
}
ItemStack hatItem = material.getItemStack(1);
ItemStack itemStack = player.getInventory().getHelmet();
ItemMeta meta = hatItem.getItemMeta();
meta.setDisplayName(getMessage("hat_name").replace("$material", material.getName()));
List<String> lore = new ArrayList<>();
lore.add(getMessage("hat_lore"));
meta.setLore(lore);
hatItem.setItemMeta(meta);
hatItem = InventoryUtils.makeReal(hatItem);
NMSUtils.makeTemporary(hatItem, getMessage("removed").replace("$material", material.getName()));
player.getInventory().setHelmet(hatItem);
if (itemStack != null && itemStack.getType() != Material.AIR && !NMSUtils.isTemporary(itemStack)) {
player.getWorld().dropItemNaturally(player.getLocation(), itemStack);
}
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class SelectorAction method prepare.
@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
super.prepare(context, parameters);
this.context = context;
defaultConfiguration = new SelectorConfiguration(parameters);
confirmFillMaterial = ConfigurationUtils.getMaterialAndData(parameters, "confirm_filler", new MaterialAndData(Material.AIR));
autoClose = parameters.getBoolean("auto_close", true);
costScale = parameters.getDouble("scale", 1);
title = parameters.getString("title");
confirmTitle = parameters.getString("confirm_title");
confirmUnlockTitle = parameters.getString("unlock_confirm_title");
finalResult = null;
isActive = false;
numSlots = 0;
showingItems = new HashMap<>();
has = 0;
Collection<ConfigurationSection> optionConfigs = ConfigurationUtils.getNodeList(parameters, "options");
if (optionConfigs != null) {
// Gather list of selector options first, to compute limits
List<SelectorOption> options = new ArrayList<>();
for (ConfigurationSection option : optionConfigs) {
SelectorOption newOption = new SelectorOption(defaultConfiguration, option, context, this);
if (newOption.hasLimit() && newOption.has(context)) {
has++;
}
options.add(newOption);
}
for (SelectorOption option : options) {
if (option.isUnavailable() && !option.showIfUnavailable()) {
continue;
}
Integer targetSlot = option.getSlot();
int slot = targetSlot == null ? numSlots : targetSlot;
showingItems.put(slot, option);
numSlots = Math.max(slot + 1, numSlots);
}
}
}
use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class RecallAction method getIcon.
@Nullable
protected MaterialAndData getIcon(CastContext context, ConfigurationSection parameters, String key) {
String iconKey = parameters.getString(key);
if (iconKey == null || iconKey.isEmpty())
return null;
MaterialAndData material = ConfigurationUtils.getMaterialAndData(parameters, key);
if (material == null || !material.isValid() || material.getMaterial() == null) {
context.getLogger().warning("Invalid material specified for " + context.getSpell().getKey() + " " + key + ": " + iconKey);
return null;
}
return material;
}
use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class RecallAction method showMarkerConfirm.
protected void showMarkerConfirm(CastContext context) {
options.clear();
String inventoryTitle = context.getMessage("move_marker_title", "Move Marker");
Inventory displayInventory = CompatibilityUtils.createInventory(null, 9, inventoryTitle);
MaterialAndData iconType = getIcon(context, parameters, "icon_move_marker");
ItemStack markerItem = iconType.getItemStack(1);
ItemMeta meta = markerItem.getItemMeta();
meta.setDisplayName(context.getMessage("title_move_marker"));
String description = context.getMessage("description_move_marker");
if (description != null && description.length() > 0) {
List<String> lore = new ArrayList<>();
lore.add(description);
meta.setLore(lore);
}
markerItem.setItemMeta(meta);
markerItem = InventoryUtils.makeReal(markerItem);
InventoryUtils.hideFlags(markerItem, (byte) 63);
InventoryUtils.setMeta(markerItem, "move_marker", "true");
displayInventory.setItem(4, markerItem);
context.getMage().activateGUI(this, displayInventory);
}
use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class RecurseAction method step.
@Override
public SpellResult step(CastContext context) {
StackEntry current = stack.peek();
Block block = current.block;
int faceIndex = current.face++;
if (faceIndex >= 0) {
block = directions.get(faceIndex).getRelative(block);
}
long id = BlockData.getBlockId(block);
if (touched.contains(id)) {
return SpellResult.NO_TARGET;
}
if (!context.isDestructible(block)) {
return SpellResult.NO_TARGET;
}
if (replaceable != null && !replaceable.contains(new MaterialAndData(block))) {
return SpellResult.NO_TARGET;
}
if (faceIndex >= 0 && stack.size() <= recursionDepth) {
if (checker) {
BlockFace direction = directions.get(faceIndex);
block = direction.getRelative(block);
}
stack.push(new StackEntry(block));
}
touched.add(id);
actionContext.setTargetLocation(block.getLocation());
actionContext.playEffects("recurse");
return startActions();
}
Aggregations