Skip to content

Commit 6bc0e80

Browse files
committed
Improved code style
1 parent 67cb039 commit 6bc0e80

37 files changed

+453
-318
lines changed

.github/workflows/maven.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v4
12-
- name: Set up JDK 21
13-
uses: actions/setup-java@v4
14-
with:
15-
java-version: '21'
16-
distribution: 'temurin'
17-
cache: maven
18-
- name: Build with Maven
19-
run: mvn -B package --file pom.xml
11+
- uses: actions/checkout@v4
12+
- name: Set up JDK 21
13+
uses: actions/setup-java@v4
14+
with:
15+
java-version: '21'
16+
distribution: 'temurin'
17+
cache: maven
18+
- name: Build with Maven
19+
run: mvn -B package --file pom.xml

Checkstyle.xml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<code_scheme name="Default" version="173">
2+
<option name="FORMATTER_TAGS_ENABLED" value="true"/>
3+
<JavaCodeStyleSettings>
4+
<option name="GENERATE_FINAL_LOCALS" value="true"/>
5+
<option name="GENERATE_FINAL_PARAMETERS" value="true"/>
6+
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="10000"/>
7+
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="10000"/>
8+
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
9+
<value/>
10+
</option>
11+
</JavaCodeStyleSettings>
12+
</code_scheme>

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
THIS PLUGIN CURRENTLY ONLY WORKS ON LATEST SPIGOT BUILD
32
AS A FIX WAS REQUIRED FOR THIS PLUGIN TO WORK.
43
(if you are on paper, you need to wait for upstream merge)
@@ -9,9 +8,12 @@ Contributions are welcome, we aim to provide bukkit, bungeecord and velocity sup
98

109
This software is still work in progress.
1110

12-
This software aims to provide a minecraft server network functionallity utilizing the transfer and cookie packets to create a fast and secure way of data transfer and transfer of players to different servers.
11+
This software aims to provide a minecraft server network functionallity utilizing the transfer and cookie packets to
12+
create a fast and secure way of data transfer and transfer of players to different servers.
1313

14-
You first need to start the server and copy the secret key from the server config into all plugin configs of the minecraft servers.
14+
You first need to start the server and copy the secret key from the server config into all plugin configs of the
15+
minecraft servers.
1516
Do not share this secret key!
1617

17-
IF YOU LEAKED THE KEY, PLEASE REMOVE THE KEY FROM THE MASTER SERVER CONFIG AND GENERATE A NEW ONE. (BY RESTARTING CONVEY)
18+
IF YOU LEAKED THE KEY, PLEASE REMOVE THE KEY FROM THE MASTER SERVER CONFIG AND GENERATE A NEW ONE. (BY RESTARTING
19+
CONVEY)

api/src/main/java/net/outfluencer/convey/api/Convey.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public static void setInstance(Convey instance) {
2828
/**
2929
* Gets the List of all convey players on the network
3030
*
31-
* @apiNote The returned list can contain LocalConveyPlayers
3231
* @return the list
32+
* @apiNote The returned list can contain LocalConveyPlayers
3333
*/
3434
public abstract List<ConveyPlayer> getGlobalPlayers();
3535
}

api/src/main/java/net/outfluencer/convey/api/player/ConveyPlayer.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package net.outfluencer.convey.api.player;
22

33
import net.outfluencer.convey.api.Server;
4-
import net.outfluencer.convey.api.cookie.InternalCookie;
54

65
import java.util.UUID;
76

@@ -19,12 +18,14 @@ public interface ConveyPlayer {
1918

2019
/**
2120
* Connects the player to a specified server
21+
*
2222
* @param server the server to connect to
2323
*/
2424
void connect(Server server);
2525

2626
/**
2727
* Send a message to the player
28+
*
2829
* @param message the message to send
2930
*/
3031
void sendMessage(String message);
@@ -37,6 +38,7 @@ public interface ConveyPlayer {
3738

3839
/**
3940
* Kicks the player from the network
41+
*
4042
* @param message the reason of the kick
4143
*/
4244
void kick(String message);

api/src/main/java/net/outfluencer/convey/api/player/LocalConveyPlayer.java

+2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ default LocalConveyPlayer getLocalPlayer() {
1717
* @return true if a cookie of the same type was already present and was replaced, false otherwise
1818
*/
1919
boolean addCookie(FriendlyCookie cookie);
20+
2021
VerifyCookie getVerifyCookie();
22+
2123
List<FriendlyCookie> getCookies();
2224

2325
}

bukkit/dependency-reduced-pom.xml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<parent>
4+
<artifactId>convy-parent</artifactId>
5+
<groupId>net.outfluencer</groupId>
6+
<version>1.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
<artifactId>convy-bukkit</artifactId>
10+
<build>
11+
<plugins>
12+
<plugin>
13+
<artifactId>maven-shade-plugin</artifactId>
14+
<version>3.4.1</version>
15+
<executions>
16+
<execution>
17+
<phase>package</phase>
18+
<goals>
19+
<goal>shade</goal>
20+
</goals>
21+
</execution>
22+
</executions>
23+
</plugin>
24+
</plugins>
25+
</build>
26+
<repositories>
27+
<repository>
28+
<id>spigot-repo</id>
29+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
30+
</repository>
31+
</repositories>
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.spigotmc</groupId>
35+
<artifactId>spigot-api</artifactId>
36+
<version>1.20.6-R0.1-SNAPSHOT</version>
37+
<scope>provided</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.spigotmc</groupId>
41+
<artifactId>plugin-annotations</artifactId>
42+
<version>1.2.3-SNAPSHOT</version>
43+
<scope>provided</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>io.netty</groupId>
47+
<artifactId>netty-all</artifactId>
48+
<version>4.1.112.Final</version>
49+
<scope>provided</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.projectlombok</groupId>
53+
<artifactId>lombok</artifactId>
54+
<version>1.18.34</version>
55+
<scope>provided</scope>
56+
</dependency>
57+
</dependencies>
58+
<properties>
59+
<maven.compiler.target>21</maven.compiler.target>
60+
<maven.compiler.source>21</maven.compiler.source>
61+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
62+
</properties>
63+
</project>

bukkit/src/main/java/net/outfluencer/convey/bukkit/ConveyBukkit.java

+37-24
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@
2121
import net.outfluencer.convey.bukkit.commands.GListCommand;
2222
import net.outfluencer.convey.bukkit.commands.ServerCommand;
2323
import net.outfluencer.convey.bukkit.handler.ClientPacketHandler;
24-
import net.outfluencer.convey.bukkit.impl.ConveyPlayerImplBukkit;
24+
import net.outfluencer.convey.bukkit.impl.BukkitConveyPlayer;
2525
import net.outfluencer.convey.bukkit.listeners.PlayerJoinListener;
2626
import net.outfluencer.convey.bukkit.listeners.PlayerKickListener;
2727
import net.outfluencer.convey.bukkit.listeners.PlayerLoginListener;
2828
import net.outfluencer.convey.bukkit.listeners.PlayerQuitListener;
2929
import net.outfluencer.convey.bukkit.utils.KickCatcher;
30-
import net.outfluencer.convey.bukkit.utils.TransferUtils;
3130
import net.outfluencer.convey.common.protocol.packets.AbstractPacket;
32-
import net.outfluencer.convey.common.protocol.pipe.*;
31+
import net.outfluencer.convey.common.protocol.pipe.AESDecoder;
32+
import net.outfluencer.convey.common.protocol.pipe.AESEncoder;
33+
import net.outfluencer.convey.common.protocol.pipe.PacketDecoder;
34+
import net.outfluencer.convey.common.protocol.pipe.PacketEncoder;
35+
import net.outfluencer.convey.common.protocol.pipe.PacketHandler;
36+
import net.outfluencer.convey.common.protocol.pipe.Varint21FrameDecoder;
37+
import net.outfluencer.convey.common.protocol.pipe.Varint21LengthFieldPrepender;
3338
import net.outfluencer.convey.common.utils.AESUtils;
3439
import org.bukkit.Bukkit;
3540
import org.bukkit.entity.Player;
@@ -41,21 +46,27 @@
4146
import java.io.IOException;
4247
import java.text.Format;
4348
import java.text.MessageFormat;
44-
import java.util.*;
49+
import java.util.ArrayList;
50+
import java.util.Base64;
51+
import java.util.Collection;
52+
import java.util.Collections;
53+
import java.util.Enumeration;
54+
import java.util.HashMap;
55+
import java.util.List;
56+
import java.util.Map;
57+
import java.util.PropertyResourceBundle;
58+
import java.util.ResourceBundle;
59+
import java.util.concurrent.TimeUnit;
4560
import java.util.function.Supplier;
4661
import java.util.logging.Level;
4762

4863
@RequiredArgsConstructor
4964
public class ConveyBukkit extends Convey {
5065

51-
public static ConveyBukkit getInstance() {
52-
return (ConveyBukkit) Convey.getInstance();
53-
}
54-
5566
@Getter
5667
private final JavaPlugin plugin;
5768
@Getter
58-
private final Map<Player, ConveyPlayerImplBukkit> playerMap = new HashMap<>();
69+
private final Map<Player, BukkitConveyPlayer> playerMap = new HashMap<>();
5970
@Setter
6071
@Getter
6172
private ClientPacketHandler master;
@@ -67,8 +78,6 @@ public static ConveyBukkit getInstance() {
6778
private Map<String, Server> servers = new HashMap<>();
6879
private Map<String, Format> messageFormats;
6980
@Getter
70-
private TransferUtils transferUtils = new TransferUtils(this);
71-
@Getter
7281
private SecretKey secretKey;
7382
@Getter
7483
private AESUtils aesUtils;
@@ -77,6 +86,10 @@ public static ConveyBukkit getInstance() {
7786
@Setter
7887
private List<String> admins = new ArrayList<>();
7988

89+
public static ConveyBukkit getInstance() {
90+
return (ConveyBukkit) Convey.getInstance();
91+
}
92+
8093
@Override
8194
public List<LocalConveyPlayer> getLocalPlayers() {
8295
Collection collection = playerMap.values();
@@ -116,20 +129,20 @@ public void onEnable() {
116129

117130
this.plugin.saveDefaultConfig();
118131
try {
119-
this.secretKey = AESUtils.bytesToSecretKey(Base64.getDecoder().decode(plugin.getConfig().getString("encryption_key")));
132+
this.secretKey = AESUtils.bytesToSecretKey(Base64.getDecoder().decode(this.plugin.getConfig().getString("encryption_key")));
120133
} catch (Exception exception) {
121134
this.plugin.getLogger().severe("Please set the encryption key in the config.yml to the same as in the convey server config.json");
122-
Bukkit.getPluginManager().disablePlugin(plugin);
135+
Bukkit.getPluginManager().disablePlugin(this.plugin);
123136
return;
124137
}
125138

126139
this.aesUtils = new AESUtils(secretKey);
127140
this.reloadMessages();
128141

129-
Bukkit.getPluginManager().registerEvents(new PlayerLoginListener(), this.plugin);
130-
Bukkit.getPluginManager().registerEvents(new PlayerKickListener(), this.plugin);
131-
Bukkit.getPluginManager().registerEvents(new PlayerQuitListener(), this.plugin);
132-
Bukkit.getPluginManager().registerEvents(new PlayerJoinListener(), this.plugin);
142+
Bukkit.getPluginManager().registerEvents(new PlayerLoginListener(this), this.plugin);
143+
Bukkit.getPluginManager().registerEvents(new PlayerKickListener(this), this.plugin);
144+
Bukkit.getPluginManager().registerEvents(new PlayerQuitListener(this), this.plugin);
145+
Bukkit.getPluginManager().registerEvents(new PlayerJoinListener(this), this.plugin);
133146

134147

135148
this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, () -> {
@@ -139,12 +152,12 @@ public void onEnable() {
139152
}
140153
}, 0, 20 * 30);
141154

142-
this.plugin.getCommand("convey").setExecutor(new ConveyCommand());
143-
this.plugin.getCommand("server").setExecutor(new ServerCommand());
144-
this.plugin.getCommand("glist").setExecutor(new GListCommand());
145-
this.plugin.getCommand("gkick").setExecutor(new GKickCommand());
155+
this.plugin.getCommand("convey").setExecutor(new ConveyCommand(this));
156+
this.plugin.getCommand("server").setExecutor(new ServerCommand(this));
157+
this.plugin.getCommand("glist").setExecutor(new GListCommand(this));
158+
this.plugin.getCommand("gkick").setExecutor(new GKickCommand(this));
146159

147-
Bukkit.getOnlinePlayers().forEach(player -> this.playerMap.put(player, new ConveyPlayerImplBukkit(player)));
160+
Bukkit.getOnlinePlayers().forEach(player -> this.playerMap.put(player, new BukkitConveyPlayer(this, player)));
148161
}
149162

150163
public void onDisable() {
@@ -212,9 +225,9 @@ public String getTranslation(String name, Object... args) {
212225
return (format != null) ? format.format(args) : "<translation '" + name + "' missing>";
213226
}
214227

215-
public boolean fallback(ConveyPlayerImplBukkit player, String reason) {
228+
public boolean fallback(BukkitConveyPlayer player, String reason) {
216229
for (Server server : servers.values()) {
217-
if (server.isFallbackServer() && transferUtils.transferPlayer(player, server, false, reason)) {
230+
if (server.isFallbackServer() && player.transfer(server, false, reason)) {
218231
return true;
219232
}
220233
}

bukkit/src/main/java/net/outfluencer/convey/bukkit/ConveyBukkitPlugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@ApiVersion(ApiVersion.Target.v1_20)
1515
public class ConveyBukkitPlugin extends JavaPlugin {
1616

17-
private ConveyBukkit convey;
17+
private ConveyBukkit convey;
1818

1919
@Override
2020
public void onEnable() {

bukkit/src/main/java/net/outfluencer/convey/bukkit/commands/ConveyCommand.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.outfluencer.convey.bukkit.commands;
22

3+
import lombok.RequiredArgsConstructor;
34
import net.outfluencer.convey.api.Server;
45
import net.outfluencer.convey.bukkit.ConveyBukkit;
56
import org.bukkit.ChatColor;
@@ -8,21 +9,24 @@
89
import org.bukkit.command.CommandSender;
910
import org.bukkit.plugin.java.annotation.command.Commands;
1011

12+
@RequiredArgsConstructor
1113
@Commands(@org.bukkit.plugin.java.annotation.command.Command(name = "convey", desc = "Convey command"))
1214
public class ConveyCommand implements CommandExecutor {
15+
16+
private final ConveyBukkit convey;
17+
1318
@Override
1419
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
15-
ConveyBukkit convey = ConveyBukkit.getInstance();
16-
if (convey.getConveyServer() == null) {
20+
if (this.convey.getConveyServer() == null) {
1721
sender.sendMessage(ChatColor.RED + "Convey is loading...");
1822
return true;
1923
}
20-
sender.sendMessage(ChatColor.BLUE + "Convey by Outfluencer, current server name " + convey.getConveyServer().getName());
21-
for (Server server : convey.getServers().values()) {
24+
sender.sendMessage(ChatColor.BLUE + "Convey by Outfluencer, current server name " + this.convey.getConveyServer().getName());
25+
for (Server server : this.convey.getServers().values()) {
2226
sender.sendMessage(ChatColor.BLUE + " - " + server);
2327
}
24-
if (convey.masterIsConnected()) {
25-
sender.sendMessage(ChatColor.BLUE + "Master is connected with last ping " + convey.getMaster().getPing() + "ms");
28+
if (this.convey.masterIsConnected()) {
29+
sender.sendMessage(ChatColor.BLUE + "Master is connected with last ping " + this.convey.getMaster().getPing() + "ms");
2630
}
2731
return false;
2832
}

bukkit/src/main/java/net/outfluencer/convey/bukkit/commands/GKickCommand.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.outfluencer.convey.bukkit.commands;
22

33
import com.google.common.collect.Iterables;
4+
import lombok.RequiredArgsConstructor;
45
import net.outfluencer.convey.api.Convey;
56
import net.outfluencer.convey.bukkit.ConveyBukkit;
67
import org.bukkit.ChatColor;
@@ -14,24 +15,27 @@
1415
import java.util.List;
1516
import java.util.Locale;
1617

18+
@RequiredArgsConstructor
1719
@Commands(@org.bukkit.plugin.java.annotation.command.Command(name = "gkick", desc = "Kicks a player from the network", permission = "convey.command.gkick", usage = "/gkick <player>"))
1820
public class GKickCommand implements TabExecutor {
21+
22+
private final ConveyBukkit convey;
23+
1924
@Override
2025
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
2126
if (args.length == 0) {
2227
return false;
2328
}
2429

25-
ConveyBukkit convey = ConveyBukkit.getInstance();
26-
if (convey.getConveyServer() == null) {
30+
if (this.convey.getConveyServer() == null) {
2731
sender.sendMessage(ChatColor.RED + "Convey is loading...");
2832
return true;
2933
}
3034

3135
String playerName = args[0];
32-
String message = args.length > 1 ? String.join(" ", args).substring(playerName.length() + 1) : convey.getTranslation("kick");
36+
String message = args.length > 1 ? String.join(" ", args).substring(playerName.length() + 1) : this.convey.getTranslation("kick");
3337

34-
ConveyBukkit.getInstance().getGlobalPlayers().forEach(player -> {
38+
this.convey.getGlobalPlayers().forEach(player -> {
3539
if (player.getName().equalsIgnoreCase(playerName)) {
3640
player.kick(message);
3741
}

0 commit comments

Comments
 (0)