Add command executed event

This commit is contained in:
Adam
2018-04-22 20:08:25 -04:00
parent 1fd9b3abcc
commit 946688cdf8
6 changed files with 424 additions and 0 deletions

View File

@@ -41,6 +41,7 @@ import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.client.account.SessionManager;
import net.runelite.client.chat.ChatMessageManager;
import net.runelite.client.chat.CommandManager;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.discord.DiscordService;
import net.runelite.client.game.ClanManager;
@@ -81,6 +82,9 @@ public class RuneLite
@Inject
private ChatMessageManager chatMessageManager;
@Inject
private CommandManager commandManager;
@Inject
private OverlayRenderer overlayRenderer;
@@ -163,6 +167,7 @@ public class RuneLite
eventBus.register(overlayRenderer);
eventBus.register(menuManager);
eventBus.register(chatMessageManager);
eventBus.register(commandManager);
eventBus.register(pluginManager);
eventBus.register(itemManager);
eventBus.register(clanManager);

View File

@@ -0,0 +1,78 @@
/*
* Copyright (c) 2018, Kamiel
* Copyright (c) 2018, 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.chat;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import java.util.Arrays;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.VarClientStr;
import net.runelite.api.Varcs;
import net.runelite.api.events.CommandExecuted;
import net.runelite.api.events.ScriptCallbackEvent;
@Slf4j
@Singleton
public class CommandManager
{
private static final String CALLBACK_NAME = "runeliteCommand";
private final Provider<Client> clientProvider;
private final EventBus eventBus;
@Inject
public CommandManager(Provider<Client> clientProvider, EventBus eventBus)
{
this.clientProvider = clientProvider;
this.eventBus = eventBus;
}
@Subscribe
private void scriptEvent(ScriptCallbackEvent event)
{
if (!CALLBACK_NAME.equals(event.getEventName()))
{
return;
}
Client client = clientProvider.get();
Varcs varcs = client.getVarcs();
String typedText = varcs.getStrVar(VarClientStr.CHATBOX_TYPED_TEXT).substring(2); // strip ::
log.debug("Command: {}", typedText);
String[] split = typedText.split(" ");
String command = split[0];
String[] args = Arrays.copyOfRange(split, 1, split.length);
CommandExecuted commandExecuted = new CommandExecuted(command, args);
eventBus.post(commandExecuted);
}
}

View File

@@ -24,6 +24,7 @@
*/
package net.runelite.client.plugins.devtools;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides;
import java.awt.Font;
import java.awt.image.BufferedImage;
@@ -31,6 +32,8 @@ import java.util.Arrays;
import java.util.Collection;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.events.CommandExecuted;
import net.runelite.api.widgets.Widget;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.plugins.Plugin;
@@ -44,6 +47,7 @@ import net.runelite.client.ui.overlay.Overlay;
name = "Developer Tools",
developerPlugin = true
)
@Slf4j
public class DevToolsPlugin extends Plugin
{
@Inject
@@ -118,6 +122,13 @@ public class DevToolsPlugin extends Plugin
return Arrays.asList(overlay, locationOverlay, borderOverlay);
}
@Subscribe
public void onCommand(CommandExecuted commandExecuted) {
if (commandExecuted.getCommand().equalsIgnoreCase("test")) {
log.debug("Test!");
}
}
Font getFont()
{
return font;