Add help to /tp

This commit is contained in:
Spencer 2018-03-07 14:20:18 -05:00 committed by Alexander Meech
parent b71538b700
commit 1fe43f87e2

View File

@ -1,7 +1,9 @@
package mineplex.mapparser.command.teleport;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -15,6 +17,11 @@ import mineplex.mapparser.command.BaseCommand;
public class TeleportCommand extends BaseCommand
{
private final static List<String> COMMANDS = Arrays.asList(
"/tp <player> - Teleport to another player",
"/tp <from> <destination> - Teleport the from player to the destination player",
"/tp <x> <y> <z> - Teleport to coordinates"
);
private final static String COORDINATE_FORMAT = "%.2f";
private TeleportManager _teleportManager;
@ -56,6 +63,22 @@ public class TeleportCommand extends BaseCommand
}
}
private void help(Player player)
{
player.sendMessage(F.main(getPlugin().getName(), "Teleport command usage:"));
COMMANDS.stream().map(c -> {
List<String> parts = Arrays.stream(c.split("\\s*-\\s*")).collect(Collectors.toList());
String commandMessage = " ";
commandMessage += C.cYellow + parts.get(0);
commandMessage += C.cGray + " - ";
commandMessage += C.cGold + parts.get(1);
return commandMessage;
}).forEach(player::sendMessage);
}
@Override
public boolean execute(Player player, String alias, String[] args)
{
@ -119,6 +142,7 @@ public class TeleportCommand extends BaseCommand
if (coordinate == null)
{
message(player, "Hmm, those coordinates don't look quite right.");
help(player);
return true;
}
}
@ -140,6 +164,7 @@ public class TeleportCommand extends BaseCommand
else
{
message(player, "Hmm, your command doesn't look quite right.");
help(player);
}
return true;