loottracker: submit loot when not logged in

This is to aid the wiki drop log project. The data is not otherwise
stored.
This commit is contained in:
Adam
2020-10-01 10:03:50 -04:00
parent 32638ccf63
commit 1799c9e593
7 changed files with 54 additions and 27 deletions

View File

@@ -82,7 +82,7 @@ public interface LootTrackerConfig extends Config
@ConfigItem(
keyName = "saveLoot",
name = "Submit loot tracker data",
description = "Submit loot tracker data (requires being logged in)"
description = "Submit loot tracker data"
)
default boolean saveLoot()
{

View File

@@ -279,7 +279,7 @@ class LootTrackerPanel extends PluginPanel
reset.addActionListener(e ->
{
final LootTrackerClient client = plugin.getLootTrackerClient();
final boolean syncLoot = client != null && config.syncPanel();
final boolean syncLoot = client.getUuid() != null && config.syncPanel();
final int result = JOptionPane.showOptionDialog(overallPanel,
syncLoot ? SYNC_RESET_ALL_WARNING_TEXT : NO_SYNC_RESET_ALL_WARNING_TEXT,
"Are you sure?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
@@ -568,7 +568,7 @@ class LootTrackerPanel extends PluginPanel
LootTrackerClient client = plugin.getLootTrackerClient();
// Without loot being grouped we have no way to identify single kills to be deleted
if (client != null && groupLoot && config.syncPanel())
if (client.getUuid() != null && groupLoot && config.syncPanel())
{
client.delete(box.getId());
}

View File

@@ -262,9 +262,6 @@ public class LootTrackerPlugin extends Plugin
@Inject
private LootManager lootManager;
@Inject
private OkHttpClient okHttpClient;
private LootTrackerPanel panel;
private NavigationButton navButton;
@VisibleForTesting
@@ -281,6 +278,7 @@ public class LootTrackerPlugin extends Plugin
private Multiset<Integer> inventorySnapshot;
@Getter(AccessLevel.PACKAGE)
@Inject
private LootTrackerClient lootTrackerClient;
private final List<LootRecord> queuedLoots = new ArrayList<>();
@@ -313,6 +311,12 @@ public class LootTrackerPlugin extends Plugin
return list;
}
@Provides
LootTrackerClient provideLootTrackerClient(OkHttpClient okHttpClient)
{
return new LootTrackerClient(okHttpClient);
}
@Provides
LootTrackerConfig provideConfig(ConfigManager configManager)
{
@@ -325,11 +329,11 @@ public class LootTrackerPlugin extends Plugin
AccountSession accountSession = sessionManager.getAccountSession();
if (accountSession.getUuid() != null)
{
lootTrackerClient = new LootTrackerClient(okHttpClient, accountSession.getUuid());
lootTrackerClient.setUuid(accountSession.getUuid());
}
else
{
lootTrackerClient = null;
lootTrackerClient.setUuid(null);
}
}
@@ -337,7 +341,7 @@ public class LootTrackerPlugin extends Plugin
public void onSessionClose(SessionClose sessionClose)
{
submitLoot();
lootTrackerClient = null;
lootTrackerClient.setUuid(null);
}
@Subscribe
@@ -373,7 +377,7 @@ public class LootTrackerPlugin extends Plugin
AccountSession accountSession = sessionManager.getAccountSession();
if (accountSession != null)
{
lootTrackerClient = new LootTrackerClient(okHttpClient, accountSession.getUuid());
lootTrackerClient.setUuid(accountSession.getUuid());
clientThread.invokeLater(() ->
{
@@ -420,7 +424,7 @@ public class LootTrackerPlugin extends Plugin
{
submitLoot();
clientToolbar.removeNavigation(navButton);
lootTrackerClient = null;
lootTrackerClient.setUuid(null);
chestLooted = false;
}
@@ -831,15 +835,14 @@ public class LootTrackerPlugin extends Plugin
queuedLoots.clear();
}
if (lootTrackerClient == null || !config.saveLoot())
if (!config.saveLoot())
{
return null;
}
log.debug("Submitting {} loot records", copy.size());
CompletableFuture<Void> future = lootTrackerClient.submit(copy);
return future;
return lootTrackerClient.submit(copy);
}
private void setEvent(LootRecordType lootRecordType, String eventType, Object metadata)