Skip to content

Commit

Permalink
remove default hub
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamesuta committed Oct 7, 2020
1 parent affb00f commit 7e94d67
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
public class ServerTeleportCommand implements Command {
private final ProxyServer server;

private final String servername;
private final String langPrefix;
private final String langUsage;
private final String langNoServer;
Expand All @@ -34,9 +33,6 @@ public class ServerTeleportCommand implements Command {
public ServerTeleportCommand(ProxyServer server, Toml toml) {
this.server = server;

// Config
this.servername = toml.getString("lobby-server");

// Localization
Toml lang = toml.getTable("lang");
this.langPrefix = lang.getString("prefix");
Expand All @@ -61,7 +57,7 @@ public void execute(@NonNull CommandSource player, String[] args) {
}

// Argument Validation
if (args.length < 1 || args[0] == null) {
if (args.length < 2) {
player.sendMessage(ComponentBuilders.text()
.content(langPrefix)
.append(langUsage)
Expand All @@ -70,7 +66,7 @@ public void execute(@NonNull CommandSource player, String[] args) {
return;
}
String srcArg = args[0];
String dstArg = args.length < 2 ? "#" + servername : args[1];
String dstArg = args[1];

// Destination Validation
Optional<RegisteredServer> dstOptional = dstArg.startsWith("#")
Expand Down Expand Up @@ -121,6 +117,14 @@ public void execute(@NonNull CommandSource player, String[] args) {
p.createConnectionRequest(dst).fireAndForget());
}

private List<String> candidate(String arg, List<String> candidates) {
if (arg.isEmpty())
return candidates;
if (candidates.contains(arg))
return Arrays.asList(arg);
return candidates.stream().filter(e -> e.startsWith(arg)).collect(Collectors.toList());
}

@Override
public List<String> suggest(CommandSource player, @NonNull String[] args) {
// Permission Validation
Expand All @@ -129,24 +133,28 @@ public List<String> suggest(CommandSource player, @NonNull String[] args) {

// Source Suggestion
if (args.length == 1)
return Stream.of(
Stream.of("@a"),
this.server.getAllServers().stream().map(RegisteredServer::getServerInfo)
.map(ServerInfo::getName).map(e -> "#" + e),
this.server.getAllPlayers().stream().map(Player::getUsername)
)
.flatMap(Function.identity())
.collect(Collectors.toList());
return candidate(args[0],
Stream.of(
Stream.of("@a"),
this.server.getAllServers().stream().map(RegisteredServer::getServerInfo)
.map(ServerInfo::getName).map(e -> "#" + e),
this.server.getAllPlayers().stream().map(Player::getUsername)
)
.flatMap(Function.identity())
.collect(Collectors.toList())
);

// Destination Suggestion
if (args.length == 2)
return Stream.of(
this.server.getAllServers().stream().map(RegisteredServer::getServerInfo)
.map(ServerInfo::getName).map(e -> "#" + e),
this.server.getAllPlayers().stream().map(Player::getUsername)
)
.flatMap(Function.identity())
.collect(Collectors.toList());
return candidate(args[1],
Stream.of(
this.server.getAllServers().stream().map(RegisteredServer::getServerInfo)
.map(ServerInfo::getName).map(e -> "#" + e),
this.server.getAllPlayers().stream().map(Player::getUsername)
)
.flatMap(Function.identity())
.collect(Collectors.toList())
);

return Collections.emptyList();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ lobby-server = "hub"

[lang]
prefix = "§d[ServerTP] "
usage = "§a/stp <player> <server>"
usage = "§a/stp <from:player|#server|@a> <to:player|#server>"
noserver = "§aNo server to teleport"
nopermission = "§cNo permission"
player-num = "§a%d players"
Expand Down

0 comments on commit 7e94d67

Please sign in to comment.