Search in sources :

Example 76 with BlockState

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();
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Island(com.wasteofplastic.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 77 with BlockState

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;
    }
}
Also used : BlockState(org.bukkit.block.BlockState) World(org.bukkit.World) Chunk(org.bukkit.Chunk)

Example 78 with BlockState

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");
    }
}
Also used : DataEntry(uk.co.oliwali.HawkEye.entry.DataEntry) BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) World(org.bukkit.World) Location(org.bukkit.Location)

Example 79 with BlockState

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));
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) BlockChangeEntry(uk.co.oliwali.HawkEye.entry.BlockChangeEntry) MaterialData(org.bukkit.material.MaterialData) Location(org.bukkit.Location) HawkEvent(uk.co.oliwali.HawkEye.HawkEvent)

Example 80 with BlockState

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();
    }
}
Also used : Player(org.bukkit.entity.Player) BlockState(org.bukkit.block.BlockState) Sign(org.bukkit.block.Sign) World(org.bukkit.World) EventHandler(org.bukkit.event.EventHandler)

Aggregations

BlockState (org.bukkit.block.BlockState)127 Block (org.bukkit.block.Block)54 EventHandler (org.bukkit.event.EventHandler)35 Sign (org.bukkit.block.Sign)17 Location (org.bukkit.Location)16 World (org.bukkit.World)15 InventoryHolder (org.bukkit.inventory.InventoryHolder)14 Material (org.bukkit.Material)13 MaterialData (org.bukkit.material.MaterialData)13 ItemStack (org.bukkit.inventory.ItemStack)11 ArrayList (java.util.ArrayList)10 CreatureSpawner (org.bukkit.block.CreatureSpawner)10 Player (org.bukkit.entity.Player)10 BlockFace (org.bukkit.block.BlockFace)9 BlockStateChangeImpl (me.botsko.prism.events.BlockStateChangeImpl)7 Vector (org.bukkit.util.Vector)7 ChangeResultImpl (me.botsko.prism.appliers.ChangeResultImpl)5 Chunk (org.bukkit.Chunk)5 CommandBlock (org.bukkit.block.CommandBlock)5 Skull (org.bukkit.block.Skull)5