From dbaee0df4c842c5670b9f9e7f6bb29d44ca5b0ae Mon Sep 17 00:00:00 2001 From: mohammed jasem alaajel Date: Thu, 16 May 2024 18:38:41 +0400 Subject: [PATCH] reduce code used in settings.gradle.kts, changes to plugin message --- build.gradle.kts | 0 plugin-message-api/LICENSE | 2 +- .../{redisbungee => api}/build.gradle.kts | 4 +- .../pluginmessage/models/Proxy.java | 0 .../protocol/ProxyboundHandler.java | 5 +-- .../protocol/ServerboundHandler.java | 7 +--- .../protocol/messages/Registry.java | 38 +++++++++++++++++ .../messages/proxybound/RequestMessage.java | 0 .../proxybound/RequestProxiesListMessage.java | 6 ++- .../servebound/ProxiesListMessage.java | 4 +- plugin-message-api/protocol/build.gradle.kts | 2 +- .../protocol/messages/HelloMessage.java | 41 ------------------- settings.gradle.kts | 41 ++++++++----------- 13 files changed, 69 insertions(+), 81 deletions(-) delete mode 100644 build.gradle.kts rename plugin-message-api/{redisbungee => api}/build.gradle.kts (74%) rename plugin-message-api/{redisbungee => api}/src/main/java/net/limework/valiobungee/pluginmessage/models/Proxy.java (100%) rename plugin-message-api/{redisbungee => api}/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ProxyboundHandler.java (64%) rename plugin-message-api/{redisbungee => api}/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ServerboundHandler.java (64%) create mode 100644 plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/Registry.java rename plugin-message-api/{redisbungee => api}/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestMessage.java (100%) rename plugin-message-api/{redisbungee => api}/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestProxiesListMessage.java (75%) rename plugin-message-api/{redisbungee => api}/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/servebound/ProxiesListMessage.java (94%) delete mode 100644 plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/messages/HelloMessage.java diff --git a/build.gradle.kts b/build.gradle.kts deleted file mode 100644 index e69de29..0000000 diff --git a/plugin-message-api/LICENSE b/plugin-message-api/LICENSE index 2171365..f6381bb 100644 --- a/plugin-message-api/LICENSE +++ b/plugin-message-api/LICENSE @@ -1,4 +1,4 @@ -Copyright 2024 +Copyright (c) 2024-present RedisBungee contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/plugin-message-api/redisbungee/build.gradle.kts b/plugin-message-api/api/build.gradle.kts similarity index 74% rename from plugin-message-api/redisbungee/build.gradle.kts rename to plugin-message-api/api/build.gradle.kts index fad0ae2..f9c4947 100644 --- a/plugin-message-api/redisbungee/build.gradle.kts +++ b/plugin-message-api/api/build.gradle.kts @@ -5,14 +5,14 @@ plugins { } dependencies { - compileOnly(project(":Limework-Plugin-Message-API-Protocol")) + api(project(":Limework-Plugin-Message-API-Protocol")) compileOnly(libs.guava) } tasks { compileJava { options.encoding = Charsets.UTF_8.name() - options.release.set(8) // use java 8 for shit servers that still stuck on 1.8 + options.release.set(17) // use java 8 for shit servers that still stuck on minecraft 1.8 } javadoc { options.encoding = Charsets.UTF_8.name() diff --git a/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/models/Proxy.java b/plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/models/Proxy.java similarity index 100% rename from plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/models/Proxy.java rename to plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/models/Proxy.java diff --git a/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ProxyboundHandler.java b/plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ProxyboundHandler.java similarity index 64% rename from plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ProxyboundHandler.java rename to plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ProxyboundHandler.java index b396648..862a73c 100644 --- a/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ProxyboundHandler.java +++ b/plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ProxyboundHandler.java @@ -3,9 +3,8 @@ package net.limework.valiobungee.pluginmessage.protocol; import net.limework.pluginmessageapi.protocol.PluginMessageHandler; import net.limework.valiobungee.pluginmessage.protocol.messages.proxybound.RequestProxiesListMessage; -public class ProxyboundHandler implements PluginMessageHandler { +public interface ProxyboundHandler extends PluginMessageHandler { - public void handle(RequestProxiesListMessage message) { + void handle(RequestProxiesListMessage message); - } } diff --git a/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ServerboundHandler.java b/plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ServerboundHandler.java similarity index 64% rename from plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ServerboundHandler.java rename to plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ServerboundHandler.java index f3385cc..d8a2adc 100644 --- a/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ServerboundHandler.java +++ b/plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ServerboundHandler.java @@ -3,11 +3,8 @@ package net.limework.valiobungee.pluginmessage.protocol; import net.limework.pluginmessageapi.protocol.PluginMessageHandler; import net.limework.valiobungee.pluginmessage.protocol.messages.servebound.ProxiesListMessage; -public class ServerboundHandler implements PluginMessageHandler { - - public void handle(ProxiesListMessage message) { - - } +public interface ServerboundHandler extends PluginMessageHandler { + void handle(ProxiesListMessage message); } diff --git a/plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/Registry.java b/plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/Registry.java new file mode 100644 index 0000000..031638d --- /dev/null +++ b/plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/Registry.java @@ -0,0 +1,38 @@ +package net.limework.valiobungee.pluginmessage.protocol.messages; + +import net.limework.pluginmessageapi.protocol.PluginMessageRegistry; +import net.limework.valiobungee.pluginmessage.protocol.messages.proxybound.RequestProxiesListMessage; +import net.limework.valiobungee.pluginmessage.protocol.messages.servebound.ProxiesListMessage; + +public class Registry { + + private static final PluginMessageRegistry serverbound = new PluginMessageRegistry(); + + private static final PluginMessageRegistry proxybound = new PluginMessageRegistry(); + + static { + registerProxybound(); + registerServerbound(); + } + + private static void registerServerbound() { + serverbound.register(0, ProxiesListMessage.class, ProxiesListMessage::new); + } + + + private static void registerProxybound() { + proxybound.register(0, RequestProxiesListMessage.class, RequestProxiesListMessage::new); + } + + + public static PluginMessageRegistry serverbound() { + return serverbound; + } + + + public static PluginMessageRegistry proxybound() { + return proxybound; + } + + +} diff --git a/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestMessage.java b/plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestMessage.java similarity index 100% rename from plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestMessage.java rename to plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestMessage.java diff --git a/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestProxiesListMessage.java b/plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestProxiesListMessage.java similarity index 75% rename from plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestProxiesListMessage.java rename to plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestProxiesListMessage.java index 4975872..c0c7ff5 100644 --- a/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestProxiesListMessage.java +++ b/plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestProxiesListMessage.java @@ -3,7 +3,11 @@ package net.limework.valiobungee.pluginmessage.protocol.messages.proxybound; import net.limework.pluginmessageapi.protocol.PluginMessageHandler; import net.limework.valiobungee.pluginmessage.protocol.ProxyboundHandler; -public class RequestProxiesListMessage extends RequestMessage{ +public class RequestProxiesListMessage extends RequestMessage { + + public RequestProxiesListMessage() { + } + @Override public void handle(PluginMessageHandler handler) { ((ProxyboundHandler) handler).handle(this); diff --git a/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/servebound/ProxiesListMessage.java b/plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/servebound/ProxiesListMessage.java similarity index 94% rename from plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/servebound/ProxiesListMessage.java rename to plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/servebound/ProxiesListMessage.java index d46cb56..e2583d1 100644 --- a/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/servebound/ProxiesListMessage.java +++ b/plugin-message-api/api/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/servebound/ProxiesListMessage.java @@ -11,8 +11,8 @@ public class ProxiesListMessage extends PluginMessage { private Proxy[] proxies; - public ProxiesListMessage(Proxy[] proxies) { - this.proxies = proxies; + public ProxiesListMessage() { + } public Proxy[] proxies() { diff --git a/plugin-message-api/protocol/build.gradle.kts b/plugin-message-api/protocol/build.gradle.kts index 6be1b5a..09b1bf9 100644 --- a/plugin-message-api/protocol/build.gradle.kts +++ b/plugin-message-api/protocol/build.gradle.kts @@ -11,7 +11,7 @@ dependencies { tasks { compileJava { options.encoding = Charsets.UTF_8.name() - options.release.set(8) // use java 8 for shit servers that still stuck on 1.8 + options.release.set(17) } javadoc { options.encoding = Charsets.UTF_8.name() diff --git a/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/messages/HelloMessage.java b/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/messages/HelloMessage.java deleted file mode 100644 index 5dfe078..0000000 --- a/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/messages/HelloMessage.java +++ /dev/null @@ -1,41 +0,0 @@ -package net.limework.pluginmessageapi.protocol.messages; - -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteArrayDataOutput; -import net.limework.pluginmessageapi.protocol.PluginMessageHandler; -import net.limework.pluginmessageapi.protocol.PluginMessage; - -// example plugin message class -public class HelloMessage extends PluginMessage { - - private String helloWorld; - - private static final String DEFAULT_MESSAGE = "hello from Limework!"; - - public HelloMessage(String helloWorld) { - this.helloWorld = helloWorld != null ? helloWorld : DEFAULT_MESSAGE; - } - - @Override - public void decode(ByteArrayDataInput in) { - this.helloWorld = in.readUTF(); - } - - @Override - public void encode(ByteArrayDataOutput out) { - out.writeUTF(this.helloWorld); - } - - @Override - public void handle(PluginMessageHandler messageHandler) { - // messageHandler.handle(this); - } - - public void setHelloWorldMessage(String helloWorld) { - this.helloWorld = helloWorld != null ? helloWorld : DEFAULT_MESSAGE; - } - - public String helloWorld() { - return helloWorld; - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 22ad600..7611256 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -6,33 +6,24 @@ pluginManagement { rootProject.name = "ValioBungee" -include(":RedisBungee-API") -project(":RedisBungee-API").projectDir = file("api") - -include(":RedisBungee-Commands") -project(":RedisBungee-Commands").projectDir = file("commands") - -include(":RedisBungee-Velocity") -project(":RedisBungee-Velocity").projectDir = file("proxies/velocity") - -include(":RedisBungee-Bungee") -project(":RedisBungee-Bungee").projectDir = file("proxies/bungeecord/bungeecord-api") - -include(":RedisBungee-Proxy-Bungee") -project(":RedisBungee-Proxy-Bungee").projectDir = file("proxies/bungeecord") - -include(":RedisBungee-Velocity") -project(":RedisBungee-Velocity").projectDir = file("proxies/velocity/velocity-api") - -include(":RedisBungee-Proxy-Velocity") -project(":RedisBungee-Proxy-Velocity").projectDir = file("proxies/velocity") - -include(":Limework-Plugin-Message-API-Protocol") -project(":Limework-Plugin-Message-API-Protocol").projectDir = file("plugin-message-api/protocol") -include(":RedisBungee-Plugin-Message-API") -project(":RedisBungee-Plugin-Message-API").projectDir = file("plugin-message-api/redisbungee") +val projects = arrayOf( + ":RedisBungee-API" to "api", + ":RedisBungee-Commands" to "commands", + ":RedisBungee-Velocity" to "proxies/velocity", + ":RedisBungee-Bungee" to "proxies/bungeecord/bungeecord-api", + ":RedisBungee-Proxy-Bungee" to "proxies/bungeecord", + ":RedisBungee-Velocity" to "proxies/velocity/velocity-api", + ":RedisBungee-Proxy-Velocity" to "proxies/velocity", + ":Limework-Plugin-Message-API-Protocol" to "plugin-message-api/protocol", + ":RedisBungee-Plugin-Message-API" to "plugin-message-api/api", + ":RedisBungee-Plugin-Message-API-Paper" to "plugin-message-api/api/paper" +) +projects.forEach { (projectName, filePath) -> + include(projectName) + project(projectName).projectDir = file(filePath) +} dependencyResolutionManagement { repositories {