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();
}
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;
}
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);
}
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();
}
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();
}
}
Aggregations