From 60590acfe350febda63badd3a96da4e6f48519fa Mon Sep 17 00:00:00 2001 From: stonar96 Date: Mon, 27 Apr 2020 00:50:53 +0200 Subject: [PATCH] Remove unnecessary checks and add comments --- .../java/com/sk89q/worldguard/bukkit/BukkitPlayer.java | 7 +++---- .../sk89q/worldguard/commands/region/RegionCommands.java | 9 ++++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitPlayer.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitPlayer.java index 1a0b2eb1..5ed933c5 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitPlayer.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/BukkitPlayer.java @@ -191,13 +191,12 @@ public void teleport(Location location, String successMessage, String failMessag PaperLib.teleportAsync(getPlayer(), BukkitAdapter.adapt(location)) .thenApply(success -> { if (success) { - if (successMessage != null && !successMessage.isEmpty()) { + // The success message can be cleared via flag + if (!successMessage.isEmpty()) { MessagingUtil.sendStringToChat(this, successMessage); } } else { - if (failMessage != null && !failMessage.isEmpty()) { - printError(failMessage); - } + printError(failMessage); } return success; }); diff --git a/worldguard-core/src/main/java/com/sk89q/worldguard/commands/region/RegionCommands.java b/worldguard-core/src/main/java/com/sk89q/worldguard/commands/region/RegionCommands.java index 02703fc4..2797e5d3 100644 --- a/worldguard-core/src/main/java/com/sk89q/worldguard/commands/region/RegionCommands.java +++ b/worldguard-core/src/main/java/com/sk89q/worldguard/commands/region/RegionCommands.java @@ -1112,8 +1112,15 @@ public void teleport(CommandContext args, Actor sender) throws CommandException } String message = existing.getFlag(Flags.TELE_MESSAGE); + + // If the flag isn't set, use the default message + // If message.isEmpty(), no message is sent by LocalPlayer#teleport(...) + if (message == null) { + message = Flags.TELE_MESSAGE.getDefault(); + } + player.teleport(teleportLocation, - (message == null ? Flags.TELE_MESSAGE.getDefault() : message).replace("%id%", existing.getId()), + message.replace("%id%", existing.getId()), "Unable to teleport to region '" + existing.getId() + "'."); }