Search in sources :

Example 6 with MaterialData

use of org.bukkit.material.MaterialData 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 7 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockFlowerPot method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (!(data instanceof FlowerPot)) {
        warnMaterialData(FlowerPot.class, data);
        return false;
    }
    if (state instanceof GlowFlowerPot) {
        GlowFlowerPot pot = (GlowFlowerPot) state;
        ItemStack heldItem = player.getItemInHand();
        // Only change contents if there is none and if the held item is valid pot contents.
        if (pot.getContents() == null && heldItem != null && isValidContents(heldItem.getData())) {
            // Null-check in isValidContents.
            pot.setContents(heldItem.getData().clone());
            return pot.update();
        }
    }
    return false;
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) GlowFlowerPot(net.glowstone.block.state.GlowFlowerPot) FlowerPot(org.bukkit.material.FlowerPot) MaterialData(org.bukkit.material.MaterialData) ItemStack(org.bukkit.inventory.ItemStack) GlowFlowerPot(net.glowstone.block.state.GlowFlowerPot)

Example 8 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockLog2 method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    // No Tree2 MaterialData
    MaterialData data = state.getData();
    data.setData(setTree(face, (byte) holding.getDurability()));
    state.setData(data);
}
Also used : MaterialData(org.bukkit.material.MaterialData)

Example 9 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockDispenser method getFacing.

public static BlockFace getFacing(GlowBlock block) {
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (!(data instanceof Dispenser)) {
        return BlockFace.SELF;
    }
    Dispenser dispenserData = (Dispenser) data;
    return dispenserData.getFacing();
}
Also used : Dispenser(org.bukkit.material.Dispenser) GlowDispenser(net.glowstone.block.state.GlowDispenser) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData)

Example 10 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockDispenser method updatePhysics.

@Override
public void updatePhysics(GlowBlock block) {
    GlowBlock up = block.getRelative(BlockFace.UP);
    boolean powered = block.isBlockPowered() || block.isBlockIndirectlyPowered() || up.isBlockPowered() || up.isBlockIndirectlyPowered();
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (!(data instanceof Dispenser)) {
        return;
    }
    boolean isTriggered = (data.getData() >> 3 & 1) != 0;
    if (powered && !isTriggered) {
        new BukkitRunnable() {

            @Override
            public void run() {
                trigger(block);
            }
        }.runTaskLater(null, 4);
        // TODO replace this with dispenser materialdata class (as soon as it provides access to this property)
        data.setData((byte) (data.getData() | 0x8));
        state.update();
    } else if (!powered && isTriggered) {
        data.setData((byte) (data.getData() & ~0x8));
        state.update();
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Dispenser(org.bukkit.material.Dispenser) GlowDispenser(net.glowstone.block.state.GlowDispenser) GlowBlockState(net.glowstone.block.GlowBlockState) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MaterialData(org.bukkit.material.MaterialData)

Aggregations

MaterialData (org.bukkit.material.MaterialData)75 GlowBlockState (net.glowstone.block.GlowBlockState)20 BlockState (org.bukkit.block.BlockState)12 GlowBlock (net.glowstone.block.GlowBlock)10 Material (org.bukkit.Material)10 Block (org.bukkit.block.Block)9 BlockFace (org.bukkit.block.BlockFace)9 ItemStack (org.bukkit.inventory.ItemStack)8 DoublePlant (org.bukkit.material.DoublePlant)6 Bed (org.bukkit.material.Bed)5 GlowDispenser (net.glowstone.block.state.GlowDispenser)3 BlockFadeEvent (org.bukkit.event.block.BlockFadeEvent)3 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)3 CocoaPlant (org.bukkit.material.CocoaPlant)3 Dispenser (org.bukkit.material.Dispenser)3 ArrayList (java.util.ArrayList)2 GlowWorld (net.glowstone.GlowWorld)2 GlowFlowerPot (net.glowstone.block.state.GlowFlowerPot)2 GlowSkull (net.glowstone.block.state.GlowSkull)2 Location (org.bukkit.Location)2