Search in sources :

Example 6 with Trigger

use of io.github.wysohn.triggerreactor.core.manager.trigger.Trigger in project TriggerReactor by wysohn.

the class TriggerReactor method showGlowStones.

@Override
protected void showGlowStones(ICommandSender sender, Set<Entry<SimpleLocation, Trigger>> set) {
    CommandSource source = sender.get();
    if (source instanceof Player) {
        Player player = (Player) source;
        for (Entry<SimpleLocation, Trigger> entry : set) {
            SimpleLocation sloc = entry.getKey();
            player.sendBlockChange(sloc.getX(), sloc.getY(), sloc.getZ(), BlockTypes.GLOWSTONE.getDefaultState());
        }
    }
}
Also used : IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) Player(org.spongepowered.api.entity.living.player.Player) DelegatedPlayer(io.github.wysohn.triggerreactor.sponge.tools.DelegatedPlayer) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.Trigger) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) CommandSource(org.spongepowered.api.command.CommandSource)

Example 7 with Trigger

use of io.github.wysohn.triggerreactor.core.manager.trigger.Trigger in project TriggerReactor by wysohn.

the class TriggerReactor method createInterrupter.

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

        @Override
        public boolean onNodeProcess(Node node) {
            return false;
        }

        @Override
        public boolean onCommand(Object context, String command, Object[] args) {
            if ("CALL".equalsIgnoreCase(command)) {
                if (args.length < 1)
                    throw new RuntimeException("Need parameter [String] or [String, boolean]");
                if (args[0] instanceof String) {
                    Trigger trigger = getNamedTriggerManager().get((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".equalsIgnoreCase(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!");
                }
            } else if ("COOLDOWN".equalsIgnoreCase(command)) {
                if (!(args[0] instanceof Number))
                    throw new RuntimeException(args[0] + " is not a number!");
                long mills = (long) (((Number) args[0]).doubleValue() * 1000L);
                if (e instanceof Event) {
                    ((Event) e).getCause().first(Player.class).ifPresent((player) -> {
                        UUID uuid = player.getUniqueId();
                        cooldowns.put(uuid, System.currentTimeMillis() + mills);
                    });
                }
                return true;
            }
            return false;
        }

        @Override
        public Object onPlaceholder(Object context, String placeholder, Object[] args) {
            // }
            return null;
        }
    };
}
Also used : IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) Player(org.spongepowered.api.entity.living.player.Player) DelegatedPlayer(io.github.wysohn.triggerreactor.sponge.tools.DelegatedPlayer) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) Cancellable(org.spongepowered.api.event.Cancellable) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) ProcessInterrupter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.ProcessInterrupter) Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.Trigger) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) GameInitializationEvent(org.spongepowered.api.event.game.state.GameInitializationEvent) GameReloadEvent(org.spongepowered.api.event.game.GameReloadEvent) GameStartedServerEvent(org.spongepowered.api.event.game.state.GameStartedServerEvent) GameStoppingServerEvent(org.spongepowered.api.event.game.state.GameStoppingServerEvent) TriggerReactorStopEvent(io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStopEvent) TabCompleteEvent(org.spongepowered.api.event.command.TabCompleteEvent) Event(org.spongepowered.api.event.Event) InteractInventoryEvent(org.spongepowered.api.event.item.inventory.InteractInventoryEvent) IEvent(io.github.wysohn.triggerreactor.core.bridge.event.IEvent) TriggerReactorStartEvent(io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStartEvent) GameAboutToStartServerEvent(org.spongepowered.api.event.game.state.GameAboutToStartServerEvent) SendCommandEvent(org.spongepowered.api.event.command.SendCommandEvent)

Example 8 with Trigger

use of io.github.wysohn.triggerreactor.core.manager.trigger.Trigger in project TriggerReactor by wysohn.

the class LocationBasedTriggerManager method showTriggerInfo.

protected void showTriggerInfo(ICommandSender sender, BlockSnapshot clicked) {
    Trigger trigger = getTriggerForLocation(LocationUtil.convertToSimpleLocation(clicked.getLocation().orElse(null)));
    if (trigger == null) {
        return;
    }
    Location<World> loc = clicked.getLocation().orElse(null);
    sender.sendMessage("- - - - - - - - - - - - - -");
    sender.sendMessage("Trigger: " + getTriggerTypeName());
    sender.sendMessage("Block Type: " + clicked.getState().getType().getName());
    sender.sendMessage("Location: " + loc.getExtent().getName() + "@" + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ());
    sender.sendMessage("");
    sender.sendMessage("Script:");
    sender.sendMessage(trigger.getScript());
    sender.sendMessage("- - - - - - - - - - - - - -");
}
Also used : Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.Trigger) World(org.spongepowered.api.world.World)

Example 9 with Trigger

use of io.github.wysohn.triggerreactor.core.manager.trigger.Trigger in project TriggerReactor by wysohn.

the class TriggerReactor 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) {
            // is still running after the inventory is closed.
            if (e instanceof InteractInventoryEvent.Open || e instanceof InteractInventoryEvent.Close) {
                Inventory inv = ((InteractInventoryEvent) e).getTargetInventory();
                if (!(inv instanceof CarriedInventory))
                    return false;
                CarriedInventory inventory = (CarriedInventory) inv;
                Carrier carrier = (Carrier) inventory.getCarrier().orElse(null);
                if (carrier == null)
                    return false;
                // it's not GUI so stop execution
                return !inventoryMap.containsKey(new SpongeInventory(inv, carrier));
            }
            return false;
        }

        @Override
        public boolean onCommand(Object context, String command, Object[] args) {
            if ("CALL".equalsIgnoreCase(command)) {
                if (args.length < 1)
                    throw new RuntimeException("Need parameter [String] or [String, boolean]");
                if (args[0] instanceof String) {
                    Trigger trigger = getNamedTriggerManager().get((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".equalsIgnoreCase(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!");
                }
            } else if ("COOLDOWN".equalsIgnoreCase(command)) {
                if (!(args[0] instanceof Number))
                    throw new RuntimeException(args[0] + " is not a number!");
                long mills = (long) (((Number) args[0]).doubleValue() * 1000L);
                if (e instanceof Event) {
                    ((Event) e).getCause().first(Player.class).ifPresent((player) -> {
                        UUID uuid = player.getUniqueId();
                        cooldowns.put(uuid, System.currentTimeMillis() + mills);
                    });
                }
                return true;
            }
            return false;
        }

        @Override
        public Object onPlaceholder(Object context, String placeholder, Object[] args) {
            // }
            return null;
        }
    };
}
Also used : IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) Player(org.spongepowered.api.entity.living.player.Player) DelegatedPlayer(io.github.wysohn.triggerreactor.sponge.tools.DelegatedPlayer) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) InteractInventoryEvent(org.spongepowered.api.event.item.inventory.InteractInventoryEvent) Cancellable(org.spongepowered.api.event.Cancellable) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) ProcessInterrupter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.ProcessInterrupter) SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory) Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.Trigger) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) GameInitializationEvent(org.spongepowered.api.event.game.state.GameInitializationEvent) GameReloadEvent(org.spongepowered.api.event.game.GameReloadEvent) GameStartedServerEvent(org.spongepowered.api.event.game.state.GameStartedServerEvent) GameStoppingServerEvent(org.spongepowered.api.event.game.state.GameStoppingServerEvent) TriggerReactorStopEvent(io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStopEvent) TabCompleteEvent(org.spongepowered.api.event.command.TabCompleteEvent) Event(org.spongepowered.api.event.Event) InteractInventoryEvent(org.spongepowered.api.event.item.inventory.InteractInventoryEvent) IEvent(io.github.wysohn.triggerreactor.core.bridge.event.IEvent) TriggerReactorStartEvent(io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStartEvent) GameAboutToStartServerEvent(org.spongepowered.api.event.game.state.GameAboutToStartServerEvent) SendCommandEvent(org.spongepowered.api.event.command.SendCommandEvent) Carrier(org.spongepowered.api.item.inventory.Carrier) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) Inventory(org.spongepowered.api.item.inventory.Inventory) SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory)

Example 10 with Trigger

use of io.github.wysohn.triggerreactor.core.manager.trigger.Trigger in project TriggerReactor by wysohn.

the class LocationBasedTriggerManager method showTriggerInfo.

@Override
protected void showTriggerInfo(ICommandSender sender, SimpleLocation sloc) {
    Trigger trigger = getTriggerForLocation(sloc);
    if (trigger == null) {
        return;
    }
    Location<World> loc = LocationUtil.convertToBukkitLocation(sloc);
    BlockState clicked = loc.getBlock();
    sender.sendMessage("- - - - - - - - - - - - - -");
    sender.sendMessage("Trigger: " + getTriggerTypeName());
    sender.sendMessage("Block Type: " + clicked.getType().getName());
    sender.sendMessage("Location: " + loc.getExtent().getName() + "@" + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ());
    sender.sendMessage("");
    sender.sendMessage("Script:");
    sender.sendMessage(trigger.getScript());
    sender.sendMessage("- - - - - - - - - - - - - -");
}
Also used : Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.Trigger) BlockState(org.spongepowered.api.block.BlockState) World(org.spongepowered.api.world.World)

Aggregations

Trigger (io.github.wysohn.triggerreactor.core.manager.trigger.Trigger)13 IPlayer (io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer)7 InventoryTrigger (io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger)7 SimpleLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)5 Node (io.github.wysohn.triggerreactor.core.script.parser.Node)4 IInventory (io.github.wysohn.triggerreactor.core.bridge.IInventory)3 IEvent (io.github.wysohn.triggerreactor.core.bridge.event.IEvent)3 SimpleChunkLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)3 ProcessInterrupter (io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.ProcessInterrupter)3 SpongePlayer (io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer)3 DelegatedPlayer (io.github.wysohn.triggerreactor.sponge.tools.DelegatedPlayer)3 Player (org.bukkit.entity.Player)3 Player (org.spongepowered.api.entity.living.player.Player)3 AbstractAreaTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.area.AbstractAreaTriggerManager)2 AreaTrigger (io.github.wysohn.triggerreactor.core.manager.trigger.area.AreaTrigger)2 TriggerReactorStartEvent (io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStartEvent)2 TriggerReactorStopEvent (io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStopEvent)2 Cancellable (org.bukkit.event.Cancellable)2 PlayerEvent (org.bukkit.event.player.PlayerEvent)2 ICommandSender (io.github.wysohn.triggerreactor.core.bridge.ICommandSender)1