Skip to content

Commit 56dbba5

Browse files
committed
Setup
1 parent 9c14611 commit 56dbba5

File tree

5 files changed

+394
-0
lines changed

5 files changed

+394
-0
lines changed

.gitignore

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# User-specific stuff
2+
server/
3+
4+
.idea/
5+
6+
*.iml
7+
*.ipr
8+
*.iws
9+
10+
# IntelliJ
11+
out/
12+
13+
# Compiled class file
14+
*.class
15+
16+
# Log file
17+
*.log
18+
19+
# BlueJ files
20+
*.ctxt
21+
22+
# Package Files #
23+
*.jar
24+
*.war
25+
*.nar
26+
*.ear
27+
*.zip
28+
*.tar.gz
29+
*.rar
30+
31+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
32+
hs_err_pid*
33+
34+
*~
35+
36+
# temporary files which can be created if a process still has a handle open of a deleted file
37+
.fuse_hidden*
38+
39+
# KDE directory preferences
40+
.directory
41+
42+
# Linux trash folder which might appear on any partition or disk
43+
.Trash-*
44+
45+
# .nfs files are created when an open file is removed but is still being accessed
46+
.nfs*
47+
48+
# General
49+
.DS_Store
50+
.AppleDouble
51+
.LSOverride
52+
53+
# Icon must end with two \r
54+
Icon
55+
56+
# Thumbnails
57+
._*
58+
59+
# Files that might appear in the root of a volume
60+
.DocumentRevisions-V100
61+
.fseventsd
62+
.Spotlight-V100
63+
.TemporaryItems
64+
.Trashes
65+
.VolumeIcon.icns
66+
.com.apple.timemachine.donotpresent
67+
68+
# Directories potentially created on remote AFP share
69+
.AppleDB
70+
.AppleDesktop
71+
Network Trash Folder
72+
Temporary Items
73+
.apdisk
74+
75+
# Windows thumbnail cache files
76+
Thumbs.db
77+
Thumbs.db:encryptable
78+
ehthumbs.db
79+
ehthumbs_vista.db
80+
81+
# Dump file
82+
*.stackdump
83+
84+
# Folder config file
85+
[Dd]esktop.ini
86+
87+
# Recycle Bin used on file shares
88+
$RECYCLE.BIN/
89+
90+
# Windows Installer files
91+
*.cab
92+
*.msi
93+
*.msix
94+
*.msm
95+
*.msp
96+
97+
# Windows shortcuts
98+
*.lnk
99+
100+
target/
101+
102+
pom.xml.tag
103+
pom.xml.releaseBackup
104+
pom.xml.versionsBackup
105+
pom.xml.next
106+
107+
release.properties
108+
dependency-reduced-pom.xml
109+
buildNumber.properties
110+
.mvn/timing.properties
111+
.mvn/wrapper/maven-wrapper.jar
112+
.flattened-pom.xml
113+
114+
# Common working directory
115+
run/

pom.xml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>net.teamfruit</groupId>
8+
<artifactId>serverteleport</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<name>ServerTeleport</name>
13+
14+
<properties>
15+
<java.version>1.8</java.version>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
</properties>
18+
19+
<build>
20+
<defaultGoal>clean package</defaultGoal>
21+
<plugins>
22+
<plugin>
23+
<groupId>org.apache.maven.plugins</groupId>
24+
<artifactId>maven-compiler-plugin</artifactId>
25+
<version>3.8.1</version>
26+
<configuration>
27+
<source>${java.version}</source>
28+
<target>${java.version}</target>
29+
</configuration>
30+
</plugin>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-shade-plugin</artifactId>
34+
<version>3.2.4</version>
35+
<executions>
36+
<execution>
37+
<phase>package</phase>
38+
<goals>
39+
<goal>shade</goal>
40+
</goals>
41+
<configuration>
42+
<createDependencyReducedPom>false</createDependencyReducedPom>
43+
</configuration>
44+
</execution>
45+
</executions>
46+
</plugin>
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<artifactId>maven-dependency-plugin</artifactId>
50+
<executions>
51+
<execution>
52+
<id>copy-installed</id>
53+
<phase>install</phase>
54+
<goals>
55+
<goal>copy</goal>
56+
</goals>
57+
<configuration>
58+
<artifactItems>
59+
<artifactItem>
60+
<groupId>${project.groupId}</groupId>
61+
<artifactId>${project.artifactId}</artifactId>
62+
<version>${project.version}</version>
63+
<type>${project.packaging}</type>
64+
</artifactItem>
65+
</artifactItems>
66+
<outputDirectory>./server/plugins</outputDirectory>
67+
</configuration>
68+
</execution>
69+
</executions>
70+
</plugin>
71+
</plugins>
72+
<resources>
73+
<resource>
74+
<directory>src/main/resources</directory>
75+
<filtering>true</filtering>
76+
</resource>
77+
</resources>
78+
</build>
79+
80+
<repositories>
81+
<repository>
82+
<id>velocity</id>
83+
<url>https://repo.velocitypowered.com/snapshots/</url>
84+
</repository>
85+
</repositories>
86+
87+
<dependencies>
88+
<dependency>
89+
<groupId>com.velocitypowered</groupId>
90+
<artifactId>velocity-api</artifactId>
91+
<version>1.0.0-SNAPSHOT</version>
92+
<scope>provided</scope>
93+
</dependency>
94+
</dependencies>
95+
</project>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package net.teamfruit.serverteleport;
2+
3+
import com.google.inject.Inject;
4+
import com.moandjiezana.toml.Toml;
5+
import com.velocitypowered.api.command.CommandManager;
6+
import com.velocitypowered.api.plugin.Plugin;
7+
import com.velocitypowered.api.plugin.annotation.DataDirectory;
8+
import com.velocitypowered.api.proxy.ProxyServer;
9+
import org.slf4j.Logger;
10+
11+
import java.io.File;
12+
import java.io.IOException;
13+
import java.io.InputStream;
14+
import java.nio.file.CopyOption;
15+
import java.nio.file.Files;
16+
import java.nio.file.Path;
17+
18+
@Plugin(id = "serverteleport",
19+
name = "ServerTeleport",
20+
version = "${project.version}",
21+
description = "Move players between server",
22+
authors = {"Kamesuta"}
23+
)
24+
public class ServerTeleport {
25+
public static String servername;
26+
27+
private final ProxyServer server;
28+
private final Logger logger;
29+
30+
private Toml loadConfig(Path path) {
31+
File folder = path.toFile();
32+
File file = new File(folder, "config.toml");
33+
if (!file.getParentFile().exists()) {
34+
file.getParentFile().mkdirs();
35+
}
36+
37+
if (!file.exists()) {
38+
try {
39+
InputStream input = this.getClass().getResourceAsStream("/" + file.getName());
40+
Throwable t = null;
41+
42+
try {
43+
if (input != null) {
44+
Files.copy(input, file.toPath());
45+
} else {
46+
file.createNewFile();
47+
}
48+
} catch (Throwable e) {
49+
t = e;
50+
throw e;
51+
} finally {
52+
if (input != null) {
53+
if (t != null) {
54+
try {
55+
input.close();
56+
} catch (Throwable ex) {
57+
t.addSuppressed(ex);
58+
}
59+
} else {
60+
input.close();
61+
}
62+
}
63+
}
64+
} catch (IOException e) {
65+
e.printStackTrace();
66+
return null;
67+
}
68+
}
69+
70+
return (new Toml()).read(file);
71+
}
72+
73+
@Inject
74+
public ServerTeleport(ProxyServer server, CommandManager commandManager, Logger logger, @DataDirectory Path folder) {
75+
this.server = server;
76+
this.logger = logger;
77+
78+
Toml toml = this.loadConfig(folder);
79+
if (toml == null) {
80+
logger.warn("Failed to load config.toml. Shutting down.");
81+
} else {
82+
servername = toml.getString("lobby-server");
83+
commandManager.register(new ServerTeleportCommand(server), "stp", "servertp");
84+
logger.info("Plugin has enabled!");
85+
}
86+
}
87+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package net.teamfruit.serverteleport;
2+
3+
import com.velocitypowered.api.command.Command;
4+
import com.velocitypowered.api.command.CommandSource;
5+
import com.velocitypowered.api.proxy.Player;
6+
import com.velocitypowered.api.proxy.ProxyServer;
7+
import com.velocitypowered.api.proxy.server.RegisteredServer;
8+
import com.velocitypowered.api.proxy.server.ServerInfo;
9+
import net.kyori.text.ComponentBuilders;
10+
import net.kyori.text.format.TextColor;
11+
import org.checkerframework.checker.nullness.qual.NonNull;
12+
13+
import java.util.*;
14+
import java.util.function.Function;
15+
import java.util.stream.Collectors;
16+
import java.util.stream.Stream;
17+
18+
public class ServerTeleportCommand implements Command {
19+
private final ProxyServer server;
20+
21+
public ServerTeleportCommand(ProxyServer server) {
22+
this.server = server;
23+
}
24+
25+
@Override
26+
public void execute(@NonNull CommandSource source, String[] args) {
27+
Player player = (Player) source;
28+
if (args.length < 1 || args[0] == null) {
29+
player.sendMessage(ComponentBuilders.text()
30+
.content("[かめすたプラグイン] ")
31+
.color(TextColor.LIGHT_PURPLE)
32+
.append("/stp <誰> <鯖>")
33+
.color(TextColor.GREEN)
34+
.build()
35+
);
36+
return;
37+
}
38+
String target = args[0];
39+
String server = args.length < 2 ? ServerTeleport.servername : args[1];
40+
41+
Collection<Player> players = Optional.ofNullable(target.startsWith("#") ? target.substring(1) : null)
42+
.flatMap(this.server::getServer)
43+
.map(RegisteredServer::getPlayersConnected)
44+
.orElse("@a".equals(target)
45+
? this.server.getAllPlayers()
46+
: this.server.getPlayer(target).map(Arrays::asList).orElse(Collections.emptyList())
47+
);
48+
49+
Optional<RegisteredServer> toConnect = this.server.getServer(server);
50+
if (!toConnect.isPresent()) {
51+
player.sendMessage(ComponentBuilders.text()
52+
.append(ComponentBuilders.text()
53+
.color(TextColor.LIGHT_PURPLE)
54+
.content("[かめすたプラグイン] "))
55+
.append(ComponentBuilders.text()
56+
.color(TextColor.RED)
57+
.append("転送先鯖が見つかりません"))
58+
.build()
59+
);
60+
} else {
61+
player.sendMessage(ComponentBuilders.text()
62+
.append(ComponentBuilders.text()
63+
.color(TextColor.LIGHT_PURPLE)
64+
.content("[かめすたプラグイン] "))
65+
.append(ComponentBuilders.text()
66+
.color(TextColor.GREEN)
67+
.append((players.size() == 1
68+
? players.stream().findFirst().get().getUsername() + " "
69+
: players.size() + "人のプレイヤー") + "を " + server + " に転送します"))
70+
.build()
71+
);
72+
players.forEach(p ->
73+
p.createConnectionRequest(toConnect.get()).fireAndForget());
74+
}
75+
}
76+
77+
@Override
78+
public List<String> suggest(CommandSource source, @NonNull String[] args) {
79+
if (args.length == 1)
80+
return Arrays.asList(
81+
Stream.of("@a"),
82+
this.server.getAllServers().stream().map(RegisteredServer::getServerInfo)
83+
.map(ServerInfo::getName).map(e -> "#" + e),
84+
this.server.getAllPlayers().stream().map(Player::getUsername)
85+
)
86+
.stream()
87+
.flatMap(Function.identity())
88+
.collect(Collectors.toList());
89+
if (args.length == 2)
90+
return this.server.getAllServers()
91+
.stream()
92+
.map(e -> e.getServerInfo().getName())
93+
.collect(Collectors.toList());
94+
return Collections.emptyList();
95+
}
96+
}

0 commit comments

Comments
 (0)