Skip to content

Commit

Permalink
feat: added simplecloud support and made the plugin usable without a …
Browse files Browse the repository at this point in the history
…cloud again
  • Loading branch information
byPixelTV committed Oct 8, 2024
1 parent e7cea36 commit af53922
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 49 deletions.
13 changes: 7 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ repositories {
name = "papermc"
url = uri("https://repo.papermc.io/repository/maven-public/")
}
maven {
name = "simplecloud"
url = uri("https://repo.thesimplecloud.eu/artifactory/list/gradle-release-local")
}
}

dependencies {
Expand All @@ -41,14 +45,12 @@ dependencies {
compileOnly(platform("eu.cloudnetservice.cloudnet:bom:$cloudNetVersion"))
compileOnly("eu.cloudnetservice.cloudnet", "bridge")
compileOnly("eu.cloudnetservice.cloudnet", "wrapper-jvm")
compileOnly("eu.cloudnetservice.cloudnet", "platform-inject-api")
compileOnly("eu.cloudnetservice.cloudnet", "driver")
compileOnly("eu.cloudnetservice.cloudnet", "syncproxy")
compileOnly("dev.derklaro.aerogel", "aerogel-auto", "2.1.0")

annotationProcessor("dev.derklaro.aerogel", "aerogel-auto", "2.1.0")
annotationProcessor("eu.cloudnetservice.cloudnet", "platform-inject-processor", cloudNetVersion)

val simpleCloudVersion = "2.8.1"
compileOnly("eu.thesimplecloud.simplecloud", "simplecloud-api", simpleCloudVersion)
compileOnly("eu.thesimplecloud.simplecloud", "simplecloud-plugin", simpleCloudVersion)
}

sourceSets {
Expand All @@ -63,7 +65,6 @@ tasks {
compileJava {
options.encoding = "UTF-8"
options.release.set(21)
options.compilerArgs.add("-AaerogelAutoFileName=autoconfigure/bindings.aero")
}

build {
Expand Down
55 changes: 21 additions & 34 deletions src/main/java/de/bypixeltv/redivelocity/RediVelocity.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package de.bypixeltv.redivelocity;

import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.proxy.ProxyServer;
import de.bypixeltv.redivelocity.commands.RediVelocityCommand;
import de.bypixeltv.redivelocity.config.Config;
import de.bypixeltv.redivelocity.config.ConfigLoader;
import de.bypixeltv.redivelocity.listeners.*;
import de.bypixeltv.redivelocity.listeners.DisconnectListener;
import de.bypixeltv.redivelocity.listeners.PostLoginListener;
import de.bypixeltv.redivelocity.listeners.ProxyPingListener;
import de.bypixeltv.redivelocity.listeners.ServerSwitchListener;
import de.bypixeltv.redivelocity.managers.RedisController;
import de.bypixeltv.redivelocity.managers.UpdateManager;
import de.bypixeltv.redivelocity.utils.CloudUtils;
import de.bypixeltv.redivelocity.utils.ProxyIdGenerator;
import dev.jorel.commandapi.CommandAPI;
import dev.jorel.commandapi.CommandAPIVelocityConfig;
import eu.cloudnetservice.ext.platforminject.api.PlatformEntrypoint;
import eu.cloudnetservice.ext.platforminject.api.stereotype.Dependency;
import eu.cloudnetservice.ext.platforminject.api.stereotype.PlatformPlugin;
import eu.cloudnetservice.wrapper.holder.ServiceInfoHolder;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.inject.Provider;
import jakarta.inject.Singleton;
import lombok.Getter;
Expand All @@ -26,24 +28,12 @@
import java.util.Optional;

@Singleton
@PlatformPlugin(
platform = "velocity",
name = "RediVelocity",
version = "1.0.3",
description = "A fast, modern and clean alternative to RedisBungee on Velocity.",
authors = "byPixelTV",
dependencies = {
@Dependency(name = "CloudNet-Bridge", optional = true)
}
)
public class RediVelocity implements PlatformEntrypoint {
public class RediVelocity {

public final ProxyServer proxy;
private final Object pluginInstance;
private final ProxyIdGenerator proxyIdGenerator;
private final UpdateManager updateManager;
private final Provider<RediVelocityCommand> rediVelocityCommandProvider;
private final ServiceInfoHolder serviceInfoHolder;

private final MiniMessage miniMessages = MiniMessage.miniMessage();
private final ConfigLoader configLoader;
Expand All @@ -56,15 +46,12 @@ public class RediVelocity implements PlatformEntrypoint {
private RedisController redisController;

@Inject
public RediVelocity(ProxyServer proxy, @Named("plugin") Object pluginInstance, ProxyIdGenerator proxyIdGenerator,
UpdateManager updateManager, Provider<RediVelocityCommand> rediVelocityCommandProvider,
ServiceInfoHolder serviceInfoHolder) {
public RediVelocity(ProxyServer proxy, ProxyIdGenerator proxyIdGenerator,
UpdateManager updateManager, Provider<RediVelocityCommand> rediVelocityCommandProvider) {
this.proxy = proxy;
this.pluginInstance = pluginInstance;
this.proxyIdGenerator = proxyIdGenerator;
this.updateManager = updateManager;
this.rediVelocityCommandProvider = rediVelocityCommandProvider;
this.serviceInfoHolder = serviceInfoHolder;

this.configLoader = new ConfigLoader("plugins/redivelocity/config.yml");
this.configLoader.load();
Expand All @@ -83,8 +70,8 @@ public void sendErrorLogs(String message) {
this.proxy.getConsoleCommandSource().sendMessage(miniMessages.deserialize("<grey>[<aqua>RediVelocity</aqua>]</grey> <red>" + message + "</red>"));
}

@Override
public void onLoad() {
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
sendLogs("Proxy initialization started");

configLoader.load();
Expand All @@ -94,8 +81,8 @@ public void onLoad() {
redisController = new RedisController(this, config);
CommandAPI.onEnable();

proxyId = config.getCloudnet().isEnabled() ?
(config.getCloudnet().isCloudnetUseServiceId() ? serviceInfoHolder.serviceInfo().name() : proxyIdGenerator.generate()) :
proxyId = config.getCloud().isEnabled() ?
(CloudUtils.getServiceName(config.getCloud().getCloudSystem()) != null ? CloudUtils.getServiceName(config.getCloud().getCloudSystem()) : proxyIdGenerator.generate()) :
proxyIdGenerator.generate();

redisController.addToList("rv-proxies", new String[]{proxyId});
Expand All @@ -119,20 +106,20 @@ public void onLoad() {

updateManager.checkForUpdate();

proxy.getEventManager().register(this.pluginInstance, new ServerSwitchListener(this, config));
proxy.getEventManager().register(this.pluginInstance, new PostLoginListener(this, config));
proxy.getEventManager().register(this.pluginInstance, new DisconnectListener(this, config));
proxy.getEventManager().register(this, new ServerSwitchListener(this, config));
proxy.getEventManager().register(this, new PostLoginListener(this, config));
proxy.getEventManager().register(this, new DisconnectListener(this, config));

if (config.isPlayerCountSync()) {
proxy.getEventManager().register(this.pluginInstance, new ProxyPingListener(this));
proxy.getEventManager().register(this, new ProxyPingListener(this));
}

rediVelocityCommandProvider.get().register();
sendLogs("Proxy initialization completed");
}

@Override
public void onDisable() {
@Subscribe
public void onProxyShutdown(ProxyShutdownEvent event) {
sendLogs("Proxy shutdown started");
redisController.removeFromListByValue("rv-proxies", proxyId);
redisController.deleteHashField("rv-proxy-players", proxyId);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/de/bypixeltv/redivelocity/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
@Getter
@Setter
public class Config {
private int configVersion = 5;
private int configVersion = 6;
private RedisConfig redis = new RedisConfig();
private CloudNetConfig cloudnet = new CloudNetConfig();
private CloudSupportConfig cloud = new CloudSupportConfig();
private VersionControlConfig versionControl = new VersionControlConfig();
private MessagesConfig messages = new MessagesConfig();
private ResourcePackConfig resourcepack = new ResourcePackConfig();
Expand All @@ -28,9 +28,9 @@ public static class RedisConfig {

@Getter
@Setter
public static class CloudNetConfig {
public static class CloudSupportConfig {
private boolean enabled = false;
private boolean cloudnetUseServiceId = true;
private String cloudSystem = "simplecloud";
}

@Getter
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/de/bypixeltv/redivelocity/config/ConfigLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ public void save() {
writer.write(" useSsl: " + config.getRedis().isUseSsl() + "\n");
writer.write(" channel: " + config.getRedis().getChannel() + "\n");

writer.write("# CloudNet hook\n");
writer.write("cloudnet:\n");
writer.write(" enabled: " + config.getCloudnet().isEnabled() + "\n");
writer.write(" # Here you can enable or disable that the proxy id is the CloudNet service id\n");
writer.write(" cloudnetUseServiceId: " + config.getCloudnet().isCloudnetUseServiceId() + "\n");
writer.write("# Cloud System hook\n");
writer.write("cloud:\n");
writer.write(" # Here you can enable or disable the hook into CloudNet or SimpleCloud, it will get the Proxy id from the cloud and not from our generator\n");
writer.write(" enabled: " + config.getCloud().isEnabled() + "\n");
writer.write(" # Here you can set the cloud system, this can be cloudnet or simplecloud\n");
writer.write(" cloudSystem: " + config.getCloud().getCloudSystem() + "\n");

writer.write("# Here you can enable or disable the player count sync\n");
writer.write("playerCountSync: " + config.isPlayerCountSync() + "\n");
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/de/bypixeltv/redivelocity/utils/CloudUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.bypixeltv.redivelocity.utils;

import eu.cloudnetservice.driver.inject.InjectionLayer;
import eu.cloudnetservice.wrapper.holder.ServiceInfoHolder;
import eu.thesimplecloud.plugin.startup.CloudPlugin;

public class CloudUtils {
public static String getServiceName(String cloud) {
if (cloud.equalsIgnoreCase("simplecloud")) {
return CloudPlugin.getInstance().thisService().getName();
} else if (cloud.equalsIgnoreCase("cloudnet")) {
final ServiceInfoHolder serviceInfoHolder = InjectionLayer.ext().instance(ServiceInfoHolder.class);
return serviceInfoHolder.serviceInfo().name();
} else {
return null;
}
}

}
9 changes: 9 additions & 0 deletions src/main/resources/velocity-plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "redivelocity",
"name": "RediVelocity",
"version": "1.0.3",
"main": "de.bypixeltv.redivelocity.RediVelocity",
"authors": ["byPixelTV"],
"description": "A fast, modern and clean alternative to RedisBungee on Velocity.",
"url": "https://bypixeltv.de"
}

0 comments on commit af53922

Please sign in to comment.