Add teleport-message flag

This commit is contained in:
stonar96 2020-04-25 04:41:48 +02:00 committed by wizjany
parent 4c351fb0e3
commit 20f89ea2ae
3 changed files with 13 additions and 4 deletions

View File

@ -25,6 +25,7 @@
import com.sk89q.worldedit.world.weather.WeatherTypes;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.util.MessagingUtil;
import io.papermc.lib.PaperLib;
import org.bukkit.BanList.Type;
import org.bukkit.Bukkit;
@ -190,9 +191,13 @@ public void teleport(Location location, String successMessage, String failMessag
PaperLib.teleportAsync(getPlayer(), BukkitAdapter.adapt(location))
.thenApply(success -> {
if (success) {
print(successMessage);
if (successMessage != null && !successMessage.isEmpty()) {
MessagingUtil.sendStringToChat(this, successMessage);
}
} else {
printError(failMessage);
if (failMessage != null && !failMessage.isEmpty()) {
printError(failMessage);
}
}
return success;
});

View File

@ -1111,8 +1111,10 @@ public void teleport(CommandContext args, Actor sender) throws CommandException
}
}
player.teleport(teleportLocation,
"Teleported you to the region '" + existing.getId() + "'.",
String message = existing.getFlag(Flags.TELE_MESSAGE);
message = message == null ? Flags.TELE_MESSAGE.getDefault() : message;
message = message == null ? "" : message.replace("%id%", existing.getId());
player.teleport(teleportLocation, message,
"Unable to teleport to region '" + existing.getId() + "'.");
}

View File

@ -134,6 +134,8 @@ public final class Flags {
public static final LocationFlag TELE_LOC = register(new LocationFlag("teleport", RegionGroup.MEMBERS));
public static final LocationFlag SPAWN_LOC = register(new LocationFlag("spawn", RegionGroup.MEMBERS));
public static final StringFlag TELE_MESSAGE = register(new StringFlag("teleport-message", "\u00A7dTeleported you to the region '%id%'."));
// idk?
public static final StateFlag INVINCIBILITY = register(new StateFlag("invincible", false));
public static final StateFlag FALL_DAMAGE = register(new StateFlag("fall-damage", true));