Merge pull request #2332 from Owain94/merge-1102
project: Merge upstream
This commit is contained in:
@@ -40,6 +40,7 @@ import net.runelite.api.AnimationID;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.ItemID;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.NPCDefinition;
|
||||
import net.runelite.api.NpcID;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.Tile;
|
||||
@@ -51,6 +52,7 @@ import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.ItemDespawned;
|
||||
import net.runelite.api.events.ItemQuantityChanged;
|
||||
import net.runelite.api.events.ItemSpawned;
|
||||
import net.runelite.api.events.NpcDefinitionChanged;
|
||||
import net.runelite.api.events.NpcDespawned;
|
||||
import net.runelite.api.events.PlayerDespawned;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
@@ -90,6 +92,9 @@ public class LootManager
|
||||
private WorldPoint playerLocationLastTick;
|
||||
private WorldPoint krakenPlayerLocation;
|
||||
|
||||
private NPC delayedLootNpc;
|
||||
private int delayedLootTickLimit;
|
||||
|
||||
@Inject
|
||||
private LootManager(
|
||||
final EventBus eventBus,
|
||||
@@ -100,6 +105,7 @@ public class LootManager
|
||||
this.client = client;
|
||||
|
||||
eventBus.subscribe(GameTick.class, this, this::onGameTick);
|
||||
eventBus.subscribe(NpcDefinitionChanged.class, this, this::onNpcChanged);
|
||||
eventBus.subscribe(NpcDespawned.class, this, this::onNpcDespawned);
|
||||
eventBus.subscribe(PlayerDespawned.class, this, this::onPlayerDespawned);
|
||||
eventBus.subscribe(ItemSpawned.class, this, this::onItemSpawned);
|
||||
@@ -111,6 +117,13 @@ public class LootManager
|
||||
private void onNpcDespawned(NpcDespawned npcDespawned)
|
||||
{
|
||||
final NPC npc = npcDespawned.getNpc();
|
||||
|
||||
if (npc == delayedLootNpc)
|
||||
{
|
||||
delayedLootNpc = null;
|
||||
delayedLootTickLimit = 0;
|
||||
}
|
||||
|
||||
if (!npc.isDead())
|
||||
{
|
||||
int id = npc.getId();
|
||||
@@ -241,13 +254,58 @@ public class LootManager
|
||||
}
|
||||
}
|
||||
|
||||
private void onNpcChanged(NpcDefinitionChanged npcChanged)
|
||||
{
|
||||
final NPC npc = npcChanged.getNpc();
|
||||
if (npc.getId() == NpcID.THE_NIGHTMARE_9433)
|
||||
{
|
||||
delayedLootNpc = npc;
|
||||
delayedLootTickLimit = 15;
|
||||
}
|
||||
}
|
||||
|
||||
private void onGameTick(GameTick gameTick)
|
||||
{
|
||||
if (delayedLootNpc != null && delayedLootTickLimit-- > 0)
|
||||
{
|
||||
processDelayedLoot();
|
||||
}
|
||||
|
||||
playerLocationLastTick = client.getLocalPlayer().getWorldLocation();
|
||||
itemSpawns.clear();
|
||||
killPoints.clear();
|
||||
}
|
||||
|
||||
private void processDelayedLoot()
|
||||
{
|
||||
final WorldPoint adjacentLootTile = getAdjacentSquareLootTile(delayedLootNpc);
|
||||
final LocalPoint localPoint = LocalPoint.fromWorld(client, adjacentLootTile);
|
||||
|
||||
if (localPoint == null)
|
||||
{
|
||||
log.debug("Scene changed away from delayed loot location");
|
||||
delayedLootNpc = null;
|
||||
delayedLootTickLimit = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
final int sceneX = localPoint.getSceneX();
|
||||
final int sceneY = localPoint.getSceneY();
|
||||
final int packed = sceneX << 8 | sceneY;
|
||||
final List<ItemStack> itemStacks = itemSpawns.get(packed);
|
||||
if (itemStacks.isEmpty())
|
||||
{
|
||||
// no loot yet
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("Got delayed loot stack from {}: {}", delayedLootNpc.getName(), itemStacks);
|
||||
eventBus.post(NpcLootReceived.class, new NpcLootReceived(delayedLootNpc, itemStacks));
|
||||
|
||||
delayedLootNpc = null;
|
||||
delayedLootTickLimit = 0;
|
||||
}
|
||||
|
||||
private void processNpcLoot(NPC npc)
|
||||
{
|
||||
final LocalPoint location = LocalPoint.fromWorld(client, getDropLocation(npc, npc.getWorldLocation()));
|
||||
@@ -337,4 +395,32 @@ public class LootManager
|
||||
|
||||
return worldLocation;
|
||||
}
|
||||
|
||||
private WorldPoint getAdjacentSquareLootTile(NPC npc)
|
||||
{
|
||||
final NPCDefinition composition = npc.getDefinition();
|
||||
final WorldPoint worldLocation = npc.getWorldLocation();
|
||||
int x = worldLocation.getX();
|
||||
int y = worldLocation.getY();
|
||||
|
||||
if (playerLocationLastTick.getX() < x)
|
||||
{
|
||||
x -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
x += Math.min(playerLocationLastTick.getX() - x, composition.getSize());
|
||||
}
|
||||
|
||||
if (playerLocationLastTick.getY() < y)
|
||||
{
|
||||
y -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
y += Math.min(playerLocationLastTick.getY() - y, composition.getSize());
|
||||
}
|
||||
|
||||
return new WorldPoint(x, y, worldLocation.getPlane());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.swing.SwingUtilities;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.config.Config;
|
||||
@@ -134,9 +135,20 @@ public class ExternalPluginLoader
|
||||
|
||||
try
|
||||
{
|
||||
pluginManager.startPlugin(plugin);
|
||||
SwingUtilities.invokeAndWait(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
pluginManager.startPlugin(plugin);
|
||||
}
|
||||
catch (PluginInstantiationException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
catch (PluginInstantiationException ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
close(loader);
|
||||
log.warn("unable to start plugin", ex);
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -343,9 +344,19 @@ class ExternalPluginManager
|
||||
|
||||
try
|
||||
{
|
||||
runelitePluginManager.startPlugin(plugin);
|
||||
SwingUtilities.invokeAndWait(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
runelitePluginManager.startPlugin(plugin);
|
||||
}
|
||||
catch (PluginInstantiationException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (PluginInstantiationException ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.warn("unable to start plugin", ex);
|
||||
return;
|
||||
@@ -423,12 +434,22 @@ class ExternalPluginManager
|
||||
|
||||
try
|
||||
{
|
||||
runelitePluginManager.stopPlugin(plugin);
|
||||
SwingUtilities.invokeAndWait(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
runelitePluginManager.stopPlugin(plugin);
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
throw new RuntimeException(e2);
|
||||
}
|
||||
});
|
||||
runelitePluginManager.remove(plugin);
|
||||
|
||||
eventBus.post(ExternalPluginChanged.class, new ExternalPluginChanged(pluginId, plugin, false));
|
||||
}
|
||||
catch (PluginInstantiationException ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.warn("unable to stop plugin", ex);
|
||||
return;
|
||||
@@ -459,14 +480,24 @@ class ExternalPluginManager
|
||||
|
||||
try
|
||||
{
|
||||
runelitePluginManager.stopPlugin(plugin);
|
||||
SwingUtilities.invokeAndWait(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
runelitePluginManager.stopPlugin(plugin);
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
throw new RuntimeException(e2);
|
||||
}
|
||||
});
|
||||
runelitePluginManager.remove(plugin);
|
||||
|
||||
eventBus.post(ExternalPluginChanged.class, new ExternalPluginChanged(pluginId, plugin, false));
|
||||
|
||||
return pluginWrapper.getPluginPath();
|
||||
}
|
||||
catch (PluginInstantiationException ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.warn("unable to stop plugin", ex);
|
||||
return null;
|
||||
|
||||
@@ -53,7 +53,6 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
@@ -90,7 +89,6 @@ public class PluginManager
|
||||
private final EventBus eventBus;
|
||||
private final Scheduler scheduler;
|
||||
private final ConfigManager configManager;
|
||||
private final ScheduledExecutorService executor;
|
||||
private final Provider<GameEventManager> sceneTileManager;
|
||||
private final List<Plugin> plugins = new CopyOnWriteArrayList<>();
|
||||
private final List<Plugin> activePlugins = new CopyOnWriteArrayList<>();
|
||||
@@ -110,14 +108,12 @@ public class PluginManager
|
||||
final EventBus eventBus,
|
||||
final Scheduler scheduler,
|
||||
final ConfigManager configManager,
|
||||
final ScheduledExecutorService executor,
|
||||
final Provider<GameEventManager> sceneTileManager)
|
||||
{
|
||||
this.developerMode = developerMode;
|
||||
this.eventBus = eventBus;
|
||||
this.scheduler = scheduler;
|
||||
this.configManager = configManager;
|
||||
this.executor = executor;
|
||||
this.sceneTileManager = sceneTileManager;
|
||||
|
||||
if (eventBus != null)
|
||||
@@ -140,21 +136,30 @@ public class PluginManager
|
||||
private void refreshPlugins()
|
||||
{
|
||||
loadDefaultPluginConfiguration();
|
||||
getPlugins()
|
||||
.forEach(plugin -> executor.submit(() ->
|
||||
SwingUtilities.invokeLater(() ->
|
||||
{
|
||||
for (Plugin plugin : getPlugins())
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!startPlugin(plugin))
|
||||
if (isPluginEnabled(plugin) != activePlugins.contains(plugin))
|
||||
{
|
||||
stopPlugin(plugin);
|
||||
if (activePlugins.contains(plugin))
|
||||
{
|
||||
stopPlugin(plugin);
|
||||
}
|
||||
else
|
||||
{
|
||||
startPlugin(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (PluginInstantiationException e)
|
||||
{
|
||||
log.warn("Error during starting/stopping plugin {}", plugin.getClass().getSimpleName(), e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Config getPluginConfigProxy(Plugin plugin)
|
||||
@@ -217,22 +222,33 @@ public class PluginManager
|
||||
public void startCorePlugins()
|
||||
{
|
||||
List<Plugin> scannedPlugins = new ArrayList<>(plugins);
|
||||
int loaded = 0, started = 0;
|
||||
int loaded = 0;
|
||||
AtomicInteger started = new AtomicInteger();
|
||||
|
||||
final Stopwatch timer = Stopwatch.createStarted();
|
||||
for (Plugin plugin : scannedPlugins)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (startPlugin(plugin))
|
||||
SwingUtilities.invokeAndWait(() ->
|
||||
{
|
||||
++started;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (startPlugin(plugin))
|
||||
{
|
||||
started.incrementAndGet();
|
||||
}
|
||||
}
|
||||
catch (PluginInstantiationException ex)
|
||||
{
|
||||
log.warn("Unable to start plugin {}", plugin.getClass().getSimpleName(), ex);
|
||||
plugins.remove(plugin);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (PluginInstantiationException ex)
|
||||
catch (InterruptedException | InvocationTargetException e)
|
||||
{
|
||||
log.warn("Unable to start plugin {}", plugin.getClass().getSimpleName(), ex);
|
||||
plugins.remove(plugin);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
loaded++;
|
||||
@@ -363,8 +379,11 @@ public class PluginManager
|
||||
return scannedPlugins;
|
||||
}
|
||||
|
||||
public synchronized boolean startPlugin(Plugin plugin) throws PluginInstantiationException
|
||||
public boolean startPlugin(Plugin plugin) throws PluginInstantiationException
|
||||
{
|
||||
// plugins always start in the EDT
|
||||
assert SwingUtilities.isEventDispatchThread();
|
||||
|
||||
if (activePlugins.contains(plugin) || !isPluginEnabled(plugin))
|
||||
{
|
||||
return false;
|
||||
@@ -374,19 +393,7 @@ public class PluginManager
|
||||
|
||||
try
|
||||
{
|
||||
// plugins always start in the event thread
|
||||
SwingUtilities.invokeAndWait(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
plugin.startUp();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.startUp();
|
||||
plugin.addAnnotatedSubscriptions(eventBus);
|
||||
|
||||
log.debug("Plugin {} is now running", plugin.getClass().getSimpleName());
|
||||
@@ -402,7 +409,7 @@ public class PluginManager
|
||||
schedule(plugin);
|
||||
eventBus.post(PluginChanged.class, new PluginChanged(plugin, true));
|
||||
}
|
||||
catch (InterruptedException | InvocationTargetException | IllegalArgumentException ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new PluginInstantiationException(ex);
|
||||
}
|
||||
@@ -410,39 +417,28 @@ public class PluginManager
|
||||
return true;
|
||||
}
|
||||
|
||||
public synchronized boolean stopPlugin(Plugin plugin) throws PluginInstantiationException
|
||||
public boolean stopPlugin(Plugin plugin) throws PluginInstantiationException
|
||||
{
|
||||
if (!activePlugins.contains(plugin) || isPluginEnabled(plugin))
|
||||
// plugins always stop in the EDT
|
||||
assert SwingUtilities.isEventDispatchThread();
|
||||
|
||||
if (!activePlugins.remove(plugin))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
activePlugins.remove(plugin);
|
||||
unschedule(plugin);
|
||||
|
||||
try
|
||||
{
|
||||
unschedule(plugin);
|
||||
|
||||
// plugins always stop in the event thread
|
||||
SwingUtilities.invokeAndWait(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
plugin.shutDown();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
});
|
||||
|
||||
plugin.shutDown();
|
||||
plugin.removeAnnotatedSubscriptions(eventBus);
|
||||
|
||||
log.debug("Plugin {} is now stopped", plugin.getClass().getSimpleName());
|
||||
eventBus.post(PluginChanged.class, new PluginChanged(plugin, false));
|
||||
|
||||
}
|
||||
catch (InterruptedException | InvocationTargetException ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new PluginInstantiationException(ex);
|
||||
}
|
||||
|
||||
@@ -79,11 +79,13 @@ public class ConfigPlugin extends Plugin
|
||||
pluginListPanel = pluginListPanelProvider.get();
|
||||
pluginListPanel.addFakePlugin(
|
||||
new PluginConfigurationDescriptor(
|
||||
"OpenOSRS", "OpenOSRS client settings", PluginType.IMPORTANT, new String[]{"client"},
|
||||
"OpenOSRS", "OpenOSRS client settings", PluginType.IMPORTANT,
|
||||
new String[]{"sorting", "external", "logs", "categories", "colors", "opacity", "pin"},
|
||||
null, openOSRSConfig, configManager.getConfigDescriptor(openOSRSConfig)
|
||||
),
|
||||
new PluginConfigurationDescriptor(
|
||||
"RuneLite", "RuneLite client settings", PluginType.IMPORTANT, new String[]{"client"},
|
||||
"RuneLite", "RuneLite client settings", PluginType.IMPORTANT,
|
||||
new String[]{"client", "notification", "size", "position", "window", "chrome", "focus", "font", "overlay", "tooltip", "infobox"},
|
||||
null, runeLiteConfig, configManager.getConfigDescriptor(runeLiteConfig)
|
||||
),
|
||||
new PluginConfigurationDescriptor(
|
||||
|
||||
@@ -427,36 +427,30 @@ public class PluginListPanel extends PluginPanel
|
||||
|
||||
void startPlugin(Plugin plugin)
|
||||
{
|
||||
executorService.submit(() ->
|
||||
{
|
||||
pluginManager.setPluginEnabled(plugin, true);
|
||||
pluginManager.setPluginEnabled(plugin, true);
|
||||
|
||||
try
|
||||
{
|
||||
pluginManager.startPlugin(plugin);
|
||||
}
|
||||
catch (PluginInstantiationException ex)
|
||||
{
|
||||
log.warn("Error when starting plugin {}", plugin.getClass().getSimpleName(), ex);
|
||||
}
|
||||
});
|
||||
try
|
||||
{
|
||||
pluginManager.startPlugin(plugin);
|
||||
}
|
||||
catch (PluginInstantiationException ex)
|
||||
{
|
||||
log.warn("Error when starting plugin {}", plugin.getClass().getSimpleName(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
void stopPlugin(Plugin plugin)
|
||||
{
|
||||
executorService.submit(() ->
|
||||
{
|
||||
pluginManager.setPluginEnabled(plugin, false);
|
||||
pluginManager.setPluginEnabled(plugin, false);
|
||||
|
||||
try
|
||||
{
|
||||
pluginManager.stopPlugin(plugin);
|
||||
}
|
||||
catch (PluginInstantiationException ex)
|
||||
{
|
||||
log.warn("Error when stopping plugin {}", plugin.getClass().getSimpleName(), ex);
|
||||
}
|
||||
});
|
||||
try
|
||||
{
|
||||
pluginManager.stopPlugin(plugin);
|
||||
}
|
||||
catch (PluginInstantiationException ex)
|
||||
{
|
||||
log.warn("Error when stopping plugin {}", plugin.getClass().getSimpleName(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getPinnedPluginNames()
|
||||
|
||||
@@ -90,7 +90,6 @@ class InfoPanel extends PluginPanel
|
||||
@Inject
|
||||
public InfoPanel(final InfoPlugin plugin, final Client client)
|
||||
{
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
setBackground(ColorScheme.DARK_GRAY_COLOR);
|
||||
setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||
|
||||
Reference in New Issue
Block a user