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) {
|
||||||
Captions.INVALID_PLAYER.send(player, args[0]);
|
if (throwable instanceof TimeoutException) {
|
||||||
|
Captions.FETCHING_PLAYERS_TIMEOUT.send(player);
|
||||||
|
} else {
|
||||||
|
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,23 +638,27 @@ public class Cluster extends SubCommand {
|
|||||||
|
|
||||||
PlotSquared.get().getImpromptuUUIDPipeline()
|
PlotSquared.get().getImpromptuUUIDPipeline()
|
||||||
.getSingle(cluster.owner, (username, throwable) -> {
|
.getSingle(cluster.owner, (username, throwable) -> {
|
||||||
final String owner;
|
if (throwable instanceof TimeoutException) {
|
||||||
if (username == null) {
|
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||||
owner = "unknown";
|
|
||||||
} else {
|
} else {
|
||||||
owner = username;
|
final String owner;
|
||||||
|
if (username == null) {
|
||||||
|
owner = "unknown";
|
||||||
|
} else {
|
||||||
|
owner = username;
|
||||||
|
}
|
||||||
|
String name = cluster.getName();
|
||||||
|
String size = (cluster.getP2().x - cluster.getP1().x + 1) + "x" + (
|
||||||
|
cluster.getP2().y - cluster.getP1().y + 1);
|
||||||
|
String rights = cluster.isAdded(player.getUUID()) + "";
|
||||||
|
String message = Captions.CLUSTER_INFO.getTranslated();
|
||||||
|
message = message.replaceAll("%id%", id);
|
||||||
|
message = message.replaceAll("%owner%", owner);
|
||||||
|
message = message.replaceAll("%name%", name);
|
||||||
|
message = message.replaceAll("%size%", size);
|
||||||
|
message = message.replaceAll("%rights%", rights);
|
||||||
|
MainUtil.sendMessage(player, message);
|
||||||
}
|
}
|
||||||
String name = cluster.getName();
|
|
||||||
String size = (cluster.getP2().x - cluster.getP1().x + 1) + "x" + (
|
|
||||||
cluster.getP2().y - cluster.getP1().y + 1);
|
|
||||||
String rights = cluster.isAdded(player.getUUID()) + "";
|
|
||||||
String message = Captions.CLUSTER_INFO.getTranslated();
|
|
||||||
message = message.replaceAll("%id%", id);
|
|
||||||
message = message.replaceAll("%owner%", owner);
|
|
||||||
message = message.replaceAll("%name%", name);
|
|
||||||
message = message.replaceAll("%size%", size);
|
|
||||||
message = message.replaceAll("%rights%", rights);
|
|
||||||
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,74 +65,59 @@ public class Remove extends SubCommand {
|
|||||||
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
|
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
int count = 0;
|
|
||||||
switch (args[0]) {
|
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||||
case "unknown": {
|
int count = 0;
|
||||||
HashSet<UUID> all = new HashSet<>();
|
if (throwable instanceof TimeoutException) {
|
||||||
all.addAll(plot.getMembers());
|
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||||
all.addAll(plot.getTrusted());
|
return;
|
||||||
all.addAll(plot.getDenied());
|
} else if (throwable != null) {
|
||||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
|
||||||
for (UUID uuid : all) {
|
return;
|
||||||
if (UUIDHandler.getName(uuid) == null) {
|
} else if (!uuids.isEmpty()) {
|
||||||
toRemove.add(uuid);
|
for (UUID uuid : uuids) {
|
||||||
count++;
|
if (plot.getTrusted().contains(uuid)) {
|
||||||
}
|
if (plot.removeTrusted(uuid)) {
|
||||||
}
|
PlotSquared.get().getEventDispatcher()
|
||||||
for (UUID uuid : toRemove) {
|
.callTrusted(player, plot, uuid, false);
|
||||||
plot.removeDenied(uuid);
|
count++;
|
||||||
plot.removeTrusted(uuid);
|
}
|
||||||
plot.removeMember(uuid);
|
} else if (plot.getMembers().contains(uuid)) {
|
||||||
}
|
if (plot.removeMember(uuid)) {
|
||||||
break;
|
PlotSquared.get().getEventDispatcher()
|
||||||
}
|
.callMember(player, plot, uuid, false);
|
||||||
default:
|
count++;
|
||||||
Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
|
}
|
||||||
if (!uuids.isEmpty()) {
|
} else if (plot.getDenied().contains(uuid)) {
|
||||||
for (UUID uuid : uuids) {
|
if (plot.removeDenied(uuid)) {
|
||||||
if (plot.getTrusted().contains(uuid)) {
|
PlotSquared.get().getEventDispatcher()
|
||||||
if (plot.removeTrusted(uuid)) {
|
.callDenied(player, plot, uuid, false);
|
||||||
PlotSquared.get().getEventDispatcher()
|
count++;
|
||||||
.callTrusted(player, plot, uuid, false);
|
}
|
||||||
count++;
|
} else if (uuid == DBFunc.EVERYONE) {
|
||||||
}
|
if (plot.removeTrusted(uuid)) {
|
||||||
} else if (plot.getMembers().contains(uuid)) {
|
PlotSquared.get().getEventDispatcher()
|
||||||
if (plot.removeMember(uuid)) {
|
.callTrusted(player, plot, uuid, false);
|
||||||
PlotSquared.get().getEventDispatcher()
|
count++;
|
||||||
.callMember(player, plot, uuid, false);
|
} else if (plot.removeMember(uuid)) {
|
||||||
count++;
|
PlotSquared.get().getEventDispatcher()
|
||||||
}
|
.callMember(player, plot, uuid, false);
|
||||||
} else if (plot.getDenied().contains(uuid)) {
|
count++;
|
||||||
if (plot.removeDenied(uuid)) {
|
} else if (plot.removeDenied(uuid)) {
|
||||||
PlotSquared.get().getEventDispatcher()
|
PlotSquared.get().getEventDispatcher()
|
||||||
.callDenied(player, plot, uuid, false);
|
.callDenied(player, plot, uuid, false);
|
||||||
count++;
|
count++;
|
||||||
}
|
|
||||||
} else if (uuid == DBFunc.EVERYONE) {
|
|
||||||
if (plot.removeTrusted(uuid)) {
|
|
||||||
PlotSquared.get().getEventDispatcher()
|
|
||||||
.callTrusted(player, plot, uuid, false);
|
|
||||||
count++;
|
|
||||||
} else if (plot.removeMember(uuid)) {
|
|
||||||
PlotSquared.get().getEventDispatcher()
|
|
||||||
.callMember(player, plot, uuid, false);
|
|
||||||
count++;
|
|
||||||
} else if (plot.removeDenied(uuid)) {
|
|
||||||
PlotSquared.get().getEventDispatcher()
|
|
||||||
.callDenied(player, plot, uuid, false);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
if (count == 0) {
|
||||||
if (count == 0) {
|
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
|
||||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
|
} else {
|
||||||
return false;
|
MainUtil.sendMessage(player, Captions.REMOVED_PLAYERS, count + "");
|
||||||
} else {
|
}
|
||||||
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,51 +65,65 @@ 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]);
|
|
||||||
checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]);
|
|
||||||
Iterator<UUID> iterator = uuids.iterator();
|
|
||||||
int size = currentPlot.getTrusted().size() + currentPlot.getMembers().size();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
UUID uuid = iterator.next();
|
|
||||||
if (uuid == DBFunc.EVERYONE && !(
|
|
||||||
Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions
|
|
||||||
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
|
||||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
|
|
||||||
iterator.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (currentPlot.isOwner(uuid)) {
|
|
||||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
|
|
||||||
iterator.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (currentPlot.getTrusted().contains(uuid)) {
|
|
||||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
|
|
||||||
iterator.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
size += currentPlot.getMembers().contains(uuid) ? 0 : 1;
|
|
||||||
}
|
|
||||||
checkTrue(!uuids.isEmpty(), null);
|
|
||||||
checkTrue(size <= currentPlot.getArea().getMaxPlotMembers() || Permissions
|
|
||||||
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST),
|
|
||||||
Captions.PLOT_MAX_MEMBERS);
|
|
||||||
// Success
|
|
||||||
confirm.run(this, () -> {
|
|
||||||
for (UUID uuid : uuids) {
|
|
||||||
if (uuid != DBFunc.EVERYONE) {
|
|
||||||
if (!currentPlot.removeMember(uuid)) {
|
|
||||||
if (currentPlot.getDenied().contains(uuid)) {
|
|
||||||
currentPlot.removeDenied(uuid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
currentPlot.addTrusted(uuid);
|
|
||||||
PlotSquared.get().getEventDispatcher().callTrusted(player, currentPlot, uuid, true);
|
|
||||||
MainUtil.sendMessage(player, Captions.TRUSTED_ADDED);
|
|
||||||
}
|
|
||||||
}, null);
|
|
||||||
|
|
||||||
|
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]);
|
||||||
|
Iterator<UUID> iterator = uuids.iterator();
|
||||||
|
int size = currentPlot.getTrusted().size() + currentPlot.getMembers().size();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
UUID uuid = iterator.next();
|
||||||
|
if (uuid == DBFunc.EVERYONE && !(
|
||||||
|
Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions
|
||||||
|
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
||||||
|
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
|
||||||
|
iterator.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (currentPlot.isOwner(uuid)) {
|
||||||
|
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
|
||||||
|
iterator.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (currentPlot.getTrusted().contains(uuid)) {
|
||||||
|
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
|
||||||
|
iterator.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
size += currentPlot.getMembers().contains(uuid) ? 0 : 1;
|
||||||
|
}
|
||||||
|
checkTrue(!uuids.isEmpty(), null);
|
||||||
|
checkTrue(size <= currentPlot.getArea().getMaxPlotMembers() || Permissions
|
||||||
|
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST),
|
||||||
|
Captions.PLOT_MAX_MEMBERS);
|
||||||
|
// Success
|
||||||
|
confirm.run(this, () -> {
|
||||||
|
for (UUID uuid : uuids) {
|
||||||
|
if (uuid != DBFunc.EVERYONE) {
|
||||||
|
if (!currentPlot.removeMember(uuid)) {
|
||||||
|
if (currentPlot.getDenied().contains(uuid)) {
|
||||||
|
currentPlot.removeDenied(uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currentPlot.addTrusted(uuid);
|
||||||
|
PlotSquared.get().getEventDispatcher().callTrusted(player, currentPlot, uuid, true);
|
||||||
|
MainUtil.sendMessage(player, Captions.TRUSTED_ADDED);
|
||||||
|
}
|
||||||
|
}, 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