raids plugin: fix matching rotation whitelist

Spaces were not being removed from the config values causing the
whitelist contains check to fail.

Additionally, change the format of the raids whitelist to be newline
separated CSV which is not interpreted by GSON as valid JSON, fixing the
config service from serializing the whitelist rotation which is adding
erroneous quotes around the room names.

This also refactors the rotation whitelist display to be a simple yes/no
instead of this unused match count logic.

Co-authored-by: Alexsuperfly <alexcsumner@gmail.com>
This commit is contained in:
Adam
2019-11-20 15:43:59 -05:00
parent ebdd3c7fce
commit 0e920bdd98
5 changed files with 150 additions and 44 deletions

View File

@@ -30,7 +30,7 @@ import lombok.Getter;
import net.runelite.client.plugins.raids.solver.Layout;
import net.runelite.client.plugins.raids.solver.Room;
public class Raid
class Raid
{
@Getter
private final RaidRoom[] rooms = new RaidRoom[16];
@@ -38,7 +38,7 @@ public class Raid
@Getter
private Layout layout;
public void updateLayout(Layout layout)
void updateLayout(Layout layout)
{
if (layout == null)
{

View File

@@ -123,7 +123,7 @@ public interface RaidsConfig extends Config
position = 8,
keyName = "whitelistedRotations",
name = "Whitelisted rotations",
description = "Warn when boss rotation doesn't match a whitelisted one. Add rotations like [tekton, muttadile, guardians]"
description = "Warn when boss rotation doesn't match a whitelisted one. Add rotations like: tekton, muttadiles, guardians - each rotation on its own line"
)
default String whitelistedRotations()
{

View File

@@ -101,14 +101,6 @@ public class RaidsOverlay extends Overlay
.color(color)
.build());
int bossMatches = 0;
int bossCount = 0;
if (config.enableRotationWhitelist())
{
bossMatches = plugin.getRotationMatches();
}
for (Room layoutRoom : plugin.getRaid().getLayout().getRooms())
{
int position = layoutRoom.getPosition();
@@ -124,13 +116,12 @@ public class RaidsOverlay extends Overlay
switch (room.getType())
{
case COMBAT:
bossCount++;
if (plugin.getRoomWhitelist().contains(room.getName().toLowerCase()))
{
color = Color.GREEN;
}
else if (plugin.getRoomBlacklist().contains(room.getName().toLowerCase())
|| config.enableRotationWhitelist() && bossCount > bossMatches)
|| config.enableRotationWhitelist() && !plugin.getRotationMatches())
{
color = Color.RED;
}

View File

@@ -24,21 +24,24 @@
*/
package net.runelite.client.plugins.raids;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.inject.Binder;
import com.google.inject.Provides;
import java.io.IOException;
import java.text.DecimalFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
@@ -96,7 +99,6 @@ public class RaidsPlugin extends Plugin
private static final String RAID_COMPLETE_MESSAGE = "Congratulations - your raid is complete!";
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("###.##");
private static final DecimalFormat POINTS_FORMAT = new DecimalFormat("#,###");
private static final Pattern ROTATION_REGEX = Pattern.compile("\\[(.*?)]");
private static final String LAYOUT_COMMAND = "!layout";
@Inject
@@ -142,17 +144,18 @@ public class RaidsPlugin extends Plugin
private ScheduledExecutorService scheduledExecutorService;
@Getter
private final ArrayList<String> roomWhitelist = new ArrayList<>();
private final Set<String> roomWhitelist = new HashSet<String>();
@Getter
private final ArrayList<String> roomBlacklist = new ArrayList<>();
private final Set<String> roomBlacklist = new HashSet<String>();
@Getter
private final ArrayList<String> rotationWhitelist = new ArrayList<>();
private final Set<String> rotationWhitelist = new HashSet<String>();
@Getter
private final ArrayList<String> layoutWhitelist = new ArrayList<>();
private final Set<String> layoutWhitelist = new HashSet<String>();
@Setter(AccessLevel.PACKAGE) // for the test
@Getter
private Raid raid;
@@ -399,38 +402,28 @@ public class RaidsPlugin extends Plugin
}
}
private void updateLists()
@VisibleForTesting
void updateLists()
{
updateList(roomWhitelist, config.whitelistedRooms());
updateList(roomBlacklist, config.blacklistedRooms());
updateList(rotationWhitelist, config.whitelistedRotations());
updateList(layoutWhitelist, config.whitelistedLayouts());
// Update rotation whitelist
rotationWhitelist.clear();
for (String line : config.whitelistedRotations().split("\\n"))
{
rotationWhitelist.add(line.toLowerCase().replace(" ", ""));
}
}
private void updateList(ArrayList<String> list, String input)
private void updateList(Collection<String> list, String input)
{
list.clear();
if (list == rotationWhitelist)
{
Matcher m = ROTATION_REGEX.matcher(input);
while (m.find())
{
String rotation = m.group(1).toLowerCase();
if (!list.contains(rotation))
{
list.add(rotation);
}
}
}
else
{
list.addAll(Text.fromCSV(input.toLowerCase()));
}
list.addAll(Text.fromCSV(input.toLowerCase()));
}
int getRotationMatches()
boolean getRotationMatches()
{
RaidRoom[] combatRooms = raid.getCombatRooms();
String rotation = Arrays.stream(combatRooms)
@@ -438,7 +431,7 @@ public class RaidsPlugin extends Plugin
.map(String::toLowerCase)
.collect(Collectors.joining(","));
return rotationWhitelist.contains(rotation) ? combatRooms.length : 0;
return rotationWhitelist.contains(rotation);
}
private Point findLobbyBase()