Convert game thread events to singletons (#794)
* Convert game thread events to singletons * Fix checkstyle * Fix copy paste error
This commit is contained in:
@@ -87,9 +87,6 @@ public class Hooks implements Callbacks
|
||||
private static final OverlayRenderer renderer = injector.getInstance(OverlayRenderer.class);
|
||||
private static final OverlayManager overlayManager = injector.getInstance(OverlayManager.class);
|
||||
|
||||
private static final GameTick GAME_TICK = new GameTick();
|
||||
private static final BeforeRender BEFORE_RENDER = new BeforeRender();
|
||||
|
||||
@Inject
|
||||
private EventBus eventBus;
|
||||
|
||||
@@ -151,13 +148,13 @@ public class Hooks implements Callbacks
|
||||
|
||||
deferredEventBus.replay();
|
||||
|
||||
eventBus.post(GAME_TICK);
|
||||
eventBus.post(GameTick.INSTANCE);
|
||||
|
||||
int tick = client.getTickCount();
|
||||
client.setTickCount(tick + 1);
|
||||
}
|
||||
|
||||
eventBus.post(BEFORE_RENDER);
|
||||
eventBus.post(BeforeRender.INSTANCE);
|
||||
|
||||
clientThread.invoke();
|
||||
|
||||
@@ -511,7 +508,7 @@ public class Hooks implements Callbacks
|
||||
|
||||
public static boolean drawMenu()
|
||||
{
|
||||
BeforeMenuRender event = new BeforeMenuRender();
|
||||
BeforeMenuRender event = BeforeMenuRender.INSTANCE;
|
||||
client.getCallbacks().post(event);
|
||||
return event.isConsumed();
|
||||
}
|
||||
|
||||
@@ -114,7 +114,9 @@ public class CommandManager
|
||||
String command = split[0];
|
||||
String[] args = Arrays.copyOfRange(split, 1, split.length);
|
||||
|
||||
CommandExecuted commandExecuted = new CommandExecuted(command, args);
|
||||
CommandExecuted commandExecuted = CommandExecuted.INSTANCE;
|
||||
commandExecuted.setCommand(command);
|
||||
commandExecuted.setArguments(args);
|
||||
eventBus.post(commandExecuted);
|
||||
}
|
||||
|
||||
|
||||
@@ -429,7 +429,7 @@ public class MenuManager
|
||||
if (curMenuOption.getMenuTarget().equals(event.getTarget())
|
||||
&& curMenuOption.getMenuOption().equals(event.getOption()))
|
||||
{
|
||||
WidgetMenuOptionClicked customMenu = new WidgetMenuOptionClicked();
|
||||
WidgetMenuOptionClicked customMenu = WidgetMenuOptionClicked.INSTANCE;
|
||||
customMenu.setMenuOption(event.getOption());
|
||||
customMenu.setMenuTarget(event.getTarget());
|
||||
customMenu.setWidget(curMenuOption.getWidget());
|
||||
@@ -444,7 +444,7 @@ public class MenuManager
|
||||
// <col=ffffff>username<col=40ff00> (level-42) or <col=ffffff><img=2>username</col>
|
||||
String username = Text.removeTags(target).split("[(]")[0].trim();
|
||||
|
||||
PlayerMenuOptionClicked playerMenuOptionClicked = new PlayerMenuOptionClicked();
|
||||
PlayerMenuOptionClicked playerMenuOptionClicked = PlayerMenuOptionClicked.INSTANCE;
|
||||
playerMenuOptionClicked.setMenuOption(event.getOption());
|
||||
playerMenuOptionClicked.setMenuTarget(username);
|
||||
|
||||
|
||||
@@ -258,7 +258,7 @@ public class DevToolsPlugin extends Plugin
|
||||
int value = Integer.parseInt(args[1]);
|
||||
client.setVarpValue(client.getVarps(), varp, value);
|
||||
client.addChatMessage(ChatMessageType.GAMEMESSAGE, "", "Set VarPlayer " + varp + " to " + value, null);
|
||||
VarbitChanged varbitChanged = new VarbitChanged();
|
||||
VarbitChanged varbitChanged = VarbitChanged.INSTANCE;
|
||||
varbitChanged.setIndex(varp);
|
||||
eventBus.post(varbitChanged); // fake event
|
||||
break;
|
||||
@@ -276,7 +276,7 @@ public class DevToolsPlugin extends Plugin
|
||||
int value = Integer.parseInt(args[1]);
|
||||
client.setVarbitValue(client.getVarps(), varbit, value);
|
||||
client.addChatMessage(ChatMessageType.GAMEMESSAGE, "", "Set varbit " + varbit + " to " + value, null);
|
||||
eventBus.post(new VarbitChanged()); // fake event
|
||||
eventBus.post(VarbitChanged.INSTANCE); // fake event
|
||||
break;
|
||||
}
|
||||
case "addxp":
|
||||
@@ -293,7 +293,7 @@ public class DevToolsPlugin extends Plugin
|
||||
|
||||
client.queueChangedSkill(skill);
|
||||
|
||||
ExperienceChanged experienceChanged = new ExperienceChanged();
|
||||
ExperienceChanged experienceChanged = ExperienceChanged.INSTANCE;
|
||||
experienceChanged.setSkill(skill);
|
||||
eventBus.post(experienceChanged);
|
||||
break;
|
||||
@@ -312,11 +312,11 @@ public class DevToolsPlugin extends Plugin
|
||||
|
||||
client.queueChangedSkill(skill);
|
||||
|
||||
ExperienceChanged experienceChanged = new ExperienceChanged();
|
||||
ExperienceChanged experienceChanged = ExperienceChanged.INSTANCE;
|
||||
experienceChanged.setSkill(skill);
|
||||
eventBus.post(experienceChanged);
|
||||
|
||||
BoostedLevelChanged boostedLevelChanged = new BoostedLevelChanged();
|
||||
BoostedLevelChanged boostedLevelChanged = BoostedLevelChanged.INSTANCE;
|
||||
boostedLevelChanged.setSkill(skill);
|
||||
eventBus.post(boostedLevelChanged);
|
||||
break;
|
||||
|
||||
@@ -121,7 +121,7 @@ public class FreezeTimersPlugin extends Plugin
|
||||
{
|
||||
if (prayerTracker.getSpotanimLastTick(actor) != actor.getSpotAnimation())
|
||||
{
|
||||
SpotAnimationChanged callback = new SpotAnimationChanged();
|
||||
SpotAnimationChanged callback = SpotAnimationChanged.INSTANCE;
|
||||
callback.setActor(actor);
|
||||
client.getCallbacks().post(callback);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,9 @@ public class GameEventManager
|
||||
|
||||
if (itemContainer != null)
|
||||
{
|
||||
eventBus.post(new ItemContainerChanged(itemContainer));
|
||||
ItemContainerChanged event = ItemContainerChanged.INSTANCE;
|
||||
event.setItemContainer(itemContainer);
|
||||
eventBus.post(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +128,8 @@ public class GameEventManager
|
||||
{
|
||||
if (npc != null)
|
||||
{
|
||||
final NpcSpawned npcSpawned = new NpcSpawned(npc);
|
||||
final NpcSpawned npcSpawned = NpcSpawned.INSTANCE;
|
||||
npcSpawned.setNpc(npc);
|
||||
eventBus.post(npcSpawned);
|
||||
}
|
||||
}
|
||||
@@ -135,7 +138,8 @@ public class GameEventManager
|
||||
{
|
||||
if (player != null)
|
||||
{
|
||||
final PlayerSpawned playerSpawned = new PlayerSpawned(player);
|
||||
final PlayerSpawned playerSpawned = PlayerSpawned.INSTANCE;
|
||||
playerSpawned.setPlayer(player);
|
||||
eventBus.post(playerSpawned);
|
||||
}
|
||||
}
|
||||
@@ -144,7 +148,7 @@ public class GameEventManager
|
||||
{
|
||||
Optional.ofNullable(tile.getWallObject()).ifPresent(object ->
|
||||
{
|
||||
final WallObjectSpawned objectSpawned = new WallObjectSpawned();
|
||||
final WallObjectSpawned objectSpawned = WallObjectSpawned.INSTANCE;
|
||||
objectSpawned.setTile(tile);
|
||||
objectSpawned.setWallObject(object);
|
||||
eventBus.post(objectSpawned);
|
||||
@@ -152,7 +156,7 @@ public class GameEventManager
|
||||
|
||||
Optional.ofNullable(tile.getDecorativeObject()).ifPresent(object ->
|
||||
{
|
||||
final DecorativeObjectSpawned objectSpawned = new DecorativeObjectSpawned();
|
||||
final DecorativeObjectSpawned objectSpawned = DecorativeObjectSpawned.INSTANCE;
|
||||
objectSpawned.setTile(tile);
|
||||
objectSpawned.setDecorativeObject(object);
|
||||
eventBus.post(objectSpawned);
|
||||
@@ -160,7 +164,7 @@ public class GameEventManager
|
||||
|
||||
Optional.ofNullable(tile.getGroundObject()).ifPresent(object ->
|
||||
{
|
||||
final GroundObjectSpawned objectSpawned = new GroundObjectSpawned();
|
||||
final GroundObjectSpawned objectSpawned = GroundObjectSpawned.INSTANCE;
|
||||
objectSpawned.setTile(tile);
|
||||
objectSpawned.setGroundObject(object);
|
||||
eventBus.post(objectSpawned);
|
||||
@@ -170,7 +174,7 @@ public class GameEventManager
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(object ->
|
||||
{
|
||||
final GameObjectSpawned objectSpawned = new GameObjectSpawned();
|
||||
final GameObjectSpawned objectSpawned = GameObjectSpawned.INSTANCE;
|
||||
objectSpawned.setTile(tile);
|
||||
objectSpawned.setGameObject(object);
|
||||
eventBus.post(objectSpawned);
|
||||
@@ -186,7 +190,9 @@ public class GameEventManager
|
||||
|
||||
current = current.getNext();
|
||||
|
||||
final ItemSpawned itemSpawned = new ItemSpawned(tile, item);
|
||||
final ItemSpawned itemSpawned = ItemSpawned.INSTANCE;
|
||||
itemSpawned.setItem(item);
|
||||
itemSpawned.setTile(tile);
|
||||
eventBus.post(itemSpawned);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user