From 64cfe240f9292cc300d1a3335aebdcc3e2577999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 17 May 2020 17:36:12 +0200 Subject: [PATCH] Port OfflinePlayerUUIDService to the new system --- .../bukkit/uuid/OfflinePlayerUUIDService.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflinePlayerUUIDService.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflinePlayerUUIDService.java index 8ba2ad76b..403832f38 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflinePlayerUUIDService.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflinePlayerUUIDService.java @@ -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 get(@NotNull final UUID uuid) { - final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); - if (offlinePlayer.hasPlayedBefore()) { - return Optional.ofNullable(offlinePlayer.getName()); + @Override public @NotNull List getNames(@NotNull List uuids) { + final List wrappers = new ArrayList<>(uuids.size()); + for (final UUID uuid : uuids) { + 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 get(@NotNull final String username) { - final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username); - if (offlinePlayer.hasPlayedBefore()) { - return Optional.of(offlinePlayer.getUniqueId()); + @Override public @NotNull List getUUIDs(@NotNull List usernames) { + final List wrappers = new ArrayList<>(usernames.size()); + for (final String username : usernames) { + final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username); + if (offlinePlayer.hasPlayedBefore()) { + wrappers.add(new UUIDMapping(offlinePlayer.getUniqueId(), offlinePlayer.getName())); + } } - return Optional.empty(); + return wrappers; } }