diff --git a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java index 1b0afded..90211fc5 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -151,6 +151,7 @@ public class AdvancedPortalsCore { this.destiCommand = new CommandWithSubCommands(this); this.destiCommand.registerSubCommand("create", new CreateDestiSubCommand()); this.destiCommand.registerSubCommand("remove", new RemoveDestiSubCommand()); + this.destiCommand.registerSubCommand("teleport", new TeleportDestiSubCommand(), "tp"); this.destiCommand.registerSubCommand("list", new ListDestiSubCommand()); this.destiCommand.registerSubCommand("show", new ShowDestiSubCommand()); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java index 62e28dd9..7f1d75f0 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java @@ -74,7 +74,7 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand { @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender); + return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/RemoveDestiSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/RemoveDestiSubCommand.java index e9a98d2f..10fd8e7b 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/RemoveDestiSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/RemoveDestiSubCommand.java @@ -28,13 +28,13 @@ public class RemoveDestiSubCommand implements SubCommand { } } else { - sender.sendMessage(Lang.translate("command.portal.remove.noname")); + sender.sendMessage(Lang.translate("command.destination.noname")); } } @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() || PortalPermissions.CREATE_PORTAL.hasPermission(sender); + return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/TeleportDestiSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/TeleportDestiSubCommand.java new file mode 100644 index 00000000..85f93eb5 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/TeleportDestiSubCommand.java @@ -0,0 +1,58 @@ +package com.sekwah.advancedportals.core.commands.subcommands.desti; + +import com.google.inject.Inject; +import com.sekwah.advancedportals.core.commands.SubCommand; +import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; +import com.sekwah.advancedportals.core.permissions.PortalPermissions; +import com.sekwah.advancedportals.core.services.DestinationServices; +import com.sekwah.advancedportals.core.util.Lang; + +import java.util.Collections; +import java.util.List; + +public class TeleportDestiSubCommand implements SubCommand { + + @Inject + DestinationServices destinationServices; + @Override + public void onCommand(CommandSenderContainer sender, String[] args) { + if(args.length > 1) { + if(destinationServices.teleportToDestination(args[1], sender.getPlayerContainer())) { + sender.sendMessage(Lang.translate("messageprefix.positive") + + Lang.translate("command.destination.teleport.success") + .replaceAll("@destiname", args[1])); + } else { + sender.sendMessage(Lang.translate("messageprefix.negative") + + Lang.translate("command.destination.teleport.error") + .replaceAll("@destiname", args[1])); + } + } else { + sender.sendMessage(Lang.translate("command.destination.noname")); + } + } + + @Override + public boolean hasPermission(CommandSenderContainer sender) { + return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender); + } + + @Override + public List onTabComplete(CommandSenderContainer sender, String[] args) { + if(args.length > 2) { + return Collections.emptyList(); + } + List destiNames = destinationServices.getDestinationNames(); + Collections.sort(destiNames); + return destiNames; + } + + @Override + public String getBasicHelpText() { + return Lang.translate("command.destination.teleport.help"); + } + + @Override + public String getDetailedHelpText() { + return Lang.translate("command.destination.teleport.detailedhelp"); + } +} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/permissions/PortalPermissions.java b/core/src/main/java/com/sekwah/advancedportals/core/permissions/PortalPermissions.java index 62ee25a3..9cf2bf81 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/permissions/PortalPermissions.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/permissions/PortalPermissions.java @@ -10,6 +10,7 @@ public class PortalPermissions { private static final PermissionBuilder PERMISSIONS = new PermissionBuilder("advancedportals"); public static final PermissionBuilder BUILD = PERMISSIONS.createChild("build"); + public static final PermissionBuilder DESTI = PERMISSIONS.createChild("desti"); public static final PermissionBuilder CREATE_PORTAL = PERMISSIONS.createChild("createportal"); public static final PermissionBuilder LANG_UPDATE = PERMISSIONS.createChild("langupdate"); public static final PermissionBuilder RELOAD = PERMISSIONS.createChild("reload"); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/services/DestinationServices.java b/core/src/main/java/com/sekwah/advancedportals/core/services/DestinationServices.java index 7386b824..e597cc8e 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/services/DestinationServices.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/services/DestinationServices.java @@ -107,4 +107,12 @@ public class DestinationServices { public Destination getDestination(String name) { return destinationCache.get(name); } + + public boolean teleportToDestination(String name, PlayerContainer playerContainer) { + if(this.destinationRepository.containsKey(name)) { + playerContainer.teleport(this.destinationRepository.get(name).getLoc()); + return true; + } + return false; + } } diff --git a/lang/src/main/resources/lang/en_GB.lang b/lang/src/main/resources/lang/en_GB.lang index 5d5797d1..6ca5e306 100644 --- a/lang/src/main/resources/lang/en_GB.lang +++ b/lang/src/main/resources/lang/en_GB.lang @@ -89,6 +89,8 @@ command.portal.show.enabled= Portal markers are now enabled. command.portal.show.disabled= Portal markers are now disabled. command.portal.show.unsupported= Portal markers are not supported on this version of minecraft. (1.16+ atm only) +command.destination.noname=No destination by that name was found + command.destination.remove.error= There was a problem removing the destination. command.destination.remove.complete= The destination has been successfully removed. @@ -98,6 +100,11 @@ command.destination.show.enabled= Destination markers are now enabled. command.destination.show.disabled= Destination markers are now disabled. command.destination.show.unsupported= Destination markers are not supported on this version of minecraft. (1.16+ atm only) +command.destination.teleport.help=Teleports to specified destination. +command.destination.teleport.detailedhelp=Teleports to destination given by the name of the destination. +command.destination.teleport.error=There was an error teleporting to your destination (@destiname). +command.destination.teleport.success=You have teleported to destination (@destiname). + command.destination.reload.help=Reloads the destination data from the repository. command.destination.reload.detailedhelp=This command will reload all destination data from the repository, updating the cache with the latest data. command.destination.reload= Destinations reloaded.