Invoke GameEventManager events on ClientThread
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -50,17 +50,20 @@ import net.runelite.api.events.ItemSpawned;
|
||||
import net.runelite.api.events.NpcSpawned;
|
||||
import net.runelite.api.events.PlayerSpawned;
|
||||
import net.runelite.api.events.WallObjectSpawned;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
|
||||
@Singleton
|
||||
public class GameEventManager
|
||||
{
|
||||
private final EventBus eventBus = new EventBus();
|
||||
private final Client client;
|
||||
private final ClientThread clientThread;
|
||||
|
||||
@Inject
|
||||
private GameEventManager(Client client)
|
||||
private GameEventManager(Client client, ClientThread clientThread)
|
||||
{
|
||||
this.client = client;
|
||||
this.clientThread = clientThread;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +73,6 @@ public class GameEventManager
|
||||
*/
|
||||
private void forEachTile(Consumer<Tile> consumer)
|
||||
{
|
||||
|
||||
final Scene scene = client.getScene();
|
||||
final Tile[][][] tiles = scene.getTiles();
|
||||
|
||||
@@ -105,88 +107,92 @@ public class GameEventManager
|
||||
return;
|
||||
}
|
||||
|
||||
eventBus.register(subscriber);
|
||||
|
||||
for (final InventoryID inventory : InventoryID.values())
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
final ItemContainer itemContainer = client.getItemContainer(inventory);
|
||||
|
||||
if (itemContainer != null)
|
||||
eventBus.register(subscriber);
|
||||
|
||||
for (final InventoryID inventory : InventoryID.values())
|
||||
{
|
||||
eventBus.post(new ItemContainerChanged(itemContainer));
|
||||
}
|
||||
}
|
||||
final ItemContainer itemContainer = client.getItemContainer(inventory);
|
||||
|
||||
for (NPC npc : client.getCachedNPCs())
|
||||
{
|
||||
if (npc != null)
|
||||
{
|
||||
final NpcSpawned npcSpawned = new NpcSpawned(npc);
|
||||
eventBus.post(npcSpawned);
|
||||
}
|
||||
}
|
||||
|
||||
for (Player player : client.getCachedPlayers())
|
||||
{
|
||||
if (player != null)
|
||||
{
|
||||
final PlayerSpawned playerSpawned = new PlayerSpawned(player);
|
||||
eventBus.post(playerSpawned);
|
||||
}
|
||||
}
|
||||
|
||||
forEachTile((tile) ->
|
||||
{
|
||||
Optional.ofNullable(tile.getWallObject()).ifPresent(object ->
|
||||
{
|
||||
final WallObjectSpawned objectSpawned = new WallObjectSpawned();
|
||||
objectSpawned.setTile(tile);
|
||||
objectSpawned.setWallObject(object);
|
||||
eventBus.post(objectSpawned);
|
||||
});
|
||||
|
||||
Optional.ofNullable(tile.getDecorativeObject()).ifPresent(object ->
|
||||
{
|
||||
final DecorativeObjectSpawned objectSpawned = new DecorativeObjectSpawned();
|
||||
objectSpawned.setTile(tile);
|
||||
objectSpawned.setDecorativeObject(object);
|
||||
eventBus.post(objectSpawned);
|
||||
});
|
||||
|
||||
Optional.ofNullable(tile.getGroundObject()).ifPresent(object ->
|
||||
{
|
||||
final GroundObjectSpawned objectSpawned = new GroundObjectSpawned();
|
||||
objectSpawned.setTile(tile);
|
||||
objectSpawned.setGroundObject(object);
|
||||
eventBus.post(objectSpawned);
|
||||
});
|
||||
|
||||
Arrays.stream(tile.getGameObjects())
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(object ->
|
||||
if (itemContainer != null)
|
||||
{
|
||||
final GameObjectSpawned objectSpawned = new GameObjectSpawned();
|
||||
eventBus.post(new ItemContainerChanged(itemContainer));
|
||||
}
|
||||
}
|
||||
|
||||
for (NPC npc : client.getCachedNPCs())
|
||||
{
|
||||
if (npc != null)
|
||||
{
|
||||
final NpcSpawned npcSpawned = new NpcSpawned(npc);
|
||||
eventBus.post(npcSpawned);
|
||||
}
|
||||
}
|
||||
|
||||
for (Player player : client.getCachedPlayers())
|
||||
{
|
||||
if (player != null)
|
||||
{
|
||||
final PlayerSpawned playerSpawned = new PlayerSpawned(player);
|
||||
eventBus.post(playerSpawned);
|
||||
}
|
||||
}
|
||||
|
||||
forEachTile((tile) ->
|
||||
{
|
||||
Optional.ofNullable(tile.getWallObject()).ifPresent(object ->
|
||||
{
|
||||
final WallObjectSpawned objectSpawned = new WallObjectSpawned();
|
||||
objectSpawned.setTile(tile);
|
||||
objectSpawned.setGameObject(object);
|
||||
objectSpawned.setWallObject(object);
|
||||
eventBus.post(objectSpawned);
|
||||
});
|
||||
|
||||
Optional.ofNullable(tile.getItemLayer()).ifPresent(itemLayer ->
|
||||
{
|
||||
Node current = itemLayer.getBottom();
|
||||
|
||||
while (current instanceof Item)
|
||||
Optional.ofNullable(tile.getDecorativeObject()).ifPresent(object ->
|
||||
{
|
||||
final Item item = (Item) current;
|
||||
final DecorativeObjectSpawned objectSpawned = new DecorativeObjectSpawned();
|
||||
objectSpawned.setTile(tile);
|
||||
objectSpawned.setDecorativeObject(object);
|
||||
eventBus.post(objectSpawned);
|
||||
});
|
||||
|
||||
current = current.getNext();
|
||||
Optional.ofNullable(tile.getGroundObject()).ifPresent(object ->
|
||||
{
|
||||
final GroundObjectSpawned objectSpawned = new GroundObjectSpawned();
|
||||
objectSpawned.setTile(tile);
|
||||
objectSpawned.setGroundObject(object);
|
||||
eventBus.post(objectSpawned);
|
||||
});
|
||||
|
||||
final ItemSpawned itemSpawned = new ItemSpawned(tile, item);
|
||||
eventBus.post(itemSpawned);
|
||||
}
|
||||
Arrays.stream(tile.getGameObjects())
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(object ->
|
||||
{
|
||||
final GameObjectSpawned objectSpawned = new GameObjectSpawned();
|
||||
objectSpawned.setTile(tile);
|
||||
objectSpawned.setGameObject(object);
|
||||
eventBus.post(objectSpawned);
|
||||
});
|
||||
|
||||
Optional.ofNullable(tile.getItemLayer()).ifPresent(itemLayer ->
|
||||
{
|
||||
Node current = itemLayer.getBottom();
|
||||
|
||||
while (current instanceof Item)
|
||||
{
|
||||
final Item item = (Item) current;
|
||||
|
||||
current = current.getNext();
|
||||
|
||||
final ItemSpawned itemSpawned = new ItemSpawned(tile, item);
|
||||
eventBus.post(itemSpawned);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
eventBus.unregister(subscriber);
|
||||
eventBus.unregister(subscriber);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user