client: add event system using eventbus
This commit is contained in:
2
cache/pom.xml
vendored
2
cache/pom.xml
vendored
@@ -47,7 +47,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>18.0</version>
|
||||
<version>21.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
||||
@@ -57,6 +57,11 @@
|
||||
<artifactId>jopt-simple</artifactId>
|
||||
<version>5.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>21.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.runelite</groupId>
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
package net.runelite.client;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.SubscriberExceptionContext;
|
||||
import java.io.File;
|
||||
import joptsimple.OptionParser;
|
||||
import joptsimple.OptionSet;
|
||||
@@ -32,10 +34,14 @@ import net.runelite.api.Client;
|
||||
import net.runelite.client.plugins.PluginManager;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
import net.runelite.client.ui.overlay.OverlayRenderer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class RuneLite
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(RuneLite.class);
|
||||
|
||||
public static final File RUNELITE_DIR = new File(System.getProperty("user.home"), ".runelite");
|
||||
public static final File REPO_DIR = new File(RUNELITE_DIR, "repository");
|
||||
|
||||
@@ -46,6 +52,7 @@ public class RuneLite
|
||||
private ClientUI gui;
|
||||
private PluginManager pluginManager;
|
||||
private OverlayRenderer renderer;
|
||||
private EventBus eventBus = new EventBus(this::eventExceptionHandler);
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
@@ -62,12 +69,17 @@ public class RuneLite
|
||||
gui = new ClientUI();
|
||||
gui.setVisible(true);
|
||||
|
||||
pluginManager = new PluginManager();
|
||||
pluginManager = new PluginManager(this);
|
||||
pluginManager.loadAll();
|
||||
|
||||
renderer = new OverlayRenderer();
|
||||
}
|
||||
|
||||
private void eventExceptionHandler(Throwable exception, SubscriberExceptionContext context)
|
||||
{
|
||||
logger.warn("uncaught exception in event subscriber", exception);
|
||||
}
|
||||
|
||||
public static Client getClient()
|
||||
{
|
||||
return client;
|
||||
@@ -93,6 +105,11 @@ public class RuneLite
|
||||
return renderer;
|
||||
}
|
||||
|
||||
public EventBus getEventBus()
|
||||
{
|
||||
return eventBus;
|
||||
}
|
||||
|
||||
public static OptionSet getOptions()
|
||||
{
|
||||
return options;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.client.events;
|
||||
|
||||
public class ExperienceChanged
|
||||
{
|
||||
|
||||
}
|
||||
@@ -28,17 +28,30 @@ package net.runelite.client.plugins;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.plugins.boosts.Boosts;
|
||||
import net.runelite.client.plugins.opponentinfo.OpponentInfo;
|
||||
|
||||
public class PluginManager
|
||||
{
|
||||
private final RuneLite runelite;
|
||||
private final List<Plugin> plugins = new ArrayList<>();
|
||||
|
||||
public PluginManager(RuneLite runelite)
|
||||
{
|
||||
this.runelite = runelite;
|
||||
}
|
||||
|
||||
public void loadAll()
|
||||
{
|
||||
plugins.add(new Boosts());
|
||||
plugins.add(new OpponentInfo());
|
||||
load(new Boosts());
|
||||
load(new OpponentInfo());
|
||||
}
|
||||
|
||||
private void load(Plugin plugin)
|
||||
{
|
||||
plugins.add(plugin);
|
||||
runelite.getEventBus().register(plugin);
|
||||
}
|
||||
|
||||
public Collection<Plugin> getPlugins()
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
*/
|
||||
package net.runelite.inject.callbacks;
|
||||
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.events.ExperienceChanged;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -31,8 +33,20 @@ public class Hooks
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Hooks.class);
|
||||
|
||||
private static final RuneLite runelite = RuneLite.getRunelite();
|
||||
|
||||
public static void callHook(String name, Object object)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "experienceChanged":
|
||||
runelite.getEventBus().post(new ExperienceChanged());
|
||||
break;
|
||||
default:
|
||||
logger.warn("Unknown event {} triggered on {}", name, object);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug("Event {} triggered on {}", name, object);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user