chat commands: add duel arena chat command

This commit is contained in:
sdburns1998
2019-06-29 00:30:28 +02:00
parent 63664fbac7
commit cfeab20179
8 changed files with 338 additions and 143 deletions

View File

@@ -39,8 +39,8 @@ import okhttp3.Response;
public class ChatClient public class ChatClient
{ {
private static final Predicate<String> LAYOUT_VALIDATOR = Pattern private static final Predicate<String> LAYOUT_VALIDATOR = Pattern
.compile("\\[[A-Z]+]:(\\s*\\w+\\s*(\\([A-Za-z]+\\))?,?)+") .compile("\\[[A-Z]+]:(\\s*\\w+\\s*(\\([A-Za-z]+\\))?,?)+")
.asPredicate(); .asPredicate();
public boolean submitKc(String username, String boss, int kc) throws IOException public boolean submitKc(String username, String boss, int kc) throws IOException
{ {
@@ -225,7 +225,7 @@ public class ChatClient
public boolean submitGc(String username, int gc) throws IOException public boolean submitGc(String username, int gc) throws IOException
{ {
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
.addPathSegment("chat") .addPathSegment("chat")
.addPathSegment("gc") .addPathSegment("gc")
.addQueryParameter("name", username) .addQueryParameter("name", username)
@@ -245,7 +245,7 @@ public class ChatClient
public int getGc(String username) throws IOException public int getGc(String username) throws IOException
{ {
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
.addPathSegment("chat") .addPathSegment("chat")
.addPathSegment("gc") .addPathSegment("gc")
.addQueryParameter("name", username) .addQueryParameter("name", username)
@@ -255,7 +255,7 @@ public class ChatClient
.url(url) .url(url)
.build(); .build();
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
{ {
if (!response.isSuccessful()) if (!response.isSuccessful())
{ {
@@ -273,16 +273,16 @@ public class ChatClient
} }
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder() HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
.addPathSegment("chat") .addPathSegment("chat")
.addPathSegment("layout") .addPathSegment("layout")
.addQueryParameter("name", username) .addQueryParameter("name", username)
.addQueryParameter("layout", layout) .addQueryParameter("layout", layout)
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(null, new byte[0])) .post(RequestBody.create(null, new byte[0]))
.url(url) .url(url)
.build(); .build();
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute()) try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
{ {
@@ -290,17 +290,40 @@ public class ChatClient
} }
} }
public boolean submitDuels(String username, int wins, int losses, int winningStreak, int losingStreak) throws IOException
{
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("chat")
.addPathSegment("duels")
.addQueryParameter("name", username)
.addQueryParameter("wins", Integer.toString(wins))
.addQueryParameter("losses", Integer.toString(losses))
.addQueryParameter("winningStreak", Integer.toString(winningStreak))
.addQueryParameter("losingStreak", Integer.toString(losingStreak))
.build();
Request request = new Request.Builder()
.post(RequestBody.create(null, new byte[0]))
.url(url)
.build();
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
{
return response.isSuccessful();
}
}
public String getLayout(String username) throws IOException public String getLayout(String username) throws IOException
{ {
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder() HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
.addPathSegment("chat") .addPathSegment("chat")
.addPathSegment("layout") .addPathSegment("layout")
.addQueryParameter("name", username) .addQueryParameter("name", username)
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.url(url) .url(url)
.build(); .build();
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute()) try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
{ {
@@ -328,15 +351,15 @@ public class ChatClient
public House[] getHosts(int world, String location) throws IOException public House[] getHosts(int world, String location) throws IOException
{ {
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder() HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
.addPathSegment("chat") .addPathSegment("chat")
.addPathSegment("hosts") .addPathSegment("hosts")
.addQueryParameter("world", Integer.toString(world)) .addQueryParameter("world", Integer.toString(world))
.addQueryParameter("location", location) .addQueryParameter("location", location)
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.url(url) .url(url)
.build(); .build();
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute()) try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
{ {
@@ -347,6 +370,35 @@ public class ChatClient
InputStream in = response.body().byteStream(); InputStream in = response.body().byteStream();
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), House[].class); return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), House[].class);
}
catch (JsonParseException ex)
{
throw new IOException(ex);
}
}
public Duels getDuels(String username) throws IOException
{
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
.addPathSegment("chat")
.addPathSegment("duels")
.addQueryParameter("name", username)
.build();
Request request = new Request.Builder()
.url(url)
.build();
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
{
if (!response.isSuccessful())
{
throw new IOException("Unable to look up duels!");
}
InputStream in = response.body().byteStream();
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), Duels.class);
} }
catch (JsonParseException ex) catch (JsonParseException ex)
{ {
@@ -357,24 +409,24 @@ public class ChatClient
public boolean submitHost(int world, String location, House house) throws IOException public boolean submitHost(int world, String location, House house) throws IOException
{ {
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder() HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
.addPathSegment("chat") .addPathSegment("chat")
.addPathSegment("hosts") .addPathSegment("hosts")
.addQueryParameter("world", Integer.toString(world)) .addQueryParameter("world", Integer.toString(world))
.addQueryParameter("location", location) .addQueryParameter("location", location)
.addQueryParameter("owner", house.getOwner()) .addQueryParameter("owner", house.getOwner())
.addQueryParameter("guildedAltar", Boolean.toString(house.isGuildedAltarPresent())) .addQueryParameter("guildedAltar", Boolean.toString(house.isGuildedAltarPresent()))
.addQueryParameter("occultAltar", Boolean.toString(house.isOccultAltarPresent())) .addQueryParameter("occultAltar", Boolean.toString(house.isOccultAltarPresent()))
.addQueryParameter("spiritTree", Boolean.toString(house.isSpiritTreePresent())) .addQueryParameter("spiritTree", Boolean.toString(house.isSpiritTreePresent()))
.addQueryParameter("fairyRing", Boolean.toString(house.isFairyRingPresent())) .addQueryParameter("fairyRing", Boolean.toString(house.isFairyRingPresent()))
.addQueryParameter("wildernessObelisk", Boolean.toString(house.isWildernessObeliskPresent())) .addQueryParameter("wildernessObelisk", Boolean.toString(house.isWildernessObeliskPresent()))
.addQueryParameter("repairStand", Boolean.toString(house.isRepairStandPresent())) .addQueryParameter("repairStand", Boolean.toString(house.isRepairStandPresent()))
.addQueryParameter("combatDummy", Boolean.toString(house.isCombatDummyPresent())) .addQueryParameter("combatDummy", Boolean.toString(house.isCombatDummyPresent()))
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(null, new byte[0])) .post(RequestBody.create(null, new byte[0]))
.url(url) .url(url)
.build(); .build();
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute()) try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
{ {
@@ -385,29 +437,29 @@ public class ChatClient
public boolean removeHost(int world, String location, House house) throws IOException public boolean removeHost(int world, String location, House house) throws IOException
{ {
HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder() HttpUrl url = RuneLiteAPI.getPlusApiBase().newBuilder()
.addPathSegment("chat") .addPathSegment("chat")
.addPathSegment("hosts") .addPathSegment("hosts")
.addQueryParameter("world", Integer.toString(world)) .addQueryParameter("world", Integer.toString(world))
.addQueryParameter("location", location) .addQueryParameter("location", location)
.addQueryParameter("owner", house.getOwner()) .addQueryParameter("owner", house.getOwner())
.addQueryParameter("guildedAltar", Boolean.toString(house.isGuildedAltarPresent())) .addQueryParameter("guildedAltar", Boolean.toString(house.isGuildedAltarPresent()))
.addQueryParameter("occultAltar", Boolean.toString(house.isOccultAltarPresent())) .addQueryParameter("occultAltar", Boolean.toString(house.isOccultAltarPresent()))
.addQueryParameter("spiritTree", Boolean.toString(house.isSpiritTreePresent())) .addQueryParameter("spiritTree", Boolean.toString(house.isSpiritTreePresent()))
.addQueryParameter("fairyRing", Boolean.toString(house.isFairyRingPresent())) .addQueryParameter("fairyRing", Boolean.toString(house.isFairyRingPresent()))
.addQueryParameter("wildernessObelisk", Boolean.toString(house.isWildernessObeliskPresent())) .addQueryParameter("wildernessObelisk", Boolean.toString(house.isWildernessObeliskPresent()))
.addQueryParameter("repairStand", Boolean.toString(house.isRepairStandPresent())) .addQueryParameter("repairStand", Boolean.toString(house.isRepairStandPresent()))
.addQueryParameter("combatDummy", Boolean.toString(house.isCombatDummyPresent())) .addQueryParameter("combatDummy", Boolean.toString(house.isCombatDummyPresent()))
.addQueryParameter("remove", Boolean.toString(true)) .addQueryParameter("remove", Boolean.toString(true))
.build(); .build();
Request request = new Request.Builder() Request request = new Request.Builder()
.post(RequestBody.create(null, new byte[0])) .post(RequestBody.create(null, new byte[0]))
.url(url) .url(url)
.build(); .build();
try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute()) try (Response response = RuneLiteAPI.RLP_CLIENT.newCall(request).execute())
{ {
return response.isSuccessful(); return response.isSuccessful();
} }
} }
} }

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2019, 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.http.api.chat;
import lombok.Data;
@Data
public class Duels
{
private int wins;
private int losses;
private int winningStreak;
private int losingStreak;
}

View File

@@ -110,6 +110,17 @@ public interface ChatCommandsConfig extends Config
@ConfigItem( @ConfigItem(
position = 7, position = 7,
keyName = "duels",
name = "Duels Command",
description = "Configures whether the duel arena command is enabled<br> !duels"
)
default boolean duels()
{
return true;
}
@ConfigItem(
position = 8,
keyName = "clearShortcuts", keyName = "clearShortcuts",
name = "Clear shortcuts", name = "Clear shortcuts",
description = "Enable shortcuts (ctrl+w and backspace) for clearing the chatbox" description = "Enable shortcuts (ctrl+w and backspace) for clearing the chatbox"

View File

@@ -64,6 +64,7 @@ import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.util.StackFormatter; import net.runelite.client.util.StackFormatter;
import static net.runelite.client.util.Text.sanitize; import static net.runelite.client.util.Text.sanitize;
import net.runelite.http.api.chat.ChatClient; import net.runelite.http.api.chat.ChatClient;
import net.runelite.http.api.chat.Duels;
import net.runelite.http.api.hiscore.HiscoreClient; import net.runelite.http.api.hiscore.HiscoreClient;
import net.runelite.http.api.hiscore.HiscoreEndpoint; import net.runelite.http.api.hiscore.HiscoreEndpoint;
import net.runelite.http.api.hiscore.HiscoreResult; import net.runelite.http.api.hiscore.HiscoreResult;
@@ -89,6 +90,8 @@ public class ChatCommandsPlugin extends Plugin
private static final Pattern BARROWS_PATTERN = Pattern.compile("Your Barrows chest count is: <col=ff0000>(\\d+)</col>"); private static final Pattern BARROWS_PATTERN = Pattern.compile("Your Barrows chest count is: <col=ff0000>(\\d+)</col>");
private static final Pattern KILL_DURATION_PATTERN = Pattern.compile("Fight duration: <col=ff0000>[0-9:]+</col>. Personal best: ([0-9:]+)"); private static final Pattern KILL_DURATION_PATTERN = Pattern.compile("Fight duration: <col=ff0000>[0-9:]+</col>. Personal best: ([0-9:]+)");
private static final Pattern NEW_PB_PATTERN = Pattern.compile("Fight duration: <col=ff0000>([0-9:]+)</col> \\(new personal best\\)"); private static final Pattern NEW_PB_PATTERN = Pattern.compile("Fight duration: <col=ff0000>([0-9:]+)</col> \\(new personal best\\)");
private static final Pattern DUEL_ARENA_WINS_PATTERN = Pattern.compile("You (were defeated|won)! You have(?: now)? won (\\d+) duels?");
private static final Pattern DUEL_ARENA_LOSSES_PATTERN = Pattern.compile("You have(?: now)? lost (\\d+) duels?");
private static final String TOTAL_LEVEL_COMMAND_STRING = "!total"; private static final String TOTAL_LEVEL_COMMAND_STRING = "!total";
private static final String PRICE_COMMAND_STRING = "!price"; private static final String PRICE_COMMAND_STRING = "!price";
private static final String LEVEL_COMMAND_STRING = "!lvl"; private static final String LEVEL_COMMAND_STRING = "!lvl";
@@ -98,7 +101,7 @@ public class ChatCommandsPlugin extends Plugin
private static final String QP_COMMAND_STRING = "!qp"; private static final String QP_COMMAND_STRING = "!qp";
private static final String GC_COMMAND_STRING = "!gc"; private static final String GC_COMMAND_STRING = "!gc";
private static final String PB_COMMAND = "!pb"; private static final String PB_COMMAND = "!pb";
private static final String GC_COMMAND_STRING = "!gc"; private static final String DUEL_ARENA_COMMAND = "!duels";
private final HiscoreClient hiscoreClient = new HiscoreClient(); private final HiscoreClient hiscoreClient = new HiscoreClient();
private final ChatClient chatClient = new ChatClient(); private final ChatClient chatClient = new ChatClient();
@@ -149,7 +152,7 @@ public class ChatCommandsPlugin extends Plugin
chatCommandManager.registerCommandAsync(QP_COMMAND_STRING, this::questPointsLookup, this::questPointsSubmit); chatCommandManager.registerCommandAsync(QP_COMMAND_STRING, this::questPointsLookup, this::questPointsSubmit);
chatCommandManager.registerCommandAsync(GC_COMMAND_STRING, this::gambleCountLookup, this::gambleCountSubmit); chatCommandManager.registerCommandAsync(GC_COMMAND_STRING, this::gambleCountLookup, this::gambleCountSubmit);
chatCommandManager.registerCommandAsync(PB_COMMAND, this::personalBestLookup, this::personalBestSubmit); chatCommandManager.registerCommandAsync(PB_COMMAND, this::personalBestLookup, this::personalBestSubmit);
chatCommandManager.registerCommandAsync(GC_COMMAND_STRING, this::gambleCountLookup, this::gambleCountSubmit); chatCommandManager.registerCommandAsync(DUEL_ARENA_COMMAND, this::duelArenaLookup, this::duelArenaSubmit);
} }
@Override @Override
@@ -168,6 +171,7 @@ public class ChatCommandsPlugin extends Plugin
chatCommandManager.unregisterCommand(QP_COMMAND_STRING); chatCommandManager.unregisterCommand(QP_COMMAND_STRING);
chatCommandManager.unregisterCommand(PB_COMMAND); chatCommandManager.unregisterCommand(PB_COMMAND);
chatCommandManager.unregisterCommand(GC_COMMAND_STRING); chatCommandManager.unregisterCommand(GC_COMMAND_STRING);
chatCommandManager.unregisterCommand(DUEL_ARENA_COMMAND);
} }
@Provides @Provides
@@ -205,7 +209,9 @@ public class ChatCommandsPlugin extends Plugin
@Subscribe @Subscribe
public void onChatMessage(ChatMessage chatMessage) public void onChatMessage(ChatMessage chatMessage)
{ {
if (chatMessage.getType() != ChatMessageType.GAMEMESSAGE && chatMessage.getType() != ChatMessageType.SPAM) if (chatMessage.getType() != ChatMessageType.TRADE
&& chatMessage.getType() != ChatMessageType.GAMEMESSAGE
&& chatMessage.getType() != ChatMessageType.SPAM)
{ {
return; return;
} }
@@ -241,6 +247,43 @@ public class ChatCommandsPlugin extends Plugin
return; return;
} }
matcher = DUEL_ARENA_WINS_PATTERN.matcher(message);
if (matcher.find())
{
final int oldWins = getKc("Duel Arena Wins");
final int wins = Integer.parseInt(matcher.group(2));
final String result = matcher.group(1);
int winningStreak = getKc("Duel Arena Win Streak");
int losingStreak = getKc("Duel Arena Lose Streak");
if (result.equals("won") && wins > oldWins)
{
losingStreak = 0;
winningStreak += 1;
}
else if (result.equals("were defeated"))
{
losingStreak += 1;
winningStreak = 0;
}
else
{
log.warn("unrecognized duel streak chat message: {}", message);
}
setKc("Duel Arena Wins", wins);
setKc("Duel Arena Win Streak", winningStreak);
setKc("Duel Arena Lose Streak", losingStreak);
}
matcher = DUEL_ARENA_LOSSES_PATTERN.matcher(message);
if (matcher.find())
{
int losses = Integer.parseInt(matcher.group(1));
setKc("Duel Arena Losses", losses);
}
matcher = BARROWS_PATTERN.matcher(message); matcher = BARROWS_PATTERN.matcher(message);
if (matcher.find()) if (matcher.find())
{ {
@@ -421,6 +464,96 @@ public class ChatCommandsPlugin extends Plugin
client.refreshChat(); client.refreshChat();
} }
private boolean duelArenaSubmit(ChatInput chatInput, String value)
{
final int wins = getKc("Duel Arena Wins");
final int losses = getKc("Duel Arena Losses");
final int winningStreak = getKc("Duel Arena Win Streak");
final int losingStreak = getKc("Duel Arena Lose Streak");
if (wins <= 0 && losses <= 0 && winningStreak <= 0 && losingStreak <= 0)
{
return false;
}
final String playerName = client.getLocalPlayer().getName();
executor.execute(() ->
{
try
{
chatClient.submitDuels(playerName, wins, losses, winningStreak, losingStreak);
}
catch (Exception ex)
{
log.warn("unable to submit duels", ex);
}
finally
{
chatInput.resume();
}
});
return true;
}
private void duelArenaLookup(ChatMessage chatMessage, String message)
{
if (!config.duels())
{
return;
}
ChatMessageType type = chatMessage.getType();
final String player;
if (type == ChatMessageType.PRIVATECHATOUT)
{
player = client.getLocalPlayer().getName();
}
else
{
player = sanitize(chatMessage.getName());
}
Duels duels;
try
{
duels = chatClient.getDuels(player);
}
catch (IOException ex)
{
log.debug("unable to lookup duels", ex);
return;
}
final int wins = duels.getWins();
final int losses = duels.getLosses();
final int winningStreak = duels.getWinningStreak();
final int losingStreak = duels.getLosingStreak();
String response = new ChatMessageBuilder()
.append(ChatColorType.NORMAL)
.append("Duel Arena wins: ")
.append(ChatColorType.HIGHLIGHT)
.append(Integer.toString(wins))
.append(ChatColorType.NORMAL)
.append(" losses: ")
.append(ChatColorType.HIGHLIGHT)
.append(Integer.toString(losses))
.append(ChatColorType.NORMAL)
.append(" streak: ")
.append(ChatColorType.HIGHLIGHT)
.append(Integer.toString((winningStreak != 0 ? winningStreak : -losingStreak)))
.build();
log.debug("Setting response {}", response);
final MessageNode messageNode = chatMessage.getMessageNode();
messageNode.setRuneLiteFormatMessage(response);
chatMessageManager.update(messageNode);
client.refreshChat();
}
private void questPointsLookup(ChatMessage chatMessage, String message) private void questPointsLookup(ChatMessage chatMessage, String message)
{ {
if (!config.qp()) if (!config.qp())
@@ -649,74 +782,6 @@ public class ChatCommandsPlugin extends Plugin
return true; 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 * Looks up the item price and changes the original message to the
* response. * response.
@@ -1301,4 +1366,4 @@ public class ChatCommandsPlugin extends Plugin
return WordUtils.capitalize(boss); return WordUtils.capitalize(boss);
} }
} }
} }

View File

@@ -71,7 +71,7 @@ public class InterfaceStylesPlugin extends Plugin
@Inject @Inject
private SpriteManager spriteManager; private SpriteManager spriteManager;
private SpritePixels[] defaultCrossSprites; private Sprite[] defaultCrossSprites;
@Provides @Provides
InterfaceStylesConfig provideConfig(ConfigManager configManager) InterfaceStylesConfig provideConfig(ConfigManager configManager)
@@ -316,19 +316,19 @@ public class InterfaceStylesPlugin extends Plugin
return; return;
} }
SpritePixels[] crossSprites = client.getCrossSprites(); Sprite[] crossSprites = client.getCrossSprites();
if (crossSprites == null) if (crossSprites == null)
{ {
return; return;
} }
defaultCrossSprites = new SpritePixels[crossSprites.length]; defaultCrossSprites = new Sprite[crossSprites.length];
System.arraycopy(crossSprites, 0, defaultCrossSprites, 0, defaultCrossSprites.length); System.arraycopy(crossSprites, 0, defaultCrossSprites, 0, defaultCrossSprites.length);
for (int i = 0; i < crossSprites.length; i++) for (int i = 0; i < crossSprites.length; i++)
{ {
SpritePixels newSprite = getFileSpritePixels("rs3/cross_sprites/" + i + ".png"); Sprite newSprite = getFileSpritePixels("rs3/cross_sprites/" + i + ".png");
if (newSprite == null) if (newSprite == null)
{ {
@@ -351,7 +351,7 @@ public class InterfaceStylesPlugin extends Plugin
return; return;
} }
SpritePixels[] crossSprites = client.getCrossSprites(); Sprite[] crossSprites = client.getCrossSprites();
if (crossSprites != null && defaultCrossSprites.length == crossSprites.length) if (crossSprites != null && defaultCrossSprites.length == crossSprites.length)
{ {

View File

@@ -1181,10 +1181,6 @@ public class MenuEntrySwapperPlugin extends Plugin
{ {
swap(client, "quick-leave", option, target, true); swap(client, "quick-leave", option, target, true);
} }
else if (config.swapQuick() && option.equals("climb-down"))
{
swap("quick-start", option, target, true);
}
else if (config.swapAdmire() && option.equals("admire")) else if (config.swapAdmire() && option.equals("admire"))
{ {
swap(client, "teleport", option, target, true); swap(client, "teleport", option, target, true);

View File

@@ -30,6 +30,7 @@ import com.google.inject.testing.fieldbinder.BoundFieldModule;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import static net.runelite.api.ChatMessageType.GAMEMESSAGE; import static net.runelite.api.ChatMessageType.GAMEMESSAGE;
import static net.runelite.api.ChatMessageType.TRADE;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.events.ChatMessage; import net.runelite.api.events.ChatMessage;
import net.runelite.client.config.ChatColorConfig; import net.runelite.client.config.ChatColorConfig;
@@ -191,4 +192,38 @@ public class ChatCommandsPluginTest
verify(configManager).setConfiguration(eq("personalbest.adam"), eq("kree'arra"), eq(181)); verify(configManager).setConfiguration(eq("personalbest.adam"), eq("kree'arra"), eq(181));
} }
}
@Test
public void testDuelArenaWin()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You won! You have now won 27 duels.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessageEvent);
verify(configManager).setConfiguration("killcount.adam", "duel arena wins", 27);
verify(configManager).setConfiguration("killcount.adam", "duel arena win streak", 1);
}
@Test
public void testDuelArenaWin2()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You were defeated! You have won 22 duels.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessageEvent);
verify(configManager).setConfiguration("killcount.adam", "duel arena wins", 22);
}
@Test
public void testDuelArenaLose()
{
when(client.getUsername()).thenReturn("Adam");
ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You have now lost 999 duels.", null, 0);
chatCommandsPlugin.onChatMessage(chatMessageEvent);
verify(configManager).setConfiguration("killcount.adam", "duel arena losses", 999);
}
}

View File

@@ -1037,5 +1037,5 @@ public interface RSClient extends RSGameShell, Client
@Import("crossSprites") @Import("crossSprites")
@Override @Override
RSSpritePixels[] getCrossSprites(); RSSprite[] getCrossSprites();
} }