Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@
<repositories>
<repository>
<id>velocity</id>
<url>https://repo.velocitypowered.com/snapshots/</url>
<url>https://nexus.velocitypowered.com/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/net/teamfruit/serverteleport/ServerTeleport.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

import com.google.inject.Inject;
import com.moandjiezana.toml.Toml;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandManager;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
Expand All @@ -23,6 +29,7 @@
public class ServerTeleport {
private final ProxyServer server;
private final Logger logger;
private ServerTeleportCommand command;

private Toml loadConfig(Path path) {
File folder = path.toFile();
Expand Down Expand Up @@ -76,7 +83,21 @@ public ServerTeleport(ProxyServer server, CommandManager commandManager, Logger
if (toml == null) {
logger.warn("Failed to load config.toml. Shutting down.");
} else {
commandManager.register(new ServerTeleportCommand(server, toml), "stp", "servertp");
this.command = new ServerTeleportCommand(server, toml);
CommandManager manager = server.getCommandManager();
LiteralCommandNode<CommandSource> shout = LiteralArgumentBuilder.<CommandSource>literal("servertp")
.requires(ctx -> ctx.hasPermission("servertp"))
.then(RequiredArgumentBuilder.<CommandSource, String>argument("message", StringArgumentType.greedyString())
.executes(command::execute)
.build())
.build();


manager.register(
manager.metaBuilder("servertp").aliases("stp").build(),
new BrigadierCommand(shout)
);

logger.info("Plugin has enabled!");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package net.teamfruit.serverteleport;

import com.moandjiezana.toml.Toml;
import com.mojang.brigadier.context.CommandContext;
import com.velocitypowered.api.command.Command;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.proxy.server.ServerInfo;
import net.kyori.text.ComponentBuilders;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.Arrays;
Expand Down Expand Up @@ -44,26 +45,26 @@ public ServerTeleportCommand(ProxyServer server, Toml toml) {
this.langSuccess = lang.getString("success");
}

@Override
public void execute(@NonNull CommandSource player, String[] args) {
public int execute(CommandContext<CommandSource> ctx) {
String[] args = ctx.getArgument("message", String.class).split(" ");
// Permission Validation
if (!player.hasPermission("servertp")) {
player.sendMessage(ComponentBuilders.text()
if (!ctx.getSource().hasPermission("servertp")) {
ctx.getSource().sendMessage(Component.text()
.content(langPrefix)
.append(langNoPermission)
.append(Component.text(langNoPermission))
.build()
);
return;
return 1;
}

// Argument Validation
if (args.length < 2) {
player.sendMessage(ComponentBuilders.text()
ctx.getSource().sendMessage(Component.text()
.content(langPrefix)
.append(langUsage)
.append(Component.text(langUsage))
.build()
);
return;
return 1;
}
String srcArg = args[0];
String dstArg = args[1];
Expand All @@ -73,14 +74,12 @@ public void execute(@NonNull CommandSource player, String[] args) {
? this.server.getServer(dstArg.substring(1))
: this.server.getPlayer(dstArg).flatMap(Player::getCurrentServer).map(ServerConnection::getServer);
if (!dstOptional.isPresent()) {
player.sendMessage(ComponentBuilders.text()
.append(ComponentBuilders.text()
.content(langPrefix))
.append(ComponentBuilders.text()
.append(langNoServer))
ctx.getSource().sendMessage(Component.text()
.append(Component.text().content(langPrefix))
.append(Component.text(langNoServer))
.build()
);
return;
return 1;
}
RegisteredServer dst = dstOptional.get();

Expand All @@ -97,24 +96,23 @@ public void execute(@NonNull CommandSource player, String[] args) {
.collect(Collectors.toList());

// Send Message
player.sendMessage(ComponentBuilders.text()
.append(ComponentBuilders.text()
ctx.getSource().sendMessage(Component.text()
.append(Component.text()
.content(langPrefix))
.append(ComponentBuilders.text()
.append(
String.format(langSuccess,
dstArg,
src.size() == 1
? String.format(langPlayerName, src.get(0).getUsername())
: String.format(langPlayerNum, src.size())
)
.append(Component.text(String.format(langSuccess,
dstArg,
src.size() == 1
? String.format(langPlayerName, src.get(0).getUsername())
: String.format(langPlayerNum, src.size())
))
)
.build()
);

// Run Redirect
src.forEach(p ->
p.createConnectionRequest(dst).fireAndForget());
return 1;
}

private List<String> candidate(String arg, List<String> candidates) {
Expand All @@ -125,7 +123,6 @@ private List<String> candidate(String arg, List<String> candidates) {
return candidates.stream().filter(e -> e.startsWith(arg)).collect(Collectors.toList());
}

@Override
public List<String> suggest(CommandSource player, @NonNull String[] args) {
// Permission Validation
if (!player.hasPermission("servertp"))
Expand Down