Skip to content
This repository was archived by the owner on Jun 7, 2022. It is now read-only.

Commit b0a317c

Browse files
author
Dytanic
committed
added screen command completer + updated and inlcude console command completer + update header
1 parent ceae81a commit b0a317c

File tree

4 files changed

+56
-25
lines changed

4 files changed

+56
-25
lines changed

cloudnet-cord/cloudnet-command/src/main/java/de/dytanic/cloudnet/command/CommandManager.java

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
package de.dytanic.cloudnet.command;
66

77
import de.dytanic.cloudnet.lib.NetworkUtils;
8+
import de.dytanic.cloudnet.lib.utility.Acceptable;
9+
import de.dytanic.cloudnet.lib.utility.CollectionWrapper;
810
import jline.console.completer.Completer;
911
import lombok.Getter;
1012

11-
import java.util.List;
12-
import java.util.Map;
13-
import java.util.Set;
13+
import java.util.*;
1414

1515
/**
1616
* Class that manages commands for the interfaces of CloudNet.
@@ -171,24 +171,34 @@ public int complete(String buffer, int cursor, List<CharSequence> candidates)
171171
{
172172
String[] input = buffer.split(" ");
173173

174-
if (input.length == 0) return cursor;
174+
List<String> responses = new ArrayList<>();
175175

176-
Command command = getCommand(input[0]);
177-
if (command instanceof TabCompletable)
176+
if (buffer.isEmpty() || buffer.indexOf(' ') == -1)
177+
responses.addAll(this.commands.keySet());
178+
else
178179
{
179-
List<String> tabCompletions = ((TabCompletable) command).onTab(input.length - 1, input[input.length - 1]);
180+
Command command = getCommand(input[0]);
180181

181-
candidates.addAll(tabCompletions);
182-
183-
final int lastSpace = buffer.lastIndexOf(' ');
184-
if (lastSpace == -1)
185-
{
186-
return cursor - buffer.length();
187-
} else
182+
if (command instanceof TabCompletable)
188183
{
189-
return cursor - (buffer.length() - lastSpace - 1);
184+
String[] args = buffer.split(" ");
185+
String testString = args[args.length - 1];
186+
187+
responses.addAll(CollectionWrapper.filterMany(((TabCompletable) command).onTab(input.length - 1, input[input.length - 1]), new Acceptable<String>() {
188+
@Override
189+
public boolean isAccepted(String s)
190+
{
191+
return s != null && (testString.isEmpty() || s.toLowerCase().contains(testString.toLowerCase()));
192+
}
193+
}));
190194
}
191195
}
192-
return cursor;
196+
197+
Collections.sort(responses);
198+
199+
candidates.addAll(responses);
200+
int lastSpace = buffer.lastIndexOf(' ');
201+
202+
return (lastSpace == -1) ? cursor - buffer.length() : cursor - (buffer.length() - lastSpace - 1);
193203
}
194204
}

cloudnet-core/src/main/java/de/dytanic/cloudnetcore/CloudNet.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,16 @@ public final class CloudNet implements Executable, Runnable, Reloadable {
102102

103103
public CloudNet(CloudConfig config, CloudLogger cloudNetLogging, OptionSet optionSet, List<String> objective, List<String> args) throws Exception
104104
{
105-
if (instance == null)
106-
this.instance = this;
105+
if (instance == null) instance = this;
107106

108107
this.config = config;
109108
this.logger = cloudNetLogging;
110109
this.preConsoleOutput = objective;
111110
this.optionSet = optionSet;
112111
this.arguments = args;
113112
this.defaultModuleManager = new DefaultModuleManager();
113+
114+
this.logger.getReader().addCompleter(commandManager);
114115
}
115116

116117
@Override

cloudnet-core/src/main/java/de/dytanic/cloudnetcore/command/CommandScreen.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@
66

77
import de.dytanic.cloudnet.command.Command;
88
import de.dytanic.cloudnet.command.CommandSender;
9+
import de.dytanic.cloudnet.command.TabCompletable;
910
import de.dytanic.cloudnet.lib.NetworkUtils;
1011
import de.dytanic.cloudnet.lib.service.ServiceId;
12+
import de.dytanic.cloudnet.lib.utility.CollectionWrapper;
1113
import de.dytanic.cloudnetcore.CloudNet;
1214
import de.dytanic.cloudnetcore.network.components.MinecraftServer;
1315
import de.dytanic.cloudnetcore.network.components.ProxyServer;
1416
import de.dytanic.cloudnetcore.network.components.Wrapper;
1517

16-
public final class CommandScreen extends Command {
18+
import java.util.ArrayList;
19+
import java.util.Collection;
20+
import java.util.Collections;
21+
import java.util.List;
22+
23+
public final class CommandScreen extends Command implements TabCompletable {
1724

1825
public CommandScreen()
1926
{
@@ -114,4 +121,15 @@ public void onExecuteCommand(CommandSender sender, String[] args)
114121
break;
115122
}
116123
}
124+
125+
@Override
126+
public List<String> onTab(long argsLength, String lastWord)
127+
{
128+
List<String> list = new ArrayList<>(CloudNet.getInstance().getServers().size() + CloudNet.getInstance().getProxys().size());
129+
130+
list.addAll(CloudNet.getInstance().getServers().keySet());
131+
list.addAll(CloudNet.getInstance().getProxys().keySet());
132+
133+
return list;
134+
}
117135
}

cloudnet-lib/src/main/java/de/dytanic/cloudnet/lib/NetworkUtils.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,18 @@ public static void header()
272272
System.out.println("█ █ █ █ █ █ █ █ █ █ █ ████ █");
273273
System.out.println("█D █Y █T █ █A █ █N █ █ █I█ █C █");
274274
System.out.println("██████ ██████ ██████ █████ █████ █ ██ ████ █");
275-
System.out.println();
276-
System.out.println("«» The Cloud Network Environment Technology");
277-
System.out.println("«» Support https://discord.gg/5NUhKuR [" + NetworkUtils.class.getPackage().getSpecificationVersion() + "]");
278-
System.out.println("«» Java " + System.getProperty("java.version") + " @" + System.getProperty("user.name") + NetworkUtils.SPACE_STRING + System.getProperty("os.name") + NetworkUtils.SPACE_STRING);
279-
System.out.println(NetworkUtils.SPACE_STRING);
275+
headerOut0();
280276
}
281277

282278
public static void headerOut()
283279
{
284-
System.out.println("«» The Cloud Network Environment Technology");
280+
headerOut0();
281+
}
282+
283+
private static void headerOut0()
284+
{
285+
System.out.println();
286+
System.out.println("«» The Cloud Network Environment Technology 2");
285287
System.out.println("«» Support https://discord.gg/5NUhKuR [" + NetworkUtils.class.getPackage().getSpecificationVersion() + "]");
286288
System.out.println("«» Java " + System.getProperty("java.version") + " @" + System.getProperty("user.name") + NetworkUtils.SPACE_STRING + System.getProperty("os.name") + NetworkUtils.SPACE_STRING);
287289
System.out.println(NetworkUtils.SPACE_STRING);

0 commit comments

Comments
 (0)