Search in sources :

Example 1 with Block

use of org.bukkit.block.Block in project HawkEye by oliverwoodings.

the class MonitorBlockListener method onBlockPlace.

@HawkEvent(dataType = DataType.BLOCK_PLACE)
public void onBlockPlace(BlockPlaceEvent event) {
    Block block = event.getBlock();
    if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
        return;
    DataManager.addEntry(new BlockChangeEntry(event.getPlayer(), DataType.BLOCK_PLACE, block.getLocation(), event.getBlockReplacedState(), block.getState()));
}
Also used : BlockChangeEntry(uk.co.oliwali.HawkEye.entry.BlockChangeEntry) Block(org.bukkit.block.Block) HawkEvent(uk.co.oliwali.HawkEye.HawkEvent)

Example 2 with Block

use of org.bukkit.block.Block in project HawkEye by oliverwoodings.

the class ToolListener method onBlockPlace.

@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event) {
    Player player = event.getPlayer();
    Block block = event.getBlock();
    if (BlockUtil.getBlockString(block).equals(Config.ToolBlock) && SessionManager.getSession(player).isUsingTool()) {
        ToolManager.toolSearch(player, block.getLocation());
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Block

use of org.bukkit.block.Block in project HawkEye by oliverwoodings.

the class Undo method run.

/**
	 * Run the undo.
	 * Contains appropriate methods of catching errors and notifying the player
	 */
public void run() {
    //Start rollback process
    int i = 0;
    while (i < 200 && undoQueue.hasNext()) {
        //If undo doesn't exist
        DataEntry entry = undoQueue.next();
        if (entry.getUndoState() == null)
            continue;
        //Global undo
        if (undoType == RollbackType.GLOBAL) {
            entry.getUndoState().update(true);
            //Add back into database if delete data is on
            if (Config.DeleteDataOnRollback)
                DataManager.addEntry(entry);
        } else //Player undo
        {
            Player player = (Player) session.getSender();
            Block block = entry.getUndoState().getBlock();
            player.sendBlockChange(block.getLocation(), block.getType(), block.getData());
        }
        counter++;
    }
    //Check if undo is finished
    if (!undoQueue.hasNext()) {
        //End timer
        Bukkit.getServer().getScheduler().cancelTask(timerID);
        session.setDoingRollback(false);
        session.setRollbackResults(null);
        Util.sendMessage(session.getSender(), "&cUndo complete, &7" + counter + " &cedits performed");
        Util.debug("Undo complete, " + counter + " edits performed");
    }
}
Also used : DataEntry(uk.co.oliwali.HawkEye.entry.DataEntry) Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block)

Example 4 with Block

use of org.bukkit.block.Block in project HawkEye by oliverwoodings.

the class Rebuild 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 && rebuildQueue.hasNext()) {
        i++;
        DataEntry entry = rebuildQueue.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);
        //Rebuild it
        entry.rebuild(block);
        counter++;
    }
    //Check if rollback is finished
    if (!rebuildQueue.hasNext()) {
        //End timer
        Bukkit.getServer().getScheduler().cancelTask(timerID);
        session.setDoingRollback(false);
        session.setRollbackResults(undo);
        Util.sendMessage(session.getSender(), "&cRebuild complete, &7" + counter + "&c edits performed");
        Util.sendMessage(session.getSender(), "&cUndo this rebuild using &7/hawk undo");
        Util.debug("Rebuild complete, " + counter + " edits performed");
    }
}
Also used : DataEntry(uk.co.oliwali.HawkEye.entry.DataEntry) Block(org.bukkit.block.Block) World(org.bukkit.World) Location(org.bukkit.Location)

Example 5 with Block

use of org.bukkit.block.Block in project Prism-Bukkit by prism.

the class BlockAction method placeBlock.

/**
     * Place a block unless something other than air occupies the spot, or if we
     * detect a falling block now sits there. This resolves the issue of falling
     * blocks taking up the space, preventing this rollback. However, it also
     * means that a rollback *could* interfere with a player-placed block.
     */
protected ChangeResult placeBlock(Player player, QueryParameters parameters, boolean is_preview, Block block, boolean is_deferred) {
    final Material m = Material.getMaterial(getBlockId());
    BlockStateChange stateChange;
    // (essentially liquid/air).
    if (!getType().requiresHandler("BlockChangeAction") && !getType().requiresHandler("PrismRollbackAction")) {
        if (!me.botsko.elixr.BlockUtils.isAcceptableForBlockPlace(block.getType()) && !parameters.hasFlag(Flag.OVERWRITE)) {
            // System.out.print("Block skipped due to being unaccaptable for block place.");
            return new ChangeResult(ChangeResultType.SKIPPED, null);
        }
    }
    // On the blacklist (except an undo)
    if (Prism.getIllegalBlocks().contains(getBlockId()) && !parameters.getProcessType().equals(PrismProcessType.UNDO)) {
        // System.out.print("Block skipped because it's not allowed to be placed.");
        return new ChangeResult(ChangeResultType.SKIPPED, null);
    }
    // If we're not in a preview, actually apply this block
    if (!is_preview) {
        // Capture the block before we change it
        final BlockState originalBlock = block.getState();
        // it's set to stationary water so the lilypad will sit
        if (getBlockId() == 111) {
            final Block below = block.getRelative(BlockFace.DOWN);
            if (below.getType().equals(Material.WATER) || below.getType().equals(Material.AIR) || below.getType().equals(Material.STATIONARY_WATER)) {
                below.setType(Material.STATIONARY_WATER);
            } else {
                // Prism.debug("Lilypad skipped because no water exists below.");
                return new ChangeResult(ChangeResultType.SKIPPED, null);
            }
        }
        // If portal, we need to light the portal. seems to be the only way.
        if (getBlockId() == 90) {
            final Block obsidian = me.botsko.elixr.BlockUtils.getFirstBlockOfMaterialBelow(Material.OBSIDIAN, block.getLocation());
            if (obsidian != null) {
                final Block above = obsidian.getRelative(BlockFace.UP);
                if (!(above.getType() == Material.PORTAL)) {
                    above.setType(Material.FIRE);
                    return new ChangeResult(ChangeResultType.APPLIED, null);
                }
            }
        }
        // it becomes unplayable
        if (getBlockId() == 84) {
            block_subid = 0;
        }
        // Set the material
        block.setTypeId(getBlockId());
        block.setData((byte) getBlockSubId());
        /**
             * Skulls
             */
        if ((getBlockId() == 144 || getBlockId() == 397) && getActionData() instanceof SkullActionData) {
            final SkullActionData s = (SkullActionData) getActionData();
            // Set skull data
            final Skull skull = (Skull) block.getState();
            skull.setRotation(s.getRotation());
            skull.setSkullType(s.getSkullType());
            if (!s.owner.isEmpty()) {
                skull.setOwner(s.owner);
            }
            skull.update();
        }
        /**
             * Spawner
             */
        if (getBlockId() == 52) {
            final SpawnerActionData s = (SpawnerActionData) getActionData();
            // Set spawner data
            final CreatureSpawner spawner = (CreatureSpawner) block.getState();
            spawner.setDelay(s.getDelay());
            spawner.setSpawnedType(s.getEntityType());
            spawner.update();
        }
        /**
             * Restoring command block
             */
        if (getBlockId() == 137) {
            final CommandBlock cmdblock = (CommandBlock) block.getState();
            cmdblock.setCommand(data);
            cmdblock.update();
        }
        /**
             * Signs
             */
        if (parameters.getProcessType().equals(PrismProcessType.ROLLBACK) && (getBlockId() == 63 || getBlockId() == 68) && getActionData() instanceof SignActionData) {
            final SignActionData s = (SignActionData) getActionData();
            // https://snowy-evening.com/botsko/prism/455/
            if (block.getState() instanceof Sign) {
                // Set sign data
                final Sign sign = (Sign) block.getState();
                int i = 0;
                if (s.lines != null && s.lines.length > 0) {
                    for (final String line : s.lines) {
                        sign.setLine(i, line);
                        i++;
                    }
                }
                sign.update();
            }
        }
        // logic to use materials.
        if (me.botsko.elixr.BlockUtils.materialRequiresSoil(block.getType())) {
            final Block below = block.getRelative(BlockFace.DOWN);
            if (below.getType().equals(Material.DIRT) || below.getType().equals(Material.AIR) || below.getType().equals(Material.GRASS)) {
                below.setType(Material.SOIL);
            } else {
                // System.out.print("Block skipped because there's no soil below.");
                return new ChangeResult(ChangeResultType.SKIPPED, null);
            }
        }
        // Capture the new state
        final BlockState newBlock = block.getState();
        // Store the state change
        stateChange = new BlockStateChange(originalBlock, newBlock);
        // If we're rolling back a door, we need to set it properly
        if (BlockUtils.isDoor(m)) {
            BlockUtils.properlySetDoor(block, getBlockId(), (byte) getBlockSubId());
        } else // Or a bed
        if (m.equals(Material.BED_BLOCK)) {
            BlockUtils.properlySetBed(block, getBlockId(), (byte) getBlockSubId());
        } else // Or double plants
        if (m.equals(Material.DOUBLE_PLANT)) {
            BlockUtils.properlySetDoublePlant(block, getBlockId(), (byte) getBlockSubId());
        }
    } else {
        // Otherwise, save the state so we can cancel if needed
        final BlockState originalBlock = block.getState();
        // Note: we save the original state as both old/new so we can re-use
        // blockStateChanges
        stateChange = new BlockStateChange(originalBlock, originalBlock);
        // Preview it
        player.sendBlockChange(block.getLocation(), getBlockId(), (byte) getBlockSubId());
        // Send preview to shared players
        for (final CommandSender sharedPlayer : parameters.getSharedPlayers()) {
            if (sharedPlayer instanceof Player) {
                ((Player) sharedPlayer).sendBlockChange(block.getLocation(), getBlockId(), (byte) getBlockSubId());
            }
        }
    }
    return new ChangeResult(ChangeResultType.APPLIED, stateChange);
}
Also used : Player(org.bukkit.entity.Player) BlockStateChange(me.botsko.prism.events.BlockStateChange) Material(org.bukkit.Material) CommandBlock(org.bukkit.block.CommandBlock) ChangeResult(me.botsko.prism.appliers.ChangeResult) CreatureSpawner(org.bukkit.block.CreatureSpawner) BlockState(org.bukkit.block.BlockState) CommandBlock(org.bukkit.block.CommandBlock) Block(org.bukkit.block.Block) Skull(org.bukkit.block.Skull) Sign(org.bukkit.block.Sign) CommandSender(org.bukkit.command.CommandSender)

Aggregations

Block (org.bukkit.block.Block)154 EventHandler (org.bukkit.event.EventHandler)47 Player (org.bukkit.entity.Player)29 BlockState (org.bukkit.block.BlockState)27 BlockFace (org.bukkit.block.BlockFace)20 GlowBlock (net.glowstone.block.GlowBlock)19 Location (org.bukkit.Location)17 Material (org.bukkit.Material)17 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)13 MaterialData (org.bukkit.material.MaterialData)13 World (org.bukkit.World)11 Sign (org.bukkit.block.Sign)11 ArrayList (java.util.ArrayList)10 Entity (org.bukkit.entity.Entity)10 ItemStack (org.bukkit.inventory.ItemStack)8 Vector (org.bukkit.util.Vector)7 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)6 IOException (java.io.IOException)5 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)5 Element (net.aufdemrand.denizencore.objects.Element)5