Simulate ItemContainerChange events on plugin startup
- Rename RegionTileManager to GameEventManager - Add simulating of ItemContainerChanged events Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -70,7 +70,7 @@ import net.runelite.client.events.PluginChanged;
|
|||||||
import net.runelite.client.task.Schedule;
|
import net.runelite.client.task.Schedule;
|
||||||
import net.runelite.client.task.ScheduledMethod;
|
import net.runelite.client.task.ScheduledMethod;
|
||||||
import net.runelite.client.task.Scheduler;
|
import net.runelite.client.task.Scheduler;
|
||||||
import net.runelite.client.util.SceneTileManager;
|
import net.runelite.client.util.GameEventManager;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -86,7 +86,7 @@ public class PluginManager
|
|||||||
private final Scheduler scheduler;
|
private final Scheduler scheduler;
|
||||||
private final ConfigManager configManager;
|
private final ConfigManager configManager;
|
||||||
private final ScheduledExecutorService executor;
|
private final ScheduledExecutorService executor;
|
||||||
private final Provider<SceneTileManager> sceneTileManager;
|
private final Provider<GameEventManager> sceneTileManager;
|
||||||
private final List<Plugin> plugins = new CopyOnWriteArrayList<>();
|
private final List<Plugin> plugins = new CopyOnWriteArrayList<>();
|
||||||
private final List<Plugin> activePlugins = new CopyOnWriteArrayList<>();
|
private final List<Plugin> activePlugins = new CopyOnWriteArrayList<>();
|
||||||
private final String runeliteGroupName = RuneLiteConfig.class
|
private final String runeliteGroupName = RuneLiteConfig.class
|
||||||
@@ -103,7 +103,7 @@ public class PluginManager
|
|||||||
final Scheduler scheduler,
|
final Scheduler scheduler,
|
||||||
final ConfigManager configManager,
|
final ConfigManager configManager,
|
||||||
final ScheduledExecutorService executor,
|
final ScheduledExecutorService executor,
|
||||||
final Provider<SceneTileManager> sceneTileManager)
|
final Provider<GameEventManager> sceneTileManager)
|
||||||
{
|
{
|
||||||
this.developerMode = developerMode;
|
this.developerMode = developerMode;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
@@ -326,10 +326,10 @@ public class PluginManager
|
|||||||
log.debug("Plugin {} is now running", plugin.getClass().getSimpleName());
|
log.debug("Plugin {} is now running", plugin.getClass().getSimpleName());
|
||||||
if (!isOutdated && sceneTileManager != null)
|
if (!isOutdated && sceneTileManager != null)
|
||||||
{
|
{
|
||||||
final SceneTileManager sceneTileManager = this.sceneTileManager.get();
|
final GameEventManager gameEventManager = this.sceneTileManager.get();
|
||||||
if (sceneTileManager != null)
|
if (gameEventManager != null)
|
||||||
{
|
{
|
||||||
sceneTileManager.simulateObjectSpawns(plugin);
|
gameEventManager.simulateGameEvents(plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,24 +34,27 @@ import javax.inject.Singleton;
|
|||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.Constants;
|
import net.runelite.api.Constants;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
|
import net.runelite.api.InventoryID;
|
||||||
import net.runelite.api.Item;
|
import net.runelite.api.Item;
|
||||||
|
import net.runelite.api.ItemContainer;
|
||||||
import net.runelite.api.Node;
|
import net.runelite.api.Node;
|
||||||
import net.runelite.api.Scene;
|
import net.runelite.api.Scene;
|
||||||
import net.runelite.api.Tile;
|
import net.runelite.api.Tile;
|
||||||
import net.runelite.api.events.DecorativeObjectSpawned;
|
import net.runelite.api.events.DecorativeObjectSpawned;
|
||||||
import net.runelite.api.events.GameObjectSpawned;
|
import net.runelite.api.events.GameObjectSpawned;
|
||||||
import net.runelite.api.events.GroundObjectSpawned;
|
import net.runelite.api.events.GroundObjectSpawned;
|
||||||
|
import net.runelite.api.events.ItemContainerChanged;
|
||||||
import net.runelite.api.events.ItemSpawned;
|
import net.runelite.api.events.ItemSpawned;
|
||||||
import net.runelite.api.events.WallObjectSpawned;
|
import net.runelite.api.events.WallObjectSpawned;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class SceneTileManager
|
public class GameEventManager
|
||||||
{
|
{
|
||||||
private final EventBus eventBus = new EventBus();
|
private final EventBus eventBus = new EventBus();
|
||||||
private final Client client;
|
private final Client client;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private SceneTileManager(Client client)
|
private GameEventManager(Client client)
|
||||||
{
|
{
|
||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
@@ -61,12 +64,8 @@ public class SceneTileManager
|
|||||||
*
|
*
|
||||||
* @param consumer consumer accepting tile as parameter
|
* @param consumer consumer accepting tile as parameter
|
||||||
*/
|
*/
|
||||||
public void forEachTile(Consumer<Tile> consumer)
|
private void forEachTile(Consumer<Tile> consumer)
|
||||||
{
|
{
|
||||||
if (client.getGameState() != GameState.LOGGED_IN)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Scene scene = client.getScene();
|
final Scene scene = client.getScene();
|
||||||
final Tile[][][] tiles = scene.getTiles();
|
final Tile[][][] tiles = scene.getTiles();
|
||||||
@@ -91,14 +90,29 @@ public class SceneTileManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simulate object spawns for EventBus subscriber
|
* Simulate game events for EventBus subscriber
|
||||||
*
|
*
|
||||||
* @param subscriber EventBus subscriber
|
* @param subscriber EventBus subscriber
|
||||||
*/
|
*/
|
||||||
public void simulateObjectSpawns(Object subscriber)
|
public void simulateGameEvents(Object subscriber)
|
||||||
{
|
{
|
||||||
|
if (client.getGameState() != GameState.LOGGED_IN)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
eventBus.register(subscriber);
|
eventBus.register(subscriber);
|
||||||
|
|
||||||
|
for (final InventoryID inventory : InventoryID.values())
|
||||||
|
{
|
||||||
|
final ItemContainer itemContainer = client.getItemContainer(inventory);
|
||||||
|
|
||||||
|
if (itemContainer != null)
|
||||||
|
{
|
||||||
|
eventBus.post(new ItemContainerChanged(itemContainer));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
forEachTile((tile) ->
|
forEachTile((tile) ->
|
||||||
{
|
{
|
||||||
Optional.ofNullable(tile.getWallObject()).ifPresent(object ->
|
Optional.ofNullable(tile.getWallObject()).ifPresent(object ->
|
||||||
Reference in New Issue
Block a user