Search in sources :

Example 6 with MaterialSet

use of com.elmakers.mine.bukkit.api.magic.MaterialSet in project MagicPlugin by elBukkit.

the class SimpleMaterialSetManager method createMaterialSetFromString.

private MaterialSet createMaterialSetFromString(String materialSet) {
    if (materialSet.equals("*")) {
        return MaterialSets.wildcard();
    }
    boolean negate;
    String materialString;
    if (materialSet.startsWith("!")) {
        materialString = materialSet.substring(1);
        negate = true;
    } else {
        materialString = materialSet;
        negate = false;
    }
    String[] names = StringUtils.split(materialString, ',');
    MaterialSet created = createMaterialSetFromStringList(Arrays.asList(names), true);
    return negate ? created.not() : created;
}
Also used : MaterialSet(com.elmakers.mine.bukkit.api.magic.MaterialSet)

Example 7 with MaterialSet

use of com.elmakers.mine.bukkit.api.magic.MaterialSet 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 8 with MaterialSet

use of com.elmakers.mine.bukkit.api.magic.MaterialSet in project MagicPlugin by elBukkit.

the class Wand method makeEnchantable.

public void makeEnchantable(boolean enchantable) {
    if (EnchantableWandMaterial == null)
        return;
    if (!enchantable) {
        item.setType(icon.getMaterial());
        item.setDurability(icon.getData());
    } else {
        MaterialSet enchantableMaterials = controller.getMaterialSetManager().getMaterialSetEmpty("enchantable");
        if (!enchantableMaterials.testItem(item)) {
            item.setType(EnchantableWandMaterial);
            item.setDurability((short) 0);
        }
    }
    updateName();
}
Also used : MaterialSet(com.elmakers.mine.bukkit.api.magic.MaterialSet)

Example 9 with MaterialSet

use of com.elmakers.mine.bukkit.api.magic.MaterialSet in project MagicPlugin by elBukkit.

the class MaterialSetsTest method testFromConfig.

@SuppressWarnings("deprecation")
@Test
public void testFromConfig() {
    MaterialAndData value = ConfigurationUtils.toMaterialAndData("stone|2");
    MaterialSet set = MaterialSets.unionBuilder().add(value).build();
    assertFalse(set.testBlock(stone()));
    assertFalse(set.testBlock(dirt()));
    Block correct = stone();
    Mockito.when(correct.getData()).thenReturn((byte) 2);
    assertTrue(set.testBlock(correct));
}
Also used : MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) MaterialSet(com.elmakers.mine.bukkit.api.magic.MaterialSet) Block(org.bukkit.block.Block) Test(org.junit.Test)

Example 10 with MaterialSet

use of com.elmakers.mine.bukkit.api.magic.MaterialSet in project MagicPlugin by elBukkit.

the class MaterialSetsTest method testTestBlock.

@Test
public void testTestBlock() {
    MaterialSet set = MaterialSets.unionBuilder().add(Material.STONE).build();
    assertTrue(set.testBlock(stone()));
    assertFalse(set.testBlock(dirt()));
}
Also used : MaterialSet(com.elmakers.mine.bukkit.api.magic.MaterialSet) Test(org.junit.Test)

Aggregations

MaterialSet (com.elmakers.mine.bukkit.api.magic.MaterialSet)13 Block (org.bukkit.block.Block)6 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)3 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 FallingBlock (org.bukkit.entity.FallingBlock)2 EventHandler (org.bukkit.event.EventHandler)2 ItemStack (org.bukkit.inventory.ItemStack)2 Test (org.junit.Test)2 BlockData (com.elmakers.mine.bukkit.api.block.BlockData)1 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1 MaterialSetManager (com.elmakers.mine.bukkit.api.magic.MaterialSetManager)1 Messages (com.elmakers.mine.bukkit.api.magic.Messages)1 Spell (com.elmakers.mine.bukkit.api.spell.Spell)1 Wand (com.elmakers.mine.bukkit.api.wand.Wand)1 Wand (com.elmakers.mine.bukkit.wand.Wand)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 Material (org.bukkit.Material)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1