Port OfflinePlayerUUIDService to the new system

This commit is contained in:
Alexander Söderberg 2020-05-17 17:36:12 +02:00
parent 29f2863cf4
commit 64cfe240f9
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678

View File

@ -25,12 +25,14 @@
*/ */
package com.plotsquared.bukkit.uuid; package com.plotsquared.bukkit.uuid;
import com.plotsquared.core.uuid.UUIDMapping;
import com.plotsquared.core.uuid.UUIDService; import com.plotsquared.core.uuid.UUIDService;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Optional; import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
/** /**
@ -38,20 +40,26 @@ import java.util.UUID;
*/ */
public class OfflinePlayerUUIDService implements UUIDService { public class OfflinePlayerUUIDService implements UUIDService {
@Override @NotNull public Optional<String> get(@NotNull final UUID uuid) { @Override public @NotNull List<UUIDMapping> getNames(@NotNull List<UUID> uuids) {
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); final List<UUIDMapping> wrappers = new ArrayList<>(uuids.size());
if (offlinePlayer.hasPlayedBefore()) { for (final UUID uuid : uuids) {
return Optional.ofNullable(offlinePlayer.getName()); final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
if (offlinePlayer.hasPlayedBefore()) {
wrappers.add(new UUIDMapping(uuid, offlinePlayer.getName()));
}
} }
return Optional.empty(); return wrappers;
} }
@Override @NotNull public Optional<UUID> get(@NotNull final String username) { @Override public @NotNull List<UUIDMapping> getUUIDs(@NotNull List<String> usernames) {
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username); final List<UUIDMapping> wrappers = new ArrayList<>(usernames.size());
if (offlinePlayer.hasPlayedBefore()) { for (final String username : usernames) {
return Optional.of(offlinePlayer.getUniqueId()); final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username);
if (offlinePlayer.hasPlayedBefore()) {
wrappers.add(new UUIDMapping(offlinePlayer.getUniqueId(), offlinePlayer.getName()));
}
} }
return Optional.empty(); return wrappers;
} }
} }