Add private message input event and add !kc to chatcommands for private messages
This commit is contained in:
@@ -25,8 +25,11 @@
|
||||
package net.runelite.client.chat;
|
||||
|
||||
import net.runelite.client.events.ChatboxInput;
|
||||
import net.runelite.client.events.PrivateMessageInput;
|
||||
|
||||
public interface ChatboxInputListener
|
||||
{
|
||||
boolean onChatboxInput(ChatboxInput chatboxInput);
|
||||
|
||||
boolean onPrivateMessageInput(PrivateMessageInput privateMessageInput);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import net.runelite.api.events.CommandExecuted;
|
||||
import net.runelite.api.events.ScriptCallbackEvent;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.events.ChatboxInput;
|
||||
import net.runelite.client.events.PrivateMessageInput;
|
||||
|
||||
@Slf4j
|
||||
@Singleton
|
||||
@@ -48,6 +49,7 @@ public class CommandManager
|
||||
{
|
||||
private static final String RUNELITE_COMMAND = "runeliteCommand";
|
||||
private static final String CHATBOX_INPUT = "chatboxInput";
|
||||
private static final String PRIVMATE_MESSAGE = "privateMessage";
|
||||
|
||||
private final Provider<Client> clientProvider;
|
||||
private final EventBus eventBus;
|
||||
@@ -90,6 +92,9 @@ public class CommandManager
|
||||
case CHATBOX_INPUT:
|
||||
handleInput(event);
|
||||
break;
|
||||
case PRIVMATE_MESSAGE:
|
||||
handlePrivateMessage(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +161,48 @@ public class CommandManager
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePrivateMessage(ScriptCallbackEvent event)
|
||||
{
|
||||
Client client = clientProvider.get();
|
||||
final String[] stringStack = client.getStringStack();
|
||||
final int[] intStack = client.getIntStack();
|
||||
int stringStackCount = client.getStringStackSize();
|
||||
int intStackCount = client.getIntStackSize();
|
||||
|
||||
final String target = stringStack[stringStackCount - 2];
|
||||
final String message = stringStack[stringStackCount - 1];
|
||||
|
||||
PrivateMessageInput privateMessageInput = new PrivateMessageInput(target, message)
|
||||
{
|
||||
private boolean resumed;
|
||||
|
||||
@Override
|
||||
public void resume()
|
||||
{
|
||||
if (resumed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
resumed = true;
|
||||
|
||||
ClientThread clientThread = clientThreadProvider.get();
|
||||
clientThread.invokeLater(() -> sendPrivmsg(target, message));
|
||||
}
|
||||
};
|
||||
|
||||
boolean stop = false;
|
||||
for (ChatboxInputListener chatboxInputListener : chatboxInputListenerList)
|
||||
{
|
||||
stop |= chatboxInputListener.onPrivateMessageInput(privateMessageInput);
|
||||
}
|
||||
|
||||
if (stop)
|
||||
{
|
||||
intStack[intStackCount - 1] = 1;
|
||||
client.setStringStackSize(stringStackCount - 2); // remove both target and message
|
||||
}
|
||||
}
|
||||
|
||||
private void sendChatboxInput(int chatType, String input)
|
||||
{
|
||||
Client client = clientProvider.get();
|
||||
@@ -169,4 +216,10 @@ public class CommandManager
|
||||
sending = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPrivmsg(String target, String message)
|
||||
{
|
||||
Client client = clientProvider.get();
|
||||
client.runScript(ScriptID.PRIVMSG, target, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.events;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public abstract class PrivateMessageInput
|
||||
{
|
||||
private final String target;
|
||||
private final String message;
|
||||
|
||||
public abstract void resume();
|
||||
}
|
||||
@@ -56,6 +56,7 @@ import net.runelite.client.chat.ChatboxInputListener;
|
||||
import net.runelite.client.chat.CommandManager;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.events.ChatboxInput;
|
||||
import net.runelite.client.events.PrivateMessageInput;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.input.KeyManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
@@ -356,6 +357,45 @@ public class ChatCommandsPlugin extends Plugin implements ChatboxInputListener
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrivateMessageInput(PrivateMessageInput privateMessageInput)
|
||||
{
|
||||
final String message = privateMessageInput.getMessage();
|
||||
if (!message.startsWith("!kc "))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int idx = message.indexOf(' ');
|
||||
final String boss = longBossName(message.substring(idx + 1));
|
||||
|
||||
final int kc = getKc(boss);
|
||||
if (kc <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final String playerName = client.getLocalPlayer().getName();
|
||||
|
||||
executor.execute(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
killCountClient.submit(playerName, boss, kc);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.warn("unable to submit killcount", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
privateMessageInput.resume();
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void killCountLookup(ChatMessageType type, SetMessage setMessage, String search)
|
||||
{
|
||||
final String player;
|
||||
|
||||
Reference in New Issue
Block a user