Search in sources :

Example 96 with Block

use of org.bukkit.block.Block in project Towny by ElgarL.

the class TownyRegenAPI method doDeleteTownBlockIds.

/**
	 * Deletes all of a specified block type from a TownBlock
	 * 
	 * @param worldCoord
	 */
public static void doDeleteTownBlockIds(WorldCoord worldCoord) {
    //Block block = null;
    World world = null;
    int plotSize = TownySettings.getTownBlockSize();
    TownyMessaging.sendDebugMsg("Processing deleteTownBlockIds");
    world = worldCoord.getBukkitWorld();
    if (world != null) {
        /*
			 * if
			 * (!world.isChunkLoaded(MinecraftTools.calcChunk(townBlock.getX()),
			 * MinecraftTools.calcChunk(townBlock.getZ())))
			 * return;
			 */
        int height = world.getMaxHeight() - 1;
        int worldx = worldCoord.getX() * plotSize, worldz = worldCoord.getZ() * plotSize;
        for (int z = 0; z < plotSize; z++) for (int x = 0; x < plotSize; x++) for (int y = height; y > 0; y--) {
            //Check from bottom up else minecraft won't remove doors
            Block block = world.getBlockAt(worldx + x, y, worldz + z);
            try {
                if (worldCoord.getTownyWorld().isPlotManagementDeleteIds(block.getType().name())) {
                    block.setType(Material.AIR);
                }
            } catch (NotRegisteredException e) {
            // Not a registered world
            }
            block = null;
        }
    }
}
Also used : NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) World(org.bukkit.World)

Example 97 with Block

use of org.bukkit.block.Block in project Towny by ElgarL.

the class TownyBlockListener method onBlockBreak.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    if (plugin.isError()) {
        event.setCancelled(true);
        return;
    }
    Player player = event.getPlayer();
    Block block = event.getBlock();
    //Get build permissions (updates cache if none exist)
    boolean bDestroy = PlayerCacheUtil.getCachePermission(player, block.getLocation(), BukkitTools.getTypeId(block), BukkitTools.getData(block), TownyPermission.ActionType.DESTROY);
    // Allow destroy if we are permitted
    if (bDestroy)
        return;
    /*
		 * Fetch the players cache
		 */
    PlayerCache cache = plugin.getCache(player);
    /*
		 * Allow destroy in a WarZone (FlagWar) if it's an editable material.
		 */
    if (cache.getStatus() == TownBlockStatus.WARZONE) {
        if (!TownyWarConfig.isEditableMaterialInWarZone(block.getType())) {
            event.setCancelled(true);
            TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_warzone_cannot_edit_material"), "destroy", block.getType().toString().toLowerCase()));
        }
        return;
    }
    /*
		 * Queue a protectionRegenTask if we have delayed regeneration set
		 */
    long delay = TownySettings.getRegenDelay();
    if (delay > 0) {
        if (!TownyRegenAPI.isPlaceholder(block)) {
            if (!TownyRegenAPI.hasProtectionRegenTask(new BlockLocation(block.getLocation()))) {
                ProtectionRegenTask task = new ProtectionRegenTask(plugin, block, true);
                task.setTaskId(plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, task, 20 * delay));
                TownyRegenAPI.addProtectionRegenTask(task);
            }
        } else {
            TownyRegenAPI.removePlaceholder(block);
            BukkitTools.setTypeId(block, 0, false);
        }
    } else {
        event.setCancelled(true);
    }
    /* 
		 * display any error recorded for this plot
		 */
    if ((cache.hasBlockErrMsg()) && (event.isCancelled()))
        TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg());
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) PlayerCache(com.palmergames.bukkit.towny.object.PlayerCache) ProtectionRegenTask(com.palmergames.bukkit.towny.tasks.ProtectionRegenTask) BlockLocation(com.palmergames.bukkit.towny.regen.block.BlockLocation) EventHandler(org.bukkit.event.EventHandler)

Example 98 with Block

use of org.bukkit.block.Block in project Towny by ElgarL.

the class TownyBlockListener method onBlockPistonRetract.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
    if (plugin.isError()) {
        event.setCancelled(true);
        return;
    }
    //fetch the piston base
    Block block = event.getBlock();
    if (block.getType() != Material.PISTON_STICKY_BASE)
        return;
    //Get the block attached to the PISTON_EXTENSION of the PISTON_STICKY_BASE
    block = block.getRelative(event.getDirection()).getRelative(event.getDirection());
    if ((block.getType() != Material.AIR) && (!block.isLiquid())) {
        //check the block to see if it's going to pass a plot boundary
        if (testBlockMove(block, event.getDirection().getOppositeFace()))
            event.setCancelled(true);
    }
}
Also used : Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) EventHandler(org.bukkit.event.EventHandler)

Example 99 with Block

use of org.bukkit.block.Block in project Towny by ElgarL.

the class TownyPlayerListener method onPlayerInteract.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (plugin.isError()) {
        event.setCancelled(true);
        return;
    }
    Player player = event.getPlayer();
    Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
    TownyWorld World = null;
    try {
        World = TownyUniverse.getDataSource().getWorld(block.getLocation().getWorld().getName());
        if (!World.isUsingTowny())
            return;
    } catch (NotRegisteredException e) {
        // World not registered with Towny.
        e.printStackTrace();
        return;
    }
    if ((event.getAction() == Action.PHYSICAL)) {
        if ((block.getType() == Material.SOIL) || (block.getType() == Material.CROPS))
            if (World.isDisablePlayerTrample() || !PlayerCacheUtil.getCachePermission(player, block.getLocation(), BukkitTools.getTypeId(block), BukkitTools.getData(block), TownyPermission.ActionType.DESTROY)) {
                event.setCancelled(true);
                return;
            }
    }
    if (event.hasItem()) {
        /*
			 * Info Tool
			 */
        if (event.getPlayer().getItemInHand().getType() == Material.getMaterial(TownySettings.getTool())) {
            if (TownyUniverse.getPermissionSource().isTownyAdmin(player)) {
                if (event.getClickedBlock() instanceof Block) {
                    block = (Block) event.getClickedBlock();
                    TownyMessaging.sendMessage(player, Arrays.asList(ChatTools.formatTitle("Block Info"), ChatTools.formatCommand("", "Block Type", "", block.getType().name()), ChatTools.formatCommand("", "Data value", "", Byte.toString(BukkitTools.getData(block)))));
                    event.setCancelled(true);
                }
            }
        }
        if (TownySettings.isItemUseMaterial(event.getItem().getType().name())) {
            event.setCancelled(onPlayerInteract(player, event.getClickedBlock(), event.getItem()));
        }
    }
    if (event.getClickedBlock() != null) {
        // Towny regen
        if (TownySettings.getRegenDelay() > 0) {
            if (event.getClickedBlock().getState().getData() instanceof Attachable) {
                Attachable attachable = (Attachable) event.getClickedBlock().getState().getData();
                BlockLocation attachedToBlock = new BlockLocation(event.getClickedBlock().getRelative(attachable.getAttachedFace()).getLocation());
                // Prevent attached blocks from falling off when interacting
                if (TownyRegenAPI.hasProtectionRegenTask(attachedToBlock)) {
                    event.setCancelled(true);
                    return;
                }
            }
        }
        if (TownySettings.isSwitchMaterial(event.getClickedBlock().getType().name()) || event.getAction() == Action.PHYSICAL) {
            onPlayerSwitchEvent(event, null, World);
            return;
        }
    }
}
Also used : Player(org.bukkit.entity.Player) NotRegisteredException(com.palmergames.bukkit.towny.exceptions.NotRegisteredException) Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) TownyWorld(com.palmergames.bukkit.towny.object.TownyWorld) Attachable(org.bukkit.material.Attachable) BlockLocation(com.palmergames.bukkit.towny.regen.block.BlockLocation) EventHandler(org.bukkit.event.EventHandler)

Example 100 with Block

use of org.bukkit.block.Block in project Towny by ElgarL.

the class TownyPlayerListener method onPlayerSwitchEvent.

public void onPlayerSwitchEvent(PlayerInteractEvent event, String errMsg, TownyWorld world) {
    Player player = event.getPlayer();
    Block block = event.getClickedBlock();
    event.setCancelled(onPlayerSwitchEvent(player, block, errMsg, world));
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock)

Aggregations

Block (org.bukkit.block.Block)187 EventHandler (org.bukkit.event.EventHandler)62 Player (org.bukkit.entity.Player)42 Location (org.bukkit.Location)30 BlockState (org.bukkit.block.BlockState)28 Sign (org.bukkit.block.Sign)24 Material (org.bukkit.Material)23 BlockFace (org.bukkit.block.BlockFace)23 GlowBlock (net.glowstone.block.GlowBlock)19 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)16 MaterialData (org.bukkit.material.MaterialData)16 ArrayList (java.util.ArrayList)15 World (org.bukkit.World)14 Entity (org.bukkit.entity.Entity)14 ItemStack (org.bukkit.inventory.ItemStack)14 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)13 Vector (org.bukkit.util.Vector)13 IOException (java.io.IOException)7 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)6 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)5