Split failed UUID batches into individual requests in order to identify the invalid UUIDs

This commit is contained in:
Alexander Söderberg 2020-07-09 20:25:16 +02:00 committed by Alexander Söderberg
parent 63c308971b
commit b36c6427d1

View File

@ -26,6 +26,8 @@
package com.plotsquared.bukkit.uuid; package com.plotsquared.bukkit.uuid;
import com.google.common.util.concurrent.RateLimiter; import com.google.common.util.concurrent.RateLimiter;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.uuid.UUIDMapping; import com.plotsquared.core.uuid.UUIDMapping;
import com.plotsquared.core.uuid.UUIDService; import com.plotsquared.core.uuid.UUIDService;
import com.sk89q.squirrelid.Profile; import com.sk89q.squirrelid.Profile;
@ -35,6 +37,7 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -64,10 +67,29 @@ public class SquirrelIdUUIDService implements UUIDService {
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) { @Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
final List<UUIDMapping> results = new ArrayList<>(uuids.size()); final List<UUIDMapping> results = new ArrayList<>(uuids.size());
this.rateLimiter.acquire(uuids.size()); this.rateLimiter.acquire(uuids.size());
try {
try { try {
for (final Profile profile : this.profileService.findAllById(uuids)) { for (final Profile profile : this.profileService.findAllById(uuids)) {
results.add(new UUIDMapping(profile.getUniqueId(), profile.getName())); results.add(new UUIDMapping(profile.getUniqueId(), profile.getName()));
} }
} catch (final IllegalArgumentException illegalArgumentException) {
//
// This means that the UUID was invalid for whatever reason, we'll try to
// go through them one by one
//
if (uuids.size() >= 2) {
PlotSquared.debug(Captions.PREFIX + "(UUID) Found invalid UUID in batch. Will try each UUID individually.");
for (final UUID uuid : uuids) {
final List<UUIDMapping> result = this.getNames(Collections.singletonList(uuid));
if (result.isEmpty()) {
continue;
}
results.add(result.get(0));
}
} else if (uuids.size() == 1) {
PlotSquared.debug(Captions.PREFIX + "(UUID) Found invalid UUID: " + uuids.get(0));
}
}
} catch (IOException | InterruptedException e) { } catch (IOException | InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }