use of org.bukkit.block.BlockState in project Essentials by drtshock.
the class BlockMetaSpawnerProvider method setEntityType.
@Override
public ItemStack setEntityType(ItemStack is, EntityType type) {
BlockStateMeta bsm = (BlockStateMeta) is.getItemMeta();
BlockState bs = bsm.getBlockState();
((CreatureSpawner) bs).setSpawnedType(type);
bsm.setBlockState(bs);
is.setItemMeta(bsm);
return setDisplayName(is, type);
}
use of org.bukkit.block.BlockState in project BKCommonLib by bergerhealer.
the class BlockStateConversion method tileEntityToBlockState.
public static BlockState tileEntityToBlockState(Block block, Object nmsTileEntity) {
// Store and restore old state in case of recursive calls to this function
// This could happen if inside BlockState construction a chunk is loaded anyway
// Would be bad, but its best to assume the worst
TileState old_state = input_state;
try {
input_state = new TileState(block, nmsTileEntity);
BlockState result = proxy_block.getState();
// Internal BlockState needs to have all proxy field instances replaced with what it should be
BlockStateCache cache = BlockStateCache.get(result.getClass());
for (SafeField<World> worldField : cache.worldFields) {
worldField.set(result, input_state.block.getWorld());
}
for (SafeField<Chunk> chunkField : cache.chunkFields) {
chunkField.set(result, input_state.block.getChunk());
}
// All done!
return result;
} catch (Throwable t) {
Logging.LOGGER_CONVERSION.once(Level.SEVERE, "Failed to convert " + nmsTileEntity.getClass().getName() + " to CraftBlockState", t);
return CraftBlockStateHandle.createNew(input_state.block);
} finally {
input_state = old_state;
}
}
use of org.bukkit.block.BlockState in project acidisland by tastybento.
the class Island method getHopperCount.
/**
* @return number of hoppers on the island
*/
public int getHopperCount() {
tileEntityCount.clear();
int result = 0;
for (int x = getMinProtectedX() / 16; x <= (getMinProtectedX() + getProtectionSize() - 1) / 16; x++) {
for (int z = getMinProtectedZ() / 16; z <= (getMinProtectedZ() + getProtectionSize() - 1) / 16; z++) {
for (BlockState holder : world.getChunkAt(x, z).getTileEntities()) {
if (holder instanceof Hopper && onIsland(holder.getLocation())) {
result++;
}
}
}
}
return result;
}
use of org.bukkit.block.BlockState in project HawkEye by oliverwoodings.
the class Rollback method run.
/**
* Run the rollback.
* Contains appropriate methods of catching errors and notifying the player
*/
public void run() {
//Start rollback process
int i = 0;
while (i < 200 && rollbackQueue.hasNext()) {
i++;
DataEntry entry = rollbackQueue.next();
//If the action can't be rolled back, skip this entry
if (entry.getType() == null || !entry.getType().canRollback())
continue;
//If the world doesn't exist, skip this entry
World world = HawkEye.server.getWorld(entry.getWorld());
if (world == null)
continue;
//Get some data from the entry
Location loc = new Location(world, entry.getX(), entry.getY(), entry.getZ());
Block block = world.getBlockAt(loc);
BlockState state = block.getState();
//Attempt global rollback
if (rollbackType == RollbackType.GLOBAL && entry.rollback(world.getBlockAt(loc))) {
entry.setUndoState(state);
undo.add(entry);
} else //Local rollback preview
if (rollbackType == RollbackType.LOCAL && entry.rollbackPlayer(block, (Player) session.getSender())) {
entry.setUndoState(state);
undo.add(entry);
}
}
//Check if rollback is finished
if (!rollbackQueue.hasNext()) {
//End timer
Bukkit.getServer().getScheduler().cancelTask(timerID);
session.setDoingRollback(false);
session.setRollbackResults(undo);
//Store undo results and notify player
if (rollbackType == RollbackType.GLOBAL) {
Util.sendMessage(session.getSender(), "&cRollback complete, &7" + undo.size() + "&c edits performed");
Util.sendMessage(session.getSender(), "&cUndo this rollback using &7/hawk undo");
//Delete data if told to
if (Config.DeleteDataOnRollback)
DataManager.deleteEntries(undo);
} else {
Util.sendMessage(session.getSender(), "&cRollback preview complete, &7" + undo.size() + "&c edits performed to you");
Util.sendMessage(session.getSender(), "&cType &7/hawk apply&c to make these changes permanent or &7/hawk cancel&c to cancel");
}
Util.debug("Rollback complete, " + undo.size() + " edits performed");
}
}
use of org.bukkit.block.BlockState in project HawkEye by oliverwoodings.
the class MonitorBlockListener method onBlockFromTo.
@HawkEvent(dataType = { DataType.LAVA_FLOW, DataType.WATER_FLOW })
public void onBlockFromTo(BlockFromToEvent event) {
List<Integer> fluidBlocks = Arrays.asList(0, 27, 28, 31, 32, 37, 38, 39, 40, 50, 51, 55, 59, 66, 69, 70, 75, 76, 78, 93, 94);
//Only interested in liquids flowing
if (!event.getBlock().isLiquid())
return;
Location loc = event.getToBlock().getLocation();
BlockState from = event.getBlock().getState();
BlockState to = event.getToBlock().getState();
MaterialData data = from.getData();
//Lava
if (from.getTypeId() == 10 || from.getTypeId() == 11) {
//Flowing into a normal block
if (fluidBlocks.contains(to.getTypeId())) {
data.setData((byte) (from.getRawData() + 1));
from.setData(data);
} else //Flowing into water
if (to.getTypeId() == 8 || to.getTypeId() == 9) {
from.setTypeId(event.getFace() == BlockFace.DOWN ? 10 : 4);
data.setData((byte) 0);
from.setData(data);
}
DataManager.addEntry(new BlockChangeEntry("Environment", DataType.LAVA_FLOW, loc, to, from));
} else //Water
if (from.getTypeId() == 8 || from.getTypeId() == 9) {
//Normal block
if (fluidBlocks.contains(to.getTypeId())) {
data.setData((byte) (from.getRawData() + 1));
from.setData(data);
DataManager.addEntry(new BlockChangeEntry("Environment", DataType.WATER_FLOW, loc, to, from));
}
//If we are flowing over lava, cobble or obsidian will form
BlockState lower = event.getToBlock().getRelative(BlockFace.DOWN).getState();
if (lower.getTypeId() == 10 || lower.getTypeId() == 11) {
from.setTypeId(lower.getData().getData() == 0 ? 49 : 4);
loc.setY(loc.getY() - 1);
DataManager.addEntry(new BlockChangeEntry("Environment", DataType.WATER_FLOW, loc, lower, from));
}
}
}
Aggregations