Skip to content

Commit fcf4c92

Browse files
authored
Merge pull request #572 from Multiverse/ben/mv5/refactor-profile-source
Ben/mv5/refactor profile source
2 parents 6d405b6 + da9a130 commit fcf4c92

File tree

13 files changed

+303
-325
lines changed

13 files changed

+303
-325
lines changed

src/main/java/org/mvplugins/multiverse/inventories/MultiverseInventories.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void onDisable() {
142142
profileContainerStoreProvider.get().getStore(ContainerType.WORLD)
143143
.getContainer(world)
144144
.getPlayerData(player)));
145-
profileDataSource.get().setLoadOnLogin(player.getUniqueId(), true);
145+
profileDataSource.get().modifyGlobalProfile(player, profile -> profile.setLoadOnLogin(true));
146146
}
147147
}
148148

src/main/java/org/mvplugins/multiverse/inventories/commands/CacheCommand.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ final class CacheCommand extends InventoriesCommand {
3434
void onCacheStatsCommand(MVCommandIssuer issuer) {
3535
Map<String, CacheStats> stats = this.profileDataSource.getCacheStats();
3636
for (Map.Entry<String, CacheStats> entry : stats.entrySet()) {
37-
issuer.sendInfo("Cache: " + entry.getKey());
38-
issuer.sendInfo(" hits count: " + entry.getValue().hitCount());
39-
issuer.sendInfo(" misses count: " + entry.getValue().missCount());
40-
issuer.sendInfo(" loads count: " + entry.getValue().loadCount());
41-
issuer.sendInfo(" avg load time: " + entry.getValue().averageLoadPenalty());
42-
issuer.sendInfo(" exceptions: " + entry.getValue().loadExceptionCount());
43-
issuer.sendInfo(" evictions: " + entry.getValue().evictionCount());
37+
issuer.sendMessage("Cache: " + entry.getKey());
38+
issuer.sendMessage(" hits count: " + entry.getValue().hitCount());
39+
issuer.sendMessage(" misses count: " + entry.getValue().missCount());
40+
issuer.sendMessage(" loads count: " + entry.getValue().loadCount());
41+
issuer.sendMessage(" exceptions: " + entry.getValue().loadExceptionCount());
42+
issuer.sendMessage(" evictions: " + entry.getValue().evictionCount());
43+
issuer.sendMessage(" hit rate: " + entry.getValue().hitRate() * 100 + "%");
44+
issuer.sendMessage(" miss rate: " + entry.getValue().missRate() * 100 + "%");
45+
issuer.sendMessage(" avg load penalty: " + entry.getValue().averageLoadPenalty() / 1000000 + "ms");
46+
issuer.sendMessage("--------");
4447
}
4548
}
4649

src/main/java/org/mvplugins/multiverse/inventories/dataimport/perworldinventory/PwiImportHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ private void saveMVDataForPlayer(Group group, OfflinePlayer offlinePlayer) throw
205205
private List<PlayerProfile> getMVPlayerData(
206206
@NotNull OfflinePlayer offlinePlayer, @NotNull Group group, @NotNull GameMode gameMode) {
207207
List<PlayerProfile> profiles = new ArrayList<>();
208-
profiles.add(profileDataSource.getPlayerData(
209-
ContainerType.GROUP, group.getName(), ProfileTypes.forGameMode(gameMode), offlinePlayer.getUniqueId()));
208+
profiles.add(profileDataSource.getPlayerData(org.mvplugins.multiverse.inventories.profile.ProfileKey
209+
.create(ContainerType.GROUP, group.getName(), ProfileTypes.forGameMode(gameMode), offlinePlayer.getUniqueId())));
210210
for (var worldName : group.getWorlds()) {
211-
profiles.add(profileDataSource.getPlayerData(
212-
ContainerType.WORLD, worldName, ProfileTypes.forGameMode(gameMode), offlinePlayer.getUniqueId()));
211+
profiles.add(profileDataSource.getPlayerData(org.mvplugins.multiverse.inventories.profile.ProfileKey
212+
.create(ContainerType.WORLD, worldName, ProfileTypes.forGameMode(gameMode), offlinePlayer.getUniqueId())));
213213
}
214214
return profiles;
215215
}

src/main/java/org/mvplugins/multiverse/inventories/handleshare/ShareHandleListener.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void playerJoin(final PlayerJoinEvent event) {
151151
// Just in case AsyncPlayerPreLoginEvent was still the old name
152152
verifyCorrectPlayerName(player.getUniqueId(), player.getName());
153153

154-
final GlobalProfile globalProfile = profileDataSource.getGlobalProfile(player.getName(), player.getUniqueId());
154+
final GlobalProfile globalProfile = profileDataSource.getGlobalProfile(player);
155155
final String world = globalProfile.getLastWorld();
156156
if (config.usingLoggingSaveLoad() && globalProfile.shouldLoadOnLogin()) {
157157
ShareHandlingUpdater.updatePlayer(inventories, player, new PersistingProfile(
@@ -167,7 +167,7 @@ void playerJoin(final PlayerJoinEvent event) {
167167
}
168168

169169
private void verifyCorrectPlayerName(UUID uuid, String name) {
170-
profileDataSource.getExistingGlobalProfile(name, uuid).peek(globalProfile -> {
170+
profileDataSource.getExistingGlobalProfile(uuid, name).peek(globalProfile -> {
171171
if (globalProfile.getLastKnownName().equals(name)) {
172172
return;
173173
}
@@ -196,16 +196,18 @@ private void verifyCorrectPlayerName(UUID uuid, String name) {
196196
void playerQuit(final PlayerQuitEvent event) {
197197
final Player player = event.getPlayer();
198198
final String world = event.getPlayer().getWorld().getName();
199-
profileDataSource.updateLastWorld(player.getUniqueId(), world);
199+
GlobalProfile globalProfile = profileDataSource.getGlobalProfile(player);
200+
globalProfile.setLastWorld(world);
200201
if (config.usingLoggingSaveLoad()) {
201202
ShareHandlingUpdater.updateProfile(inventories, player, new PersistingProfile(
202203
Sharables.allOf(),
203204
profileContainerStoreProvider.getStore(ContainerType.WORLD)
204205
.getContainer(world)
205206
.getPlayerData(player)
206207
));
207-
profileDataSource.setLoadOnLogin(player.getUniqueId(), true);
208+
globalProfile.setLoadOnLogin(true);
208209
}
210+
profileDataSource.updateGlobalProfile(globalProfile);
209211
SingleShareWriter.of(this.inventories, player, Sharables.LAST_LOCATION).write(player.getLocation().clone());
210212
}
211213

@@ -261,7 +263,7 @@ void playerChangedWorld(PlayerChangedWorldEvent event) {
261263

262264
long startTime = System.nanoTime();
263265
new WorldChangeShareHandler(this.inventories, player, fromWorld.getName(), toWorld.getName()).handleSharing();
264-
profileDataSource.updateLastWorld(player.getUniqueId(), toWorld.getName());
266+
profileDataSource.modifyGlobalProfile(player, profile -> profile.setLastWorld(toWorld.getName()));
265267
Logging.finest("WorldChangeShareHandler took " + (System.nanoTime() - startTime) / 1000000 + " ms.");
266268
}
267269

@@ -323,7 +325,7 @@ void playerRespawn(PlayerRespawnEvent event) {
323325
() -> verifyCorrectWorld(
324326
player,
325327
player.getWorld().getName(),
326-
profileDataSource.getGlobalProfile(player.getName(), player.getUniqueId())),
328+
profileDataSource.getGlobalProfile(player)),
327329
2L);
328330
}
329331

0 commit comments

Comments
 (0)