Search in sources :

Example 1 with Rotatable

use of org.bukkit.block.data.Rotatable in project Minigames by AddstarMC.

the class RollbackScheduler method run.

@Override
public void run() {
    long time = System.nanoTime();
    while (iterator.hasNext()) {
        MgBlockData bdata = iterator.next();
        bdata.getBlockState().update(true);
        if (System.nanoTime() - time > Minigames.getPlugin().getConfig().getDouble("regeneration.maxDelay") * 1000000)
            return;
    }
    while (physIterator.hasNext()) {
        MgBlockData bdata = physIterator.next();
        bdata.getBlockState().update(true);
        switch(bdata.getBlockState().getType()) {
            case OAK_SIGN:
            case OAK_WALL_SIGN:
                if (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();
                }
                break;
            case SKELETON_SKULL:
            case WITHER_SKELETON_SKULL:
            case CREEPER_HEAD:
            case PLAYER_HEAD:
            case PLAYER_WALL_HEAD:
            case SKELETON_WALL_SKULL:
            case CREEPER_WALL_HEAD:
            case WITHER_SKELETON_WALL_SKULL:
                if (bdata.getBlockState() instanceof Skull) {
                    Skull skull = (Skull) bdata.getBlockState().getBlock().getState();
                    Rotatable skullData = (Rotatable) skull.getBlockData();
                    Skull orig = (Skull) bdata.getBlockState();
                    Rotatable origData = (Rotatable) orig.getBlockData();
                    if (orig.getOwningPlayer() != null)
                        skull.setOwningPlayer(orig.getOwningPlayer());
                    skullData.setRotation(origData.getRotation());
                    skull.update();
                }
                break;
            case JUKEBOX:
                Jukebox jbox = (Jukebox) bdata.getLocation().getBlock().getState();
                Jukebox orig = (Jukebox) bdata.getBlockState();
                jbox.setPlaying(orig.getPlaying());
                jbox.update();
                break;
            case FLOWER_POT:
            case POTTED_ACACIA_SAPLING:
            case POTTED_ALLIUM:
            case POTTED_AZURE_BLUET:
            case POTTED_BIRCH_SAPLING:
        }
        if (bdata.getLocation().getBlock().getState() instanceof InventoryHolder) {
            InventoryHolder block = (InventoryHolder) bdata.getLocation().getBlock().getState();
            if (bdata.getItems() != null)
                block.getInventory().setContents(bdata.getItems().clone());
        }
        if (System.nanoTime() - time > Minigames.getPlugin().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 : Rotatable(org.bukkit.block.data.Rotatable) InventoryHolder(org.bukkit.inventory.InventoryHolder)

Example 2 with Rotatable

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

the class BlockAction method setBlockRotation.

private void setBlockRotation(BlockState block, RotatableActionData rotatableActionData) {
    if (block.getBlockData() instanceof Rotatable) {
        final Rotatable r = (Rotatable) block.getBlockData();
        rotatableActionData.rotation = r.getRotation().toString();
    } else {
        final Directional d = (Directional) block.getBlockData();
        rotatableActionData.rotation = d.getFacing().name().toLowerCase();
    }
}
Also used : Rotatable(org.bukkit.block.data.Rotatable) Directional(org.bukkit.block.data.Directional)

Example 3 with Rotatable

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

the class BlockAction method setBlockRotatable.

private void setBlockRotatable(BlockState state, RotatableActionData actionData) {
    if (state.getBlockData() instanceof Rotatable) {
        final Rotatable r = (Rotatable) state.getBlockData();
        r.setRotation(actionData.getRotation());
        state.setBlockData(r);
    } else {
        final Directional d = (Directional) state.getBlockData();
        d.setFacing(actionData.getRotation());
        state.setBlockData(d);
    }
    state.update();
}
Also used : Rotatable(org.bukkit.block.data.Rotatable) Directional(org.bukkit.block.data.Directional)

Aggregations

Rotatable (org.bukkit.block.data.Rotatable)3 Directional (org.bukkit.block.data.Directional)2 InventoryHolder (org.bukkit.inventory.InventoryHolder)1