Skip to content

Commit 422a678

Browse files
committed
Replace deprecated use of player name in favour of player uuid
1 parent c4ad2ae commit 422a678

File tree

6 files changed

+42
-46
lines changed

6 files changed

+42
-46
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
@@ -154,7 +154,7 @@ public void onDisable() {
154154
profileContainerStoreProvider.get().getStore(ContainerType.WORLD)
155155
.getContainer(world)
156156
.getPlayerData(player)));
157-
profileDataSource.get().setLoadOnLogin(player.getName(), true);
157+
profileDataSource.get().setLoadOnLogin(player.getUniqueId(), true);
158158
}
159159
}
160160

src/main/java/org/mvplugins/multiverse/inventories/listeners/InventoriesListener.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public void playerJoin(final PlayerJoinEvent event) {
224224
.getPlayerData(player)
225225
));
226226
}
227-
profileDataSource.setLoadOnLogin(player.getName(), false);
227+
profileDataSource.setLoadOnLogin(player.getUniqueId(), false);
228228
verifyCorrectWorld(player, player.getWorld().getName(), globalProfile);
229229
}
230230

@@ -237,28 +237,28 @@ public void playerJoin(final PlayerJoinEvent event) {
237237
public void playerQuit(final PlayerQuitEvent event) {
238238
final Player player = event.getPlayer();
239239
final String world = event.getPlayer().getWorld().getName();
240-
profileDataSource.updateLastWorld(player.getName(), world);
240+
profileDataSource.updateLastWorld(player.getUniqueId(), world);
241241
if (config.usingLoggingSaveLoad()) {
242242
ShareHandlingUpdater.updateProfile(inventories, player, new PersistingProfile(
243243
Sharables.allOf(),
244244
profileContainerStoreProvider.getStore(ContainerType.WORLD)
245245
.getContainer(world)
246246
.getPlayerData(player)
247247
));
248-
profileDataSource.setLoadOnLogin(player.getName(), true);
248+
profileDataSource.setLoadOnLogin(player.getUniqueId(), true);
249249
}
250250
SingleShareWriter.of(this.inventories, player, Sharables.LAST_LOCATION).write(player.getLocation());
251251
}
252252

253253
private void verifyCorrectWorld(Player player, String world, GlobalProfile globalProfile) {
254254
if (globalProfile.getLastWorld() == null) {
255-
profileDataSource.updateLastWorld(player.getName(), world);
255+
profileDataSource.updateLastWorld(player.getUniqueId(), world);
256256
} else {
257257
if (!world.equals(globalProfile.getLastWorld())) {
258258
Logging.fine("Player did not spawn in the world they were last reported to be in!");
259259
new WorldChangeShareHandler(this.inventories, player,
260260
globalProfile.getLastWorld(), world).handleSharing();
261-
profileDataSource.updateLastWorld(player.getName(), world);
261+
profileDataSource.updateLastWorld(player.getUniqueId(), world);
262262
}
263263
}
264264
}
@@ -300,7 +300,7 @@ public void playerChangedWorld(PlayerChangedWorldEvent event) {
300300
}
301301

302302
new WorldChangeShareHandler(this.inventories, player, fromWorld.getName(), toWorld.getName()).handleSharing();
303-
profileDataSource.updateLastWorld(player.getName(), toWorld.getName());
303+
profileDataSource.updateLastWorld(player.getUniqueId(), toWorld.getName());
304304
}
305305

306306
/**

src/main/java/org/mvplugins/multiverse/inventories/profile/FlatFileProfileDataSource.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.google.common.cache.CacheBuilder;
77
import net.minidev.json.parser.JSONParser;
88
import net.minidev.json.parser.ParseException;
9+
import org.bukkit.OfflinePlayer;
910
import org.bukkit.configuration.InvalidConfigurationException;
1011
import org.jvnet.hk2.annotations.Service;
1112
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
@@ -423,9 +424,13 @@ private Map<String, Object> convertSection(ConfigurationSection section) {
423424
}
424425

425426
@Override
426-
@Deprecated
427-
public GlobalProfile getGlobalProfile(String playerName) {
428-
return getGlobalProfile(playerName, Bukkit.getOfflinePlayer(playerName).getUniqueId());
427+
public GlobalProfile getGlobalProfile(UUID playerUUID) {
428+
return getGlobalProfile(Bukkit.getOfflinePlayer(playerUUID));
429+
}
430+
431+
@Override
432+
public GlobalProfile getGlobalProfile(OfflinePlayer player) {
433+
return getGlobalProfile(player.getName(), player.getUniqueId());
429434
}
430435

431436
@Override
@@ -442,7 +447,7 @@ public GlobalProfile getGlobalProfile(String playerName, UUID playerUUID) {
442447
} catch (IOException e) {
443448
// This won't ever happen
444449
e.printStackTrace();
445-
return GlobalProfile.createGlobalProfile(playerName);
450+
return GlobalProfile.createGlobalProfile(playerName, playerUUID);
446451
}
447452
if (playerFile.exists()) {
448453
GlobalProfile profile = loadGlobalProfile(playerFile, playerName, playerUUID);
@@ -529,19 +534,15 @@ private Map<String, Object> serializeGlobalProfile(GlobalProfile profile) {
529534
}
530535

531536
@Override
532-
@Deprecated
533-
// TODO replace for UUID
534-
public void updateLastWorld(String playerName, String worldName) {
535-
GlobalProfile globalProfile = getGlobalProfile(playerName);
537+
public void updateLastWorld(UUID playerUUID, String worldName) {
538+
GlobalProfile globalProfile = getGlobalProfile(playerUUID);
536539
globalProfile.setLastWorld(worldName);
537540
updateGlobalProfile(globalProfile);
538541
}
539542

540543
@Override
541-
@Deprecated
542-
// TODO replace for UUID
543-
public void setLoadOnLogin(final String playerName, final boolean loadOnLogin) {
544-
final GlobalProfile globalProfile = getGlobalProfile(playerName);
544+
public void setLoadOnLogin(final UUID playerUUID, final boolean loadOnLogin) {
545+
final GlobalProfile globalProfile = getGlobalProfile(playerUUID);
545546
globalProfile.setLoadOnLogin(loadOnLogin);
546547
updateGlobalProfile(globalProfile);
547548
}

src/main/java/org/mvplugins/multiverse/inventories/profile/GlobalProfile.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.mvplugins.multiverse.inventories.profile;
22

3-
import org.bukkit.Bukkit;
3+
import org.bukkit.OfflinePlayer;
44

55
import java.util.UUID;
66

@@ -12,13 +12,11 @@ public final class GlobalProfile {
1212
/**
1313
* Creates a global profile object for the given player with default values.
1414
*
15-
* @param playerName the player to create the profile object for.
15+
* @param player the player to create the profile object for.
1616
* @return a new GlobalProfile for the given player.
17-
* @deprecated Needs to use UUID.
1817
*/
19-
@Deprecated
20-
public static GlobalProfile createGlobalProfile(String playerName) {
21-
return new GlobalProfile(playerName, Bukkit.getOfflinePlayer(playerName).getUniqueId());
18+
public static GlobalProfile createGlobalProfile(OfflinePlayer player) {
19+
return new GlobalProfile(player.getName(), player.getUniqueId());
2220
}
2321

2422
/**

src/main/java/org/mvplugins/multiverse/inventories/profile/PlayerProfile.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.mvplugins.multiverse.inventories.share.Sharable;
44
import org.mvplugins.multiverse.inventories.share.SharableEntry;
55
import org.mvplugins.multiverse.inventories.profile.container.ContainerType;
6-
import org.bukkit.Bukkit;
76
import org.bukkit.OfflinePlayer;
87

98
import java.util.HashMap;
@@ -20,15 +19,6 @@ public static PlayerProfile createPlayerProfile(ContainerType containerType, Str
2019
return new PlayerProfile(containerType, containerName, profileType, player);
2120
}
2221

23-
/**
24-
* @deprecated Needs to use UUID for players
25-
*/
26-
@Deprecated
27-
public static PlayerProfile createPlayerProfile(ContainerType containerType, String containerName,
28-
ProfileType profileType, String playerName) {
29-
return new PlayerProfile(containerType, containerName, profileType, Bukkit.getOfflinePlayer(playerName));
30-
}
31-
3222
private Map<Sharable, SharableEntry> data = new HashMap<Sharable, SharableEntry>();
3323

3424
private final OfflinePlayer player;

src/main/java/org/mvplugins/multiverse/inventories/profile/ProfileDataSource.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.mvplugins.multiverse.inventories.profile;
22

3+
import org.bukkit.OfflinePlayer;
34
import org.jvnet.hk2.annotations.Contract;
45
import org.mvplugins.multiverse.inventories.profile.container.ContainerType;
56

@@ -47,19 +48,25 @@ public sealed interface ProfileDataSource permits FlatFileProfileDataSource {
4748
/**
4849
* Retrieves the global profile for a player which contains meta-data for the player.
4950
*
50-
* @param playerName The name of player to retrieve for.
51+
* @param playerUUID The UUID of the player.
5152
* @return The global profile for the specified player.
52-
* @deprecated UUID must be supported now.
5353
*/
54-
@Deprecated
55-
GlobalProfile getGlobalProfile(String playerName);
54+
GlobalProfile getGlobalProfile(UUID playerUUID);
5655

5756
/**
5857
* Retrieves the global profile for a player which contains meta-data for the player.
5958
*
60-
* @param playerName The name of the player to retrieve for. This is required for updating name last known as.
61-
* @param playerUUID The UUID of the player.
62-
* @return the global profile for the player with the given UUID.
59+
* @param player The player.
60+
* @return The global profile for the specified player.
61+
*/
62+
GlobalProfile getGlobalProfile(OfflinePlayer player);
63+
64+
/**
65+
* Retrieves the global profile for a player which contains meta-data for the player.
66+
*
67+
* @param playerName The name of the player.
68+
* @param playerUUID The UUID of the player.
69+
* @return The global profile for the specified player.
6370
*/
6471
GlobalProfile getGlobalProfile(String playerName, UUID playerUUID);
6572

@@ -74,18 +81,18 @@ public sealed interface ProfileDataSource permits FlatFileProfileDataSource {
7481
/**
7582
* A convenience method to update the GlobalProfile of a player with a specified world.
7683
*
77-
* @param playerName The player whose global profile this will update.
84+
* @param playerUUID The player whose global profile this will update.
7885
* @param worldName The world to update the global profile with.
7986
*/
80-
void updateLastWorld(String playerName, String worldName);
87+
void updateLastWorld(UUID playerUUID, String worldName);
8188

8289
/**
8390
* A convenience method for setting whether player data should be loaded on login for the specified player.
8491
*
85-
* @param playerName The player whose data should be loaded.
92+
* @param playerUUID The player whose data should be loaded.
8693
* @param loadOnLogin Whether or not to load on login.
8794
*/
88-
void setLoadOnLogin(String playerName, boolean loadOnLogin);
95+
void setLoadOnLogin(UUID playerUUID, boolean loadOnLogin);
8996

9097
/**
9198
* Copies all the data belonging to oldName to newName and removes the old data.

0 commit comments

Comments
 (0)