Search in sources :

Example 1 with Skull

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

the class BlockAction method setBlock.

/**
     *
     * @param state
     */
public void setBlock(BlockState state) {
    if (state != null) {
        block_id = BlockUtils.blockIdMustRecordAs(state.getTypeId());
        block_subid = state.getRawData();
        // @todo clean this up
        if (block_id == 144 || block_id == 397 || block_id == 52 || block_id == 63 || block_id == 68) {
            actionData = new BlockActionData();
        }
        // spawner
        if (state.getTypeId() == 52) {
            final SpawnerActionData spawnerActionData = new SpawnerActionData();
            final CreatureSpawner s = (CreatureSpawner) state;
            spawnerActionData.entity_type = s.getSpawnedType().name().toLowerCase();
            spawnerActionData.delay = s.getDelay();
            actionData = spawnerActionData;
        } else // skulls
        if ((state.getTypeId() == 144 || state.getTypeId() == 397)) {
            final SkullActionData skullActionData = new SkullActionData();
            final Skull s = (Skull) state;
            skullActionData.rotation = s.getRotation().name().toLowerCase();
            skullActionData.owner = s.getOwner();
            skullActionData.skull_type = s.getSkullType().name().toLowerCase();
            actionData = skullActionData;
        } else // signs
        if ((state.getTypeId() == 63 || state.getTypeId() == 68)) {
            final SignActionData signActionData = new SignActionData();
            final Sign s = (Sign) state;
            signActionData.lines = s.getLines();
            actionData = signActionData;
        } else // command block
        if ((state.getTypeId() == 137)) {
            final CommandBlock cmdblock = (CommandBlock) state;
            data = cmdblock.getCommand();
        }
        this.world_name = state.getWorld().getName();
        this.x = state.getLocation().getBlockX();
        this.y = state.getLocation().getBlockY();
        this.z = state.getLocation().getBlockZ();
    }
}
Also used : Skull(org.bukkit.block.Skull) Sign(org.bukkit.block.Sign) CommandBlock(org.bukkit.block.CommandBlock) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Example 2 with Skull

use of org.bukkit.block.Skull 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 3 with Skull

use of org.bukkit.block.Skull in project Minigames by AddstarMC.

the class RollbackScheduler method run.

@Override
public void run() {
    long time = System.nanoTime();
    while (iterator.hasNext()) {
        BlockData bdata = iterator.next();
        bdata.getBlockState().update(true);
        if (System.nanoTime() - time > Minigames.plugin.getConfig().getDouble("regeneration.maxDelay") * 1000000)
            return;
    }
    while (physIterator.hasNext()) {
        BlockData bdata = physIterator.next();
        bdata.getBlockState().update(true);
        if ((bdata.getBlockState().getType() == Material.SIGN_POST || bdata.getBlockState().getType() == Material.WALL_SIGN) && bdata.getBlockState() instanceof Sign) {
            Sign sign = (Sign) bdata.getLocation().getBlock().getState();
            Sign signOld = (Sign) bdata.getBlockState();
            sign.setLine(0, signOld.getLine(0));
            sign.setLine(1, signOld.getLine(1));
            sign.setLine(2, signOld.getLine(2));
            sign.setLine(3, signOld.getLine(3));
            sign.update();
        } else if (bdata.getLocation().getBlock().getState() instanceof InventoryHolder) {
            InventoryHolder block = (InventoryHolder) bdata.getLocation().getBlock().getState();
            if (bdata.getItems() != null)
                block.getInventory().setContents(bdata.getItems().clone());
        } else if (bdata.getBlockState() instanceof FlowerPot) {
            FlowerPot pot = (FlowerPot) bdata.getLocation().getBlock().getState();
            if (bdata.getSpecialData("contents") != null)
                pot.setContents((MaterialData) bdata.getSpecialData("contents"));
        } else if (bdata.getBlockState().getType() == Material.JUKEBOX) {
            Jukebox jbox = (Jukebox) bdata.getLocation().getBlock().getState();
            Jukebox orig = (Jukebox) bdata.getBlockState();
            jbox.setPlaying(orig.getPlaying());
            jbox.update();
        } else if (bdata.getBlockState().getType() == Material.SKULL) {
            Skull skull = (Skull) bdata.getBlockState().getBlock().getState();
            Skull orig = (Skull) bdata.getBlockState();
            if (orig.getOwningPlayer() != null)
                skull.setOwningPlayer(orig.getOwningPlayer());
            skull.setRotation(orig.getRotation());
            skull.setSkullType(orig.getSkullType());
            skull.update();
        }
        if (System.nanoTime() - time > Minigames.plugin.getConfig().getDouble("regeneration.maxDelay") * 1000000)
            return;
    }
    // When rolling back a single player's changes dont change the overall games state
    if (modifier == null) {
        HandlerList.unregisterAll(minigame.getBlockRecorder());
        HandlerList.bakeAll();
        minigame.setState(MinigameState.IDLE);
    }
    task.cancel();
}
Also used : Jukebox(org.bukkit.block.Jukebox) FlowerPot(org.bukkit.block.FlowerPot) Skull(org.bukkit.block.Skull) Sign(org.bukkit.block.Sign) MaterialData(org.bukkit.material.MaterialData) InventoryHolder(org.bukkit.inventory.InventoryHolder)

Example 4 with Skull

use of org.bukkit.block.Skull in project TotalFreedomMod by TotalFreedom.

the class CageData method generateHollowCube.

public static void generateHollowCube(Location location, int length, Material material) {
    final Block center = location.getBlock();
    for (int xOffset = -length; xOffset <= length; xOffset++) {
        for (int yOffset = -length; yOffset <= length; yOffset++) {
            for (int zOffset = -length; zOffset <= length; zOffset++) {
                // Hollow
                if (Math.abs(xOffset) != length && Math.abs(yOffset) != length && Math.abs(zOffset) != length) {
                    continue;
                }
                final Block block = center.getRelative(xOffset, yOffset, zOffset);
                if (material != Material.SKULL) {
                    // Glowstone light
                    if (material != Material.GLASS && xOffset == 0 && yOffset == 2 && zOffset == 0) {
                        block.setType(Material.GLOWSTONE);
                        continue;
                    }
                    block.setType(material);
                } else // Darth mode
                {
                    if (Math.abs(xOffset) == length && Math.abs(yOffset) == length && Math.abs(zOffset) == length) {
                        block.setType(Material.GLOWSTONE);
                        continue;
                    }
                    block.setType(Material.SKULL);
                    final Skull skull = (Skull) block.getState();
                    skull.setSkullType(SkullType.PLAYER);
                    skull.setOwner("Prozza");
                    skull.update();
                }
            }
        }
    }
}
Also used : Block(org.bukkit.block.Block) Skull(org.bukkit.block.Skull)

Aggregations

Skull (org.bukkit.block.Skull)4 Sign (org.bukkit.block.Sign)3 Block (org.bukkit.block.Block)2 CommandBlock (org.bukkit.block.CommandBlock)2 CreatureSpawner (org.bukkit.block.CreatureSpawner)2 ChangeResult (me.botsko.prism.appliers.ChangeResult)1 BlockStateChange (me.botsko.prism.events.BlockStateChange)1 Material (org.bukkit.Material)1 BlockState (org.bukkit.block.BlockState)1 FlowerPot (org.bukkit.block.FlowerPot)1 Jukebox (org.bukkit.block.Jukebox)1 CommandSender (org.bukkit.command.CommandSender)1 Player (org.bukkit.entity.Player)1 InventoryHolder (org.bukkit.inventory.InventoryHolder)1 MaterialData (org.bukkit.material.MaterialData)1