Java Code Examples for org.spongepowered.api.event.block.ChangeBlockEvent#setCancelled()

The following examples show how to use org.spongepowered.api.event.block.ChangeBlockEvent#setCancelled() . 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: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener
public void onIceForm(ChangeBlockEvent e) {
    if (e.getTransactions().isEmpty()) return;

    Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getFinal().getLocation().get(), this.getClass().getName());

    if (r == null && (e.getTransactions().get(0).getOriginal().getState().getType().equals(BlockTypes.ICE) ||
            e.getTransactions().get(0).getOriginal().getState().getType().equals(BlockTypes.FROSTED_ICE))) {
        if (e.getCause().containsType(Player.class)) {
            if (!RedProtect.get().config.globalFlagsRoot().worlds.get(e.getTransactions().get(0).getFinal().getLocation().get().getExtent().getName()).iceform_by.player) {
                e.setCancelled(true);
            }
        } else if (!RedProtect.get().config.globalFlagsRoot().worlds.get(e.getTransactions().get(0).getFinal().getLocation().get().getExtent().getName()).iceform_by.entity) {
            e.setCancelled(true);
        }
    }
}
 
Example 2
Source File: ChangeBlockListener.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Listener
public void onPlayerChangeBlock(ChangeBlockEvent event, @Root Player player)
{
	if(EssentialCmds.jailedPlayers.contains(player.getUniqueId()))
	{
		player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You may not modify blocks while in jail!"));
		event.setCancelled(true);
	}
}
 
Example 3
Source File: JailListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@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 4
Source File: ChangeBlockListener.java    From Prism with MIT License 4 votes vote down vote up
/**
 * Listens to the base change block event.
 *
 * @param event ChangeBlockEvent
 */
@Listener(order = Order.POST)
public void onChangeBlock(ChangeBlockEvent event) {

    if (event.getCause().allOf(PluginContainer.class).stream().map(PluginContainer::getId).anyMatch(id ->
            Prism.getInstance().getConfig().getGeneralCategory().getBlacklist().contains(id))) {
        // Don't do anything
        return;
    }

    if (event.getCause().first(Player.class).map(Player::getUniqueId).map(Prism.getInstance().getActiveWands()::contains).orElse(false)) {
        // Cancel and exit event here, not supposed to place/track a block with an active wand.
        event.setCancelled(true);
        return;
    }

    if (event.getTransactions().isEmpty()
            || (!Prism.getInstance().getConfig().getEventCategory().isBlockBreak()
            && !Prism.getInstance().getConfig().getEventCategory().isBlockDecay()
            && !Prism.getInstance().getConfig().getEventCategory().isBlockGrow()
            && !Prism.getInstance().getConfig().getEventCategory().isBlockPlace())) {
        return;
    }

    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        if (!transaction.isValid() || !transaction.getOriginal().getLocation().isPresent()) {
            continue;
        }

        BlockType originalBlockType = transaction.getOriginal().getState().getType();
        BlockType finalBlockType = transaction.getFinal().getState().getType();

        PrismRecord.EventBuilder eventBuilder = PrismRecord.create()
                .source(event.getCause())
                .blockOriginal(transaction.getOriginal())
                .blockReplacement(transaction.getFinal())
                .location(transaction.getOriginal().getLocation().get());

        if (event instanceof ChangeBlockEvent.Break) {
            if (!Prism.getInstance().getConfig().getEventCategory().isBlockBreak()
                    || BlockUtil.rejectBreakCombination(originalBlockType, finalBlockType)
                    || EventUtil.rejectBreakEventIdentity(originalBlockType, finalBlockType, event.getCause())) {
                continue;
            }

            eventBuilder
                    .event(PrismEvents.BLOCK_BREAK)
                    .target(originalBlockType.getId().replace("_", " "))
                    .buildAndSave();
        } else if (event instanceof ChangeBlockEvent.Decay) {
            if (!Prism.getInstance().getConfig().getEventCategory().isBlockDecay()) {
                continue;
            }

            eventBuilder
                    .event(PrismEvents.BLOCK_DECAY)
                    .target(originalBlockType.getId().replace("_", " "))
                    .buildAndSave();
        } else if (event instanceof ChangeBlockEvent.Grow) {
            if (!Prism.getInstance().getConfig().getEventCategory().isBlockGrow()) {
                continue;
            }

            eventBuilder
                    .event(PrismEvents.BLOCK_GROW)
                    .target(finalBlockType.getId().replace("_", " "))
                    .buildAndSave();
        } else if (event instanceof ChangeBlockEvent.Place) {
            if (!Prism.getInstance().getConfig().getEventCategory().isBlockPlace()
                    || BlockUtil.rejectPlaceCombination(originalBlockType, finalBlockType)
                    || EventUtil.rejectPlaceEventIdentity(originalBlockType, finalBlockType, event.getCause())) {
                continue;
            }

            eventBuilder
                    .event(PrismEvents.BLOCK_PLACE)
                    .target(finalBlockType.getId().replace("_", " "))
                    .buildAndSave();
        }
    }
}