2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-12-23 10:38:01 +00:00

move plugin message into seperate project

This commit is contained in:
mohammed jasem alaajel 2024-05-16 19:20:24 +04:00
parent dbaee0df4c
commit 0871bda3f3
Signed by: ham1255
GPG Key ID: EF343502046229F4
16 changed files with 0 additions and 335 deletions

View File

@ -1,7 +0,0 @@
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:
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.

View File

@ -1,31 +0,0 @@
plugins {
`java-library`
`maven-publish`
}
dependencies {
api(project(":Limework-Plugin-Message-API-Protocol"))
compileOnly(libs.guava)
}
tasks {
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17) // use java 8 for shit servers that still stuck on minecraft 1.8
}
javadoc {
options.encoding = Charsets.UTF_8.name()
}
processResources {
filteringCharset = Charsets.UTF_8.name()
}
}
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
}
}

View File

@ -1,24 +0,0 @@
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;
}
}

View File

@ -1,10 +0,0 @@
package net.limework.valiobungee.pluginmessage.protocol;
import net.limework.pluginmessageapi.protocol.PluginMessageHandler;
import net.limework.valiobungee.pluginmessage.protocol.messages.proxybound.RequestProxiesListMessage;
public interface ProxyboundHandler extends PluginMessageHandler {
void handle(RequestProxiesListMessage message);
}

View File

@ -1,10 +0,0 @@
package net.limework.valiobungee.pluginmessage.protocol;
import net.limework.pluginmessageapi.protocol.PluginMessageHandler;
import net.limework.valiobungee.pluginmessage.protocol.messages.servebound.ProxiesListMessage;
public interface ServerboundHandler extends PluginMessageHandler {
void handle(ProxiesListMessage message);
}

View File

@ -1,38 +0,0 @@
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;
}
}

View File

@ -1,24 +0,0 @@
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
}
}

View File

@ -1,15 +0,0 @@
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 RequestProxiesListMessage() {
}
@Override
public void handle(PluginMessageHandler handler) {
((ProxyboundHandler) handler).handle(this);
}
}

View File

@ -1,46 +0,0 @@
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() {
}
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);
}
}

View File

@ -1,7 +0,0 @@
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

View File

@ -1,30 +0,0 @@
plugins {
`java-library`
`maven-publish`
}
dependencies {
compileOnly(libs.guava)
}
tasks {
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
}
javadoc {
options.encoding = Charsets.UTF_8.name()
}
processResources {
filteringCharset = Charsets.UTF_8.name()
}
}
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
}
}

View File

@ -1,31 +0,0 @@
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;
}
}

View File

@ -1,16 +0,0 @@
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);
}

View File

@ -1,9 +0,0 @@
package net.limework.pluginmessageapi.protocol;
public interface PluginMessageHandler {
}

View File

@ -1,34 +0,0 @@
package net.limework.pluginmessageapi.protocol;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
public class PluginMessageRegistry {
private final Map<Integer, Supplier<PluginMessage>> messageById = new HashMap<>();
private final Map<Class<? extends PluginMessage>, Integer> idByMessage = new HashMap<>();
public void register(int id, Class<? extends PluginMessage> clazz, Supplier<PluginMessage> 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<? extends PluginMessage> clazz) {
if (!idByMessage.containsKey(clazz)) {
throw new IllegalArgumentException("plugin Message clazz " + clazz + " does not exists in the registry");
}
return idByMessage.get(clazz);
}
}

View File

@ -14,9 +14,6 @@ val projects = arrayOf(
":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"
)