diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml index b94221c89..d01f91307 100644 --- a/Bukkit/pom.xml +++ b/Bukkit/pom.xml @@ -21,7 +21,7 @@ com.plotsquared PlotSquared-Core - 5.12.0 + 5.12.2 compile diff --git a/Core/src/main/java/com/plotsquared/core/command/Visit.java b/Core/src/main/java/com/plotsquared/core/command/Visit.java index 077f1f6de..f5243b4ba 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Visit.java +++ b/Core/src/main/java/com/plotsquared/core/command/Visit.java @@ -40,6 +40,7 @@ import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.query.SortingStrategy; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; +import com.plotsquared.core.uuid.UUIDMapping; import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -193,7 +194,18 @@ public class Visit extends Command { case 1: final String[] finalArgs = args; int finalPage = page; - if (args[0].length() >= 2 && !args[0].contains(";") && !args[0].contains(",")) { + // Try to determine whether the given argument is a username + // or an ordinal + boolean isNumber = false; + if (args[0].length() < 2) { + isNumber = true; + } else if (args[0].length() <= 4 && MathMan.isInteger(args[0])) { + // Check if it's an all-digit username that is stored in cache + final UUIDMapping mapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(args[0]); + // If no UUID could be found, then we assume it's a number and not a username + isNumber = mapping == null; + } + if (!isNumber && args[0].length() >= 2 && !args[0].contains(";") && !args[0].contains(",")) { PlotSquared.get().getImpromptuUUIDPipeline().getSingle(args[0], (uuid, throwable) -> { if (throwable instanceof TimeoutException) { // The request timed out @@ -240,9 +252,7 @@ public class Visit extends Command { } else { // Try to parse a plot final Plot plot = MainUtil.getPlotFromString(player, finalArgs[0], true); - if (plot == null) { - MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_ID); - } else { + if (plot != null) { this.visit(player, PlotQuery.newQuery().withPlot(plot), null, confirm, whenDone, 1); } } diff --git a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java index 8546298b6..9e2a78853 100644 --- a/Core/src/main/java/com/plotsquared/core/util/MainUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/MainUtil.java @@ -55,6 +55,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -515,7 +516,7 @@ public class MainUtil { * @param message If a message should be sent to the player if a plot cannot be found * @return The plot if only 1 result is found, or null */ - public static Plot getPlotFromString(PlotPlayer player, String arg, boolean message) { + @Nullable public static Plot getPlotFromString(PlotPlayer player, String arg, boolean message) { if (arg == null) { if (player == null) { if (message) { diff --git a/Core/src/main/java/com/plotsquared/core/uuid/CacheUUIDService.java b/Core/src/main/java/com/plotsquared/core/uuid/CacheUUIDService.java index 484146dae..563618afa 100644 --- a/Core/src/main/java/com/plotsquared/core/uuid/CacheUUIDService.java +++ b/Core/src/main/java/com/plotsquared/core/uuid/CacheUUIDService.java @@ -28,9 +28,11 @@ package com.plotsquared.core.uuid; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.UUID; import java.util.function.Consumer; @@ -81,4 +83,20 @@ public class CacheUUIDService implements UUIDService, Consumer @Override public boolean canBeSynchronous() { return true; } + + @Override @Nullable public UUIDMapping getImmediately(@NotNull final Object object) { + final List list; + if (object instanceof String) { + list = getUUIDs(Collections.singletonList((String) object)); + } else if (object instanceof UUID) { + list = getNames(Collections.singletonList((UUID) object)); + } else { + list = Collections.emptyList(); + } + if (list.isEmpty()) { + return null; + } + return list.get(0); + } + } diff --git a/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java b/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java index 8c8baa06d..997cdfdc1 100644 --- a/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java +++ b/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java @@ -405,4 +405,20 @@ public class UUIDPipeline { return mappings; } + /** + * Get a single UUID mapping immediately, if possible + * + * @param object Username ({@link String}) or {@link UUID} + * @return Mapping, if it could be found immediately + */ + @Nullable public final UUIDMapping getImmediately(@NotNull final Object object) { + for (final UUIDService uuidService : this.getServiceListInstance()) { + final UUIDMapping mapping = uuidService.getImmediately(object); + if (mapping != null) { + return mapping; + } + } + return null; + } + } diff --git a/Core/src/main/java/com/plotsquared/core/uuid/UUIDService.java b/Core/src/main/java/com/plotsquared/core/uuid/UUIDService.java index 3b6419bd6..f6fe86f11 100644 --- a/Core/src/main/java/com/plotsquared/core/uuid/UUIDService.java +++ b/Core/src/main/java/com/plotsquared/core/uuid/UUIDService.java @@ -26,6 +26,7 @@ package com.plotsquared.core.uuid; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Collections; @@ -75,4 +76,14 @@ public interface UUIDService { return false; } + /** + * Get a single UUID mapping immediately, if possible + * + * @param object Username ({@link String}) or {@link UUID} + * @return Mapping, if it could be found immediately + */ + default @Nullable UUIDMapping getImmediately(@NotNull final Object object) { + return null; + } + } diff --git a/build.gradle b/build.gradle index 03053e64a..635cd7ea4 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ ext { git = Grgit.open(dir: new File(rootDir.toString() + "/.git")) } -def ver = "5.12.1" +def ver = "5.12.2" def versuffix = "" ext { if (project.hasProperty("versionsuffix")) {