Search in sources :

Example 6 with Cancellable

use of org.bukkit.event.Cancellable in project Conquer by xXAndrew28Xx.

the class SFEventForwarder method onFactionCreate.

@EventHandler
public void onFactionCreate(FactionCreateEvent event) {
    ConquerFactionCreateEvent forwardEvent = new ConquerFactionCreateEvent(SFPlayer.get(plugin, event.getFPlayer()), event.getFactionTag());
    callEvent(forwardEvent);
    if (forwardEvent.isCancelled()) {
        if (event instanceof Cancellable) {
            ((Cancellable) event).setCancelled(true);
        }
    }
}
Also used : Cancellable(org.bukkit.event.Cancellable) ConquerFactionCreateEvent(me.andrew28.addons.conquer.api.events.ConquerFactionCreateEvent) EventHandler(org.bukkit.event.EventHandler)

Example 7 with Cancellable

use of org.bukkit.event.Cancellable in project Conquer by xXAndrew28Xx.

the class FOEventForwarder method onUnclaimAll.

@EventHandler
public void onUnclaimAll(LandUnclaimAllEvent event) {
    ConquerUnclaimAllEvent forwardEvent = new ConquerUnclaimAllEvent(FOFaction.get(plugin, event.getFaction()), FOPlayer.get(plugin, event.getFPlayer()));
    callEvent(forwardEvent);
    if (forwardEvent.isCancelled()) {
        // In some versions of FactionsOne, it is cancelled, some others, it's not
        if (event instanceof Cancellable) {
            ((Cancellable) event).setCancelled(true);
        }
    }
}
Also used : Cancellable(org.bukkit.event.Cancellable) ConquerUnclaimAllEvent(me.andrew28.addons.conquer.api.events.ConquerUnclaimAllEvent) EventHandler(org.bukkit.event.EventHandler)

Example 8 with Cancellable

use of org.bukkit.event.Cancellable in project TriggerReactor by wysohn.

the class JavaPluginBridge method createInterrupter.

@Override
public ProcessInterrupter createInterrupter(Object e, Interpreter interpreter, Map<UUID, Long> cooldowns) {
    return new ProcessInterrupter() {

        @Override
        public boolean onNodeProcess(Node node) {
            if (interpreter.isCooldown() && e instanceof PlayerEvent) {
                Player player = ((PlayerEvent) e).getPlayer();
                UUID uuid = player.getUniqueId();
                cooldowns.put(uuid, interpreter.getCooldownEnd());
            }
            return false;
        }

        @Override
        public boolean onCommand(Object context, String command, Object[] args) {
            if ("CALL".equals(command)) {
                if (args.length < 1)
                    throw new RuntimeException("Need parameter [String] or [String, boolean]");
                if (args[0] instanceof String) {
                    Trigger trigger = getNamedTriggerManager().getTriggerForName((String) args[0]);
                    if (trigger == null)
                        throw new RuntimeException("No trigger found for Named Trigger " + args[0]);
                    if (args.length > 1 && args[1] instanceof Boolean) {
                        trigger.setSync((boolean) args[1]);
                    } else {
                        trigger.setSync(true);
                    }
                    if (trigger.isSync()) {
                        trigger.activate(e, interpreter.getVars());
                    } else {
                        // use snapshot to avoid concurrent modification
                        trigger.activate(e, new HashMap<>(interpreter.getVars()));
                    }
                    return true;
                } else {
                    throw new RuntimeException("Parameter type not match; it should be a String." + " Make sure to put double quotes, if you provided String literal.");
                }
            } else if ("CANCELEVENT".equals(command)) {
                if (!interpreter.isSync())
                    throw new RuntimeException("CANCELEVENT is illegal in async mode!");
                if (context instanceof Cancellable) {
                    ((Cancellable) context).setCancelled(true);
                    return true;
                } else {
                    throw new RuntimeException(context + " is not a Cancellable event!");
                }
            }
            return false;
        }
    };
}
Also used : ProcessInterrupter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.ProcessInterrupter) DelegatedPlayer(io.github.wysohn.triggerreactor.bukkit.tools.DelegatedPlayer) IPlayer(io.github.wysohn.triggerreactor.core.bridge.player.IPlayer) Player(org.bukkit.entity.Player) BukkitPlayer(io.github.wysohn.triggerreactor.bukkit.bridge.player.BukkitPlayer) Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager.Trigger) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractInventoryTriggerManager.InventoryTrigger) Cancellable(org.bukkit.event.Cancellable) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) PlayerEvent(org.bukkit.event.player.PlayerEvent) UUID(java.util.UUID)

Example 9 with Cancellable

use of org.bukkit.event.Cancellable in project Arcade2 by ShootGame.

the class BlockTransformListeners method post.

private boolean post(Event cause, Block block, BlockState oldState, BlockState newState, Player bukkit, boolean cancel) {
    ArcadePlayer player = null;
    if (bukkit != null) {
        player = this.plugin.getPlayer(bukkit);
    }
    BlockTransformEvent event = new BlockTransformEvent(this.plugin, block, cause, newState, oldState, player);
    this.plugin.getEventBus().publish(event);
    boolean canceled = cancel && event.isCanceled() && cause instanceof Cancellable;
    if (canceled) {
        ((Cancellable) cause).setCancelled(true);
    }
    return event.isCanceled();
}
Also used : ArcadePlayer(pl.themolka.arcade.session.ArcadePlayer) Cancellable(org.bukkit.event.Cancellable) BlockTransformEvent(pl.themolka.arcade.event.BlockTransformEvent)

Aggregations

Cancellable (org.bukkit.event.Cancellable)9 EventHandler (org.bukkit.event.EventHandler)6 ConquerFactionCreateEvent (me.andrew28.addons.conquer.api.events.ConquerFactionCreateEvent)5 ConquerFactionDisbandEvent (me.andrew28.addons.conquer.api.events.ConquerFactionDisbandEvent)3 ConquerFactionJoinEvent (me.andrew28.addons.conquer.api.events.ConquerFactionJoinEvent)3 ConquerFactionLeaveEvent (me.andrew28.addons.conquer.api.events.ConquerFactionLeaveEvent)3 ConquerFactionRelationEvent (me.andrew28.addons.conquer.api.events.ConquerFactionRelationEvent)3 ConquerFactionRelationWishEvent (me.andrew28.addons.conquer.api.events.ConquerFactionRelationWishEvent)3 ConquerLandClaimEvent (me.andrew28.addons.conquer.api.events.ConquerLandClaimEvent)3 ConquerPowerLossEvent (me.andrew28.addons.conquer.api.events.ConquerPowerLossEvent)3 ConquerUnclaimAllEvent (me.andrew28.addons.conquer.api.events.ConquerUnclaimAllEvent)3 Event (org.bukkit.event.Event)3 BukkitPlayer (io.github.wysohn.triggerreactor.bukkit.bridge.player.BukkitPlayer)2 DelegatedPlayer (io.github.wysohn.triggerreactor.bukkit.tools.DelegatedPlayer)2 IPlayer (io.github.wysohn.triggerreactor.core.bridge.player.IPlayer)2 InventoryTrigger (io.github.wysohn.triggerreactor.core.manager.trigger.AbstractInventoryTriggerManager.InventoryTrigger)2 Trigger (io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager.Trigger)2 ProcessInterrupter (io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.ProcessInterrupter)2 Node (io.github.wysohn.triggerreactor.core.script.parser.Node)2 UUID (java.util.UUID)2