Search in sources :

Example 1 with FlowerPot

use of org.bukkit.block.FlowerPot 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)

Aggregations

FlowerPot (org.bukkit.block.FlowerPot)1 Jukebox (org.bukkit.block.Jukebox)1 Sign (org.bukkit.block.Sign)1 Skull (org.bukkit.block.Skull)1 InventoryHolder (org.bukkit.inventory.InventoryHolder)1 MaterialData (org.bukkit.material.MaterialData)1