Merge pull request #675 from Kamielvf/raids-plugin-fix

Fix minor issues with Raids plugin
This commit is contained in:
Tomas Slusny
2018-02-25 10:47:27 +01:00
committed by GitHub
7 changed files with 106 additions and 5 deletions

View File

@@ -41,14 +41,18 @@ public class Raid
public void updateLayout(Layout layout) public void updateLayout(Layout layout)
{ {
if (layout == null) if (layout == null)
{
return; return;
}
this.layout = layout; this.layout = layout;
for (int i = 0; i < rooms.length; i++) for (int i = 0; i < rooms.length; i++)
{ {
if (layout.getRoomAt(i) == null) if (layout.getRoomAt(i) == null)
{
continue; continue;
}
RaidRoom room = rooms[i]; RaidRoom room = rooms[i];
@@ -58,10 +62,14 @@ public class Raid
room = new RaidRoom(null, type); room = new RaidRoom(null, type);
if (type == RaidRoom.Type.COMBAT) if (type == RaidRoom.Type.COMBAT)
{
room.setBoss(RaidRoom.Boss.UNKNOWN); room.setBoss(RaidRoom.Boss.UNKNOWN);
}
if (type == RaidRoom.Type.PUZZLE) if (type == RaidRoom.Type.PUZZLE)
{
room.setPuzzle(RaidRoom.Puzzle.UNKNOWN); room.setPuzzle(RaidRoom.Puzzle.UNKNOWN);
}
setRoom(room, i); setRoom(room, i);
} }
@@ -76,7 +84,9 @@ public class Raid
public void setRoom(RaidRoom room, int position) public void setRoom(RaidRoom room, int position)
{ {
if (position < rooms.length) if (position < rooms.length)
{
rooms[position] = room; rooms[position] = room;
}
} }
public RaidRoom[] getCombatRooms() public RaidRoom[] getCombatRooms()
@@ -86,10 +96,14 @@ public class Raid
for (Room room : layout.getRooms()) for (Room room : layout.getRooms())
{ {
if (room == null) if (room == null)
{
continue; continue;
}
if (rooms[room.getPosition()].getType() == RaidRoom.Type.COMBAT) if (rooms[room.getPosition()].getType() == RaidRoom.Type.COMBAT)
{
combatRooms.add(rooms[room.getPosition()]); combatRooms.add(rooms[room.getPosition()]);
}
} }
return combatRooms.toArray(new RaidRoom[combatRooms.size()]); return combatRooms.toArray(new RaidRoom[combatRooms.size()]);
@@ -102,9 +116,13 @@ public class Raid
for (RaidRoom room : rooms) for (RaidRoom room : rooms)
{ {
if (room != null) if (room != null)
{
builder.append(room.getType().getCode()); builder.append(room.getType().getCode());
}
else else
{
builder.append(" "); builder.append(" ");
}
} }
return builder.toString(); return builder.toString();

View File

@@ -55,7 +55,9 @@ public class RaidRoom
for (Type type : Type.values()) for (Type type : Type.values())
{ {
if (type.getCode().equalsIgnoreCase(String.valueOf(code))) if (type.getCode().equalsIgnoreCase(String.valueOf(code)))
{
return type; return type;
}
} }
return Type.EMPTY; return Type.EMPTY;
@@ -83,7 +85,9 @@ public class RaidRoom
for (Boss boss : Boss.values()) for (Boss boss : Boss.values())
{ {
if (boss.getName().equalsIgnoreCase(name)) if (boss.getName().equalsIgnoreCase(name))
{
return boss; return boss;
}
} }
return null; return null;
@@ -107,7 +111,9 @@ public class RaidRoom
for (Puzzle puzzle : Puzzle.values()) for (Puzzle puzzle : Puzzle.values())
{ {
if (puzzle.getName().equalsIgnoreCase(name)) if (puzzle.getName().equalsIgnoreCase(name))
{
return puzzle; return puzzle;
}
} }
return null; return null;

View File

@@ -61,7 +61,7 @@ import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager; import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
@PluginDescriptor( @PluginDescriptor(
name = "Raids Plugin" name = "Raids"
) )
@Slf4j @Slf4j
public class RaidsPlugin extends Plugin public class RaidsPlugin extends Plugin
@@ -127,6 +127,11 @@ public class RaidsPlugin extends Plugin
updateInfoBoxState(); updateInfoBoxState();
} }
if (config.pointsMessage())
{
cacheColors();
}
updateBlacklist(); updateBlacklist();
} }
@@ -134,20 +139,28 @@ public class RaidsPlugin extends Plugin
protected void shutDown() throws Exception protected void shutDown() throws Exception
{ {
if (timer != null) if (timer != null)
{
infoBoxManager.removeInfoBox(timer); infoBoxManager.removeInfoBox(timer);
}
} }
@Subscribe @Subscribe
public void onConfigChanged(ConfigChanged event) public void onConfigChanged(ConfigChanged event)
{ {
if (config.pointsMessage()) if (config.pointsMessage())
{
cacheColors(); cacheColors();
}
if (event.getKey().equals("raidsTimer")) if (event.getKey().equals("raidsTimer"))
{
updateInfoBoxState(); updateInfoBoxState();
}
if (event.getKey().equals("blacklistedRooms")) if (event.getKey().equals("blacklistedRooms"))
{
updateBlacklist(); updateBlacklist();
}
} }
@Subscribe @Subscribe
@@ -212,7 +225,9 @@ public class RaidsPlugin extends Plugin
if (message.startsWith(RAID_COMPLETE_MESSAGE)) if (message.startsWith(RAID_COMPLETE_MESSAGE))
{ {
if (timer != null) if (timer != null)
{
timer.setStopped(true); timer.setStopped(true);
}
if (config.pointsMessage()) if (config.pointsMessage())
{ {
@@ -254,19 +269,25 @@ public class RaidsPlugin extends Plugin
if (timer != null) if (timer != null)
{ {
if (inRaidChambers && config.raidsTimer()) if (inRaidChambers && config.raidsTimer())
{
infoBoxManager.addInfoBox(timer); infoBoxManager.addInfoBox(timer);
}
else else
{
infoBoxManager.removeInfoBox(timer); infoBoxManager.removeInfoBox(timer);
}
if (!inRaidChambers) if (!inRaidChambers)
{
timer = null; timer = null;
}
} }
} }
private void updateBlacklist() private void updateBlacklist()
{ {
blacklist.clear(); blacklist.clear();
blacklist.addAll(Arrays.asList(config.blacklistedRooms().toLowerCase().split(", "))); blacklist.addAll(Arrays.asList(config.blacklistedRooms().toLowerCase().split("\\s*,\\s*")));
} }
private void cacheColors() private void cacheColors()
@@ -287,10 +308,14 @@ public class RaidsPlugin extends Plugin
for (int y = 0; y < SCENE_SIZE; y++) for (int y = 0; y < SCENE_SIZE; y++)
{ {
if (tiles[x][y] == null || tiles[x][y].getWallObject() == null) if (tiles[x][y] == null || tiles[x][y].getWallObject() == null)
{
continue; continue;
}
if (tiles[x][y].getWallObject().getId() == ObjectID.NULL_12231) if (tiles[x][y].getWallObject().getId() == ObjectID.NULL_12231)
{
return tiles[x][y].getRegionLocation(); return tiles[x][y].getRegionLocation();
}
} }
} }
@@ -302,7 +327,9 @@ public class RaidsPlugin extends Plugin
Point gridBase = findLobbyBase(); Point gridBase = findLobbyBase();
if (gridBase == null) if (gridBase == null)
{
return null; return null;
}
Raid raid = new Raid(); Raid raid = new Raid();
Tile[][] tiles; Tile[][] tiles;
@@ -314,9 +341,13 @@ public class RaidsPlugin extends Plugin
tiles = client.getRegion().getTiles()[plane]; tiles = client.getRegion().getTiles()[plane];
if (tiles[gridBase.getX() + RaidRoom.ROOM_MAX_SIZE][gridBase.getY()] == null) if (tiles[gridBase.getX() + RaidRoom.ROOM_MAX_SIZE][gridBase.getY()] == null)
{
position = 1; position = 1;
}
else else
{
position = 0; position = 0;
}
for (int i = 1; i > -2; i--) for (int i = 1; i > -2; i--)
{ {
@@ -328,10 +359,14 @@ public class RaidsPlugin extends Plugin
offsetX = 0; offsetX = 0;
if (x > SCENE_SIZE && position > 1 && position < 4) if (x > SCENE_SIZE && position > 1 && position < 4)
{
position++; position++;
}
if (x < 0) if (x < 0)
{
offsetX = Math.abs(x) + 1; //add 1 because the tile at x=0 will always be null offsetX = Math.abs(x) + 1; //add 1 because the tile at x=0 will always be null
}
if (x < SCENE_SIZE && y >= 0 && y < SCENE_SIZE) if (x < SCENE_SIZE && y >= 0 && y < SCENE_SIZE)
{ {
@@ -347,7 +382,9 @@ public class RaidsPlugin extends Plugin
} }
if (position == 0 && startX != j) if (position == 0 && startX != j)
{
startX = j; startX = j;
}
Tile base = tiles[offsetX > 0 ? 1 : x][y]; Tile base = tiles[offsetX > 0 ? 1 : x][y];
RaidRoom room = determineRoom(base); RaidRoom room = determineRoom(base);
@@ -368,7 +405,9 @@ public class RaidsPlugin extends Plugin
InstanceTemplates template = InstanceTemplates.findMatch(chunkData); InstanceTemplates template = InstanceTemplates.findMatch(chunkData);
if (template == null) if (template == null)
{
return room; return room;
}
switch (template) switch (template)
{ {
@@ -458,7 +497,9 @@ public class RaidsPlugin extends Plugin
private BufferedImage getRaidsIcon() private BufferedImage getRaidsIcon()
{ {
if (raidsIcon != null) if (raidsIcon != null)
{
return raidsIcon; return raidsIcon;
}
InputStream in = RaidsPlugin.class.getResourceAsStream("raids_icon.png"); InputStream in = RaidsPlugin.class.getResourceAsStream("raids_icon.png");

View File

@@ -52,7 +52,9 @@ public class RaidsTimer extends InfoBox
public String getText() public String getText()
{ {
if (startTime == null) if (startTime == null)
{
return ""; return "";
}
if (!stopped) if (!stopped)
{ {
@@ -61,7 +63,9 @@ public class RaidsTimer extends InfoBox
} }
if (time.getHour() > 0) if (time.getHour() > 0)
{
return time.format(DateTimeFormatter.ofPattern("HH:mm")); return time.format(DateTimeFormatter.ofPattern("HH:mm"));
}
return time.format(DateTimeFormatter.ofPattern("mm:ss")); return time.format(DateTimeFormatter.ofPattern("mm:ss"));
} }
@@ -70,7 +74,9 @@ public class RaidsTimer extends InfoBox
public Color getTextColor() public Color getTextColor()
{ {
if (stopped) if (stopped)
{
return Color.GREEN; return Color.GREEN;
}
return Color.WHITE; return Color.WHITE;
} }

View File

@@ -43,7 +43,9 @@ public class Layout
for (Room room : rooms) for (Room room : rooms)
{ {
if (room.getPosition() == position) if (room.getPosition() == position)
{
return room; return room;
}
} }
return null; return null;

View File

@@ -119,9 +119,11 @@ public class LayoutSolver
} }
if (matches == 1) if (matches == 1)
{
return solution; return solution;
else }
return null;
return null;
} }
private int calcStart(String directions) private int calcStart(String directions)
@@ -173,7 +175,9 @@ public class LayoutSolver
Matcher match = regex.matcher(code); Matcher match = regex.matcher(code);
if (!match.find()) if (!match.find())
{
continue; continue;
}
String symbols, directions; String symbols, directions;
int position = calcStart(match.group(3)); int position = calcStart(match.group(3));

View File

@@ -43,7 +43,9 @@ public class RotationSolver
public E get(int index) public E get(int index)
{ {
if (index < 0) if (index < 0)
{
index = index + size(); index = index + size();
}
return super.get(index % size()); return super.get(index % size());
} }
@@ -59,8 +61,10 @@ public class RotationSolver
public static boolean solve(RaidRoom[] rooms) public static boolean solve(RaidRoom[] rooms)
{ {
if (rooms == null) if (rooms == null)
{
return false; return false;
}
Rotation<Boss> match = null; Rotation<Boss> match = null;
Integer start = null; Integer start = null;
@@ -70,19 +74,27 @@ public class RotationSolver
for (int i = 0; i < rooms.length; i++) for (int i = 0; i < rooms.length; i++)
{ {
if (rooms[i] == null || rooms[i].getBoss() == null || rooms[i].getBoss() == Boss.UNKNOWN) if (rooms[i] == null || rooms[i].getBoss() == null || rooms[i].getBoss() == Boss.UNKNOWN)
{
continue; continue;
}
if (start == null) if (start == null)
{
start = i; start = i;
}
known++; known++;
} }
if (known < 2) if (known < 2)
{
return false; return false;
}
if (known == rooms.length) if (known == rooms.length)
{
return true; return true;
}
for (Rotation rotation : ROTATIONS) for (Rotation rotation : ROTATIONS)
{ {
@@ -94,14 +106,20 @@ public class RotationSolver
for (int j = start + 1; j < rooms.length; j++) for (int j = start + 1; j < rooms.length; j++)
{ {
if (rooms[j].getBoss() == null || rooms[j].getBoss() == Boss.UNKNOWN) if (rooms[j].getBoss() == null || rooms[j].getBoss() == Boss.UNKNOWN)
{
continue; continue;
}
if (rooms[j].getBoss() != rotation.get(i + j - start)) if (rooms[j].getBoss() != rotation.get(i + j - start))
{
break COMPARE; break COMPARE;
}
} }
if (match != null && match != rotation) if (match != null && match != rotation)
{
return false; return false;
}
index = i - start; index = i - start;
match = rotation; match = rotation;
@@ -110,15 +128,21 @@ public class RotationSolver
} }
if (match == null) if (match == null)
{
return false; return false;
}
for (int i = 0; i < rooms.length; i++) for (int i = 0; i < rooms.length; i++)
{ {
if (rooms[i] == null) if (rooms[i] == null)
{
continue; continue;
}
if (rooms[i].getBoss() == null || rooms[i].getBoss() == Boss.UNKNOWN) if (rooms[i].getBoss() == null || rooms[i].getBoss() == Boss.UNKNOWN)
{
rooms[i].setBoss(match.get(index + i)); rooms[i].setBoss(match.get(index + i));
}
} }
return true; return true;