loottracker plugin: Add Loot Received event

This commit is contained in:
TheStonedTurtle
2019-12-21 16:23:47 -08:00
parent e197b17637
commit 0bcab39e49
2 changed files with 70 additions and 43 deletions

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2019, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.loottracker;
import java.util.Collection;
import lombok.AllArgsConstructor;
import lombok.Data;
import net.runelite.client.game.ItemStack;
import net.runelite.http.api.loottracker.LootRecordType;
/**
* Event published by the loottracker plugin when new loot is received
*/
@Data
@AllArgsConstructor
public class LootReceived
{
private String name;
private int combatLevel;
private LootRecordType type;
private Collection<ItemStack> items;
}

View File

@@ -64,7 +64,6 @@ import net.runelite.api.Player;
import net.runelite.api.SpriteID;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.ChatMessage;
import net.runelite.client.events.ConfigChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.ItemContainerChanged;
import net.runelite.api.events.WidgetLoaded;
@@ -73,7 +72,9 @@ import net.runelite.client.account.AccountSession;
import net.runelite.client.account.SessionManager;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.events.NpcLootReceived;
import net.runelite.client.events.PlayerLootReceived;
import net.runelite.client.events.SessionClose;
@@ -159,6 +160,9 @@ public class LootTrackerPlugin extends Plugin
@Inject
private ScheduledExecutorService executor;
@Inject
private EventBus eventBus;
private LootTrackerPanel panel;
private NavigationButton navButton;
private String eventType;
@@ -320,6 +324,23 @@ public class LootTrackerPlugin extends Plugin
}
}
void addLoot(String name, int combatLevel, LootRecordType type, Collection<ItemStack> items)
{
final LootTrackerItem[] entries = buildEntries(stack(items));
SwingUtilities.invokeLater(() -> panel.add(name, combatLevel, entries));
if (config.saveLoot())
{
LootRecord lootRecord = new LootRecord(name, type, toGameItems(items), Instant.now());
synchronized (queuedLoots)
{
queuedLoots.add(lootRecord);
}
}
eventBus.post(new LootReceived(name, combatLevel, type, items));
}
@Subscribe
public void onNpcLootReceived(final NpcLootReceived npcLootReceived)
{
@@ -327,17 +348,8 @@ public class LootTrackerPlugin extends Plugin
final Collection<ItemStack> items = npcLootReceived.getItems();
final String name = npc.getName();
final int combat = npc.getCombatLevel();
final LootTrackerItem[] entries = buildEntries(stack(items));
SwingUtilities.invokeLater(() -> panel.add(name, combat, entries));
if (config.saveLoot())
{
LootRecord lootRecord = new LootRecord(name, LootRecordType.NPC, toGameItems(items), Instant.now());
synchronized (queuedLoots)
{
queuedLoots.add(lootRecord);
}
}
addLoot(name, combat, LootRecordType.NPC, items);
}
@Subscribe
@@ -353,17 +365,8 @@ public class LootTrackerPlugin extends Plugin
final Collection<ItemStack> items = playerLootReceived.getItems();
final String name = player.getName();
final int combat = player.getCombatLevel();
final LootTrackerItem[] entries = buildEntries(stack(items));
SwingUtilities.invokeLater(() -> panel.add(name, combat, entries));
if (config.saveLoot())
{
LootRecord lootRecord = new LootRecord(name, LootRecordType.PLAYER, toGameItems(items), Instant.now());
synchronized (queuedLoots)
{
queuedLoots.add(lootRecord);
}
}
addLoot(name, combat, LootRecordType.PLAYER, items);
}
@Subscribe
@@ -433,17 +436,7 @@ public class LootTrackerPlugin extends Plugin
return;
}
final LootTrackerItem[] entries = buildEntries(stack(items));
SwingUtilities.invokeLater(() -> panel.add(eventType, -1, entries));
if (config.saveLoot())
{
LootRecord lootRecord = new LootRecord(eventType, LootRecordType.EVENT, toGameItems(items), Instant.now());
synchronized (queuedLoots)
{
queuedLoots.add(lootRecord);
}
}
addLoot(eventType, -1, LootRecordType.EVENT, items);
}
@Subscribe
@@ -599,17 +592,7 @@ public class LootTrackerPlugin extends Plugin
.map(e -> new ItemStack(e.getElement(), e.getCount(), client.getLocalPlayer().getLocalLocation()))
.collect(Collectors.toList());
final LootTrackerItem[] entries = buildEntries(stack(items));
SwingUtilities.invokeLater(() -> panel.add(chestType, -1, entries));
if (config.saveLoot())
{
LootRecord lootRecord = new LootRecord(chestType, LootRecordType.EVENT, toGameItems(items), Instant.now());
synchronized (queuedLoots)
{
queuedLoots.add(lootRecord);
}
}
addLoot(chestType, -1, LootRecordType.EVENT, items);
inventorySnapshot = null;
}