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;
}
}
}
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());
}
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);
}
}
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;
}
}
}
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));
}
Aggregations