use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class EffectPlayer method getWorkingMaterial.
@SuppressWarnings("deprecation")
protected MaterialAndData getWorkingMaterial() {
Location target = getTarget();
if (sampleTarget && target != null) {
return new MaterialAndData(target.getBlock().getType(), target.getBlock().getData());
}
if (material1 != null)
return material1;
MaterialAndData result = material;
Location origin = getOrigin();
if (result == null && target != null) {
result = new MaterialAndData(target.getBlock().getType(), target.getBlock().getData());
} else if (result == null && origin != null) {
result = new MaterialAndData(origin.getBlock().getType(), origin.getBlock().getData());
} else if (result == null) {
result = new MaterialAndData(Material.AIR);
}
return result;
}
use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class RaiseSpell method onCast.
@Override
public SpellResult onCast(ConfigurationSection parameters) {
Block targetBlock = getTargetBlock();
if (targetBlock == null) {
return SpellResult.NO_TARGET;
}
if (!isDestructible(targetBlock)) {
return SpellResult.NO_TARGET;
}
if (!hasBuildPermission(targetBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
BlockFace direction = BlockFace.UP;
int distance = parameters.getInt("distance", 5);
Block highestBlock = targetBlock;
while (distance > 0) {
highestBlock = highestBlock.getRelative(direction);
if (highestBlock.getType() != Material.AIR) {
return SpellResult.NO_TARGET;
}
distance--;
}
if (!hasBuildPermission(highestBlock)) {
return SpellResult.INSUFFICIENT_PERMISSION;
}
MaterialAndData blockState = new MaterialAndData(targetBlock);
registerForUndo(targetBlock);
registerForUndo(highestBlock);
targetBlock.setType(Material.AIR);
blockState.modify(highestBlock);
currentCast.registerBreakable(highestBlock, 1);
registerForUndo();
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class LevitateSpell method getEffectMaterial.
@Override
public com.elmakers.mine.bukkit.api.block.MaterialAndData getEffectMaterial() {
Block block = mage.getEntity().getLocation().getBlock();
block = block.getRelative(BlockFace.DOWN);
return new MaterialAndData(block);
}
use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class Messages method describeItem.
@Override
public String describeItem(ItemStack item) {
String displayName = null;
if (item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();
displayName = meta.getDisplayName();
if ((displayName == null || displayName.isEmpty()) && meta instanceof BookMeta) {
BookMeta book = (BookMeta) meta;
displayName = book.getTitle();
}
}
if (displayName == null || displayName.isEmpty()) {
MaterialAndData material = new MaterialAndData(item);
displayName = material.getName();
}
return displayName;
}
use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.
the class AbsorbAction method perform.
@SuppressWarnings("deprecation")
@Override
public SpellResult perform(CastContext context) {
Block target = context.getTargetBlock();
Mage mage = context.getMage();
Wand wand = context.getWand();
if (wand == null) {
return SpellResult.FAIL;
}
MageController controller = context.getController();
Material material = target.getType();
byte data = target.getData();
MaterialSet buildingMaterials = controller.getBuildingMaterialSet();
MaterialSet restrictedMaterials = mage.getRestrictedMaterialSet();
if (material == null || material == Material.AIR) {
return SpellResult.NO_TARGET;
}
if (!mage.getCommandSender().hasPermission("Magic.bypass_restricted") && (!buildingMaterials.testBlock(target) || restrictedMaterials.testBlock(target))) {
return SpellResult.NO_TARGET;
}
// Add to the wand
MaterialAndData mat = new MaterialAndData(material, data);
if (!wand.addBrush(mat.getKey())) {
// Still try and activate it
wand.setActiveBrush(mat.getKey());
return SpellResult.NO_TARGET;
}
// And activate it
wand.setActiveBrush(mat.getKey());
return SpellResult.CAST;
}
Aggregations