mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Split failed UUID batches into individual requests in order to identify the invalid UUIDs
This commit is contained in:
parent
63c308971b
commit
b36c6427d1
@ -26,6 +26,8 @@
|
||||
package com.plotsquared.bukkit.uuid;
|
||||
|
||||
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.UUIDService;
|
||||
import com.sk89q.squirrelid.Profile;
|
||||
@ -35,6 +37,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -64,10 +67,29 @@ public class SquirrelIdUUIDService implements UUIDService {
|
||||
@Override @NotNull public List<UUIDMapping> getNames(@NotNull final List<UUID> uuids) {
|
||||
final List<UUIDMapping> results = new ArrayList<>(uuids.size());
|
||||
this.rateLimiter.acquire(uuids.size());
|
||||
try {
|
||||
try {
|
||||
for (final Profile profile : this.profileService.findAllById(uuids)) {
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user