org.spongepowered.api.block.BlockSnapshot Java Examples
The following examples show how to use
org.spongepowered.api.block.BlockSnapshot.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Visualization.java From GriefPrevention with MIT License | 6 votes |
public void addLeftLine(World world, int y, BlockType cornerMaterial, BlockType accentMaterial) { BlockSnapshot leftVisualBlock1 = snapshotBuilder.from(new Location<World>(world, this.smallx, y, this.smallz)).blockState(cornerMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(leftVisualBlock1.getLocation().get().createSnapshot(), leftVisualBlock1)); this.corners.add(leftVisualBlock1.getPosition()); BlockSnapshot leftVisualBlock2 = snapshotBuilder.from(new Location<World>(world, this.smallx, y, this.smallz + 1)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(leftVisualBlock2.getLocation().get().createSnapshot(), leftVisualBlock2)); BlockSnapshot leftVisualBlock3 = snapshotBuilder.from(new Location<World>(world, this.smallx, y, this.bigz - 1)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(leftVisualBlock3.getLocation().get().createSnapshot(), leftVisualBlock3)); if (STEP != 0) { for (int z = this.smallz + STEP; z < this.bigz - STEP / 2; z += STEP) { if ((y != 0 && z >= this.smallz && z <= this.bigz) || (z > this.minz && z < this.maxz)) { BlockSnapshot visualBlock = snapshotBuilder.from(new Location<World>(world, this.smallx, y, z)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(visualBlock.getLocation().get().createSnapshot(), visualBlock)); } } } }
Example #2
Source File: PlayerInteractListener.java From EagleFactions with MIT License | 6 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onBlockInteract(final InteractBlockEvent event, @Root final Player player) { //If AIR or NONE then return if (event.getTargetBlock() == BlockSnapshot.NONE || event.getTargetBlock().getState().getType() == BlockTypes.AIR) return; final Optional<Location<World>> optionalLocation = event.getTargetBlock().getLocation(); if (!optionalLocation.isPresent()) return; final Location<World> blockLocation = optionalLocation.get(); final ProtectionResult protectionResult = super.getPlugin().getProtectionManager().canInteractWithBlock(blockLocation, player, true); if (!protectionResult.hasAccess()) { event.setCancelled(true); return; } else { if(event instanceof InteractBlockEvent.Secondary && protectionResult.isEagleFeather()) removeEagleFeather(player); } }
Example #3
Source File: ExplosionListener.java From Nations with MIT License | 6 votes |
@Listener(order=Order.FIRST, beforeModifications = true) public void onExplosion(ExplosionEvent.Post event) { if (!ConfigHandler.getNode("worlds").getNode(event.getTargetWorld().getName()).getNode("enabled").getBoolean()) { return; } if (event.getTransactions().size() > 100) { event.setCancelled(true); } for (Transaction<BlockSnapshot> transaction : event.getTransactions()) { BlockSnapshot blockSnapshot = transaction.getOriginal(); if (blockSnapshot.getLocation().isPresent() && !DataHandler.getFlag("explosions", blockSnapshot.getLocation().get())) { transaction.setValid(false); } } }
Example #4
Source File: ConfigManager.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public boolean needClaimToBuild(Player p, BlockSnapshot b) { if (p.hasPermission("redprotect.need-claim-to-build.bypass")) return false; boolean bool = root.needed_claim_to_build.worlds.contains(p.getWorld().getName()); if (bool) { if (b != null && root.needed_claim_to_build.allow_only_protections_blocks && (getWorldClaimType(p.getWorld().getName()).equalsIgnoreCase("BLOCK") || getWorldClaimType(p.getWorld().getName()).equalsIgnoreCase("BOTH"))) { boolean blocks = b.getState().getId().contains(root.region_settings.block_id) || root.needed_claim_to_build.allow_break_blocks.stream().anyMatch(str -> str.equalsIgnoreCase(b.getState().getId())); if (!blocks) { RedProtect.get().lang.sendMessage(p, "need.claim.blockids"); } else { return false; } } RedProtect.get().lang.sendMessage(p, "need.claim.tobuild"); } return bool; }
Example #5
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onBlockBreakGlobal(ChangeBlockEvent.Break e, @Root Player p) { RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is BlockBreakEvent event! Cancelled? " + false); BlockSnapshot bt = e.getTransactions().get(0).getOriginal(); Region r = RedProtect.get().rm.getTopRegion(bt.getLocation().get(), this.getClass().getName()); if (r != null) { return; } if (!RedProtect.get().getUtil().canBuildNear(p, bt.getLocation().get())) { e.setCancelled(true); return; } if (!bypassBuild(p, bt, 2)) { e.setCancelled(true); RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Can't Break!"); } }
Example #6
Source File: SignListener.java From UltimateCore with MIT License | 6 votes |
@Listener public void onSignDestroy(ChangeBlockEvent.Break event, @Root Player p) { for (Transaction<BlockSnapshot> transaction : event.getTransactions()) { BlockSnapshot snapshot = transaction.getOriginal(); if (snapshot.supports(Keys.SIGN_LINES) && snapshot.getLocation().isPresent()) { List<Text> texts = snapshot.get(Keys.SIGN_LINES).get(); //Checking for sign contents for (UCSign usign : UltimateCore.get().getSignService().get().getRegisteredSigns()) { if (texts.get(0).toPlain().equalsIgnoreCase("[" + usign.getIdentifier() + "]")) { if (!p.hasPermission(usign.getDestroyPermission().get())) { Messages.send(p, "core.nopermissions"); } SignDestroyEvent cevent = new SignDestroyEvent(usign, snapshot.getLocation().get(), Cause.builder().append(UltimateCore.getContainer()).append(p).build(EventContext.builder().build())); Sponge.getEventManager().post(cevent); if (!cevent.isCancelled() && usign.onDestroy(p, event, texts)) { Messages.send(p, "sign.destroy", "%sign%", usign.getIdentifier()); } } } } } }
Example #7
Source File: Visualization.java From GriefPrevention with MIT License | 6 votes |
public void addTopLine(World world, int y, BlockType cornerMaterial, BlockType accentMaterial) { BlockSnapshot topVisualBlock1 = snapshotBuilder.from(new Location<World>(world, this.smallx, y, this.bigz)).blockState(cornerMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(topVisualBlock1.getLocation().get().createSnapshot(), topVisualBlock1)); this.corners.add(topVisualBlock1.getPosition()); BlockSnapshot topVisualBlock2 = snapshotBuilder.from(new Location<World>(world, this.smallx + 1, y, this.bigz)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(topVisualBlock2.getLocation().get().createSnapshot(), topVisualBlock2)); BlockSnapshot topVisualBlock3 = snapshotBuilder.from(new Location<World>(world, this.bigx - 1, y, this.bigz)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(topVisualBlock3.getLocation().get().createSnapshot(), topVisualBlock3)); if (STEP != 0) { for (int x = this.smallx + STEP; x < this.bigx - STEP / 2; x += STEP) { if ((y != 0 && x >= this.smallx && x <= this.bigx) || (x > this.minx && x < this.maxx)) { BlockSnapshot visualBlock = snapshotBuilder.from(new Location<World>(world, x, y, this.bigz)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(visualBlock.getLocation().get().createSnapshot(), visualBlock)); } } } }
Example #8
Source File: Visualization.java From GriefPrevention with MIT License | 6 votes |
public void addBottomLine(World world, int y, BlockType cornerMaterial, BlockType accentMaterial) { BlockSnapshot bottomVisualBlock1 = this.snapshotBuilder.from(new Location<World>(world, this.smallx + 1, y, this.smallz)).blockState(accentMaterial.getDefaultState()).build(); this.newElements.add(new Transaction<BlockSnapshot>(bottomVisualBlock1.getLocation().get().createSnapshot(), bottomVisualBlock1)); this.corners.add(bottomVisualBlock1.getPosition()); BlockSnapshot bottomVisualBlock2 = this.snapshotBuilder.from(new Location<World>(world, this.bigx - 1, y, this.smallz)).blockState(accentMaterial.getDefaultState()).build(); this.newElements.add(new Transaction<BlockSnapshot>(bottomVisualBlock2.getLocation().get().createSnapshot(), bottomVisualBlock2)); if (STEP != 0) { for (int x = this.smallx + STEP; x < this.bigx - STEP / 2; x += STEP) { if ((y != 0 && x >= this.smallx && x <= this.bigx) || (x > this.minx && x < this.maxx)) { BlockSnapshot visualBlock = this.snapshotBuilder.from(new Location<World>(world, x, y, this.smallz)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(visualBlock.getLocation().get().createSnapshot(), visualBlock)); } } } }
Example #9
Source File: Visualization.java From GriefPrevention with MIT License | 6 votes |
public void addRightLine(World world, int y, BlockType cornerMaterial, BlockType accentMaterial) { BlockSnapshot rightVisualBlock1 = snapshotBuilder.from(new Location<World>(world, this.bigx, y, this.smallz)).blockState(cornerMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(rightVisualBlock1.getLocation().get().createSnapshot(), rightVisualBlock1)); this.corners.add(rightVisualBlock1.getPosition()); BlockSnapshot rightVisualBlock2 = snapshotBuilder.from(new Location<World>(world, this.bigx, y, this.smallz + 1)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(rightVisualBlock2.getLocation().get().createSnapshot(), rightVisualBlock2)); if (STEP != 0) { for (int z = this.smallz + STEP; z < this.bigz - STEP / 2; z += STEP) { if ((y != 0 && z >= this.smallz && z <= this.bigz) || (z > this.minz && z < this.maxz)) { BlockSnapshot visualBlock = snapshotBuilder.from(new Location<World>(world, this.bigx, y, z)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(visualBlock.getLocation().get().createSnapshot(), visualBlock)); } } } BlockSnapshot rightVisualBlock3 = snapshotBuilder.from(new Location<World>(world, this.bigx, y, this.bigz - 1)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(rightVisualBlock3.getLocation().get().createSnapshot(), rightVisualBlock3)); BlockSnapshot rightVisualBlock4 = snapshotBuilder.from(new Location<World>(world, this.bigx, y, this.bigz)).blockState(cornerMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(rightVisualBlock4.getLocation().get().createSnapshot(), rightVisualBlock4)); this.corners.add(rightVisualBlock4.getPosition()); }
Example #10
Source File: BlacklistListener.java From EssentialCmds with MIT License | 6 votes |
@Listener public void onPlaceBlock(ChangeBlockEvent.Place event, @Root Player player) { if (!player.hasPermission("essentialcmds.blacklist.bypass")) { for (Transaction<BlockSnapshot> transaction : event.getTransactions()) { if (Utils.getBlacklistItems().contains(transaction.getFinal().getState().getType().getId())) { if (Utils.areBlacklistMsgsEnabled()) player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().getState().getType().getId(), TextColors.RED, " has been confiscated as it is blacklisted.")); event.setCancelled(true); } } } }
Example #11
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onFireSpread(ChangeBlockEvent.Break e, @First LocatableBlock locatable) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onBlockBreakGeneric event"); BlockState sourceState = locatable.getBlockState(); if (sourceState.getType() == BlockTypes.FIRE) { BlockSnapshot b = e.getTransactions().get(0).getOriginal(); boolean fireDamage = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).fire_block_damage; if (!fireDamage && b.getState().getType() != BlockTypes.FIRE) { Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get(), this.getClass().getName()); if (r == null) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "Tryed to break from FIRE!"); e.setCancelled(true); } } } }
Example #12
Source File: PrismRecord.java From Prism with MIT License | 6 votes |
/** * Removes unnecessary/duplicate data from a BlockSnapshot's DataContainer. * * @param block {@link BlockSnapshot BlockSnapshot} * @return Formatted {@link DataContainer DataContainer} */ private DataContainer formatBlockDataContainer(BlockSnapshot block) { Preconditions.checkNotNull(block); Preconditions.checkNotNull(block.getState(), "Missing BlockState: " + block.toString()); DataContainer blockData = block.toContainer(); blockData.remove(DataQueries.Position); blockData.remove(DataQueries.WorldUuid); DataView unsafeData = blockData.getObject(DataQueries.UnsafeData, DataView.class).orElse(null); if (unsafeData != null) { unsafeData.remove(DataQueries.X); unsafeData.remove(DataQueries.Y); unsafeData.remove(DataQueries.Z); blockData.set(DataQueries.UnsafeData, unsafeData); } return blockData; }
Example #13
Source File: RestoreNatureProcessingTask.java From GriefPrevention with MIT License | 6 votes |
private int highestY(int x, int z, boolean ignoreLeaves) { int y; for (y = snapshots[0].length - 1; y > 0; y--) { BlockSnapshot block = this.snapshots[x][y][z]; if (block.getState().getType() != BlockTypes.AIR && !(ignoreLeaves && block.getState().getType() == BlockTypes.SNOW) && !(ignoreLeaves && block.getState().getType() == BlockTypes.LEAVES) && !(block.getState().getType() == BlockTypes.WATER) && !(block.getState().getType() == BlockTypes.FLOWING_WATER) && !(block.getState().getType() == BlockTypes.LAVA) && !(block.getState().getType() == BlockTypes.FLOWING_LAVA)) { return y; } } return y; }
Example #14
Source File: GPPlayerData.java From GriefPrevention with MIT License | 6 votes |
public void revertActiveVisual(Player player) { if (this.visualRevertTask != null) { this.visualRevertTask.cancel(); this.visualRevertTask = null; } if (this.visualClaimId != null) { GPClaim claim = (GPClaim) GriefPreventionPlugin.instance.dataStore.getClaim(this.worldProperties, this.visualClaimId); if (claim != null) { claim.playersWatching.remove(this.playerID); } } this.visualClaimId = null; if (this.visualBlocks == null || !player.getWorld().equals(this.visualBlocks.get(0).getFinal().getLocation().get().getExtent())) { return; } for (int i = 0; i < this.visualBlocks.size(); i++) { BlockSnapshot snapshot = this.visualBlocks.get(i).getOriginal(); player.sendBlockChange(snapshot.getPosition(), snapshot.getState()); } }
Example #15
Source File: RestoreNatureProcessingTask.java From GriefPrevention with MIT License | 6 votes |
private void coverSurfaceStone() { for (int x = 1; x < snapshots.length - 1; x++) { for (int z = 1; z < snapshots[0][0].length - 1; z++) { int y = this.highestY(x, z, true); BlockSnapshot block = snapshots[x][y][z]; if (block.getState().getType() == BlockTypes.STONE || block.getState().getType() == BlockTypes.GRAVEL || block.getState().getType() == BlockTypes.FARMLAND || block.getState().getType() == BlockTypes.DIRT || block.getState().getType() == BlockTypes.SANDSTONE) { if (this.biome == BiomeTypes.DESERT || this.biome == BiomeTypes.DESERT_HILLS || this.biome == BiomeTypes.BEACH) { this.snapshots[x][y][z] = this.snapshots[x][y][z].withState(BlockTypes.SAND.getDefaultState()); } else { this.snapshots[x][y][z] = this.snapshots[x][y][z].withState(BlockTypes.GRASS.getDefaultState()); } } } } }
Example #16
Source File: RestoreNatureProcessingTask.java From GriefPrevention with MIT License | 6 votes |
private void removeHanging() { int miny = this.miny; if (miny < 1) { miny = 1; } for (int x = 1; x < snapshots.length - 1; x++) { for (int z = 1; z < snapshots[0][0].length - 1; z++) { for (int y = miny; y < snapshots[0].length - 1; y++) { BlockSnapshot block = snapshots[x][y][z]; BlockSnapshot underBlock = snapshots[x][y - 1][z]; if (underBlock.getState().getType() == BlockTypes.AIR || underBlock.getState().getType() == BlockTypes.WATER || underBlock.getState().getType() == BlockTypes.LAVA || underBlock.getState().getType() == BlockTypes.LEAVES) { if (this.notAllowedToHang.contains(block.getState().getType())) { snapshots[x][y][z] = block.withState(BlockTypes.AIR.getDefaultState()); } } } } } }
Example #17
Source File: RestoreNatureProcessingTask.java From GriefPrevention with MIT License | 6 votes |
private void removePlayerLeaves() { if (this.seaLevel < 1) { return; } for (int x = 1; x < snapshots.length - 1; x++) { for (int z = 1; z < snapshots[0][0].length - 1; z++) { for (int y = this.seaLevel - 1; y < snapshots[0].length; y++) { // note: see minecraft wiki data values for leaves BlockSnapshot block = snapshots[x][y][z]; if (block.getState().getType() == BlockTypes.LEAVES && (BlockUtils.getBlockStateMeta(block.getState()) & 0x4) != 0) { snapshots[x][y][z] = block.withState(BlockTypes.AIR.getDefaultState()); } } } } }
Example #18
Source File: RestoreNatureProcessingTask.java From GriefPrevention with MIT License | 6 votes |
private void removePlayerBlocks() { int miny = this.miny; if (miny < 1) { miny = 1; } // remove all player blocks for (int x = 1; x < snapshots.length - 1; x++) { for (int z = 1; z < snapshots[0][0].length - 1; z++) { for (int y = miny; y < snapshots[0].length - 1; y++) { BlockSnapshot block = snapshots[x][y][z]; if (this.playerBlocks.contains(block.getState().getType())) { snapshots[x][y][z] = block.withState(BlockTypes.AIR.getDefaultState()); } } } } }
Example #19
Source File: DoorManager.java From RedProtect with GNU General Public License v3.0 | 5 votes |
public static void ChangeDoor(BlockSnapshot b, Region r) { if ((!r.flagExists("smart-door") && !RedProtect.get().config.configRoot().flags.get("smart-door")) || !r.getFlagBool("smart-door")) { return; } Location<World> loc = b.getLocation().get(); World w = loc.getExtent(); if (isDoor(b)) { boolean iron = b.getState().getType() == BlockTypes.IRON_DOOR; if (iron) { changeDoorState(b); if (getDoorState(b)) { w.playSound(SoundTypes.BLOCK_IRON_DOOR_OPEN, loc.getPosition(), 1); } else { w.playSound(SoundTypes.BLOCK_IRON_DOOR_CLOSE, loc.getPosition(), 1); } } if (loc.getRelative(Direction.DOWN).getBlock().getType() == b.getState().getType() && loc.get(Keys.PORTION_TYPE).get() == PortionTypes.TOP) { loc = loc.getRelative(Direction.DOWN); } //check side block if is door BlockSnapshot[] block = new BlockSnapshot[4]; block[0] = loc.getRelative(Direction.EAST).createSnapshot(); block[1] = loc.getRelative(Direction.WEST).createSnapshot(); block[2] = loc.getRelative(Direction.NORTH).createSnapshot(); block[3] = loc.getRelative(Direction.SOUTH).createSnapshot(); for (BlockSnapshot b2 : block) { if (b.getState().getType() == b2.getState().getType()) { changeDoorState(b2); break; } } } }
Example #20
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onBlockBurnGlobal(ChangeBlockEvent.Modify e) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onBlockBurnGlobal event"); Transaction<BlockSnapshot> b = e.getTransactions().get(0); if (e.getCause().first(Monster.class).isPresent()) { Region r = RedProtect.get().rm.getTopRegion(b.getOriginal().getLocation().get(), this.getClass().getName()); if (r == null && !RedProtect.get().config.globalFlagsRoot().worlds.get(b.getOriginal().getLocation().get().getExtent().getName()).use_minecart) { e.setCancelled(true); } } }
Example #21
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onInteractPrimBlock(InteractBlockEvent.Primary event, @First Player p) { BlockSnapshot b = event.getTargetBlock(); RedProtect.get().logger.debug(LogLevel.PLAYER, "BlockListener - Is InteractBlockEvent.Primary event"); if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) { if (b.getState().getType().getName().contains("sign") && !cont.canBreak(p, b)) { RedProtect.get().lang.sendMessage(p, "blocklistener.container.breakinside"); event.setCancelled(true); } } }
Example #22
Source File: EntityListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void WitherBlockBreak(ChangeBlockEvent.Break event, @First Entity e) { if (e instanceof Monster) { BlockSnapshot b = event.getTransactions().get(0).getOriginal(); RedProtect.get().logger.debug(LogLevel.ENTITY, "EntityListener - Is EntityChangeBlockEvent event! Block " + b.getState().getType().getName()); Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get(), this.getClass().getName()); if (!cont.canWorldBreak(b)) { event.setCancelled(true); return; } if (r != null && !r.canMobLoot()) { event.setCancelled(true); } } }
Example #23
Source File: RestoreNatureExecutionTask.java From GriefPrevention with MIT License | 5 votes |
public RestoreNatureExecutionTask(BlockSnapshot[][][] snapshots, int miny, Location<World> lesserCorner, Location<World> greaterCorner, Player player) { this.snapshots = snapshots; this.miny = miny; this.lesserCorner = lesserCorner; this.greaterCorner = greaterCorner; this.player = player; }
Example #24
Source File: VisualizationApplicationTask.java From GriefPrevention with MIT License | 5 votes |
@Override public void run() { if (this.playerData.visualBlocks != null) { if (this.resetActive) { this.playerData.revertActiveVisual(this.player); } } for (int i = 0; i < this.visualization.elements.size(); i++) { BlockSnapshot snapshot = this.visualization.elements.get(i).getFinal(); this.player.sendBlockChange(snapshot.getPosition(), snapshot.getState()); } // remember the visualization applied to this player for later (so it can be inexpensively reverted) if (this.visualization.getClaim() != null) { this.playerData.visualClaimId = this.visualization.getClaim().id; this.visualization.getClaim().playersWatching.add(this.player.getUniqueId()); } if (this.playerData.visualBlocks == null) { this.playerData.visualBlocks = new ArrayList<>(this.visualization.elements); } else { this.playerData.visualBlocks.addAll(this.visualization.elements); } if (this.playerData.visualRevertTask != null) { this.playerData.visualRevertTask.cancel(); this.playerData.visualRevertTask = Sponge.getGame().getScheduler().createTaskBuilder().async().delay(1, TimeUnit.MINUTES) .execute(new VisualizationReversionTask(this.player, this.playerData)).submit(GriefPreventionPlugin.instance); } else { // schedule automatic visualization reversion in 60 seconds. // only create revert task if not resizing/starting a claim if (playerData.lastShovelLocation == null) { this.playerData.visualRevertTask = Sponge.getGame().getScheduler().createTaskBuilder().async().delay(1, TimeUnit.MINUTES) .execute(new VisualizationReversionTask(this.player, this.playerData)).submit(GriefPreventionPlugin.instance); } } }
Example #25
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
/** * @param p - Player * @param b - Block * @param fat - 1 = Place Block | 2 = Break Block * @return Boolean - Can build or not. */ private boolean bypassBuild(Player p, BlockSnapshot b, int fat) { if (p.hasPermission("redprotect.bypass.world")) return true; if (RedProtect.get().config.needClaimToBuild(p, b)) return false; return (fat == 1 && canPlaceList(p.getWorld(), b.getState().getType().getName())) || (fat == 2 && canBreakList(p.getWorld(), b.getState().getType().getName())) || RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).build; }
Example #26
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onDecay(ChangeBlockEvent.Decay e) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onDecay event"); BlockSnapshot bfrom = e.getTransactions().get(0).getOriginal(); boolean allowDecay = RedProtect.get().config.globalFlagsRoot().worlds.get(bfrom.getLocation().get().getExtent().getName()).allow_changes_of.leaves_decay; Region r = RedProtect.get().rm.getTopRegion(bfrom.getLocation().get(), this.getClass().getName()); if (r == null && !allowDecay) { e.setCancelled(true); } }
Example #27
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onBlockPlace(ChangeBlockEvent.Place e, @Root Player p) { RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is ChangeBlockEvent event! Cancelled? " + false); BlockSnapshot b = e.getTransactions().get(0).getFinal(); ItemType item = RedProtect.get().getVersionHelper().getItemInHand(p); Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getOriginal().getLocation().get(), this.getClass().getName()); if (r != null) { return; } if (!RedProtect.get().getUtil().canBuildNear(p, b.getLocation().get())) { e.setCancelled(true); return; } if (item.getName().contains("minecart") || item.getName().contains("boat")) { if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).use_minecart && !p.hasPermission("redprotect.world.bypass")) { e.setCancelled(true); RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Can't place minecart/boat!"); } } else { if (!bypassBuild(p, b, 1)) { e.setCancelled(true); RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Can't Build!"); } } }
Example #28
Source File: PrismRecord.java From Prism with MIT License | 5 votes |
/** * Helper method for writing original BlockSnapshot container data. * * @param block The original BlockSnapshot to write */ public EventBuilder blockOriginal(BlockSnapshot block) { Preconditions.checkNotNull(block); DataUtil.writeToDataView(getDataContainer(), DataQueries.OriginalBlock, formatBlockDataContainer(block)); return this; }
Example #29
Source File: EventForwarder.java From BlueMap with MIT License | 5 votes |
@Listener(order = Order.POST) @Exclude({ChangeBlockEvent.Post.class, ChangeBlockEvent.Pre.class, ChangeBlockEvent.Modify.class}) public void onBlockChange(ChangeBlockEvent evt) { for (Transaction<BlockSnapshot> tr : evt.getTransactions()) { if(!tr.isValid()) continue; Optional<Location<org.spongepowered.api.world.World>> ow = tr.getFinal().getLocation(); if (ow.isPresent()) { listener.onBlockChange(ow.get().getExtent().getUniqueId(), ow.get().getPosition().toInt()); } } }
Example #30
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onBlockGrow(ChangeBlockEvent.Grow e) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is ChangeBlockEvent.Grow event"); BlockSnapshot b = e.getTransactions().get(0).getOriginal(); Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get(), this.getClass().getName()); if (r == null && !RedProtect.get().config.globalFlagsRoot().worlds.get(b.getLocation().get().getExtent().getName()).block_grow) { e.setCancelled(true); RedProtect.get().logger.debug(LogLevel.BLOCKS, "Cancel grow " + b.getState().getName()); } }