Search in sources :

Example 1 with Cancellable

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

the class FUEventForwarder method onFactionCreate.

@EventHandler
public void onFactionCreate(FactionCreateEvent event) {
    ConquerFactionCreateEvent forwardEvent = new ConquerFactionCreateEvent(FUPlayer.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 2 with Cancellable

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

the class LFEventForwarder method onFactionsChange.

@EventHandler
public void onFactionsChange(EventFactionsChange event) {
    Event forwardEvent;
    if (event.getFactionNew().isWilderness()) {
        forwardEvent = new ConquerFactionLeaveEvent(LFFaction.get(plugin, event.getFactionOld()), LFPlayer.get(plugin, event.getFPlayer()));
    } else {
        forwardEvent = new ConquerFactionJoinEvent(LFFaction.get(plugin, event.getFactionNew()), LFPlayer.get(plugin, event.getFPlayer()));
    }
    callEvent(forwardEvent);
    if (((Cancellable) forwardEvent).isCancelled()) {
        event.setCancelled(true);
    }
}
Also used : ConquerFactionJoinEvent(me.andrew28.addons.conquer.api.events.ConquerFactionJoinEvent) Cancellable(org.bukkit.event.Cancellable) Event(org.bukkit.event.Event) ConquerFactionRelationEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationEvent) ConquerFactionLeaveEvent(me.andrew28.addons.conquer.api.events.ConquerFactionLeaveEvent) ConquerPowerLossEvent(me.andrew28.addons.conquer.api.events.ConquerPowerLossEvent) ConquerFactionDisbandEvent(me.andrew28.addons.conquer.api.events.ConquerFactionDisbandEvent) ConquerFactionRelationWishEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationWishEvent) ConquerLandClaimEvent(me.andrew28.addons.conquer.api.events.ConquerLandClaimEvent) ConquerFactionJoinEvent(me.andrew28.addons.conquer.api.events.ConquerFactionJoinEvent) ConquerFactionCreateEvent(me.andrew28.addons.conquer.api.events.ConquerFactionCreateEvent) ConquerFactionLeaveEvent(me.andrew28.addons.conquer.api.events.ConquerFactionLeaveEvent) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Cancellable

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

the class JavaPluginBridge method createInterrupterForInv.

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

        @Override
        public boolean onNodeProcess(Node node) {
            if (interpreter.isCooldown()) {
                if (e instanceof InventoryInteractEvent) {
                    HumanEntity he = ((InventoryInteractEvent) e).getWhoClicked();
                    if (he instanceof Player) {
                        Player player = (Player) he;
                        UUID uuid = player.getUniqueId();
                        cooldowns.put(uuid, interpreter.getCooldownEnd());
                    }
                }
                return false;
            }
            // is still running after the inventory is closed.
            if (e instanceof InventoryOpenEvent || e instanceof InventoryClickEvent) {
                Inventory inv = ((InventoryEvent) e).getInventory();
                // it's not GUI so stop execution
                if (!inventoryMap.containsKey(new BukkitInventory(inv)))
                    return true;
            }
            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 : InventoryOpenEvent(org.bukkit.event.inventory.InventoryOpenEvent) InventoryEvent(org.bukkit.event.inventory.InventoryEvent) 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) Cancellable(org.bukkit.event.Cancellable) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) ProcessInterrupter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.ProcessInterrupter) InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager.Trigger) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractInventoryTriggerManager.InventoryTrigger) BukkitInventory(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitInventory) HumanEntity(org.bukkit.entity.HumanEntity) InventoryInteractEvent(org.bukkit.event.inventory.InventoryInteractEvent) UUID(java.util.UUID) BukkitInventory(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitInventory) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) Inventory(org.bukkit.inventory.Inventory)

Example 4 with Cancellable

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

the class MSEventForwarder method onClaimChange.

@EventHandler
public void onClaimChange(EventFactionsChunksChange event) {
    ConquerFaction faction = MSFaction.get(plugin, event.getNewFaction());
    ConquerPlayer player = MSPlayer.get(plugin, event.getMPlayer());
    Set<PS> chunks = event.getChunks();
    Map<PS, EventFactionsChunkChangeType> chunkTypeMap = event.getChunkType();
    // Check if it's an unclaim all
    if (chunks.size() == faction.getClaims().length && chunkTypeMap.values().stream().allMatch(type -> type == EventFactionsChunkChangeType.SELL)) {
        ConquerUnclaimAllEvent forwardEvent = new ConquerUnclaimAllEvent(faction, player);
        callEvent(forwardEvent);
        if (forwardEvent.isCancelled()) {
            event.setCancelled(true);
        }
    }
    for (PS chunk : chunks) {
        EventFactionsChunkChangeType type = chunkTypeMap.get(chunk);
        ConquerClaim claim = MSClaim.get(plugin, chunk);
        Event forwardEvent;
        switch(type) {
            case NONE:
                continue;
            case BUY:
                forwardEvent = new ConquerLandClaimEvent(claim, true, faction, player);
                break;
            case CONQUER:
            case PILLAGE:
                forwardEvent = new ConquerLandClaimEvent(claim, false, faction, player);
                break;
            default:
                return;
        }
        callEvent(forwardEvent);
        if (((Cancellable) forwardEvent).isCancelled()) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : EventForwarder(me.andrew28.addons.conquer.api.EventForwarder) Cancellable(org.bukkit.event.Cancellable) ConquerUnclaimAllEvent(me.andrew28.addons.conquer.api.events.ConquerUnclaimAllEvent) EventFactionsCreate(com.massivecraft.factions.event.EventFactionsCreate) EventFactionsRelationChange(com.massivecraft.factions.event.EventFactionsRelationChange) Event(org.bukkit.event.Event) ConquerFactionRelationEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationEvent) EventHandler(org.bukkit.event.EventHandler) EventFactionsDisband(com.massivecraft.factions.event.EventFactionsDisband) ConquerClaim(me.andrew28.addons.conquer.api.ConquerClaim) Map(java.util.Map) EventFactionsMembershipChange(com.massivecraft.factions.event.EventFactionsMembershipChange) ConquerFactionLeaveEvent(me.andrew28.addons.conquer.api.events.ConquerFactionLeaveEvent) ConquerFaction(me.andrew28.addons.conquer.api.ConquerFaction) ConquerPowerLossEvent(me.andrew28.addons.conquer.api.events.ConquerPowerLossEvent) EventFactionsChunkChangeType(com.massivecraft.factions.event.EventFactionsChunkChangeType) ConquerFactionDisbandEvent(me.andrew28.addons.conquer.api.events.ConquerFactionDisbandEvent) Relation(me.andrew28.addons.conquer.api.Relation) PS(com.massivecraft.massivecore.ps.PS) ConquerFactionRelationWishEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationWishEvent) ConquerLandClaimEvent(me.andrew28.addons.conquer.api.events.ConquerLandClaimEvent) EventFactionsPowerChange(com.massivecraft.factions.event.EventFactionsPowerChange) Set(java.util.Set) ConquerFactionJoinEvent(me.andrew28.addons.conquer.api.events.ConquerFactionJoinEvent) EventFactionsChunksChange(com.massivecraft.factions.event.EventFactionsChunksChange) ConquerPlayer(me.andrew28.addons.conquer.api.ConquerPlayer) ConquerFactionCreateEvent(me.andrew28.addons.conquer.api.events.ConquerFactionCreateEvent) PS(com.massivecraft.massivecore.ps.PS) ConquerFaction(me.andrew28.addons.conquer.api.ConquerFaction) Cancellable(org.bukkit.event.Cancellable) ConquerUnclaimAllEvent(me.andrew28.addons.conquer.api.events.ConquerUnclaimAllEvent) Event(org.bukkit.event.Event) ConquerFactionRelationEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationEvent) ConquerFactionLeaveEvent(me.andrew28.addons.conquer.api.events.ConquerFactionLeaveEvent) ConquerPowerLossEvent(me.andrew28.addons.conquer.api.events.ConquerPowerLossEvent) ConquerFactionDisbandEvent(me.andrew28.addons.conquer.api.events.ConquerFactionDisbandEvent) ConquerFactionRelationWishEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationWishEvent) ConquerLandClaimEvent(me.andrew28.addons.conquer.api.events.ConquerLandClaimEvent) ConquerFactionJoinEvent(me.andrew28.addons.conquer.api.events.ConquerFactionJoinEvent) ConquerFactionCreateEvent(me.andrew28.addons.conquer.api.events.ConquerFactionCreateEvent) ConquerUnclaimAllEvent(me.andrew28.addons.conquer.api.events.ConquerUnclaimAllEvent) ConquerLandClaimEvent(me.andrew28.addons.conquer.api.events.ConquerLandClaimEvent) ConquerPlayer(me.andrew28.addons.conquer.api.ConquerPlayer) ConquerClaim(me.andrew28.addons.conquer.api.ConquerClaim) EventFactionsChunkChangeType(com.massivecraft.factions.event.EventFactionsChunkChangeType) EventHandler(org.bukkit.event.EventHandler)

Example 5 with Cancellable

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

the class MSEventForwarder method onMembershipChange.

@EventHandler
public void onMembershipChange(EventFactionsMembershipChange event) {
    ConquerFaction faction = MSFaction.get(plugin, event.getNewFaction());
    ConquerPlayer player = MSPlayer.get(plugin, event.getMPlayer());
    Event forwardEvent;
    switch(event.getReason()) {
        case JOIN:
        case CREATE:
            forwardEvent = new ConquerFactionJoinEvent(faction, player);
            break;
        case LEAVE:
        case KICK:
        case DISBAND:
            forwardEvent = new ConquerFactionLeaveEvent(faction, player);
            break;
        default:
            return;
    }
    callEvent(forwardEvent);
    if (((Cancellable) forwardEvent).isCancelled()) {
        event.setCancelled(true);
    }
}
Also used : ConquerFaction(me.andrew28.addons.conquer.api.ConquerFaction) ConquerFactionJoinEvent(me.andrew28.addons.conquer.api.events.ConquerFactionJoinEvent) Cancellable(org.bukkit.event.Cancellable) ConquerUnclaimAllEvent(me.andrew28.addons.conquer.api.events.ConquerUnclaimAllEvent) Event(org.bukkit.event.Event) ConquerFactionRelationEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationEvent) ConquerFactionLeaveEvent(me.andrew28.addons.conquer.api.events.ConquerFactionLeaveEvent) ConquerPowerLossEvent(me.andrew28.addons.conquer.api.events.ConquerPowerLossEvent) ConquerFactionDisbandEvent(me.andrew28.addons.conquer.api.events.ConquerFactionDisbandEvent) ConquerFactionRelationWishEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationWishEvent) ConquerLandClaimEvent(me.andrew28.addons.conquer.api.events.ConquerLandClaimEvent) ConquerFactionJoinEvent(me.andrew28.addons.conquer.api.events.ConquerFactionJoinEvent) ConquerFactionCreateEvent(me.andrew28.addons.conquer.api.events.ConquerFactionCreateEvent) ConquerPlayer(me.andrew28.addons.conquer.api.ConquerPlayer) ConquerFactionLeaveEvent(me.andrew28.addons.conquer.api.events.ConquerFactionLeaveEvent) EventHandler(org.bukkit.event.EventHandler)

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