Skip to content

Commit 4b0068a

Browse files
committed
Fix DR cache wiring for loaded profiles
1 parent c09a013 commit 4b0068a

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

Changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Version 2.2.054
22
Fixed party/admin chat allowing player color code tokens without the 'mcmmo.chat.colors' permission
3+
Fixed diminished returns resetting in certain situations when players reconnected
34

45
Version 2.2.053
56
!! -- This build has important fixes for anyone using Paper (or forks of Paper), please read the notes carefully.
@@ -14,7 +15,6 @@ Version 2.2.053
1415
Fixed KnockOnWood XP orbs never spawning on nether/warped tree cap blocks during Tree Feller
1516
Fixed Impale (Tridents) damage bonus formula applying one fewer rank of the multiplier than intended
1617
Fixed melee attack strength scale resolving to near-zero after Paper fixed a vanilla attack cooldown bug in 26.1.2 (See notes)
17-
Fixed server-side diminished returns state being evicted too early, allowing reconnects to bypass the DR window (See notes)
1818
Added option to allow Magic Hunter (Fishing) to grant items with conflicting enchantments; disabled by default (Thanks Warriorrrr)
1919
Added 'Skills.Fishing.Allow_Conflicting_Enchants' to config.yml (Thanks Warriorrrr)
2020
(Codebase) Removed 27 dead JSON.* locale keys from all locale files (See notes)

src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ public PlayerProfile(@NotNull String playerName, @Nullable UUID uuid,
9898
this.playerName = playerName;
9999
this.uuid = uuid;
100100
this.scoreboardTipsShown = scoreboardTipsShown;
101-
// This constructor is used for save copies only — do not pull DR state from cache.
102-
this.diminishedReturnsState = DiminishedReturnsCache.getOrCreate(null);
101+
this.diminishedReturnsState = DiminishedReturnsCache.getOrCreate(uuid);
103102

104103
skills.putAll(levelData);
105104
skillsXp.putAll(xpData);

src/test/java/com/gmail/nossr50/datatypes/experience/DiminishedReturnsCacheTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
import static org.mockito.Mockito.when;
1212

1313
import com.gmail.nossr50.config.experience.ExperienceConfig;
14+
import com.gmail.nossr50.datatypes.player.PlayerProfile;
15+
import com.gmail.nossr50.datatypes.player.UniqueDataType;
16+
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
17+
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
1418
import java.lang.reflect.Field;
19+
import java.util.EnumMap;
20+
import java.util.Map;
1521
import java.util.UUID;
1622
import org.junit.jupiter.api.AfterEach;
1723
import org.junit.jupiter.api.BeforeEach;
@@ -288,4 +294,29 @@ void stateWithFutureExpiryHasActiveEntries() throws Exception {
288294
"state with a future latestExpiryTimeMillis should report active entries");
289295
}
290296
}
297+
298+
@Nested
299+
class PlayerProfileConstructorIntegration {
300+
301+
@Test
302+
void mapBasedConstructorShouldUseUuidCacheState() {
303+
// Given - a player UUID with an existing cached DR state
304+
final UUID playerUuid = UUID.randomUUID();
305+
final DiminishedReturnsState cachedState = DiminishedReturnsCache.getOrCreate(playerUuid);
306+
307+
final Map<PrimarySkillType, Integer> levelData = new EnumMap<>(PrimarySkillType.class);
308+
final Map<PrimarySkillType, Float> xpData = new EnumMap<>(PrimarySkillType.class);
309+
final Map<SuperAbilityType, Integer> cooldownData = new EnumMap<>(SuperAbilityType.class);
310+
final Map<UniqueDataType, Integer> uniqueData = new EnumMap<>(UniqueDataType.class);
311+
312+
// When - profile is created using the map-based constructor used by DB loaders
313+
final PlayerProfile loadedProfile = new PlayerProfile("TestPlayer", playerUuid,
314+
levelData, xpData, cooldownData, 0, uniqueData, null);
315+
loadedProfile.registerXpGain(PrimarySkillType.MINING, 50F);
316+
317+
// Then - cached state should reflect the XP registered by that loaded profile
318+
assertEquals(50F, cachedState.getRegisteredXpGain(PrimarySkillType.MINING),
319+
"loaded profiles with UUID must use the UUID-cached DR state");
320+
}
321+
}
291322
}

0 commit comments

Comments
 (0)