|
| 1 | +package com.sekwah.advancedportals.core.commands.subcommands.desti; |
| 2 | + |
| 3 | +import com.google.inject.Inject; |
| 4 | +import com.sekwah.advancedportals.core.commands.SubCommand; |
| 5 | +import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; |
| 6 | +import com.sekwah.advancedportals.core.permissions.PortalPermissions; |
| 7 | +import com.sekwah.advancedportals.core.services.DestinationServices; |
| 8 | +import com.sekwah.advancedportals.core.util.Lang; |
| 9 | + |
| 10 | +import java.util.Collections; |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | +public class TeleportDestiSubCommand implements SubCommand { |
| 14 | + |
| 15 | + @Inject |
| 16 | + DestinationServices destinationServices; |
| 17 | + @Override |
| 18 | + public void onCommand(CommandSenderContainer sender, String[] args) { |
| 19 | + if(args.length > 1) { |
| 20 | + if(destinationServices.teleportToDestination(args[1], sender.getPlayerContainer())) { |
| 21 | + sender.sendMessage(Lang.translate("messageprefix.positive") |
| 22 | + + Lang.translate("command.destination.teleport.success") |
| 23 | + .replaceAll("@destiname", args[1])); |
| 24 | + } else { |
| 25 | + sender.sendMessage(Lang.translate("messageprefix.negative") + |
| 26 | + Lang.translate("command.destination.teleport.error") |
| 27 | + .replaceAll("@destiname", args[1])); |
| 28 | + } |
| 29 | + } else { |
| 30 | + sender.sendMessage(Lang.translate("command.destination.noname")); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + public boolean hasPermission(CommandSenderContainer sender) { |
| 36 | + return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender); |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public List<String> onTabComplete(CommandSenderContainer sender, String[] args) { |
| 41 | + if(args.length > 2) { |
| 42 | + return Collections.emptyList(); |
| 43 | + } |
| 44 | + List<String> destiNames = destinationServices.getDestinationNames(); |
| 45 | + Collections.sort(destiNames); |
| 46 | + return destiNames; |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public String getBasicHelpText() { |
| 51 | + return Lang.translate("command.destination.teleport.help"); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public String getDetailedHelpText() { |
| 56 | + return Lang.translate("command.destination.teleport.detailedhelp"); |
| 57 | + } |
| 58 | +} |
0 commit comments