Skip to content

Commit

Permalink
Merge pull request #1 from Aelysium-Group/development
Browse files Browse the repository at this point in the history
Implement /tpa, /rc send, bstats, and more
  • Loading branch information
nathan-i-martin authored Mar 26, 2023
2 parents a8857dd + 88a915a commit 307b52b
Show file tree
Hide file tree
Showing 70 changed files with 3,283 additions and 264 deletions.
1 change: 1 addition & 0 deletions assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<exclude>*.png</exclude>
<exclude>*.html</exclude>
<exclude>*.jpeg</exclude>
<exclude>*.java</exclude>
</excludes>
</filter>
</filters>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package group.aelysium.rustyconnector.core.lib;

public class Version {
protected int major;
protected int minor;
protected int fix;

public Version(int major, int minor, int fix) {
this.major = major;
this.minor = minor;
this.fix = fix;
}
public Version(String string) throws NumberFormatException{
String[] stringSplit = string.split("\\.");
this.major = Integer.parseInt(stringSplit[0]);
this.minor = Integer.parseInt(stringSplit[1]);
this.fix = Integer.parseInt(stringSplit[2]);
}
public int getMajor() {
return major;
}

public int getMinor() {
return minor;
}

public int getFix() {
return fix;
}

public boolean isGreaterThan(Version anotherVersion) {
if(!(this.getMajor() == this.getMinor())) return this.getMajor() > this.getMinor();
if(!(this.getMinor() == this.getMinor())) return this.getMinor() > this.getMinor();
return this.getFix() > this.getFix();
}

public boolean equals(Version anotherVersion) {
return (this.getMajor() == anotherVersion.getMajor()) &&
(this.getMinor() == anotherVersion.getMinor()) &&
(this.getFix() == anotherVersion.getFix());
}

public String toString() {
return this.major +"."+ this.minor +"."+ this.fix;
}

public static Version create(int major, int minor, int fix) {
return new Version(major, minor, fix);
}
public static Version create(String string) {
return new Version(string);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package group.aelysium.rustyconnector.core.lib.config;

import java.util.HashMap;
import java.util.Map;

public class MigrationDirections {
private static final Map<Integer, String> directions = new HashMap<>();

public static void init() {
directions.put(1 + 2, "https://github.com/Aelysium-Group/rusty-connector/wiki/Update-from-Config-v1-to-v2");
}

public static String findUpgradeDirections(int from, int to) {
String url = directions.get(from + to);
if(url == null) return "https://github.com/Aelysium-Group/rusty-connector/wiki/Config-Migration";
return url;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package group.aelysium.rustyconnector.core.lib.config;

import group.aelysium.rustyconnector.core.lib.Version;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;

Expand All @@ -8,6 +9,9 @@
import java.util.Arrays;

public class YAML {
// Plugin version does not necessarily equal the current plugin version.
// Instead, when the configs are updated, pluginVersion should be set to the current plugin version.
protected static int currentVersion = 2;
protected File configPointer;
protected String template;
protected ConfigurationNode data;
Expand All @@ -19,6 +23,9 @@ public YAML(File configPointer, String template) {
this.template = template;
}

public static int getCurrentConfigVersion() {
return currentVersion;
}
public String getName() {
return this.configPointer.getName();
}
Expand Down Expand Up @@ -73,4 +80,41 @@ public ConfigurationNode loadYAML(File file) throws IOException {
.setPath(file.toPath())
.build().load();
}

/**
* Process the version of this config.
* @throws UnsupportedClassVersionError If the config version doesn't match the plugin version.
* @throws RuntimeException If the config version is invalid or can't be processed.
*/
public void processVersion() {
try {
Integer version = this.getNode(this.data, "version", Integer.class);

if(YAML.getCurrentConfigVersion() > version)
throw new UnsupportedClassVersionError("Your configuration file is outdated! " +
"(v"+ version +" < v"+ YAML.getCurrentConfigVersion() +") " +
"Please refer to the following link for assistance with upgrading your config! "+MigrationDirections.findUpgradeDirections(version, YAML.getCurrentConfigVersion()));

if(YAML.getCurrentConfigVersion() != version)
throw new UnsupportedClassVersionError("Your configuration file is from a version of RustyConnector that is newer than the version you currently have installed! We will not provide support for downgrading RustyConnector configs! " +
"(v"+ version +" > v"+ YAML.getCurrentConfigVersion() +")");

return;
} catch (IllegalStateException e1) {
try {
this.getNode(this.data, "version", String.class);

throw new RuntimeException("You have set the value of `version` in config.yml to be a string! `version` must be an integer!");
} catch (IllegalStateException e2) {
try {
this.getNode(this.data, "config-version", Integer.class);

throw new UnsupportedClassVersionError("Your configuration file is outdated! " +
"(v1 < v"+ YAML.getCurrentConfigVersion() +") " +
"Please refer to the following link for assistance with upgrading your config! "+MigrationDirections.findUpgradeDirections(1, 2));
} catch (IllegalStateException ignore) {}
}
}
throw new RuntimeException("Could not identify any config version! Make sure that `version` is being used in your `config.yml`!");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package group.aelysium.rustyconnector.core.lib.data_messaging;

import group.aelysium.rustyconnector.core.lib.data_messaging.cache.CacheableMessage;

import java.security.InvalidAlgorithmParameterException;

public interface MessageHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static RedisMessage create(String rawMessage, MessageOrigin origin, InetS
JsonElement assumedToAddress = messageObject.get("to");

// If `from` is NOT null. We have a problem.
if(!(assumedFromAddress == null)) throw new IllegalArgumentException("`from` shouldn't be set for messages sent from the proxy!");
if(!(assumedFromAddress == null)) throw new IllegalArgumentException("Message is from another sub-server! Ignoring...");

if(assumedPrivateKey == null) throw new NullPointerException("`private-key` is required in transit messages!");
if(assumedType == null) throw new NullPointerException("`type` is required in transit messages!");
Expand Down Expand Up @@ -154,7 +154,7 @@ public static RedisMessage create(String rawMessage, MessageOrigin origin, InetS
JsonElement assumedToAddress = messageObject.get("to");

// If `to` is NOT null. We have a problem.
if(!(assumedToAddress == null)) throw new IllegalArgumentException("`to` shouldn't be set for messages sent from sub-servers!");
if(!(assumedToAddress == null)) throw new IllegalArgumentException("Message is from proxy! Ignoring...");

if(assumedPrivateKey == null) throw new NullPointerException("`private-key` is required in transit messages!");
if(assumedType == null) throw new NullPointerException("`type` is required in transit messages!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public enum RedisMessageType {
REG_FAMILY, // Proxy > Server | An outbound request for servers of a particular family to register themselves
REG, // Server > Proxy | A server's response to the REG_OUT message. This is also used when a server boots up and needs to register itself.
UNREG, // Server > Proxy | A server's message to the proxy when it needs to un-register itself.

SEND, // Server > Proxy | Request to send a player to a family
RESPONSE, // Server >< Proxy | A message to be returned in response to a request made

TPA_QUEUE_PLAYER, // Add a player's teleportation to the TPA queue on a specific server.
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package group.aelysium.rustyconnector.core.lib.data_messaging.cache;

import group.aelysium.rustyconnector.core.lib.data_messaging.MessageStatus;
import org.jetbrains.annotations.NotNull;

import java.util.Date;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import java.util.List;

public class MessageTunnel {
private boolean hasBlacklist = false;
private boolean hasWhitelist = false;
private int maxLength = 512;
private final boolean hasBlacklist;
private final boolean hasWhitelist;
private final int maxLength;
private final List<InetSocketAddress> blacklist = new ArrayList<>();
private final List<InetSocketAddress> whitelist = new ArrayList<>();

Expand All @@ -23,20 +23,10 @@ public MessageTunnel(boolean hasBlacklist, boolean hasWhitelist, int maxLength)
public void blacklistAddress(InetSocketAddress address) {
this.blacklist.add(address);
}
public void blacklistAddress(String hostname, int port) {
InetSocketAddress address = new InetSocketAddress(hostname, port);

this.blacklist.add(address);
}

public void whitelistAddress(InetSocketAddress address) {
this.whitelist.add(address);
}
public void whitelistAddress(String hostname, int port) {
InetSocketAddress address = new InetSocketAddress(hostname, port);

this.whitelist.add(address);
}

/**
* Validate a message.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package group.aelysium.rustyconnector.core.lib.database;

import group.aelysium.rustyconnector.core.lib.data_messaging.MessageStatus;
import group.aelysium.rustyconnector.core.lib.data_messaging.cache.CacheableMessage;
import group.aelysium.rustyconnector.core.lib.data_messaging.cache.MessageCache;
import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessageType;
import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang;
import net.kyori.adventure.text.Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import javax.crypto.Cipher;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Arrays;

public class Asymmetric {
private static final String RSA = "RSA";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.format.NamedTextColor;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ static JoinConfiguration newlines() {

Component SPACING = text("");

Component UNKNOWN_COMMAND = text("Unknown command. Type \"/help\" for help.",WHITE);

Message WORDMARK_INFO = () -> ASCIIAlphabet.generate("info");

Message WORDMARK_USAGE = () -> ASCIIAlphabet.generate("usage");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import group.aelysium.rustyconnector.core.lib.model.Sortable;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

Expand Down
1 change: 0 additions & 1 deletion paper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
<dependency>
<groupId>cloud.commandframework</groupId>
<artifactId>cloud-paper</artifactId>
<!--<version>1.7.1</version>-->
<version>1.8.0</version>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.paper.PaperCommandManager;
import group.aelysium.rustyconnector.core.lib.config.MigrationDirections;
import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang;
import group.aelysium.rustyconnector.plugin.paper.commands.CommandRusty;
import group.aelysium.rustyconnector.plugin.paper.lib.PaperServer;
import group.aelysium.rustyconnector.plugin.paper.lib.config.DefaultConfig;
import group.aelysium.rustyconnector.plugin.paper.lib.events.OnPlayerJoin;
import group.aelysium.rustyconnector.plugin.paper.lib.events.OnPlayerLeave;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.ConsoleCommandSender;

import java.io.File;
import java.util.function.Function;
Expand All @@ -17,6 +19,8 @@ public class Engine {
public static boolean start() {
PaperRustyConnector plugin = PaperRustyConnector.getInstance();

MigrationDirections.init();

if(!initConfigs(plugin)) return false;
if(!initCommands(plugin)) return false;
if(!initEvents(plugin)) return false;
Expand Down Expand Up @@ -79,6 +83,8 @@ private static boolean initCommands(PaperRustyConnector plugin) {
}

private static boolean initEvents(PaperRustyConnector plugin) {
plugin.getServer().getPluginManager().registerEvents(new OnPlayerJoin(), plugin);
plugin.getServer().getPluginManager().registerEvents(new OnPlayerLeave(), plugin);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import cloud.commandframework.paper.PaperCommandManager;
import group.aelysium.rustyconnector.core.RustyConnector;
import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang;
import group.aelysium.rustyconnector.plugin.paper.lib.PaperServer;
import group.aelysium.rustyconnector.plugin.paper.lib.bstats.Metrics;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -50,6 +50,8 @@ public void onEnable() {
instance = this;
this.logger = new PluginLogger(this.getSLF4JLogger());

Metrics metrics = new Metrics(this, 17973);

if(!Engine.start()) this.killPlugin();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import group.aelysium.rustyconnector.core.lib.data_messaging.cache.MessageCache;
import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector;
import group.aelysium.rustyconnector.plugin.paper.lib.lang_messaging.PaperLang;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
import group.aelysium.rustyconnector.core.lib.data_messaging.MessageOrigin;
import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessage;
import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessageType;
import group.aelysium.rustyconnector.core.lib.data_messaging.firewall.MessageTunnel;
import group.aelysium.rustyconnector.core.lib.hash.MD5;
import group.aelysium.rustyconnector.core.lib.data_messaging.cache.MessageCache;
import group.aelysium.rustyconnector.core.lib.model.Server;
import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector;
import group.aelysium.rustyconnector.plugin.paper.lib.config.DefaultConfig;
import group.aelysium.rustyconnector.plugin.paper.lib.database.Redis;
import group.aelysium.rustyconnector.plugin.paper.lib.tpa.TPAQueue;
import org.bukkit.entity.Player;

import java.net.InetSocketAddress;

public class PaperServer implements Server {
private TPAQueue tpaQueue = new TPAQueue();
private MessageCache messageCache;
private Redis redis;
private String family;
Expand Down Expand Up @@ -208,4 +209,8 @@ public static PaperServer init(DefaultConfig config) throws IllegalAccessExcepti

return server;
}

public TPAQueue getTPAQueue() {
return this.tpaQueue;
}
}
Loading

0 comments on commit 307b52b

Please sign in to comment.