diff --git a/copyright_print.txt b/copyright_print_epl.txt similarity index 100% rename from copyright_print.txt rename to copyright_print_epl.txt diff --git a/plugin-message-api/LICENSE b/plugin-message-api/LICENSE new file mode 100644 index 0000000..2171365 --- /dev/null +++ b/plugin-message-api/LICENSE @@ -0,0 +1,7 @@ +Copyright 2024 + +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: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/plugin-message-api/copyright_print_mit.txt b/plugin-message-api/copyright_print_mit.txt new file mode 100644 index 0000000..58da367 --- /dev/null +++ b/plugin-message-api/copyright_print_mit.txt @@ -0,0 +1,7 @@ +Copyright (c) 2013-present RedisBungee contributors + +All rights reserved. This program and the accompanying materials +are made available under the terms of the MIT License +which accompanies this api, and is available at + +https://opensource.org/license/mit \ No newline at end of file diff --git a/plugin-message-api/protocol/build.gradle.kts b/plugin-message-api/protocol/build.gradle.kts new file mode 100644 index 0000000..6be1b5a --- /dev/null +++ b/plugin-message-api/protocol/build.gradle.kts @@ -0,0 +1,30 @@ +plugins { + `java-library` + `maven-publish` + +} + +dependencies { + 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 + } + javadoc { + options.encoding = Charsets.UTF_8.name() + } + processResources { + filteringCharset = Charsets.UTF_8.name() + } +} + +publishing { + publications { + create("maven") { + from(components["java"]) + } + } +} diff --git a/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/MessageEncoderDecoder.java b/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/MessageEncoderDecoder.java new file mode 100644 index 0000000..1ecc3d2 --- /dev/null +++ b/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/MessageEncoderDecoder.java @@ -0,0 +1,31 @@ +package net.limework.pluginmessageapi.protocol; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; + +public class MessageEncoderDecoder { + + private final PluginMessageRegistry registry; + + public MessageEncoderDecoder(PluginMessageRegistry registry) { + this.registry = registry; + } + + public byte[] encode(PluginMessage pluginMessage) { + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + // write packet id + out.write(registry.idByMessage(pluginMessage.getClass())); + pluginMessage.encode(out); + return out.toByteArray(); + } + + public PluginMessage decode(byte[] data) { + ByteArrayDataInput in = ByteStreams.newDataInput(data); + int messageId = in.readInt(); + PluginMessage pluginMessage = registry.messageById(messageId); + pluginMessage.decode(in); + return pluginMessage; + } + +} diff --git a/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/PluginMessage.java b/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/PluginMessage.java new file mode 100644 index 0000000..8ebe77e --- /dev/null +++ b/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/PluginMessage.java @@ -0,0 +1,16 @@ +package net.limework.pluginmessageapi.protocol; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; + +public abstract class PluginMessage { + + + public abstract void decode(ByteArrayDataInput in); + + public abstract void encode(ByteArrayDataOutput out); + + public abstract void handle(PluginMessageHandler handler); + + +} diff --git a/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/PluginMessageHandler.java b/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/PluginMessageHandler.java new file mode 100644 index 0000000..3596564 --- /dev/null +++ b/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/PluginMessageHandler.java @@ -0,0 +1,9 @@ +package net.limework.pluginmessageapi.protocol; + +public interface PluginMessageHandler { + + + + + +} diff --git a/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/PluginMessageRegistry.java b/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/PluginMessageRegistry.java new file mode 100644 index 0000000..1b58fb2 --- /dev/null +++ b/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/PluginMessageRegistry.java @@ -0,0 +1,34 @@ +package net.limework.pluginmessageapi.protocol; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; + +public class PluginMessageRegistry { + + private final Map> messageById = new HashMap<>(); + private final Map, Integer> idByMessage = new HashMap<>(); + + + public void register(int id, Class clazz, Supplier messageSupplier) { + messageById.put(id, messageSupplier); + idByMessage.put(clazz, id); + } + + + public PluginMessage messageById(int id) { + if (!messageById.containsKey(id)) { + throw new IllegalArgumentException("plugin Message id " + id + " does not exists in the registry"); + } + return messageById.get(id).get(); + } + + + public int idByMessage(Class clazz) { + if (!idByMessage.containsKey(clazz)) { + throw new IllegalArgumentException("plugin Message clazz " + clazz + " does not exists in the registry"); + } + return idByMessage.get(clazz); + } + +} 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 new file mode 100644 index 0000000..5dfe078 --- /dev/null +++ b/plugin-message-api/protocol/src/main/java/net/limework/pluginmessageapi/protocol/messages/HelloMessage.java @@ -0,0 +1,41 @@ +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/plugin-message-api/redisbungee/build.gradle.kts b/plugin-message-api/redisbungee/build.gradle.kts new file mode 100644 index 0000000..fad0ae2 --- /dev/null +++ b/plugin-message-api/redisbungee/build.gradle.kts @@ -0,0 +1,31 @@ +plugins { + `java-library` + `maven-publish` + +} + +dependencies { + compileOnly(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 + } + javadoc { + options.encoding = Charsets.UTF_8.name() + } + processResources { + filteringCharset = Charsets.UTF_8.name() + } +} + +publishing { + publications { + create("maven") { + from(components["java"]) + } + } +} diff --git a/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/models/Proxy.java b/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/models/Proxy.java new file mode 100644 index 0000000..01d0d9e --- /dev/null +++ b/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/models/Proxy.java @@ -0,0 +1,24 @@ +package net.limework.valiobungee.pluginmessage.models; + +public class Proxy { + + private String proxyId; + + private int players; + + public Proxy() { + } + + public Proxy(String proxyId, int players) { + this.proxyId = proxyId; + this.players = players; + } + + public String proxyId() { + return proxyId; + } + + public int players() { + return players; + } +} diff --git a/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ProxyboundHandler.java b/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ProxyboundHandler.java new file mode 100644 index 0000000..b396648 --- /dev/null +++ b/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ProxyboundHandler.java @@ -0,0 +1,11 @@ +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 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/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ServerboundHandler.java new file mode 100644 index 0000000..f3385cc --- /dev/null +++ b/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/ServerboundHandler.java @@ -0,0 +1,13 @@ +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) { + + } + + +} diff --git a/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestMessage.java b/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestMessage.java new file mode 100644 index 0000000..50f75f6 --- /dev/null +++ b/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestMessage.java @@ -0,0 +1,24 @@ +package net.limework.valiobungee.pluginmessage.protocol.messages.proxybound; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import net.limework.pluginmessageapi.protocol.PluginMessage; + + +public abstract class RequestMessage extends PluginMessage { + + + public RequestMessage() { + + } + + @Override + public void encode(ByteArrayDataOutput out) { + // do nothing + } + + @Override + public void decode(ByteArrayDataInput in) { + // do nothing + } +} diff --git a/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestProxiesListMessage.java b/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestProxiesListMessage.java new file mode 100644 index 0000000..4975872 --- /dev/null +++ b/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/proxybound/RequestProxiesListMessage.java @@ -0,0 +1,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{ + @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/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/servebound/ProxiesListMessage.java new file mode 100644 index 0000000..d46cb56 --- /dev/null +++ b/plugin-message-api/redisbungee/src/main/java/net/limework/valiobungee/pluginmessage/protocol/messages/servebound/ProxiesListMessage.java @@ -0,0 +1,46 @@ +package net.limework.valiobungee.pluginmessage.protocol.messages.servebound; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import net.limework.pluginmessageapi.protocol.PluginMessage; +import net.limework.pluginmessageapi.protocol.PluginMessageHandler; +import net.limework.valiobungee.pluginmessage.models.Proxy; +import net.limework.valiobungee.pluginmessage.protocol.ServerboundHandler; + +public class ProxiesListMessage extends PluginMessage { + + private Proxy[] proxies; + + public ProxiesListMessage(Proxy[] proxies) { + this.proxies = proxies; + } + + public Proxy[] proxies() { + return proxies; + } + + @Override + public void decode(ByteArrayDataInput in) { + int proxiesNumber = in.readInt(); + this.proxies = new Proxy[proxiesNumber]; + for (int i = 0; i < proxiesNumber; i++) { + String id = in.readUTF(); + int players = in.readInt(); + proxies[i] = new Proxy(id, players); + } + } + + @Override + public void encode(ByteArrayDataOutput out) { + out.writeInt(proxies.length); + for (Proxy proxy : proxies) { + out.writeUTF(proxy.proxyId()); + out.writeInt(proxy.players()); + } + } + + @Override + public void handle(PluginMessageHandler handler) { + ((ServerboundHandler) handler).handle(this); + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index ed11c0a..22ad600 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -27,6 +27,10 @@ project(":RedisBungee-Velocity").projectDir = file("proxies/velocity/velocity-ap 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")