use of org.bukkit.Material 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;
}
use of org.bukkit.Material in project MassiveCore by MassiveCraft.
the class TypeItemStack method read.
@Override
public ItemStack read(String arg, CommandSender sender) throws MassiveException {
if (!(sender instanceof Player))
throw new MassiveException().addMsg("<b>You must be a player to hold an item in your hand.");
Player player = (Player) sender;
ItemStack ret = InventoryUtil.getWeapon(player);
if (InventoryUtil.isNothing(ret))
throw new MassiveException().addMsg("<b>You must hold an item in your hand.");
Material material = ret.getType();
if (!this.materialsAllowed.contains(material))
throw new MassiveException().addMsg("<h>%s <b>is not allowed.", Txt.getNicedEnum(material));
ret = new ItemStack(ret);
return ret;
}
use of org.bukkit.Material in project MassiveCore by MassiveCraft.
the class MUtil method getEatenMaterial.
// -------------------------------------------- //
// EVENT DERP
// -------------------------------------------- //
// Note that this one is unstable and invalid. It cannot catch all cases.
public static Material getEatenMaterial(PlayerInteractEvent event) {
Action action = event.getAction();
if (action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK)
return null;
Material ret = null;
if (action == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.CAKE_BLOCK) {
ret = Material.CAKE_BLOCK;
} else if (FOOD_MATERIALS.contains(event.getMaterial())) {
ret = event.getMaterial();
}
return ret;
}
use of org.bukkit.Material in project MassiveCore by MassiveCraft.
the class RecipeUtil method createShapeless.
// ------------------------------------------- //
// SHAPELESS
// -------------------------------------------- //
@SuppressWarnings("deprecation")
public static ShapelessRecipe createShapeless(ItemStack result, Object... objects) {
ShapelessRecipe recipe = new ShapelessRecipe(NamespacedKey.randomKey(), result);
int quantity = 1;
int data = 0;
Material material = null;
for (Object object : objects) {
if (object instanceof Number) {
if (object instanceof Integer) {
quantity = ((Integer) object).intValue();
} else {
data = ((Number) object).intValue();
}
} else if (object instanceof Material) {
material = (Material) object;
recipe.addIngredient(quantity, material, data);
quantity = 1;
data = 0;
material = null;
} else {
throw new IllegalArgumentException(String.valueOf(object));
}
}
return recipe;
}
use of org.bukkit.Material in project TokenManager by RealizedMC.
the class ItemUtil method loadFromString.
public static ItemStack loadFromString(final String line) {
if (line == null || line.isEmpty()) {
throw new IllegalArgumentException("Line is empty or null!");
}
final String[] args = line.split(" +");
final String[] materialData = args[0].split(":");
final Material material = Material.matchMaterial(materialData[0]);
if (material == null) {
throw new IllegalArgumentException("'" + args[0] + "' is not a valid material.");
}
ItemStack result = new ItemStack(material, 1);
if (materialData.length > 1) {
// Handle potions and spawn eggs switching to NBT in 1.9+
if (!ItemUtil.isPre1_9()) {
if (material.name().contains("POTION")) {
final String[] values = materialData[1].split("-");
final PotionType type;
if ((type = EnumUtil.getByName(values[0], PotionType.class)) == null) {
throw new IllegalArgumentException("'" + values[0] + "' is not a valid PotionType. Available: " + EnumUtil.getNames(PotionType.class));
}
result = new Potions(type, Arrays.asList(values)).toItemStack();
} else if (material == Material.MONSTER_EGG) {
final EntityType type;
if ((type = EnumUtil.getByName(materialData[1], EntityType.class)) == null) {
throw new IllegalArgumentException("'" + materialData[0] + "' is not a valid EntityType. Available: " + EnumUtil.getNames(EntityType.class));
}
result = new SpawnEggs(type).toItemStack();
}
}
final OptionalLong value;
if ((value = NumberUtil.parseLong(materialData[1])).isPresent()) {
result.setDurability((short) value.getAsLong());
}
}
if (args.length < 2) {
return result;
}
result.setAmount(Integer.parseInt(args[1]));
if (args.length > 2) {
for (int i = 2; i < args.length; i++) {
final String argument = args[i];
final String[] pair = argument.split(":", 2);
if (pair.length < 2) {
continue;
}
applyMeta(result, pair[0], pair[1]);
}
}
return result;
}
Aggregations