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;
import com.plotsquared.core.uuid.UUIDMapping;
import com.plotsquared.core.uuid.UUIDService;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
@ -38,20 +40,26 @@ import java.util.UUID;
*/
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 List<UUIDMapping> wrappers = new ArrayList<>(uuids.size());
for (final UUID uuid : uuids) {
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
if (offlinePlayer.hasPlayedBefore()) {
return Optional.ofNullable(offlinePlayer.getName());
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 List<UUIDMapping> wrappers = new ArrayList<>(usernames.size());
for (final String username : usernames) {
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username);
if (offlinePlayer.hasPlayedBefore()) {
return Optional.of(offlinePlayer.getUniqueId());
wrappers.add(new UUIDMapping(offlinePlayer.getUniqueId(), offlinePlayer.getName()));
}
return Optional.empty();
}
return wrappers;
}
}