Search in sources :

Example 6 with IPlayer

use of io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer 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 7 with IPlayer

use of io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer in project TriggerReactor by wysohn.

the class InventoryEditManager method saveEdit.

@Override
public void saveEdit(IPlayer player) {
    UUID u = player.getUniqueId();
    if (!suspended.containsKey(u)) {
        return;
    }
    Inventory inv = suspended.get(u).get();
    InventoryTrigger trigger = sessions.get(u);
    int size = inv.capacity();
    IItemStack[] iitems = new IItemStack[size];
    for (Inventory slot : inv.slots()) {
        slot.getInventoryProperty(SlotIndex.class).ifPresent(slotIndex -> slot.peek().ifPresent(itemStack -> iitems[slotIndex.getValue()] = new SpongeItemStack(itemStack)));
    }
    // TODO this causes an error waaay down the call chain.  replaceItems also saves the inventory trigger manager
    // but while trying to write the new data, NPE is thrown.  Starting a new edit shows that the new data at least
    // gets written to the trigger, but reloading will throw away the edits.
    // None of the items I want to save are null, so that isn't the source of the NPE.
    // I know this because item.createSnapshot() in the sponge InventoryTriggerManager.writeItemsList() succeeds.
    // please investigate this wysohn, because I have no idea at all why it can't save.
    replaceItems(trigger, iitems);
    stopEdit(player);
    player.sendMessage("Saved edits");
}
Also used : Inventory(org.spongepowered.api.item.inventory.Inventory) TextStyle(org.spongepowered.api.text.format.TextStyle) Keys(org.spongepowered.api.data.key.Keys) ItemTypes(org.spongepowered.api.item.ItemTypes) TriggerReactorCore(io.github.wysohn.triggerreactor.core.main.TriggerReactorCore) SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Text(org.spongepowered.api.text.Text) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) InventoryArchetypes(org.spongepowered.api.item.inventory.InventoryArchetypes) TextColors(org.spongepowered.api.text.format.TextColors) TextActions(org.spongepowered.api.text.action.TextActions) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) TextStyles(org.spongepowered.api.text.format.TextStyles) GridInventory(org.spongepowered.api.item.inventory.type.GridInventory) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) InteractInventoryEvent(org.spongepowered.api.event.item.inventory.InteractInventoryEvent) Slot(org.spongepowered.api.item.inventory.Slot) UUID(java.util.UUID) InventoryTitle(org.spongepowered.api.item.inventory.property.InventoryTitle) SpongeItemStack(io.github.wysohn.triggerreactor.sponge.bridge.SpongeItemStack) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) List(java.util.List) TextUtil(io.github.wysohn.triggerreactor.sponge.tools.TextUtil) QueryOperationTypes(org.spongepowered.api.item.inventory.query.QueryOperationTypes) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) AbstractInventoryEditManager(io.github.wysohn.triggerreactor.core.manager.AbstractInventoryEditManager) InventoryDimension(org.spongepowered.api.item.inventory.property.InventoryDimension) Player(org.spongepowered.api.entity.living.player.Player) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) Listener(org.spongepowered.api.event.Listener) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) UUID(java.util.UUID) SpongeItemStack(io.github.wysohn.triggerreactor.sponge.bridge.SpongeItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory) SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) GridInventory(org.spongepowered.api.item.inventory.type.GridInventory)

Example 8 with IPlayer

use of io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer in project TriggerReactor by wysohn.

the class LocationBasedTriggerManager method handleLocationSetting.

private void handleLocationSetting(Block clicked, Player p) {
    IPlayer bukkitPlayer = BukkitTriggerReactorCore.getWrapper().wrap(p);
    Location loc = clicked.getLocation();
    T trigger = getTriggerForLocation(loc);
    if (trigger != null) {
        bukkitPlayer.sendMessage(ChatColor.RED + "Another trigger is set at there!");
        showTriggerInfo(bukkitPlayer, clicked);
        return;
    }
    String script = getSettingLocationScript(bukkitPlayer);
    if (script == null) {
        bukkitPlayer.sendMessage(ChatColor.RED + "Could not find script... but how?");
        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 (TriggerInitFailedException e1) {
        bukkitPlayer.sendMessage(ChatColor.RED + "Encounterd an error!");
        bukkitPlayer.sendMessage(ChatColor.RED + e1.getMessage());
        bukkitPlayer.sendMessage(ChatColor.RED + "If you are an administrator, check console to see details.");
        e1.printStackTrace();
        stopLocationSet(bukkitPlayer);
        return;
    }
    setTriggerForLocation(loc, trigger);
    showTriggerInfo(bukkitPlayer, clicked);
    stopLocationSet(bukkitPlayer);
    plugin.saveAsynchronously(this);
}
Also used : IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) IConfigSource(io.github.wysohn.triggerreactor.core.config.source.IConfigSource) File(java.io.File) Location(org.bukkit.Location) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)

Aggregations

IPlayer (io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer)8 IInventory (io.github.wysohn.triggerreactor.core.bridge.IInventory)3 TriggerInfo (io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo)3 File (java.io.File)3 IItemStack (io.github.wysohn.triggerreactor.core.bridge.IItemStack)2 IConfigSource (io.github.wysohn.triggerreactor.core.config.source.IConfigSource)2 TriggerReactorCore (io.github.wysohn.triggerreactor.core.main.TriggerReactorCore)2 SimpleChunkLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)2 SimpleLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)2 AbstractInventoryTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.inventory.AbstractInventoryTriggerManager)2 InventoryTrigger (io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger)2 SpongePlayer (io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer)2 SaveHandler (io.github.wysohn.triggerreactor.tools.ScriptEditor.SaveHandler)2 EventHandler (org.bukkit.event.EventHandler)2 BukkitTriggerReactorCore (io.github.wysohn.triggerreactor.bukkit.main.BukkitTriggerReactorCore)1 ICommandSender (io.github.wysohn.triggerreactor.core.bridge.ICommandSender)1 ILocation (io.github.wysohn.triggerreactor.core.bridge.ILocation)1 IEvent (io.github.wysohn.triggerreactor.core.bridge.event.IEvent)1 io.github.wysohn.triggerreactor.core.manager (io.github.wysohn.triggerreactor.core.manager)1 AbstractInventoryEditManager (io.github.wysohn.triggerreactor.core.manager.AbstractInventoryEditManager)1