chat commands: add ba high gamble command
This commit is contained in:
@@ -225,7 +225,7 @@ public class ChatClient
|
||||
|
||||
public boolean submitGc(String username, int gc) throws IOException
|
||||
{
|
||||
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
|
||||
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
||||
.addPathSegment("chat")
|
||||
.addPathSegment("gc")
|
||||
.addQueryParameter("name", username)
|
||||
@@ -237,7 +237,7 @@ public class ChatClient
|
||||
.url(url)
|
||||
.build();
|
||||
|
||||
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
|
||||
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||
{
|
||||
return response.isSuccessful();
|
||||
}
|
||||
@@ -245,7 +245,7 @@ public class ChatClient
|
||||
|
||||
public int getGc(String username) throws IOException
|
||||
{
|
||||
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
|
||||
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
||||
.addPathSegment("chat")
|
||||
.addPathSegment("gc")
|
||||
.addQueryParameter("name", username)
|
||||
@@ -255,7 +255,7 @@ public class ChatClient
|
||||
.url(url)
|
||||
.build();
|
||||
|
||||
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
|
||||
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||
{
|
||||
if (!response.isSuccessful())
|
||||
{
|
||||
|
||||
@@ -100,4 +100,4 @@ public class ChatController
|
||||
{
|
||||
return chatService.getHosts(world, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,4 +117,4 @@ public class ChatService
|
||||
jedis.lrem(key, 0, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,6 +98,7 @@ public class ChatCommandsPlugin extends Plugin
|
||||
private static final String QP_COMMAND_STRING = "!qp";
|
||||
private static final String GC_COMMAND_STRING = "!gc";
|
||||
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();
|
||||
@@ -148,6 +149,7 @@ public class ChatCommandsPlugin extends Plugin
|
||||
chatCommandManager.registerCommandAsync(QP_COMMAND_STRING, this::questPointsLookup, this::questPointsSubmit);
|
||||
chatCommandManager.registerCommandAsync(GC_COMMAND_STRING, this::gambleCountLookup, this::gambleCountSubmit);
|
||||
chatCommandManager.registerCommandAsync(PB_COMMAND, this::personalBestLookup, this::personalBestSubmit);
|
||||
chatCommandManager.registerCommandAsync(GC_COMMAND_STRING, this::gambleCountLookup, this::gambleCountSubmit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -647,6 +649,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.
|
||||
|
||||
Reference in New Issue
Block a user