Add chatbox input listener and use for chatbox input event
The immediate eventbus does not pass classloader validation: java.lang.SecurityException: class "com.google.common.eventbus.ImmediateEventBus"'s signer information does not match signer information of other classes in the same package
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* 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 net.runelite.client.events.ChatboxInput;
|
||||||
|
|
||||||
|
public interface ChatboxInputListener
|
||||||
|
{
|
||||||
|
boolean onChatboxInput(ChatboxInput chatboxInput);
|
||||||
|
}
|
||||||
@@ -27,7 +27,9 @@ package net.runelite.client.chat;
|
|||||||
|
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@@ -52,6 +54,8 @@ public class CommandManager
|
|||||||
private final Provider<ClientThread> clientThreadProvider;
|
private final Provider<ClientThread> clientThreadProvider;
|
||||||
private boolean sending;
|
private boolean sending;
|
||||||
|
|
||||||
|
private final List<ChatboxInputListener> chatboxInputListenerList = new ArrayList<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public CommandManager(Provider<Client> clientProvider, EventBus eventBus, Provider<ClientThread> clientThreadProvider)
|
public CommandManager(Provider<Client> clientProvider, EventBus eventBus, Provider<ClientThread> clientThreadProvider)
|
||||||
{
|
{
|
||||||
@@ -60,6 +64,16 @@ public class CommandManager
|
|||||||
this.clientThreadProvider = clientThreadProvider;
|
this.clientThreadProvider = clientThreadProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void register(ChatboxInputListener chatboxInputListener)
|
||||||
|
{
|
||||||
|
chatboxInputListenerList.add(chatboxInputListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregister(ChatboxInputListener chatboxInputListener)
|
||||||
|
{
|
||||||
|
chatboxInputListenerList.remove(chatboxInputListener);
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void scriptEvent(ScriptCallbackEvent event)
|
private void scriptEvent(ScriptCallbackEvent event)
|
||||||
{
|
{
|
||||||
@@ -129,9 +143,13 @@ public class CommandManager
|
|||||||
clientThread.invokeLater(() -> sendChatboxInput(chatType, typedText));
|
clientThread.invokeLater(() -> sendChatboxInput(chatType, typedText));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
eventBus.post(chatboxInput);
|
boolean stop = false;
|
||||||
|
for (ChatboxInputListener chatboxInputListener : chatboxInputListenerList)
|
||||||
|
{
|
||||||
|
stop |= chatboxInputListener.onChatboxInput(chatboxInput);
|
||||||
|
}
|
||||||
|
|
||||||
if (chatboxInput.isStop())
|
if (stop)
|
||||||
{
|
{
|
||||||
// input was blocked.
|
// input was blocked.
|
||||||
stringStack[stringStackCount - 1] = ""; // prevent script from sending
|
stringStack[stringStackCount - 1] = ""; // prevent script from sending
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ public abstract class ChatboxInput
|
|||||||
{
|
{
|
||||||
private final String value;
|
private final String value;
|
||||||
private final int chatType;
|
private final int chatType;
|
||||||
private boolean stop;
|
|
||||||
|
|
||||||
public abstract void resume();
|
public abstract void resume();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import net.runelite.api.vars.AccountType;
|
|||||||
import net.runelite.client.chat.ChatColorType;
|
import net.runelite.client.chat.ChatColorType;
|
||||||
import net.runelite.client.chat.ChatMessageBuilder;
|
import net.runelite.client.chat.ChatMessageBuilder;
|
||||||
import net.runelite.client.chat.ChatMessageManager;
|
import net.runelite.client.chat.ChatMessageManager;
|
||||||
|
import net.runelite.client.chat.ChatboxInputListener;
|
||||||
import net.runelite.client.chat.CommandManager;
|
import net.runelite.client.chat.CommandManager;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.events.ChatboxInput;
|
import net.runelite.client.events.ChatboxInput;
|
||||||
@@ -72,7 +73,7 @@ import net.runelite.http.api.kc.KillCountClient;
|
|||||||
tags = {"grand", "exchange", "level", "prices"}
|
tags = {"grand", "exchange", "level", "prices"}
|
||||||
)
|
)
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ChatCommandsPlugin extends Plugin
|
public class ChatCommandsPlugin extends Plugin implements ChatboxInputListener
|
||||||
{
|
{
|
||||||
private static final float HIGH_ALCHEMY_CONSTANT = 0.6f;
|
private static final float HIGH_ALCHEMY_CONSTANT = 0.6f;
|
||||||
private static final Pattern KILLCOUNT_PATERN = Pattern.compile("Your ([a-zA-Z ]+) kill count is: <col=ff0000>(\\d+)</col>.");
|
private static final Pattern KILLCOUNT_PATERN = Pattern.compile("Your ([a-zA-Z ]+) kill count is: <col=ff0000>(\\d+)</col>.");
|
||||||
@@ -112,12 +113,14 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
public void startUp()
|
public void startUp()
|
||||||
{
|
{
|
||||||
keyManager.registerKeyListener(chatKeyboardListener);
|
keyManager.registerKeyListener(chatKeyboardListener);
|
||||||
|
commandManager.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shutDown()
|
public void shutDown()
|
||||||
{
|
{
|
||||||
keyManager.unregisterKeyListener(chatKeyboardListener);
|
keyManager.unregisterKeyListener(chatKeyboardListener);
|
||||||
|
commandManager.unregister(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@@ -237,13 +240,13 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Override
|
||||||
public void onChatboxInput(ChatboxInput chatboxInput)
|
public boolean onChatboxInput(ChatboxInput chatboxInput)
|
||||||
{
|
{
|
||||||
final String value = chatboxInput.getValue();
|
final String value = chatboxInput.getValue();
|
||||||
if (!value.startsWith("!kc ") && !value.startsWith("/!kc "))
|
if (!value.startsWith("!kc ") && !value.startsWith("/!kc "))
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int idx = value.indexOf(' ');
|
int idx = value.indexOf(' ');
|
||||||
@@ -252,10 +255,9 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
final int kc = getKc(boss);
|
final int kc = getKc(boss);
|
||||||
if (kc <= 0)
|
if (kc <= 0)
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
chatboxInput.setStop(true);
|
|
||||||
final String playerName = client.getLocalPlayer().getName();
|
final String playerName = client.getLocalPlayer().getName();
|
||||||
|
|
||||||
executor.execute(() ->
|
executor.execute(() ->
|
||||||
@@ -273,6 +275,8 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
chatboxInput.resume();
|
chatboxInput.resume();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void killCountLookup(ChatMessageType type, SetMessage setMessage, String search)
|
private void killCountLookup(ChatMessageType type, SetMessage setMessage, String search)
|
||||||
|
|||||||
Reference in New Issue
Block a user