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
15 changes: 13 additions & 2 deletions src/main/java/net/tfminecraft/companionpets/estate/PetEstate.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,21 @@ public static void start(Plugin plugin, PetRuntime runtime, PetActions actions)
@Override public String id() { return "companionpets"; }
@Override public Holdings describe(UUID character) {
List<String> labels = new ArrayList<>();
runtime.store().ofCharacter(character).forEach(pet -> labels.add("Pet: " + pet.name()));
runtime.store().kennelCharacters().forEach((key, owner) -> { if (character.equals(owner)) labels.add("Pet House: " + key); });
runtime.store().ofCharacter(character).forEach(pet -> labels.add(pet.name()));
runtime.store().kennelCharacters().forEach((key, owner) -> { if (character.equals(owner)) labels.add(houseLabel(key, mainWorld.get())); });
return labels.isEmpty() ? Holdings.NONE : new Holdings(Map.of("pets-and-houses", labels.size()), labels);
}
/** The first world's name, or null; a house elsewhere names its world. */
static Supplier<String> mainWorld = () -> Bukkit.getWorlds().isEmpty() ? null : Bukkit.getWorlds().getFirst().getName();
/** {@code world,x,y,z} as "Pet house at x y z", adding the world when it is not {@code main}. */
static String houseLabel(String key, String main) {
String[] part = key.split(",");
if (part.length < 4) return "Pet house " + key;
// A world name may hold commas; the last three fields are the coordinates.
int n = part.length;
String world = String.join(",", java.util.Arrays.copyOf(part, n - 3));
return "Pet house at " + part[n - 3] + " " + part[n - 2] + " " + part[n - 1] + (world.equals(main) ? "" : " (" + world + ")");
}
@Override public Outcome settle(EstateDecision decision) {
if (runtime.store().persistenceConflict()) return Outcome.blocked("Pet source changed outside its current writer; review is required");
if (!net.tfminecraft.companionpets.ownership.CharacterAccess.heirReady() || !runtime.store().ownershipReady())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,19 @@ void unrelatedIncompleteDeathDoesNotBlockThisExactHeldIntentResume() throws Exce
assertInstanceOf(Outcome.Blocked.class,estate.settle(decision(1,Recipient.character(to))));
assertEquals(changed,Files.readString(file));assertEquals(from.characterId(),pet.ownerCharacterId());assertTrue(pet.ownershipHeld());
}
@Test void willLabelsNamePetsAndPlaceHouses() {
assertEquals("Pet house at 6077 238 5231", PetEstate.houseLabel("TFMC_Map,6077,238,5231", "TFMC_Map"));
assertEquals("Pet house at 1 2 3 (nether)", PetEstate.houseLabel("nether,1,2,3", "TFMC_Map"));
assertEquals("Pet house at 1 2 3 (nether)", PetEstate.houseLabel("nether,1,2,3", null));
assertEquals("Pet house odd", PetEstate.houseLabel("odd", "TFMC_Map"));
assertEquals("Pet house at 1 2 3", PetEstate.houseLabel("build,world,1,2,3", "build,world"));
assertEquals("Pet house at 1 2 3 (build,world)", PetEstate.houseLabel("build,world,1,2,3", "TFMC_Map"));
var original = PetEstate.mainWorld;
assertEquals(org.bukkit.Bukkit.getWorlds().isEmpty() ? null : org.bukkit.Bukkit.getWorlds().getFirst().getName(), original.get());
PetEstate.mainWorld = () -> "unloaded";
try {
assertTrue(estate.describe(from.characterId()).labels().contains("Pet house at 1 2 3"), estate.describe(from.characterId()).labels().toString());
assertTrue(estate.describe(from.characterId()).labels().contains(pet.name()));
} finally { PetEstate.mainWorld = original; }
}
}
Loading