use of org.bukkit.block.BlockState in project acidisland by tastybento.
the class EntityLimits method onTreeGrow.
/**
* Prevents trees from growing outside of the protected area.
*
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTreeGrow(final StructureGrowEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
// Check world
if (!IslandGuard.inWorld(e.getLocation())) {
return;
}
// Check if this is on an island
Island island = plugin.getGrid().getIslandAt(e.getLocation());
if (island == null || island.isSpawn()) {
return;
}
Iterator<BlockState> it = e.getBlocks().iterator();
while (it.hasNext()) {
BlockState b = it.next();
if (b.getType() == Material.LOG || b.getType() == Material.LOG_2 || b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
if (!island.onIsland(b.getLocation())) {
it.remove();
}
}
}
}
use of org.bukkit.block.BlockState in project BKCommonLib by bergerhealer.
the class BlockStateConversion_1_12_2 method tileEntityToBlockState.
public synchronized 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 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));
}
}
}
use of org.bukkit.block.BlockState in project WildernessTp by AcmeProject.
the class WildSignListener method onClick.
@EventHandler
private void onClick(PlayerInteractEvent ev) {
if (ev.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
Player bob = ev.getPlayer();
if (!bob.hasPermission("wild.wildtp.sign"))
return;
BlockState bs = ev.getClickedBlock().getState();
if (bs instanceof Sign && isThisRealLife(((Sign) bs).getLines(), bs.getWorld())) {
World asylum = seekAsylum(((Sign) bs).getLines(), false);
WildTP.debug(bob.getName() + " used a WildTP sign (world:" + asylum + ")");
new TeleportGoneWild(Trigger.SIGN, ev.getPlayer(), asylum).WildTeleport();
}
}
Aggregations