Search in sources :

Example 1 with SpongePlayer

use of io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer in project TriggerReactor by wysohn.

the class LocationBasedTriggerManager method onClick.

@Listener(order = Order.LATE)
@Exclude({ InteractBlockEvent.Primary.OffHand.class, InteractBlockEvent.Secondary.OffHand.class })
public void onClick(InteractBlockEvent e) {
    Player player = e.getCause().first(Player.class).orElse(null);
    // maybe something other than a player can interact with a block?
    if (player == null)
        return;
    ItemStack IS = player.getItemInHand(HandTypes.MAIN_HAND).orElse(null);
    BlockSnapshot clicked = e.getTargetBlock();
    if (clicked == null)
        return;
    Location<World> loc = clicked.getLocation().orElse(null);
    if (loc == null)
        return;
    T trigger = getTriggerForLocation(loc);
    if (IS != null && !e.isCancelled() && player.hasPermission("triggerreactor.admin")) {
        if (IS.getType() == INSPECTION_TOOL) {
            if (trigger != null && e instanceof InteractBlockEvent.Primary) {
                removeTriggerForLocation(loc);
                player.sendMessage(Text.builder("A trigger has deleted.").color(TextColors.GREEN).build());
                e.setCancelled(true);
            } else if (trigger != null && e instanceof InteractBlockEvent.Secondary) {
                if (player.get(Keys.IS_SNEAKING).orElse(false)) {
                    handleScriptEdit(player, trigger);
                    e.setCancelled(true);
                } else {
                    this.showTriggerInfo(new SpongePlayer(player), clicked);
                    e.setCancelled(true);
                }
            }
        } else if (IS.getType() == CUT_TOOL) {
            if (e instanceof InteractBlockEvent.Primary) {
                if (pasteTrigger(player, loc)) {
                    player.sendMessage(Text.builder("Successfully pasted the trigger!").color(TextColors.GREEN).build());
                    this.showTriggerInfo(new SpongePlayer(player), clicked);
                    e.setCancelled(true);
                }
            } else if (trigger != null && e instanceof InteractBlockEvent.Secondary) {
                if (cutTrigger(player, loc)) {
                    player.sendMessage(Text.builder("Cut Complete!").color(TextColors.GREEN).build());
                    player.sendMessage(Text.builder("Now you can paste it by left click on any block!").color(TextColors.GREEN).build());
                    e.setCancelled(true);
                }
            }
        } else if (IS.getType() == COPY_TOOL) {
            if (e instanceof InteractBlockEvent.Primary) {
                if (pasteTrigger(player, loc)) {
                    player.sendMessage(Text.builder("Successfully pasted the trigger!").color(TextColors.GREEN).build());
                    this.showTriggerInfo(new SpongePlayer(player), clicked);
                    e.setCancelled(true);
                }
            } else if (e instanceof InteractBlockEvent.Secondary) {
                if (trigger != null && copyTrigger(player, loc)) {
                    player.sendMessage(Text.builder("Copy Complete!").color(TextColors.GREEN).build());
                    player.sendMessage(Text.builder("Now you can paste it by left click on any block!").color(TextColors.GREEN).build());
                    e.setCancelled(true);
                }
            }
        }
    }
    if (!e.isCancelled() && isLocationSetting(new SpongePlayer(player))) {
        handleLocationSetting(clicked, player);
        e.setCancelled(true);
    }
}
Also used : IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) Player(org.spongepowered.api.entity.living.player.Player) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener) Exclude(org.spongepowered.api.event.filter.type.Exclude)

Example 2 with SpongePlayer

use of io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer in project TriggerReactor by wysohn.

the class LocationBasedTriggerManager method handleLocationSetting.

private void handleLocationSetting(BlockSnapshot clicked, Player p) {
    IPlayer player = new SpongePlayer(p);
    Location<World> loc = clicked.getLocation().orElse(null);
    if (loc == null)
        return;
    T trigger = getTriggerForLocation(loc);
    if (trigger != null) {
        p.sendMessage(Text.builder("Another trigger is set at there!").color(TextColors.RED).build());
        showTriggerInfo(player, clicked);
        return;
    }
    String script = getSettingLocationScript(player);
    if (script == null) {
        p.sendMessage(Text.builder("Could not find script... but how?").color(TextColors.RED).build());
        return;
    }
    File file = getTriggerFile(folder, LocationUtil.convertToSimpleLocation(loc).toString(), true);
    try {
        String name = TriggerInfo.extractName(file);
        IConfigSource config = configSourceFactory.create(folder, name);
        TriggerInfo info = TriggerInfo.defaultInfo(file, config);
        trigger = newTrigger(info, script);
    } catch (Exception e1) {
        p.sendMessage(Text.builder("Encounterd an error!").color(TextColors.RED).build());
        p.sendMessage(Text.builder(e1.getMessage()).color(TextColors.RED).build());
        p.sendMessage(Text.builder("If you are an administrator, check console to see details.").color(TextColors.RED).build());
        e1.printStackTrace();
        stopLocationSet(player);
        return;
    }
    setTriggerForLocation(loc, trigger);
    showTriggerInfo(player, clicked);
    stopLocationSet(player);
    plugin.saveAsynchronously(this);
}
Also used : IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) World(org.spongepowered.api.world.World) IConfigSource(io.github.wysohn.triggerreactor.core.config.source.IConfigSource) File(java.io.File)

Example 3 with SpongePlayer

use of io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer in project TriggerReactor by wysohn.

the class TriggerReactor method onInitialize.

@Listener
public void onInitialize(GameAboutToStartServerEvent e) {
    Sponge.getCommandManager().register(this, new CommandCallable() {

        @Override
        public CommandResult process(CommandSource src, String args) throws CommandException {
            if (src instanceof Player) {
                onCommand(new SpongePlayer((Player) src), "triggerreactor", args.split(" "));
            } else {
                onCommand(new SpongeCommandSender(src), "triggerreactor", args.split(" "));
            }
            return CommandResult.success();
        }

        @Override
        public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
            // return io.github.wysohn.triggerreactor.core.main.TriggerReactor.onTabComplete(arguments.split(" "));
            return new ArrayList<>();
        }

        @Override
        public boolean testPermission(CommandSource source) {
            return source.hasPermission("triggerreactor.admin");
        }

        @Override
        public Optional<Text> getShortDescription(CommandSource source) {
            return Optional.of(Text.of("TriggerReactor"));
        }

        @Override
        public Optional<Text> getHelp(CommandSource source) {
            return Optional.of(Text.of("/trg for details"));
        }

        @Override
        public Text getUsage(CommandSource source) {
            return Text.of("/trg for details");
        }
    }, "trg", "trigger");
    migrateOldConfig();
}
Also used : SpongeCommandSender(io.github.wysohn.triggerreactor.sponge.bridge.SpongeCommandSender) 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) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) Text(org.spongepowered.api.text.Text) CommandException(org.spongepowered.api.command.CommandException) CommandSource(org.spongepowered.api.command.CommandSource) World(org.spongepowered.api.world.World) CommandCallable(org.spongepowered.api.command.CommandCallable) CommandResult(org.spongepowered.api.command.CommandResult) Listener(org.spongepowered.api.event.Listener)

Example 4 with SpongePlayer

use of io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer in project TriggerReactor by wysohn.

the class InventoryEditManager method onQuit.

@Listener
public void onQuit(ClientConnectionEvent.Disconnect e) {
    Player player = e.getTargetEntity();
    stopEdit(new SpongePlayer(player));
}
Also used : IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) Player(org.spongepowered.api.entity.living.player.Player) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) Listener(org.spongepowered.api.event.Listener)

Example 5 with SpongePlayer

use of io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer in project TriggerReactor by wysohn.

the class InventoryTriggerManager method onClose.

@Listener
public void onClose(InteractInventoryEvent.Close e, @First Player player) {
    if (player == null)
        return;
    Inventory inv = e.getTargetInventory();
    if (!(inv instanceof CarriedInventory))
        return;
    CarriedInventory inventory = (CarriedInventory) inv;
    Carrier carrier = (Carrier) inventory.getCarrier().orElse(null);
    if (carrier == null)
        return;
    onInventoryClose(e, new SpongePlayer(player), new SpongeInventory(inv, carrier));
}
Also used : SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) GridInventory(org.spongepowered.api.item.inventory.type.GridInventory) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) Listener(org.spongepowered.api.event.Listener)

Aggregations

SpongePlayer (io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer)5 IPlayer (io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer)4 Listener (org.spongepowered.api.event.Listener)4 Player (org.spongepowered.api.entity.living.player.Player)3 World (org.spongepowered.api.world.World)3 IInventory (io.github.wysohn.triggerreactor.core.bridge.IInventory)1 IConfigSource (io.github.wysohn.triggerreactor.core.config.source.IConfigSource)1 TriggerInfo (io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo)1 SpongeCommandSender (io.github.wysohn.triggerreactor.sponge.bridge.SpongeCommandSender)1 SpongeInventory (io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory)1 DelegatedPlayer (io.github.wysohn.triggerreactor.sponge.tools.DelegatedPlayer)1 File (java.io.File)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 CommandCallable (org.spongepowered.api.command.CommandCallable)1 CommandException (org.spongepowered.api.command.CommandException)1 CommandResult (org.spongepowered.api.command.CommandResult)1 CommandSource (org.spongepowered.api.command.CommandSource)1 InteractBlockEvent (org.spongepowered.api.event.block.InteractBlockEvent)1 Exclude (org.spongepowered.api.event.filter.type.Exclude)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1