mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Fix issue where numbers were sometimes parsed as usernames when they shouldn't be. This commit also fixes an issue where "Not a valid plot ID" was sent twice.
This commit is contained in:
parent
159b35c717
commit
f6f26c6102
@ -21,7 +21,7 @@
|
||||
<dependency>
|
||||
<groupId>com.plotsquared</groupId>
|
||||
<artifactId>PlotSquared-Core</artifactId>
|
||||
<version>5.12.0</version>
|
||||
<version>5.12.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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<List<UUIDMapping>
|
||||
@Override public boolean canBeSynchronous() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override @Nullable public UUIDMapping getImmediately(@NotNull final Object object) {
|
||||
final List<UUIDMapping> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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")) {
|
||||
|
Loading…
Reference in New Issue
Block a user