diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbottom.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbottom.java new file mode 100644 index 000000000..4c3d0d5b9 --- /dev/null +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbottom.java @@ -0,0 +1,36 @@ +package com.earth2me.essentials.commands; + +import com.earth2me.essentials.Trade; +import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.LocationUtil; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.event.player.PlayerTeleportEvent; + +import java.util.concurrent.CompletableFuture; + +import static com.earth2me.essentials.I18n.tl; + +public class Commandbottom extends EssentialsCommand { + + public Commandbottom() { + super("bottom"); + } + + @Override + public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { + final int bottomX = user.getLocation().getBlockX(); + final int bottomZ = user.getLocation().getBlockZ(); + final float pitch = user.getLocation().getPitch(); + final float yaw = user.getLocation().getYaw(); + final Location unsafe = new Location(user.getWorld(), bottomX, ess.getWorldInfoProvider().getMinHeight(user.getWorld()), bottomZ, yaw, pitch); + final Location safe = LocationUtil.getSafeDestination(ess, unsafe); + final CompletableFuture future = getNewExceptionFuture(user.getSource(), commandLabel); + future.thenAccept(success -> { + if (success) { + user.sendMessage(tl("teleportBottom", safe.getWorld().getName(), safe.getBlockX(), safe.getBlockY(), safe.getBlockZ())); + } + }); + user.getAsyncTeleport().teleport(safe, new Trade(this.getName(), ess), PlayerTeleportEvent.TeleportCause.COMMAND, future); + } +} diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index e033025ff..46567df00 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -100,6 +100,8 @@ bookCommandUsage3=/ title bookCommandUsage3Description=Sets the title of a signed book bookLocked=\u00a76This book is now locked. bookTitleSet=\u00a76Title of the book set to {0}. +bottomCommandDescription=Teleport to the lowest block at your current position. +bottomCommandUsage=/<command> breakCommandDescription=Breaks the block you are looking at. breakCommandUsage=/<command> broadcast=\u00a76[\u00a74Broadcast\u00a76]\u00a7a {0} @@ -1253,6 +1255,7 @@ teleportationDisabledWarning=\u00a76You must enable teleportation before other p teleportationEnabled=\u00a76Teleportation \u00a7cenabled\u00a76. teleportationEnabledFor=\u00a76Teleportation \u00a7cenabled \u00a76for \u00a7c{0}\u00a76. teleportAtoB=\u00a7c{0}\u00a76 teleported you to \u00a7c{1}\u00a76. +teleportBottom=\u00a76Teleporting to bottom. teleportDisabled=\u00a7c{0} \u00a74has teleportation disabled. teleportHereRequest=\u00a7c{0}\u00a76 has requested that you teleport to them. teleportHome=\u00a76Teleporting to \u00a7c{0}\u00a76. diff --git a/Essentials/src/main/resources/plugin.yml b/Essentials/src/main/resources/plugin.yml index 3faa7e5bb..0ec11754b 100644 --- a/Essentials/src/main/resources/plugin.yml +++ b/Essentials/src/main/resources/plugin.yml @@ -53,6 +53,10 @@ commands: description: Allows reopening and editing of sealed books. usage: /<command> [title|author [name]] aliases: [ebook] + bottom: + description: Teleport to the lowest block at your current position. + usage: /<command> + aliases: [ ebottom ] break: description: Breaks the block you are looking at. usage: /<command>