Search in sources :

Example 61 with Material

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;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) MaterialSet(com.elmakers.mine.bukkit.api.magic.MaterialSet) Block(org.bukkit.block.Block) Wand(com.elmakers.mine.bukkit.api.wand.Wand) Material(org.bukkit.Material)

Example 62 with Material

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;
}
Also used : Player(org.bukkit.entity.Player) MassiveException(com.massivecraft.massivecore.MassiveException) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack)

Example 63 with Material

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;
}
Also used : Action(org.bukkit.event.block.Action) Material(org.bukkit.Material)

Example 64 with Material

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;
}
Also used : ShapelessRecipe(org.bukkit.inventory.ShapelessRecipe) Material(org.bukkit.Material)

Example 65 with Material

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;
}
Also used : Potions(me.realized.tokenmanager.util.compat.Potions) EntityType(org.bukkit.entity.EntityType) SpawnEggs(me.realized.tokenmanager.util.compat.SpawnEggs) OptionalLong(java.util.OptionalLong) Material(org.bukkit.Material) PotionType(org.bukkit.potion.PotionType) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

Material (org.bukkit.Material)427 ItemStack (org.bukkit.inventory.ItemStack)99 Block (org.bukkit.block.Block)87 EventHandler (org.bukkit.event.EventHandler)51 ArrayList (java.util.ArrayList)46 Player (org.bukkit.entity.Player)44 Location (org.bukkit.Location)42 Vector (org.bukkit.util.Vector)27 EntityType (org.bukkit.entity.EntityType)26 GlowBlock (net.glowstone.block.GlowBlock)24 Test (org.junit.Test)24 BlockFace (org.bukkit.block.BlockFace)23 Entity (org.bukkit.entity.Entity)22 MaterialData (org.bukkit.material.MaterialData)22 World (org.bukkit.World)20 HashMap (java.util.HashMap)19 IOException (java.io.IOException)17 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)16 File (java.io.File)15 HashSet (java.util.HashSet)13