Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-25 15:50:10 +01:00
Inject into Bungee, (does not get past login from when i've tested)
Also add commands
Dieser Commit ist enthalten in:
Ursprung
42edffb309
Commit
cdab5b3f5b
@ -1,6 +1,7 @@
|
|||||||
package us.myles.ViaVersion;
|
package us.myles.ViaVersion;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
@ -10,6 +11,8 @@ import us.myles.ViaVersion.api.ViaVersionConfig;
|
|||||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||||
|
import us.myles.ViaVersion.bungee.command.BungeeCommand;
|
||||||
|
import us.myles.ViaVersion.bungee.command.BungeeCommandHandler;
|
||||||
import us.myles.ViaVersion.bungee.BungeeViaAPI;
|
import us.myles.ViaVersion.bungee.BungeeViaAPI;
|
||||||
import us.myles.ViaVersion.bungee.BungeeViaInjector;
|
import us.myles.ViaVersion.bungee.BungeeViaInjector;
|
||||||
import us.myles.ViaVersion.bungee.BungeeViaLoader;
|
import us.myles.ViaVersion.bungee.BungeeViaLoader;
|
||||||
@ -23,16 +26,20 @@ public class Bungee extends Plugin implements ViaPlatform {
|
|||||||
|
|
||||||
private BungeeViaAPI api;
|
private BungeeViaAPI api;
|
||||||
private BungeeConfigProvider config;
|
private BungeeConfigProvider config;
|
||||||
|
private BungeeCommandHandler commandHandler;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
api = new BungeeViaAPI();
|
api = new BungeeViaAPI();
|
||||||
config = new BungeeConfigProvider();
|
config = new BungeeConfigProvider();
|
||||||
|
commandHandler = new BungeeCommandHandler();
|
||||||
|
ProxyServer.getInstance().getPluginManager().registerCommand(this, new BungeeCommand(commandHandler));
|
||||||
// Init platform
|
// Init platform
|
||||||
Via.init(ViaManager.builder()
|
Via.init(ViaManager.builder()
|
||||||
.platform(this)
|
.platform(this)
|
||||||
.injector(new BungeeViaInjector())
|
.injector(new BungeeViaInjector())
|
||||||
.loader(new BungeeViaLoader())
|
.loader(new BungeeViaLoader())
|
||||||
|
.commandHandler(commandHandler)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package us.myles.ViaVersion.bungee.command;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
|
||||||
|
public class BungeeCommand extends Command {
|
||||||
|
private final BungeeCommandHandler handler;
|
||||||
|
|
||||||
|
public BungeeCommand(BungeeCommandHandler handler) {
|
||||||
|
super("viaversion"); // TODO PERMS HERE
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender commandSender, String[] strings) {
|
||||||
|
handler.onCommand(new BungeeCommandSender(commandSender), strings);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package us.myles.ViaVersion.bungee.command;
|
||||||
|
|
||||||
|
import us.myles.ViaVersion.commands.ViaCommandHandler;
|
||||||
|
|
||||||
|
public class BungeeCommandHandler extends ViaCommandHandler {
|
||||||
|
|
||||||
|
}
|
@ -3,6 +3,7 @@ package us.myles.ViaVersion.bungee.config;
|
|||||||
import us.myles.ViaVersion.api.ViaVersionConfig;
|
import us.myles.ViaVersion.api.ViaVersionConfig;
|
||||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -145,7 +146,7 @@ public class BungeeConfigProvider implements ViaVersionConfig, ConfigurationProv
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Integer> getBlockedProtocols() {
|
public List<Integer> getBlockedProtocols() {
|
||||||
return null;
|
return Arrays.asList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,9 +3,14 @@ package us.myles.ViaVersion.bungee.handlers;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||||
|
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.protocol.MinecraftDecoder;
|
||||||
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
import us.myles.ViaVersion.bungee.util.BungeePipelineUtil;
|
||||||
import us.myles.ViaVersion.exception.CancelException;
|
import us.myles.ViaVersion.exception.CancelException;
|
||||||
import us.myles.ViaVersion.packets.Direction;
|
import us.myles.ViaVersion.packets.Direction;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
@ -14,12 +19,13 @@ import us.myles.ViaVersion.util.PipelineUtil;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ViaDecodeHandler extends ByteToMessageDecoder {
|
public class ViaDecodeHandler extends MinecraftDecoder {
|
||||||
|
|
||||||
private final ByteToMessageDecoder minecraftDecoder;
|
private final MinecraftDecoder minecraftDecoder;
|
||||||
private final UserConnection info;
|
private final UserConnection info;
|
||||||
|
|
||||||
public ViaDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder) {
|
public ViaDecodeHandler(UserConnection info, MinecraftDecoder minecraftDecoder) {
|
||||||
|
super(Protocol.HANDSHAKE, true, ProxyServer.getInstance().getProtocolVersion());
|
||||||
this.info = info;
|
this.info = info;
|
||||||
this.minecraftDecoder = minecraftDecoder;
|
this.minecraftDecoder = minecraftDecoder;
|
||||||
}
|
}
|
||||||
@ -68,7 +74,7 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
|
|||||||
|
|
||||||
// call minecraft decoder
|
// call minecraft decoder
|
||||||
try {
|
try {
|
||||||
list.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, bytebuf));
|
list.addAll(BungeePipelineUtil.callDecode(this.minecraftDecoder, ctx, bytebuf));
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
if (e.getCause() instanceof Exception) {
|
if (e.getCause() instanceof Exception) {
|
||||||
throw (Exception) e.getCause();
|
throw (Exception) e.getCause();
|
||||||
@ -86,4 +92,14 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
|
|||||||
if (PipelineUtil.containsCause(cause, CancelException.class)) return;
|
if (PipelineUtil.containsCause(cause, CancelException.class)) return;
|
||||||
super.exceptionCaught(ctx, cause);
|
super.exceptionCaught(ctx, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setProtocol(Protocol protocol) {
|
||||||
|
this.minecraftDecoder.setProtocol(protocol);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setProtocolVersion(int protocolVersion) {
|
||||||
|
this.minecraftDecoder.setProtocolVersion(protocolVersion);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,14 @@ package us.myles.ViaVersion.bungee.handlers;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.MessageToByteEncoder;
|
import io.netty.handler.codec.MessageToByteEncoder;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.MinecraftEncoder;
|
||||||
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
import us.myles.ViaVersion.bungee.util.BungeePipelineUtil;
|
||||||
import us.myles.ViaVersion.exception.CancelException;
|
import us.myles.ViaVersion.exception.CancelException;
|
||||||
import us.myles.ViaVersion.packets.Direction;
|
import us.myles.ViaVersion.packets.Direction;
|
||||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
@ -13,29 +18,27 @@ import us.myles.ViaVersion.util.PipelineUtil;
|
|||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
public class ViaEncodeHandler extends MessageToByteEncoder {
|
public class ViaEncodeHandler extends MinecraftEncoder {
|
||||||
private final UserConnection info;
|
private final UserConnection info;
|
||||||
private final MessageToByteEncoder minecraftEncoder;
|
private final MinecraftEncoder minecraftEncoder;
|
||||||
|
|
||||||
public ViaEncodeHandler(UserConnection info, MessageToByteEncoder minecraftEncoder) {
|
public ViaEncodeHandler(UserConnection info, MinecraftEncoder minecraftEncoder) {
|
||||||
|
super(Protocol.HANDSHAKE, true, ProxyServer.getInstance().getProtocolVersion());
|
||||||
this.info = info;
|
this.info = info;
|
||||||
this.minecraftEncoder = minecraftEncoder;
|
this.minecraftEncoder = minecraftEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void encode(final ChannelHandlerContext ctx, Object o, final ByteBuf bytebuf) throws Exception {
|
protected void encode(final ChannelHandlerContext ctx, DefinedPacket o, final ByteBuf bytebuf) throws Exception {
|
||||||
// handle the packet type
|
|
||||||
if (!(o instanceof ByteBuf)) {
|
|
||||||
// call minecraft encoder
|
// call minecraft encoder
|
||||||
try {
|
try {
|
||||||
PipelineUtil.callEncode(this.minecraftEncoder, ctx, o, bytebuf);
|
BungeePipelineUtil.callEncode(this.minecraftEncoder, ctx, o, bytebuf);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
if (e.getCause() instanceof Exception) {
|
if (e.getCause() instanceof Exception) {
|
||||||
throw (Exception) e.getCause();
|
throw (Exception) e.getCause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (bytebuf.readableBytes() == 0) {
|
if (bytebuf.readableBytes() == 0) {
|
||||||
throw new CancelException();
|
throw new CancelException();
|
||||||
}
|
}
|
||||||
@ -67,4 +70,14 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
|
|||||||
if (PipelineUtil.containsCause(cause, CancelException.class)) return;
|
if (PipelineUtil.containsCause(cause, CancelException.class)) return;
|
||||||
super.exceptionCaught(ctx, cause);
|
super.exceptionCaught(ctx, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setProtocol(Protocol protocol) {
|
||||||
|
this.minecraftEncoder.setProtocol(protocol);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setProtocolVersion(int protocolVersion) {
|
||||||
|
this.minecraftEncoder.setProtocolVersion(protocolVersion);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,9 @@ import io.netty.channel.ChannelInitializer;
|
|||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||||
import io.netty.handler.codec.MessageToByteEncoder;
|
import io.netty.handler.codec.MessageToByteEncoder;
|
||||||
|
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||||
|
import net.md_5.bungee.protocol.MinecraftDecoder;
|
||||||
|
import net.md_5.bungee.protocol.MinecraftEncoder;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
|
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
|
||||||
|
|
||||||
@ -37,12 +40,12 @@ public class ViaVersionInitializer extends ChannelInitializer<SocketChannel> {
|
|||||||
// Add originals
|
// Add originals
|
||||||
this.method.invoke(this.original, socketChannel);
|
this.method.invoke(this.original, socketChannel);
|
||||||
// Add our transformers
|
// Add our transformers
|
||||||
MessageToByteEncoder encoder = new ViaEncodeHandler(info, (MessageToByteEncoder) socketChannel.pipeline().get("encoder"));
|
ViaEncodeHandler encoder = new ViaEncodeHandler(info, (MinecraftEncoder) socketChannel.pipeline().get("packet-encoder"));
|
||||||
ByteToMessageDecoder decoder = new ViaDecodeHandler(info, (ByteToMessageDecoder) socketChannel.pipeline().get("decoder"));
|
ViaDecodeHandler decoder = new ViaDecodeHandler(info, (MinecraftDecoder) socketChannel.pipeline().get("packet-decoder"));
|
||||||
ViaPacketHandler chunkHandler = new ViaPacketHandler(info);
|
// ViaPacketHandler chunkHandler = new ViaPacketHandler(info);
|
||||||
|
|
||||||
socketChannel.pipeline().replace("encoder", "encoder", encoder);
|
socketChannel.pipeline().replace("packet-encoder", "packet-encoder", encoder);
|
||||||
socketChannel.pipeline().replace("decoder", "decoder", decoder);
|
socketChannel.pipeline().replace("packet-decoder", "packet-decoder", decoder);
|
||||||
socketChannel.pipeline().addAfter("packet_handler", "viaversion_packet_handler", chunkHandler);
|
// socketChannel.pipeline().addAfter("packet_handler", "viaversion_packet_handler", chunkHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
package us.myles.ViaVersion.bungee.util;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||||
|
import io.netty.handler.codec.MessageToByteEncoder;
|
||||||
|
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||||
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.MinecraftDecoder;
|
||||||
|
import net.md_5.bungee.protocol.MinecraftEncoder;
|
||||||
|
import us.myles.ViaVersion.Bungee;
|
||||||
|
import us.myles.ViaVersion.util.PipelineUtil;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BungeePipelineUtil {
|
||||||
|
private static Method DECODE_METHOD;
|
||||||
|
private static Method ENCODE_METHOD;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
DECODE_METHOD = MinecraftDecoder.class.getDeclaredMethod("decode", ChannelHandlerContext.class, ByteBuf.class, List.class);
|
||||||
|
DECODE_METHOD.setAccessible(true);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.out.println("Netty issue?");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ENCODE_METHOD = MinecraftEncoder.class.getDeclaredMethod("encode", ChannelHandlerContext.class, DefinedPacket.class, ByteBuf.class);
|
||||||
|
ENCODE_METHOD.setAccessible(true);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.out.println("Netty issue?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static List<Object> callDecode(MessageToMessageDecoder decoder, ChannelHandlerContext ctx, Object input) throws InvocationTargetException {
|
||||||
|
List<Object> output = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
BungeePipelineUtil.DECODE_METHOD.invoke(decoder, ctx, input, output);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void callEncode(MessageToByteEncoder encoder, ChannelHandlerContext ctx, Object msg, ByteBuf output) throws InvocationTargetException {
|
||||||
|
try {
|
||||||
|
BungeePipelineUtil.ENCODE_METHOD.invoke(encoder, ctx, msg, output);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import com.google.common.collect.Maps;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -30,6 +31,10 @@ public class ReflectionUtil {
|
|||||||
public static void setStatic(Class<?> clazz, String f, Object value) throws NoSuchFieldException, IllegalAccessException {
|
public static void setStatic(Class<?> clazz, String f, Object value) throws NoSuchFieldException, IllegalAccessException {
|
||||||
Field field = clazz.getDeclaredField(f);
|
Field field = clazz.getDeclaredField(f);
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
|
// Remove any final stuff
|
||||||
|
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||||
|
modifiersField.setAccessible(true);
|
||||||
|
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||||
field.set(null, value);
|
field.set(null, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren