Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
isExternal = PluginConstants.IS_EXTERNAL
)
public class MahoganyHomesPlugin extends Plugin {
public static final String version = "0.0.15";
public static final String version = "0.0.16";
private static final List<Integer> PLANKS = Arrays.asList(ItemID.PLANK, ItemID.OAK_PLANK, ItemID.TEAK_PLANK, ItemID.MAHOGANY_PLANK);
private static final List<String> PLANK_NAMES = Arrays.asList("Plank", "Oak plank", "Teak plank", "Mahogany plank");
private static final Map<Integer, Integer> MAHOGANY_HOMES_REPAIRS = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ private List<GameObject> getFixableObjects() {
List<Hotspot> fixableHotspots = Hotspot.getBrokenHotspots();
HotspotObjects hotspotObjects = plugin.getCurrentHome().getHotspotObjects();

// Precompute the set of IDs
Set<Integer> ids = fixableHotspots.stream()
.map(hotspot -> hotspotObjects.objects[hotspot.ordinal()].getObjectId())
.collect(Collectors.toSet());
Set<Integer> ids = getFixableObjectIds(fixableHotspots, hotspotObjects);

// Filter using the precomputed set
return objects.stream()
Expand All @@ -86,6 +83,13 @@ private List<GameObject> getFixableObjects() {
.collect(Collectors.toList());
}

static Set<Integer> getFixableObjectIds(List<Hotspot> hotspots, HotspotObjects hotspotObjects) {
return hotspots.stream()
.filter(hotspot -> hotspot.ordinal() < hotspotObjects.objects.length)
.map(hotspot -> hotspotObjects.objects[hotspot.ordinal()].getObjectId())
.collect(Collectors.toSet());
}

// Custom logging methods
private void log(String message) {
if (plugin.getConfig().logMessages()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import net.runelite.api.coords.WorldPoint;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand Down Expand Up @@ -42,6 +45,28 @@ void isAwayFromHomeComparesPlayerLocationToHomeArea() {
assertFalse(script.isAwayFromHome(Home.JESS, new WorldPoint(2615, 3293, 1)));
}

@Test
void fixableObjectIdsSkipsHotspotsBeyondHomeObjectCount() {
Set<Integer> ids = MahoganyHomesScript.getFixableObjectIds(Arrays.asList(Hotspot.values()), HotspotObjects.ROSS);
assertEquals(HotspotObjects.ROSS.objects.length, ids.size());
assertTrue(ids.contains(HotspotObjects.ROSS.objects[6].getObjectId()));
}

@Test
void fixableObjectIdsSkipsHotspotsBeyondSixObjectHome() {
Set<Integer> ids = MahoganyHomesScript.getFixableObjectIds(
Arrays.asList(Hotspot.MAHOGANY_HOMES_HOTSPOT_1, Hotspot.MAHOGANY_HOMES_HOTSPOT_7, Hotspot.MAHOGANY_HOMES_HOTSPOT_8),
HotspotObjects.SARAH);
assertEquals(Set.of(HotspotObjects.SARAH.objects[0].getObjectId()), ids);
}

@Test
void fixableObjectIdsMapsAllHotspotsForEightObjectHome() {
Set<Integer> ids = MahoganyHomesScript.getFixableObjectIds(Arrays.asList(Hotspot.values()), HotspotObjects.JESS);
assertEquals(8, ids.size());
assertTrue(ids.contains(HotspotObjects.JESS.objects[7].getObjectId()));
}

private static MahoganyHomesScript scriptWithPlugin() {
MahoganyHomesScript script = new MahoganyHomesScript();
script.plugin = new MahoganyHomesPlugin();
Expand Down
Loading