|
4 | 4 |
|
5 | 5 | package de.dytanic.cloudnet.bridge.internal.command.proxied;
|
6 | 6 |
|
| 7 | +import com.google.common.collect.ImmutableList; |
7 | 8 | import de.dytanic.cloudnet.api.CloudAPI;
|
8 | 9 | import de.dytanic.cloudnet.bridge.CloudProxy;
|
| 10 | +import de.dytanic.cloudnet.bridge.internal.util.StringUtil; |
9 | 11 | import de.dytanic.cloudnet.lib.DefaultType;
|
10 | 12 | import de.dytanic.cloudnet.lib.NetworkUtils;
|
11 | 13 | import de.dytanic.cloudnet.lib.database.Database;
|
|
19 | 21 | import de.dytanic.cloudnet.lib.server.info.ProxyInfo;
|
20 | 22 | import de.dytanic.cloudnet.lib.server.info.ServerInfo;
|
21 | 23 | import de.dytanic.cloudnet.lib.server.template.Template;
|
| 24 | +import de.dytanic.cloudnet.lib.service.ServiceId; |
22 | 25 | import de.dytanic.cloudnet.lib.utility.Acceptable;
|
23 | 26 | import de.dytanic.cloudnet.lib.utility.CollectionWrapper;
|
24 | 27 | import de.dytanic.cloudnet.lib.utility.document.Document;
|
|
31 | 34 |
|
32 | 35 | import java.util.*;
|
33 | 36 | import java.util.concurrent.TimeUnit;
|
| 37 | +import java.util.stream.Collectors; |
34 | 38 |
|
35 | 39 | /**
|
36 | 40 | * Created by Tareko on 02.06.2017.
|
@@ -544,7 +548,7 @@ public boolean isAccepted(Template value)
|
544 | 548 | CloudAPI.getInstance().getPrefix() + "§7/cloud startcs <name> <memory> <priorityStop>",
|
545 | 549 | CloudAPI.getInstance().getPrefix() + "§7/cloud cmds (command server) <server> <command>",
|
546 | 550 | CloudAPI.getInstance().getPrefix() + "§7/cloud cmdp (command proxy) <proxy> <command>",
|
547 |
| - CloudAPI.getInstance().getPrefix() + "§7/cloud stop <serverId>", |
| 551 | + CloudAPI.getInstance().getPrefix() + "§7/cloud stop <server>", |
548 | 552 | CloudAPI.getInstance().getPrefix() + "§7/cloud stopGroup <group>",
|
549 | 553 | CloudAPI.getInstance().getPrefix() + "§7/cloud ustopGroup <group>",
|
550 | 554 | CloudAPI.getInstance().getPrefix() + "§7/cloud listProxys",
|
@@ -581,6 +585,103 @@ private boolean checkAsNumber(String input)
|
581 | 585 | @Override
|
582 | 586 | public Iterable<String> onTabComplete(CommandSender commandSender, String[] args)
|
583 | 587 | {
|
584 |
| - return new LinkedList<>(CloudProxy.getInstance().getCachedServers().keySet()); |
| 588 | + List<String> tabCompletes = ImmutableList |
| 589 | + .of(); |
| 590 | + switch (args.length) |
| 591 | + { |
| 592 | + case 1: |
| 593 | + { |
| 594 | + tabCompletes = ImmutableList |
| 595 | + .of("toggle", "setMaxPlayers", "whitelist", "start", "startcs", "cmds", "cmdp", "stop", "stopGroup" |
| 596 | + , "ustopGroup", "listProxys", "listOnline", "listServers", "log", "listGroups", "rl", "list" |
| 597 | + , "maintenance", "copy", "version", "statistics"); |
| 598 | + break; |
| 599 | + } |
| 600 | + case 2: |
| 601 | + { |
| 602 | + switch (args[0].toLowerCase()) |
| 603 | + { |
| 604 | + case "toggle": |
| 605 | + { |
| 606 | + tabCompletes = ImmutableList.of("autoslot", "maintenance"); |
| 607 | + break; |
| 608 | + } |
| 609 | + case "whitelist": |
| 610 | + { |
| 611 | + tabCompletes = ImmutableList.of("add", "remove"); |
| 612 | + break; |
| 613 | + } |
| 614 | + case "start": |
| 615 | + case "stopgroup": |
| 616 | + case "ustopgroup": |
| 617 | + { |
| 618 | + tabCompletes = getProxyAndServerGroups(); |
| 619 | + break; |
| 620 | + } |
| 621 | + case "stop": |
| 622 | + { |
| 623 | + tabCompletes = getProxiesAndServers(); |
| 624 | + break; |
| 625 | + } |
| 626 | + case "log": |
| 627 | + { |
| 628 | + tabCompletes = new LinkedList<>(CloudProxy.getInstance().getCachedServers().keySet()); |
| 629 | + break; |
| 630 | + } |
| 631 | + case "maintenance": |
| 632 | + { |
| 633 | + tabCompletes = new LinkedList<>(CloudAPI.getInstance().getServerGroupMap().keySet()); |
| 634 | + break; |
| 635 | + } |
| 636 | + |
| 637 | + case "cmds": |
| 638 | + { |
| 639 | + tabCompletes = CloudAPI.getInstance().getServers().stream() |
| 640 | + .map(ServerInfo::getServiceId).map(ServiceId::getServerId).collect(Collectors.toList()); |
| 641 | + break; |
| 642 | + } |
| 643 | + case "cmdp": |
| 644 | + { |
| 645 | + tabCompletes = CloudAPI.getInstance().getProxys().stream() |
| 646 | + .map(ProxyInfo::getServiceId).map(ServiceId::getServerId).collect(Collectors.toList()); |
| 647 | + break; |
| 648 | + } |
| 649 | + |
| 650 | + } |
| 651 | + break; |
| 652 | + } |
| 653 | + case 3: |
| 654 | + { |
| 655 | + switch (args[0].toLowerCase()) |
| 656 | + { |
| 657 | + case "whitelist": |
| 658 | + { |
| 659 | + tabCompletes = CloudAPI.getInstance().getOnlinePlayers() |
| 660 | + .stream().map(CloudPlayer::getName).collect(Collectors.toList()); |
| 661 | + break; |
| 662 | + } |
| 663 | + } |
| 664 | + break; |
| 665 | + } |
| 666 | + } |
| 667 | + return new LinkedList<>(StringUtil.copyPartialMatches(args[args.length-1], tabCompletes, new ArrayList<>(tabCompletes.size()))); |
| 668 | + } |
| 669 | + |
| 670 | + private LinkedList<String> getProxyAndServerGroups() |
| 671 | + { |
| 672 | + LinkedList<String> groups = new LinkedList<>(CloudAPI.getInstance().getProxyGroupMap().keySet()); |
| 673 | + groups.addAll(CloudAPI.getInstance().getServerGroupMap().keySet()); |
| 674 | + groups.sort(Collections.reverseOrder()); |
| 675 | + return groups; |
| 676 | + } |
| 677 | + |
| 678 | + private LinkedList<String> getProxiesAndServers() |
| 679 | + { |
| 680 | + LinkedList<String> groups = new LinkedList<>(CloudAPI.getInstance().getProxys().stream() |
| 681 | + .map(ProxyInfo::getServiceId).map(ServiceId::getServerId).collect(Collectors.toList())); |
| 682 | + groups.addAll(CloudAPI.getInstance().getServers().stream() |
| 683 | + .map(ServerInfo::getServiceId).map(ServiceId::getServerId).collect(Collectors.toList())); |
| 684 | + groups.sort(Collections.reverseOrder()); |
| 685 | + return groups; |
585 | 686 | }
|
586 | 687 | }
|
0 commit comments