diff --git a/src/main/java/com/lovetropics/extras/command/TpCommand.java b/src/main/java/com/lovetropics/extras/command/TpCommand.java index 5069e520..81588f0d 100644 --- a/src/main/java/com/lovetropics/extras/command/TpCommand.java +++ b/src/main/java/com/lovetropics/extras/command/TpCommand.java @@ -51,6 +51,7 @@ public class TpCommand { private static final String ARGUMENT_NAME = "name"; private static final DynamicCommandExceptionType PLAYER_NOT_FOUND = new DynamicCommandExceptionType(o -> Component.translatable("commands.tpa.player_not_found")); + private static final DynamicCommandExceptionType REQUEST_NOT_FOUND = new DynamicCommandExceptionType(o -> Component.translatable("commands.tpa.request_not_found")); private static final DynamicCommandExceptionType GENERAL_ERROR = new DynamicCommandExceptionType(o -> Component.translatable("commands.tpa.general_error")); private static final DynamicCommandExceptionType TOO_MUCH = new DynamicCommandExceptionType(o -> Component.translatable("commands.tpa.toomuch")); @@ -111,13 +112,14 @@ private static int tpHelp(final CommandContext ctx) throws C } private static int tpBack(final CommandContext ctx) throws CommandSyntaxException { - final BlockPos blockPos = backCache.getIfPresent(ctx.getSource().getDisplayName().getString().toLowerCase()); + final BlockPos blockPos = backCache.getIfPresent(nonNullSourcePlayer(ctx).getName().getString().toLowerCase()); if (blockPos == null) { throw GENERAL_ERROR.create(null); } final ServerPlayer executingPlayer = nonNullSourcePlayer(ctx); + backCache.put(executingPlayer.getName().getString().toLowerCase(), executingPlayer.blockPosition()); //This allows going back and forth using /back executingPlayer.connection.teleport(blockPos.getX(), blockPos.getY(), blockPos.getZ(), executingPlayer.yya, executingPlayer.xxa, Collections.emptySet()); return Command.SINGLE_SUCCESS; @@ -125,10 +127,11 @@ private static int tpBack(final CommandContext ctx) throws C private static int tpAccept(final CommandContext ctx) throws CommandSyntaxException { final String tpRequester = ctx.getArgument(ARGUMENT_NAME, String.class); - final String requestedTarget = requestCache.getIfPresent(tpRequester); + final String requestedTarget = requestCache.getIfPresent(tpRequester.toLowerCase()); + final String commandExecutorName = nonNullSourcePlayer(ctx).getName().getString(); - if (requestedTarget == null || !requestedTarget.equalsIgnoreCase(ctx.getSource().getDisplayName().getString())) { - throw PLAYER_NOT_FOUND.create(null); + if (requestedTarget == null || !requestedTarget.equalsIgnoreCase(commandExecutorName)) { + throw REQUEST_NOT_FOUND.create(null); } final ServerPlayer executingPlayer = nonNullSourcePlayer(ctx); @@ -141,7 +144,7 @@ private static int tpAccept(final CommandContext ctx) throws private static int acceptAllTpRequests(final CommandContext ctx) throws CommandSyntaxException { final ServerPlayer executingPlayer = nonNullSourcePlayer(ctx); - final String targetPlayerName = ctx.getSource().getDisplayName().getString(); + final String targetPlayerName = executingPlayer.getName().getString(); final String targetPlayerNameLowerCase = targetPlayerName.toLowerCase(); final Map requesterTargetMap = requestCache.asMap().entrySet().stream() .filter(entry -> entry.getValue().equalsIgnoreCase(targetPlayerNameLowerCase)) @@ -157,7 +160,7 @@ private static int acceptAllTpRequests(final CommandContext private static int tpRequest(final CommandContext ctx) throws CommandSyntaxException { final ServerPlayer executingPlayer = nonNullSourcePlayer(ctx); - final String requester = executingPlayer.getDisplayName().getString(); + final String requester = executingPlayer.getName().getString(); final String requesterLowerCase = requester.toLowerCase(); final String target = ctx.getArgument(ARGUMENT_NAME, String.class); final String targetLowerCase = target.toLowerCase(); @@ -178,9 +181,9 @@ private static int tpRequest(final CommandContext ctx) throw } private static void teleportAndSendMessage(ServerPlayer player, ServerPlayer target) { - requestCache.invalidate(player.getDisplayName().getString().toLowerCase()); - backCache.put(player.getDisplayName().toString().toLowerCase(), player.blockPosition()); - player.sendSystemMessage(Component.translatable("commands.tpa.tp_accepted", target.getDisplayName())); + requestCache.invalidate(player.getName().getString().toLowerCase()); + backCache.put(player.getName().getString().toLowerCase(), player.blockPosition()); + player.sendSystemMessage(Component.translatable("commands.tpa.tp_accepted", target.getName().getString())); player.connection.teleport(target.getX(), target.getY(), target.getZ(), target.yya, target.xxa, Collections.emptySet()); } @@ -214,6 +217,7 @@ public static void addTranslations(final RegistrateLangProvider provider) { provider.add("commands.tpa.too_much", "You are doing that too much"); provider.add("commands.tpa.request_sent", "Request sent"); provider.add("commands.tpa.player_not_found", "Player not found"); + provider.add("commands.tpa.request_not_found", "No teleport request"); provider.add("commands.tpa.general_error", "Unable to teleport"); provider.add("commands.tpa.help.tpa", "/tpa - Request to teleport to a player"); provider.add("commands.tpa.help.tpaccept", "/tpaccept - Accept a teleport request from a player");