chat commands: add ba high gamble command

This commit is contained in:
Jacob McElroy
2019-06-27 08:50:32 -04:00
committed by Adam
parent 1e112f97d5
commit 8757d25bd3
6 changed files with 166 additions and 0 deletions

View File

@@ -99,6 +99,17 @@ public interface ChatCommandsConfig extends Config
@ConfigItem(
position = 6,
keyName = "gc",
name = "GC Command",
description = "Configures whether the Barbarian Assault High gamble count command is enabled<br> !gc"
)
default boolean gc()
{
return true;
}
@ConfigItem(
position = 7,
keyName = "clearShortcuts",
name = "Clear shortcuts",
description = "Enable shortcuts (ctrl+w and backspace) for clearing the chatbox"

View File

@@ -42,6 +42,7 @@ import net.runelite.api.IconID;
import net.runelite.api.ItemComposition;
import net.runelite.api.MessageNode;
import net.runelite.api.VarPlayer;
import net.runelite.api.Varbits;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.VarbitChanged;
@@ -95,6 +96,7 @@ public class ChatCommandsPlugin extends Plugin
private static final String CMB_COMMAND_STRING = "!cmb";
private static final String QP_COMMAND_STRING = "!qp";
private static final String PB_COMMAND = "!pb";
private static final String GC_COMMAND_STRING = "!gc";
private final HiscoreClient hiscoreClient = new HiscoreClient();
private final ChatClient chatClient = new ChatClient();
@@ -143,6 +145,7 @@ public class ChatCommandsPlugin extends Plugin
chatCommandManager.registerCommandAsync(KILLCOUNT_COMMAND_STRING, this::killCountLookup, this::killCountSubmit);
chatCommandManager.registerCommandAsync(QP_COMMAND_STRING, this::questPointsLookup, this::questPointsSubmit);
chatCommandManager.registerCommandAsync(PB_COMMAND, this::personalBestLookup, this::personalBestSubmit);
chatCommandManager.registerCommandAsync(GC_COMMAND_STRING, this::gambleCountLookup, this::gambleCountSubmit);
}
@Override
@@ -160,6 +163,7 @@ public class ChatCommandsPlugin extends Plugin
chatCommandManager.unregisterCommand(KILLCOUNT_COMMAND_STRING);
chatCommandManager.unregisterCommand(QP_COMMAND_STRING);
chatCommandManager.unregisterCommand(PB_COMMAND);
chatCommandManager.unregisterCommand(GC_COMMAND_STRING);
}
@Provides
@@ -570,6 +574,74 @@ public class ChatCommandsPlugin extends Plugin
return true;
}
private void gambleCountLookup(ChatMessage chatMessage, String message)
{
if (!config.gc())
{
return;
}
ChatMessageType type = chatMessage.getType();
final String player;
if (type == ChatMessageType.PRIVATECHATOUT)
{
player = client.getLocalPlayer().getName();
}
else
{
player = sanitize(chatMessage.getName());
}
int gc;
try
{
gc = chatClient.getGc(player);
}
catch (IOException ex)
{
log.debug("unable to lookup gamble count", ex);
return;
}
String response = new ChatMessageBuilder()
.append(ChatColorType.NORMAL)
.append("Barbarian Assault High-level gambles: ")
.append(ChatColorType.HIGHLIGHT)
.append(Integer.toString(gc))
.build();
log.debug("Setting response {}", response);
final MessageNode messageNode = chatMessage.getMessageNode();
messageNode.setRuneLiteFormatMessage(response);
chatMessageManager.update(messageNode);
client.refreshChat();
}
private boolean gambleCountSubmit(ChatInput chatInput, String value)
{
final int gc = client.getVar(Varbits.BA_GC);
final String playerName = client.getLocalPlayer().getName();
executor.execute(() ->
{
try
{
chatClient.submitGc(playerName, gc);
}
catch (Exception ex)
{
log.warn("unable to submit gamble count", ex);
}
finally
{
chatInput.resume();
}
});
return true;
}
/**
* Looks up the item price and changes the original message to the
* response.