mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Update more commands and add proper request timeouts
This commit is contained in:
parent
37b065a097
commit
123ca8efe9
@ -26,6 +26,7 @@
|
|||||||
package com.plotsquared.bukkit.placeholder;
|
package com.plotsquared.bukkit.placeholder;
|
||||||
|
|
||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
|
import com.plotsquared.core.configuration.Settings;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||||
@ -123,7 +124,8 @@ public class Placeholders extends PlaceholderExpansion {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = PlotSquared.get().getImpromptuUUIDPipeline() .getSingle(uid, 5L);
|
String name = PlotSquared.get().getImpromptuUUIDPipeline() .getSingle(uid,
|
||||||
|
Settings.UUID.BLOCKING_TIMEOUT);
|
||||||
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
return name;
|
return name;
|
||||||
|
@ -963,7 +963,7 @@ public class PlotSquared {
|
|||||||
* @return Set of Plot
|
* @return Set of Plot
|
||||||
*/
|
*/
|
||||||
public Set<Plot> getPlots(String world, String player) {
|
public Set<Plot> getPlots(String world, String player) {
|
||||||
final UUID uuid = this.impromptuUUIDPipeline.getSingle(player, 10L);
|
final UUID uuid = this.impromptuUUIDPipeline.getSingle(player, Settings.UUID.BLOCKING_TIMEOUT);
|
||||||
return getPlots(world, uuid);
|
return getPlots(world, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -975,7 +975,7 @@ public class PlotSquared {
|
|||||||
* @return Set of Plot
|
* @return Set of Plot
|
||||||
*/
|
*/
|
||||||
public Set<Plot> getPlots(PlotArea area, String player) {
|
public Set<Plot> getPlots(PlotArea area, String player) {
|
||||||
final UUID uuid = this.impromptuUUIDPipeline.getSingle(player, 10L);
|
final UUID uuid = this.impromptuUUIDPipeline.getSingle(player, Settings.UUID.BLOCKING_TIMEOUT);
|
||||||
return getPlots(area, uuid);
|
return getPlots(area, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ import com.plotsquared.core.util.task.RunnableVal3;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
@CommandDeclaration(command = "add",
|
@CommandDeclaration(command = "add",
|
||||||
description = "Allow a user to build in a plot while the plot owner is online.",
|
description = "Allow a user to build in a plot while the plot owner is online.",
|
||||||
@ -65,7 +66,11 @@ public class Add extends Command {
|
|||||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||||
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
|
if (throwable instanceof TimeoutException) {
|
||||||
|
Captions.FETCHING_PLAYERS_TIMEOUT.send(player);
|
||||||
|
} else {
|
||||||
Captions.INVALID_PLAYER.send(player, args[0]);
|
Captions.INVALID_PLAYER.send(player, args[0]);
|
||||||
|
}
|
||||||
future.completeExceptionally(throwable);
|
future.completeExceptionally(throwable);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -121,4 +126,5 @@ public class Add extends Command {
|
|||||||
});
|
});
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,8 @@ import com.plotsquared.core.util.MainUtil;
|
|||||||
import com.plotsquared.core.util.MathMan;
|
import com.plotsquared.core.util.MathMan;
|
||||||
import com.plotsquared.core.util.Permissions;
|
import com.plotsquared.core.util.Permissions;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
@CommandDeclaration(command = "setalias",
|
@CommandDeclaration(command = "setalias",
|
||||||
permission = "plots.alias",
|
permission = "plots.alias",
|
||||||
description = "Set the plot name",
|
description = "Set the plot name",
|
||||||
@ -115,7 +117,9 @@ public class Alias extends SubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(alias, ((uuid, throwable) -> {
|
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(alias, ((uuid, throwable) -> {
|
||||||
if (uuid != null) {
|
if (throwable instanceof TimeoutException) {
|
||||||
|
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||||
|
} else if (uuid != null) {
|
||||||
MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
|
MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
|
||||||
} else {
|
} else {
|
||||||
plot.setAlias(alias);
|
plot.setAlias(alias);
|
||||||
|
@ -44,6 +44,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
@CommandDeclaration(command = "cluster",
|
@CommandDeclaration(command = "cluster",
|
||||||
aliases = "clusters",
|
aliases = "clusters",
|
||||||
@ -373,7 +374,9 @@ public class Cluster extends SubCommand {
|
|||||||
|
|
||||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||||
.getSingle(args[1], (uuid, throwable) -> {
|
.getSingle(args[1], (uuid, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable instanceof TimeoutException) {
|
||||||
|
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||||
|
} else if (throwable != null) {
|
||||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[1]);
|
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[1]);
|
||||||
} else {
|
} else {
|
||||||
if (!cluster.isAdded(uuid)) {
|
if (!cluster.isAdded(uuid)) {
|
||||||
@ -426,7 +429,9 @@ public class Cluster extends SubCommand {
|
|||||||
// check uuid
|
// check uuid
|
||||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||||
.getSingle(args[1], (uuid, throwable) -> {
|
.getSingle(args[1], (uuid, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable instanceof TimeoutException) {
|
||||||
|
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||||
|
} else if (throwable != null) {
|
||||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[1]);
|
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[1]);
|
||||||
} else {
|
} else {
|
||||||
// Can't kick if the player is yourself, the owner, or not added to the cluster
|
// Can't kick if the player is yourself, the owner, or not added to the cluster
|
||||||
@ -542,7 +547,9 @@ public class Cluster extends SubCommand {
|
|||||||
|
|
||||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||||
.getSingle(args[2], (uuid, throwable) -> {
|
.getSingle(args[2], (uuid, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable instanceof TimeoutException) {
|
||||||
|
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||||
|
} else if (throwable != null) {
|
||||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[2]);
|
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[2]);
|
||||||
} else {
|
} else {
|
||||||
if (args[1].equalsIgnoreCase("add")) {
|
if (args[1].equalsIgnoreCase("add")) {
|
||||||
@ -631,6 +638,9 @@ public class Cluster extends SubCommand {
|
|||||||
|
|
||||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||||
.getSingle(cluster.owner, (username, throwable) -> {
|
.getSingle(cluster.owner, (username, throwable) -> {
|
||||||
|
if (throwable instanceof TimeoutException) {
|
||||||
|
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||||
|
} else {
|
||||||
final String owner;
|
final String owner;
|
||||||
if (username == null) {
|
if (username == null) {
|
||||||
owner = "unknown";
|
owner = "unknown";
|
||||||
@ -648,6 +658,7 @@ public class Cluster extends SubCommand {
|
|||||||
message = message.replaceAll("%size%", size);
|
message = message.replaceAll("%size%", size);
|
||||||
message = message.replaceAll("%rights%", rights);
|
message = message.replaceAll("%rights%", rights);
|
||||||
MainUtil.sendMessage(player, message);
|
MainUtil.sendMessage(player, message);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ import com.plotsquared.core.util.WorldUtil;
|
|||||||
import com.sk89q.worldedit.world.gamemode.GameModes;
|
import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
@CommandDeclaration(command = "deny",
|
@CommandDeclaration(command = "deny",
|
||||||
aliases = {"d", "ban"},
|
aliases = {"d", "ban"},
|
||||||
@ -68,7 +69,9 @@ public class Deny extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||||
if (throwable != null || uuids.isEmpty()) {
|
if (throwable instanceof TimeoutException) {
|
||||||
|
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||||
|
} else if (throwable != null || uuids.isEmpty()) {
|
||||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
|
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
|
||||||
} else {
|
} else {
|
||||||
for (UUID uuid : uuids) {
|
for (UUID uuid : uuids) {
|
||||||
|
@ -33,12 +33,9 @@ import com.plotsquared.core.player.PlotPlayer;
|
|||||||
import com.plotsquared.core.plot.Plot;
|
import com.plotsquared.core.plot.Plot;
|
||||||
import com.plotsquared.core.util.MainUtil;
|
import com.plotsquared.core.util.MainUtil;
|
||||||
import com.plotsquared.core.util.Permissions;
|
import com.plotsquared.core.util.Permissions;
|
||||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
@CommandDeclaration(command = "remove",
|
@CommandDeclaration(command = "remove",
|
||||||
aliases = {"r", "untrust", "ut", "undeny", "unban", "ud"},
|
aliases = {"r", "untrust", "ut", "undeny", "unban", "ud"},
|
||||||
@ -68,30 +65,16 @@ public class Remove extends SubCommand {
|
|||||||
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
|
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
switch (args[0]) {
|
if (throwable instanceof TimeoutException) {
|
||||||
case "unknown": {
|
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||||
HashSet<UUID> all = new HashSet<>();
|
return;
|
||||||
all.addAll(plot.getMembers());
|
} else if (throwable != null) {
|
||||||
all.addAll(plot.getTrusted());
|
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
|
||||||
all.addAll(plot.getDenied());
|
return;
|
||||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
} else if (!uuids.isEmpty()) {
|
||||||
for (UUID uuid : all) {
|
|
||||||
if (UUIDHandler.getName(uuid) == null) {
|
|
||||||
toRemove.add(uuid);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (UUID uuid : toRemove) {
|
|
||||||
plot.removeDenied(uuid);
|
|
||||||
plot.removeTrusted(uuid);
|
|
||||||
plot.removeMember(uuid);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
|
|
||||||
if (!uuids.isEmpty()) {
|
|
||||||
for (UUID uuid : uuids) {
|
for (UUID uuid : uuids) {
|
||||||
if (plot.getTrusted().contains(uuid)) {
|
if (plot.getTrusted().contains(uuid)) {
|
||||||
if (plot.removeTrusted(uuid)) {
|
if (plot.removeTrusted(uuid)) {
|
||||||
@ -128,14 +111,13 @@ public class Remove extends SubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
|
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
|
||||||
return false;
|
|
||||||
} else {
|
} else {
|
||||||
MainUtil.sendMessage(player, Captions.REMOVED_PLAYERS, count + "");
|
MainUtil.sendMessage(player, Captions.REMOVED_PLAYERS, count + "");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,9 +36,9 @@ import com.plotsquared.core.util.task.RunnableVal2;
|
|||||||
import com.plotsquared.core.util.task.RunnableVal3;
|
import com.plotsquared.core.util.task.RunnableVal3;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
@CommandDeclaration(command = "trust",
|
@CommandDeclaration(command = "trust",
|
||||||
aliases = {"t"},
|
aliases = {"t"},
|
||||||
@ -65,7 +65,18 @@ public class Trust extends Command {
|
|||||||
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST),
|
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST),
|
||||||
Captions.NO_PLOT_PERMS);
|
Captions.NO_PLOT_PERMS);
|
||||||
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
|
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
|
||||||
final Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
|
|
||||||
|
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||||
|
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||||
|
if (throwable != null) {
|
||||||
|
if (throwable instanceof TimeoutException) {
|
||||||
|
Captions.FETCHING_PLAYERS_TIMEOUT.send(player);
|
||||||
|
} else {
|
||||||
|
Captions.INVALID_PLAYER.send(player, args[0]);
|
||||||
|
}
|
||||||
|
future.completeExceptionally(throwable);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]);
|
checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]);
|
||||||
Iterator<UUID> iterator = uuids.iterator();
|
Iterator<UUID> iterator = uuids.iterator();
|
||||||
int size = currentPlot.getTrusted().size() + currentPlot.getMembers().size();
|
int size = currentPlot.getTrusted().size() + currentPlot.getMembers().size();
|
||||||
@ -109,7 +120,10 @@ public class Trust extends Command {
|
|||||||
MainUtil.sendMessage(player, Captions.TRUSTED_ADDED);
|
MainUtil.sendMessage(player, Captions.TRUSTED_ADDED);
|
||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
|
}
|
||||||
|
future.complete(true);
|
||||||
|
});
|
||||||
return CompletableFuture.completedFuture(true);
|
return CompletableFuture.completedFuture(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@ -156,7 +157,9 @@ public class Visit extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||||
if (throwable != null || uuids.size() != 1) {
|
if (throwable instanceof TimeoutException) {
|
||||||
|
Captions.FETCHING_PLAYERS_TIMEOUT.send(player);
|
||||||
|
} else if (throwable != null || uuids.size() != 1) {
|
||||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||||
} else {
|
} else {
|
||||||
unsortedPre.addAll(PlotSquared.get().getBasePlots((UUID) uuids.toArray()[0]));
|
unsortedPre.addAll(PlotSquared.get().getBasePlots((UUID) uuids.toArray()[0]));
|
||||||
@ -188,7 +191,9 @@ public class Visit extends Command {
|
|||||||
|
|
||||||
if (args[0].length() >= 2) {
|
if (args[0].length() >= 2) {
|
||||||
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(args[0], (uuid, throwable) -> {
|
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(args[0], (uuid, throwable) -> {
|
||||||
if (uuid != null && !PlotSquared.get().hasPlot(uuid)) {
|
if (throwable instanceof TimeoutException) {
|
||||||
|
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||||
|
} else if (uuid != null && !PlotSquared.get().hasPlot(uuid)) {
|
||||||
uuidConsumer.accept(null);
|
uuidConsumer.accept(null);
|
||||||
} else {
|
} else {
|
||||||
uuidConsumer.accept(uuid);
|
uuidConsumer.accept(uuid);
|
||||||
|
@ -451,6 +451,7 @@ public enum Captions implements Caption {
|
|||||||
DEBUG_REPORT_CREATED("$1Uploaded a full debug to: $1%url%", "Paste"),
|
DEBUG_REPORT_CREATED("$1Uploaded a full debug to: $1%url%", "Paste"),
|
||||||
PURGE_SUCCESS("$4Successfully purged %s plots", "Purge"),
|
PURGE_SUCCESS("$4Successfully purged %s plots", "Purge"),
|
||||||
FETCHING_PLAYER("$1PlotSquared is attempting to find the specified player from your argument(s). This may take a while.", "Players"),
|
FETCHING_PLAYER("$1PlotSquared is attempting to find the specified player from your argument(s). This may take a while.", "Players"),
|
||||||
|
FETCHING_PLAYERS_TIMEOUT("$2The specified users did not exist in the cache and will be fetched in the background. Please wait a couple of minutes.", "Players"),
|
||||||
//<editor-fold desc="Trim">
|
//<editor-fold desc="Trim">
|
||||||
TRIM_IN_PROGRESS("A world trim task is already in progress!", "Trim"),
|
TRIM_IN_PROGRESS("A world trim task is already in progress!", "Trim"),
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
|
@ -245,6 +245,10 @@ public class Settings extends Config {
|
|||||||
public static int BACKGROUND_LIMIT = 200;
|
public static int BACKGROUND_LIMIT = 200;
|
||||||
@Comment("Rate limit (per 10 minutes) for random UUID fetching from the Mojang API")
|
@Comment("Rate limit (per 10 minutes) for random UUID fetching from the Mojang API")
|
||||||
public static int IMPROMPTU_LIMIT = 300;
|
public static int IMPROMPTU_LIMIT = 300;
|
||||||
|
@Comment("Timeout (in milliseconds) for non-blocking UUID requests (mostly commands)")
|
||||||
|
public static long NON_BLOCKING_TIMEOUT = 3000L;
|
||||||
|
@Comment("Timeout (in milliseconds) for blocking UUID requests (events)")
|
||||||
|
public static long BLOCKING_TIMEOUT = 10L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -383,7 +383,7 @@ public class MainUtil {
|
|||||||
if (owner.equals(DBFunc.SERVER)) {
|
if (owner.equals(DBFunc.SERVER)) {
|
||||||
return Captions.SERVER.getTranslated();
|
return Captions.SERVER.getTranslated();
|
||||||
}
|
}
|
||||||
String name = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(owner, 10L);
|
String name = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(owner, Settings.UUID.BLOCKING_TIMEOUT);
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return Captions.UNKNOWN.getTranslated();
|
return Captions.UNKNOWN.getTranslated();
|
||||||
}
|
}
|
||||||
@ -454,7 +454,7 @@ public class MainUtil {
|
|||||||
|
|
||||||
for (String term : split) {
|
for (String term : split) {
|
||||||
try {
|
try {
|
||||||
UUID uuid = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(term, 10L);
|
UUID uuid = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(term, Settings.UUID.BLOCKING_TIMEOUT);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
uuid = UUID.fromString(term);
|
uuid = UUID.fromString(term);
|
||||||
}
|
}
|
||||||
@ -752,7 +752,8 @@ public class MainUtil {
|
|||||||
if (request.isEmpty()) {
|
if (request.isEmpty()) {
|
||||||
consumer.accept(result, null);
|
consumer.accept(result, null);
|
||||||
} else {
|
} else {
|
||||||
PlotSquared.get().getImpromptuUUIDPipeline().getUUIDs(request).whenComplete((uuids, throwable) -> {
|
PlotSquared.get().getImpromptuUUIDPipeline().getUUIDs(request, Settings.UUID.NON_BLOCKING_TIMEOUT)
|
||||||
|
.whenComplete((uuids, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
consumer.accept(null, throwable);
|
consumer.accept(null, throwable);
|
||||||
} else {
|
} else {
|
||||||
|
@ -27,6 +27,7 @@ package com.plotsquared.core.uuid;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
|
import com.plotsquared.core.configuration.Settings;
|
||||||
import com.plotsquared.core.util.ThreadUtils;
|
import com.plotsquared.core.util.ThreadUtils;
|
||||||
import com.plotsquared.core.util.task.TaskManager;
|
import com.plotsquared.core.util.task.TaskManager;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -42,10 +43,13 @@ import java.util.UUID;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An UUID pipeline is essentially an ordered list of
|
* An UUID pipeline is essentially an ordered list of
|
||||||
@ -60,6 +64,7 @@ public class UUIDPipeline {
|
|||||||
private final Executor executor;
|
private final Executor executor;
|
||||||
private final List<UUIDService> serviceList;
|
private final List<UUIDService> serviceList;
|
||||||
private final List<Consumer<List<UUIDMapping>>> consumerList;
|
private final List<Consumer<List<UUIDMapping>>> consumerList;
|
||||||
|
private final ScheduledExecutorService timeoutExecutor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new UUID pipeline
|
* Construct a new UUID pipeline
|
||||||
@ -71,6 +76,7 @@ public class UUIDPipeline {
|
|||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.serviceList = Lists.newLinkedList();
|
this.serviceList = Lists.newLinkedList();
|
||||||
this.consumerList = Lists.newLinkedList();
|
this.consumerList = Lists.newLinkedList();
|
||||||
|
this.timeoutExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,8 +190,10 @@ public class UUIDPipeline {
|
|||||||
* @param username Username
|
* @param username Username
|
||||||
* @param uuid UUID consumer
|
* @param uuid UUID consumer
|
||||||
*/
|
*/
|
||||||
public void getSingle(@NotNull final String username, @NotNull final BiConsumer<UUID, Throwable> uuid) {
|
public void getSingle(@NotNull final String username,
|
||||||
this.getUUIDs(Collections.singletonList(username)).whenComplete((uuids, throwable) -> {
|
@NotNull final BiConsumer<UUID, Throwable> uuid) {
|
||||||
|
this.getUUIDs(Collections.singletonList(username)).applyToEither(timeoutAfter(Settings.UUID.NON_BLOCKING_TIMEOUT), Function.identity())
|
||||||
|
.whenComplete((uuids, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
uuid.accept(null, throwable);
|
uuid.accept(null, throwable);
|
||||||
} else {
|
} else {
|
||||||
@ -204,8 +212,10 @@ public class UUIDPipeline {
|
|||||||
* @param uuid UUID
|
* @param uuid UUID
|
||||||
* @param username Username consumer
|
* @param username Username consumer
|
||||||
*/
|
*/
|
||||||
public void getSingle(@NotNull final UUID uuid, @NotNull final BiConsumer<String, Throwable> username) {
|
public void getSingle(@NotNull final UUID uuid,
|
||||||
this.getNames(Collections.singletonList(uuid)).whenComplete((uuids, throwable) -> {
|
@NotNull final BiConsumer<String, Throwable> username) {
|
||||||
|
this.getNames(Collections.singletonList(uuid)).applyToEither(timeoutAfter(Settings.UUID.NON_BLOCKING_TIMEOUT), Function.identity())
|
||||||
|
.whenComplete((uuids, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
username.accept(null, throwable);
|
username.accept(null, throwable);
|
||||||
} else {
|
} else {
|
||||||
@ -218,6 +228,42 @@ public class UUIDPipeline {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously attempt to fetch the mapping from a list of UUIDs.
|
||||||
|
* <p>
|
||||||
|
* This will timeout after the specified time and throws a {@link TimeoutException}
|
||||||
|
* if this happens
|
||||||
|
*
|
||||||
|
* @param requests UUIDs
|
||||||
|
* @param timeout Timeout in milliseconds
|
||||||
|
* @return Mappings
|
||||||
|
*/
|
||||||
|
public CompletableFuture<List<UUIDMapping>> getNames(@NotNull final Collection<UUID> requests,
|
||||||
|
final long timeout) {
|
||||||
|
return this.getNames(requests).applyToEither(timeoutAfter(timeout), Function.identity());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously attempt to fetch the mapping from a list of names.
|
||||||
|
* <p>
|
||||||
|
* This will timeout after the specified time and throws a {@link TimeoutException}
|
||||||
|
* if this happens
|
||||||
|
*
|
||||||
|
* @param requests Names
|
||||||
|
* @param timeout Timeout in milliseconds
|
||||||
|
* @return Mappings
|
||||||
|
*/
|
||||||
|
public CompletableFuture<List<UUIDMapping>> getUUIDs(@NotNull final Collection<String> requests,
|
||||||
|
final long timeout) {
|
||||||
|
return this.getUUIDs(requests).applyToEither(timeoutAfter(timeout), Function.identity());
|
||||||
|
}
|
||||||
|
|
||||||
|
private CompletableFuture<List<UUIDMapping>> timeoutAfter(final long timeout) {
|
||||||
|
final CompletableFuture<List<UUIDMapping>> result = new CompletableFuture<>();
|
||||||
|
this.timeoutExecutor.schedule(() -> result.completeExceptionally(new TimeoutException()), timeout, TimeUnit.MILLISECONDS);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously attempt to fetch the mapping from a list of UUIDs
|
* Asynchronously attempt to fetch the mapping from a list of UUIDs
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user