From fd06c0cdd7767a8445aecfc7febe8f712e4daf1c Mon Sep 17 00:00:00 2001 From: wellnesscookie <46493763+wellnesscookie@users.noreply.github.com> Date: Thu, 6 Aug 2020 21:14:50 +0200 Subject: [PATCH] Fixes unwanted parsing when warping to an island (#86) * Fixes incorrect parsing when warping to similiar players * Removes debug lines --- .../bentobox/warps/commands/WarpCommand.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/world/bentobox/warps/commands/WarpCommand.java b/src/main/java/world/bentobox/warps/commands/WarpCommand.java index be45106..d593192 100644 --- a/src/main/java/world/bentobox/warps/commands/WarpCommand.java +++ b/src/main/java/world/bentobox/warps/commands/WarpCommand.java @@ -17,7 +17,6 @@ import world.bentobox.warps.Warp; * The /is warp command * * @author tastybento - * */ public class WarpCommand extends DelayedTeleportCommand { @@ -52,12 +51,22 @@ public class WarpCommand extends DelayedTeleportCommand { user.sendMessage("warps.warpTip", "[text]", addon.getSettings().getWelcomeLine()); return false; } else { - // Check if this is part of a name - UUID foundWarp = warpList.stream().filter(u -> getPlayers().getName(u).equalsIgnoreCase(args.get(0)) - || getPlayers().getName(u).toLowerCase().startsWith(args.get(0).toLowerCase())).findFirst().orElse(null); + // Attemp to find warp with exact player's name + UUID foundWarp = warpList.stream().filter(u -> getPlayers().getName(u).equalsIgnoreCase(args.get(0))).findFirst().orElse(null); + if (foundWarp == null) { - user.sendMessage("warps.error.does-not-exist"); - return false; + + // Atempt to find warp which starts with the given name + UUID foundAlernativeWarp = warpList.stream().filter(u -> getPlayers().getName(u).toLowerCase().startsWith(args.get(0).toLowerCase())).findFirst().orElse(null); + + if (foundAlernativeWarp == null) { + user.sendMessage("warps.error.does-not-exist"); + return false; + } else { + // Alternative warp found! + this.delayCommand(user, () -> addon.getWarpSignsManager().warpPlayer(world, user, foundAlernativeWarp)); + return true; + } } else { // Warp exists! this.delayCommand(user, () -> addon.getWarpSignsManager().warpPlayer(world, user, foundWarp));