Search in sources :

Example 16 with Material

use of org.bukkit.Material in project Glowstone by GlowstoneMC.

the class BlockSapling method canPlaceAt.

@Override
public boolean canPlaceAt(GlowBlock block, BlockFace against) {
    int typeIdBelow = block.getWorld().getBlockTypeIdAt(block.getX(), block.getY() - 1, block.getZ());
    Material typeBelow = Material.getMaterial(typeIdBelow);
    return typeBelow == Material.GRASS || typeBelow == Material.DIRT || typeBelow == Material.SOIL;
}
Also used : Material(org.bukkit.Material)

Example 17 with Material

use of org.bukkit.Material in project Prism-Bukkit by prism.

the class BlockAction method placeBlock.

/**
     * Place a block unless something other than air occupies the spot, or if we
     * detect a falling block now sits there. This resolves the issue of falling
     * blocks taking up the space, preventing this rollback. However, it also
     * means that a rollback *could* interfere with a player-placed block.
     */
protected ChangeResult placeBlock(Player player, QueryParameters parameters, boolean is_preview, Block block, boolean is_deferred) {
    final Material m = Material.getMaterial(getBlockId());
    BlockStateChange stateChange;
    // (essentially liquid/air).
    if (!getType().requiresHandler("BlockChangeAction") && !getType().requiresHandler("PrismRollbackAction")) {
        if (!me.botsko.elixr.BlockUtils.isAcceptableForBlockPlace(block.getType()) && !parameters.hasFlag(Flag.OVERWRITE)) {
            // System.out.print("Block skipped due to being unaccaptable for block place.");
            return new ChangeResult(ChangeResultType.SKIPPED, null);
        }
    }
    // On the blacklist (except an undo)
    if (Prism.getIllegalBlocks().contains(getBlockId()) && !parameters.getProcessType().equals(PrismProcessType.UNDO)) {
        // System.out.print("Block skipped because it's not allowed to be placed.");
        return new ChangeResult(ChangeResultType.SKIPPED, null);
    }
    // If we're not in a preview, actually apply this block
    if (!is_preview) {
        // Capture the block before we change it
        final BlockState originalBlock = block.getState();
        // it's set to stationary water so the lilypad will sit
        if (getBlockId() == 111) {
            final Block below = block.getRelative(BlockFace.DOWN);
            if (below.getType().equals(Material.WATER) || below.getType().equals(Material.AIR) || below.getType().equals(Material.STATIONARY_WATER)) {
                below.setType(Material.STATIONARY_WATER);
            } else {
                // Prism.debug("Lilypad skipped because no water exists below.");
                return new ChangeResult(ChangeResultType.SKIPPED, null);
            }
        }
        // If portal, we need to light the portal. seems to be the only way.
        if (getBlockId() == 90) {
            final Block obsidian = me.botsko.elixr.BlockUtils.getFirstBlockOfMaterialBelow(Material.OBSIDIAN, block.getLocation());
            if (obsidian != null) {
                final Block above = obsidian.getRelative(BlockFace.UP);
                if (!(above.getType() == Material.PORTAL)) {
                    above.setType(Material.FIRE);
                    return new ChangeResult(ChangeResultType.APPLIED, null);
                }
            }
        }
        // it becomes unplayable
        if (getBlockId() == 84) {
            block_subid = 0;
        }
        // Set the material
        block.setTypeId(getBlockId());
        block.setData((byte) getBlockSubId());
        /**
             * Skulls
             */
        if ((getBlockId() == 144 || getBlockId() == 397) && getActionData() instanceof SkullActionData) {
            final SkullActionData s = (SkullActionData) getActionData();
            // Set skull data
            final Skull skull = (Skull) block.getState();
            skull.setRotation(s.getRotation());
            skull.setSkullType(s.getSkullType());
            if (!s.owner.isEmpty()) {
                skull.setOwner(s.owner);
            }
            skull.update();
        }
        /**
             * Spawner
             */
        if (getBlockId() == 52) {
            final SpawnerActionData s = (SpawnerActionData) getActionData();
            // Set spawner data
            final CreatureSpawner spawner = (CreatureSpawner) block.getState();
            spawner.setDelay(s.getDelay());
            spawner.setSpawnedType(s.getEntityType());
            spawner.update();
        }
        /**
             * Restoring command block
             */
        if (getBlockId() == 137) {
            final CommandBlock cmdblock = (CommandBlock) block.getState();
            cmdblock.setCommand(data);
            cmdblock.update();
        }
        /**
             * Signs
             */
        if (parameters.getProcessType().equals(PrismProcessType.ROLLBACK) && (getBlockId() == 63 || getBlockId() == 68) && getActionData() instanceof SignActionData) {
            final SignActionData s = (SignActionData) getActionData();
            // https://snowy-evening.com/botsko/prism/455/
            if (block.getState() instanceof Sign) {
                // Set sign data
                final Sign sign = (Sign) block.getState();
                int i = 0;
                if (s.lines != null && s.lines.length > 0) {
                    for (final String line : s.lines) {
                        sign.setLine(i, line);
                        i++;
                    }
                }
                sign.update();
            }
        }
        // logic to use materials.
        if (me.botsko.elixr.BlockUtils.materialRequiresSoil(block.getType())) {
            final Block below = block.getRelative(BlockFace.DOWN);
            if (below.getType().equals(Material.DIRT) || below.getType().equals(Material.AIR) || below.getType().equals(Material.GRASS)) {
                below.setType(Material.SOIL);
            } else {
                // System.out.print("Block skipped because there's no soil below.");
                return new ChangeResult(ChangeResultType.SKIPPED, null);
            }
        }
        // Capture the new state
        final BlockState newBlock = block.getState();
        // Store the state change
        stateChange = new BlockStateChange(originalBlock, newBlock);
        // If we're rolling back a door, we need to set it properly
        if (BlockUtils.isDoor(m)) {
            BlockUtils.properlySetDoor(block, getBlockId(), (byte) getBlockSubId());
        } else // Or a bed
        if (m.equals(Material.BED_BLOCK)) {
            BlockUtils.properlySetBed(block, getBlockId(), (byte) getBlockSubId());
        } else // Or double plants
        if (m.equals(Material.DOUBLE_PLANT)) {
            BlockUtils.properlySetDoublePlant(block, getBlockId(), (byte) getBlockSubId());
        }
    } else {
        // Otherwise, save the state so we can cancel if needed
        final BlockState originalBlock = block.getState();
        // Note: we save the original state as both old/new so we can re-use
        // blockStateChanges
        stateChange = new BlockStateChange(originalBlock, originalBlock);
        // Preview it
        player.sendBlockChange(block.getLocation(), getBlockId(), (byte) getBlockSubId());
        // Send preview to shared players
        for (final CommandSender sharedPlayer : parameters.getSharedPlayers()) {
            if (sharedPlayer instanceof Player) {
                ((Player) sharedPlayer).sendBlockChange(block.getLocation(), getBlockId(), (byte) getBlockSubId());
            }
        }
    }
    return new ChangeResult(ChangeResultType.APPLIED, stateChange);
}
Also used : Player(org.bukkit.entity.Player) BlockStateChange(me.botsko.prism.events.BlockStateChange) Material(org.bukkit.Material) CommandBlock(org.bukkit.block.CommandBlock) ChangeResult(me.botsko.prism.appliers.ChangeResult) CreatureSpawner(org.bukkit.block.CreatureSpawner) BlockState(org.bukkit.block.BlockState) CommandBlock(org.bukkit.block.CommandBlock) Block(org.bukkit.block.Block) Skull(org.bukkit.block.Skull) Sign(org.bukkit.block.Sign) CommandSender(org.bukkit.command.CommandSender)

Example 18 with Material

use of org.bukkit.Material in project BKCommonLib by bergerhealer.

the class BlockData method newMaterialData.

/**
     * Creates a new MaterialData instance appropriate for this Block
     * 
     * @return Block Material Data
     */
@SuppressWarnings("deprecation")
public final MaterialData newMaterialData() {
    Material type = this.getType();
    // Null: return AIR
    if (type == null) {
        return new MaterialData(0, (byte) 0);
    }
    // Create new MaterialData + some fixes.
    final MaterialData mdata;
    if (type == Material.GOLD_PLATE || type == Material.IRON_PLATE) {
        // Bukkit bugfix.
        mdata = new org.bukkit.material.PressurePlate(type, (byte) this.getRawData());
    } else {
        mdata = type.getNewData((byte) this.getRawData());
    }
    // Fix attachable face returning NULL sometimes
    if (mdata instanceof Attachable) {
        Attachable att = (Attachable) mdata;
        if (att.getAttachedFace() == null) {
            att.setFacingDirection(BlockFace.NORTH);
        }
    }
    return mdata;
}
Also used : Material(org.bukkit.Material) MaterialData(org.bukkit.material.MaterialData) Attachable(org.bukkit.material.Attachable)

Example 19 with Material

use of org.bukkit.Material in project BKCommonLib by bergerhealer.

the class NMSEntity method playStepSound.

@Deprecated
public static void playStepSound(Object entityHandle, int x, int y, int z, int typeId) {
    Material mat = Material.getMaterial(typeId);
    playStepSound(entityHandle, x, y, z, mat == null ? null : HandleConversion.toBlockHandle(mat));
}
Also used : Material(org.bukkit.Material)

Example 20 with Material

use of org.bukkit.Material in project Essentials by drtshock.

the class Commandrepair method repairItem.

private void repairItem(final ItemStack item) throws Exception {
    final Material material = Material.getMaterial(item.getTypeId());
    if (material.isBlock() || material.getMaxDurability() < 1) {
        throw new Exception(tl("repairInvalidType"));
    }
    if (item.getDurability() == 0) {
        throw new Exception(tl("repairAlreadyFixed"));
    }
    item.setDurability((short) 0);
}
Also used : Material(org.bukkit.Material) ChargeException(com.earth2me.essentials.ChargeException)

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