Java Code Examples for org.spongepowered.api.event.block.ChangeBlockEvent#Pre
The following examples show how to use
org.spongepowered.api.event.block.ChangeBlockEvent#Pre .
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: BuildPermListener.java From Nations with MIT License | 6 votes |
@Listener(order=Order.FIRST, beforeModifications = true) public void onPlayerChangeBlock(ChangeBlockEvent.Pre event, @First Player player) { if (player.hasPermission("nations.admin.bypass.perm.build")) { return; } if (Utils.isFakePlayer(event)) { return; } for (Location<World> loc : event.getLocations()) { if (ConfigHandler.getNode("worlds").getNode(loc.getExtent().getName()).getNode("enabled").getBoolean() && !ConfigHandler.isWhitelisted("break", loc.getBlock().getId()) && !DataHandler.getPerm("build", player.getUniqueId(), loc)) { event.setCancelled(true); try { player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD)); } catch (Exception e) {} return; } } }
Example 2
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onFlow(ChangeBlockEvent.Pre e, @First LocatableBlock locatable) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockListener - onFlow event"); BlockState sourceState = locatable.getBlockState(); //liquid check MatterProperty mat = sourceState.getProperty(MatterProperty.class).orElse(null); if (mat != null && mat.getValue() == MatterProperty.Matter.LIQUID) { e.getLocations().forEach(loc -> { Region r = RedProtect.get().rm.getTopRegion(loc, this.getClass().getName()); if (r == null) { boolean flow = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.liquid_flow; boolean allowWater = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.water_flow; boolean allowLava = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.lava_flow; if (!flow) e.setCancelled(true); if (!allowWater && (loc.getBlockType() == BlockTypes.WATER || loc.getBlockType() == BlockTypes.FLOWING_WATER)) e.setCancelled(true); if (!allowLava && (loc.getBlockType() == BlockTypes.LAVA || loc.getBlockType() == BlockTypes.FLOWING_LAVA)) e.setCancelled(true); } }); } }
Example 3
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onFlow(ChangeBlockEvent.Pre e, @First LocatableBlock locatable) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockListener - onFlow event"); BlockState sourceState = locatable.getBlockState(); //liquid check MatterProperty mat = sourceState.getProperty(MatterProperty.class).orElse(null); if (mat != null && mat.getValue() == MatterProperty.Matter.LIQUID) { e.getLocations().forEach(loc -> { Region r = RedProtect.get().rm.getTopRegion(loc, this.getClass().getName()); if (r != null && !r.canFlow()) { e.setCancelled(true); } }); } }
Example 4
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 5
Source File: JailListener.java From UltimateCore with MIT License | 5 votes |
@Listener public void onBlockChange(ChangeBlockEvent event, @First Player p) { if (event instanceof ChangeBlockEvent.Pre || event instanceof ChangeBlockEvent.Post) { return; } UltimateUser up = UltimateCore.get().getUserService().getUser(p); if (up.get(JailKeys.JAIL).isPresent()) { if (!Modules.JAIL.get().getConfig().get().get().getNode("allow-block-modify").getBoolean()) { JailData data = up.get(JailKeys.JAIL).get(); event.setCancelled(true); Messages.send(p, "jail.event.block", "%time%", (data.getEndtime() == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.formatDateDiff(data.getEndtime())), "%reason%", data.getReason()); } } }
Example 6
Source File: RPBlockListener7.java From RedProtect with GNU General Public License v3.0 | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPiston(ChangeBlockEvent.Pre e) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "RPBlockListener7 - Is onChangeBlock event"); EventContext context = e.getContext(); Cause cause = e.getCause(); LocatableBlock sourceLoc = cause.first(LocatableBlock.class).orElse(null); if (sourceLoc != null) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "sourceLoc"); if (context.containsKey(EventContextKeys.PISTON_EXTEND) || context.containsKey(EventContextKeys.PISTON_RETRACT)) { if (RedProtect.get().config.configRoot().performance.disable_PistonEvent_handler) { return; } Region r = RedProtect.get().rm.getTopRegion(sourceLoc.getLocation(), this.getClass().getName()); for (Location<World> pistonLoc : e.getLocations()) { Region targetr = RedProtect.get().rm.getTopRegion(pistonLoc, this.getClass().getName()); boolean antih = RedProtect.get().config.configRoot().region_settings.anti_hopper; RedProtect.get().logger.debug(LogLevel.BLOCKS, "getLocations"); if (targetr != null && (r == null || r != targetr)) { if (cause.first(Player.class).isPresent() && targetr.canBuild(cause.first(Player.class).get())) { continue; } if (antih) { BlockSnapshot ib = e.getLocations().get(0).add(0, 1, 0).createSnapshot(); if (cont.canWorldBreak(ib) || cont.canWorldBreak(e.getLocations().get(0).createSnapshot())) { continue; } } e.setCancelled(true); break; } } } } }
Example 7
Source File: RPBlockListener8.java From RedProtect with GNU General Public License v3.0 | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPiston(ChangeBlockEvent.Pre e) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "RPBlockListener8 - Is onChangeBlock event"); EventContext context = e.getContext(); Cause cause = e.getCause(); LocatableBlock sourceLoc = cause.first(LocatableBlock.class).orElse(null); if (sourceLoc != null) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "sourceLoc"); if (context.containsKey(EventContextKeys.PISTON_EXTEND) || context.containsKey(EventContextKeys.PISTON_RETRACT)) { if (RedProtect.get().config.configRoot().performance.disable_PistonEvent_handler) { return; } Region r = RedProtect.get().rm.getTopRegion(sourceLoc.getLocation(), this.getClass().getName()); for (Location<World> pistonLoc : e.getLocations()) { Region targetr = RedProtect.get().rm.getTopRegion(pistonLoc, this.getClass().getName()); boolean antih = RedProtect.get().config.configRoot().region_settings.anti_hopper; RedProtect.get().logger.debug(LogLevel.BLOCKS, "getLocations"); if (targetr != null && (r == null || r != targetr)) { if (cause.first(Player.class).isPresent() && targetr.canBuild(cause.first(Player.class).get())) { continue; } if (antih) { BlockSnapshot ib = e.getLocations().get(0).add(0, 1, 0).createSnapshot(); if (cont.canWorldBreak(ib) || cont.canWorldBreak(e.getLocations().get(0).createSnapshot())) { continue; } } e.setCancelled(true); break; } } } } }