Skip to content

Commit 6d04ece

Browse files
committed
Fix counter goal icon and cover persistence
1 parent c3f4ec4 commit 6d04ece

3 files changed

Lines changed: 47 additions & 1 deletion

File tree

‎src/main/java/net/tfminecraft/simplefactions/managers/inventory/WarView.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private void counterGoalView(Player player, War war) {
197197
if (vassalTypes != null && !vassalTypes.isEmpty()) {
198198
for (RelationType type : vassalTypes) {
199199
if (slot >= 17) break;
200-
ItemStack option = goalOption(Material.CHAIN, "§eSubjugate: " + type.getName(),
200+
ItemStack option = goalOption(Material.CHAINMAIL_CHESTPLATE, "§eSubjugate: " + type.getName(),
201201
"§7Make the attacker your " + type.getName());
202202
ItemMeta meta = option.getItemMeta();
203203
meta.getPersistentDataContainer().set(

‎src/test/java/net/tfminecraft/simplefactions/war/core/WarMapperTest.java‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,37 @@ void fromData_omittedInstallationPicksDefaultsEmpty() {
823823
}
824824
}
825825

826+
@Test
827+
void fromData_restoresDefenderCounterGoalAndBattleLock() {
828+
Faction attacker = mock(Faction.class);
829+
Faction defender = mock(Faction.class);
830+
when(attacker.getId()).thenReturn("faction_a");
831+
when(defender.getId()).thenReturn("faction_b");
832+
FactionManager.factions.add(attacker);
833+
FactionManager.factions.add(defender);
834+
try {
835+
WarData data = minimalWarData();
836+
data.defenderCounterGoal = "subjugate";
837+
data.defenderCounterRelationTypeId = "march";
838+
data.firstBattleStarted = true;
839+
840+
War war = WarMapper.fromData(data);
841+
assertEquals(WarGoalType.SUBJUGATE, war.getDefenderCounterGoal());
842+
assertEquals("march", war.getDefenderCounterRelationTypeId());
843+
assertTrue(war.hasFirstBattleStarted());
844+
845+
war.setDefenderCounterGoal(WarGoalType.TRIBUTARY, null);
846+
assertEquals(WarGoalType.SUBJUGATE, war.getDefenderCounterGoal());
847+
WarData roundTripped = WarMapper.toData(war);
848+
assertEquals("subjugate", roundTripped.defenderCounterGoal);
849+
assertEquals("march", roundTripped.defenderCounterRelationTypeId);
850+
assertTrue(roundTripped.firstBattleStarted);
851+
} finally {
852+
FactionManager.factions.remove(attacker);
853+
FactionManager.factions.remove(defender);
854+
}
855+
}
856+
826857
private static WarData minimalWarData() {
827858
WarData data = new WarData();
828859
data.id = 9;

‎src/test/java/net/tfminecraft/simplefactions/war/resolution/WarOutcomeServiceTest.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,21 @@ void defenderVictory_addsObligationOnAttacker() {
619619
assertEquals(10, obligation.getDaysRemaining());
620620
}
621621

622+
@Test
623+
void defenderVictory_selectedCounterGoalAppliesAgainstAttackerInsteadOfReparations() {
624+
Fixture fx = fixture();
625+
fx.war.setDefenderCounterGoal(WarGoalType.TRIBUTARY, null);
626+
RelationType tributary = mock(RelationType.class);
627+
when(tributary.getId()).thenReturn("tributary");
628+
try (MockedStatic<RelationLoader> loader = mockStatic(RelationLoader.class);
629+
MockedStatic<RelationManager> relations = mockStatic(RelationManager.class)) {
630+
loader.when(() -> RelationLoader.getType("tributary")).thenReturn(tributary);
631+
WarOutcomeService.apply(fx.war, WarEndReason.DEFENDER_VICTORY);
632+
relations.verify(() -> RelationManager.setRelationForced(tributary, fx.attacker, fx.defender));
633+
}
634+
assertTrue(fx.payerObligations.isEmpty());
635+
}
636+
622637
@Test
623638
void tickAfterDailySettlement_decrementsThenRemoves() {
624639
Faction payer = mock(Faction.class);

0 commit comments

Comments
 (0)