@Override public void inject() throws Exception { Object connectionManager = ReflectionUtil.get(VelocityPlugin.PROXY, "cm", Object.class); Object channelInitializerHolder = ReflectionUtil.invoke(connectionManager, "getServerChannelInitializer"); ChannelInitializer originalIntializer = (ChannelInitializer) ReflectionUtil.invoke(channelInitializerHolder, "get"); channelInitializerHolder.getClass().getMethod("set", ChannelInitializer.class) .invoke(channelInitializerHolder, new VelocityChannelInitializer(originalIntializer)); }
@Override public int getServerProtocolVersion() throws Exception { return (int) ReflectionUtil.getStatic(Class.forName("net.md_5.bungee.protocol.ProtocolConstants"), "SUPPORTED_VERSION_IDS", List.class).get(0); }
public static Object getServerConnection() throws Exception { Class<?> serverClazz = NMSUtil.nms("MinecraftServer"); Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer"); Object connection = null; for (Method m : serverClazz.getDeclaredMethods()) { if (m.getReturnType() != null) { if (m.getReturnType().getSimpleName().equals("ServerConnection")) { if (m.getParameterTypes().length == 0) { connection = m.invoke(server); } } } } return connection; }
ChannelHandler handler = future.channel().pipeline().get(name); try { ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class); bootstrapAcceptor = handler; } catch (Exception e) { ChannelInitializer<SocketChannel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); ChannelInitializer newInit = new BukkitChannelInitializer(oldInit); ReflectionUtil.set(bootstrapAcceptor, "childHandler", newInit); injectedFutures.add(future); } catch (NoSuchFieldException e) { PluginDescriptionFile yaml = ReflectionUtil.get(cl, "description", PluginDescriptionFile.class); throw new Exception("Unable to inject, due to " + bootstrapAcceptor.getClass().getName() + ", try without the plugin " + yaml.getName() + "?"); } else {
try { Object world = mapChunkBulkRef.getFieldValue("world", packet, Object.class); Object spigotConfig = ReflectionUtil.getPublic(world, "spigotConfig", Object.class); Object antiXrayInstance = ReflectionUtil.getPublic(spigotConfig, "antiXrayInstance", Object.class); Object b = ReflectionUtil.get(chunkMaps[i], "b", Object.class); Object a = ReflectionUtil.get(chunkMaps[i], "a", Object.class);
packet = windowClickPacketClass.getDeclaredConstructor().newInstance(); Object nmsItem = itemstack == null ? null : nmsItemMethod.invoke(null, itemstack); ReflectionUtil.set(packet, "a", (int) storage.getWindowId()); ReflectionUtil.set(packet, "slot", (int) slotId); ReflectionUtil.set(packet, "button", 0); // shift + left mouse click ReflectionUtil.set(packet, "d", storage.getActionId()); ReflectionUtil.set(packet, "item", nmsItem); int protocolId = ProtocolRegistry.SERVER_PROTOCOL; if (protocolId == ProtocolVersion.v1_8.getId()) { ReflectionUtil.set(packet, "shift", 1); } else if (protocolId >= ProtocolVersion.v1_9.getId()) { // 1.9+ ReflectionUtil.set(packet, "shift", clickTypeEnum);
public void saveServerBossBars() { // Get bossbar list if it's supported try { Object connection = ReflectionUtil.invoke(player, "getMinecraftConnection"); Object sessionHandler = ReflectionUtil.invoke(connection, "getSessionHandler"); if (sessionHandler.getClass().getSimpleName().contains("Play")) { bossbar = (List<UUID>) ReflectionUtil.invoke(sessionHandler, "getServerBossBars"); } } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { e.printStackTrace(); } } }
ChannelHandler handler = future.channel().pipeline().get(name); try { ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class); bootstrapAcceptor = handler; } catch (Exception e) { ChannelInitializer<Channel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); ChannelInitializer newInit = new SpongeChannelInitializer(oldInit); ReflectionUtil.set(bootstrapAcceptor, "childHandler", newInit); injectedFutures.add(future); } catch (NoSuchFieldException e) {
ReflectionUtil.invoke( getMinecraftConnection.invoke(e.getPlayer()), "getSessionHandler"
ChannelHandler handler = future.channel().pipeline().get(name); try { ChannelInitializer<Channel> oldInit = ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class); if (oldInit instanceof SpongeChannelInitializer) { bootstrapAcceptor = handler; ChannelInitializer<Channel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); if (oldInit instanceof SpongeChannelInitializer) { ReflectionUtil.set(bootstrapAcceptor, "childHandler", ((SpongeChannelInitializer) oldInit).getOriginal());
public static int getLowestSupportedVersion() { List<Integer> list; try { list = ReflectionUtil.getStatic(ref, "SUPPORTED_VERSION_IDS", List.class); return list.get(0); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } // Fallback return ProxyServer.getInstance().getProtocolVersion(); } }
try { Class<?> serverClazz = NMSUtil.nms("MinecraftServer"); Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer"); Class<?> pingClazz = NMSUtil.nms("ServerPing"); Object ping = null;
ChannelHandler handler = future.channel().pipeline().get(name); try { ChannelInitializer<SocketChannel> oldInit = ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class); if (oldInit instanceof BukkitChannelInitializer) { bootstrapAcceptor = handler; ChannelInitializer<SocketChannel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class); if (oldInit instanceof BukkitChannelInitializer) { ReflectionUtil.set(bootstrapAcceptor, "childHandler", ((BukkitChannelInitializer) oldInit).getOriginal());
@Override public int getServerProtocol(UserConnection user) throws Exception { if (ref == null) return super.getServerProtocol(user); // TODO Have one constant list forever until restart? (Might limit plugins if they change this) List<Integer> list = ReflectionUtil.getStatic(ref, "SUPPORTED_VERSION_IDS", List.class); List<Integer> sorted = new ArrayList<>(list); Collections.sort(sorted); ProtocolInfo info = user.get(ProtocolInfo.class); // Bungee supports it if (sorted.contains(info.getProtocolVersion())) return info.getProtocolVersion(); // Older than bungee supports, get the lowest version if (info.getProtocolVersion() < sorted.get(0)) { return getLowestSupportedVersion(); } // Loop through all protocols to get the closest protocol id that bungee supports (and that viaversion does too) // TODO: This needs a better fix, i.e checking ProtocolRegistry to see if it would work. // This is more of a workaround for snapshot support by bungee. for (Integer protocol : Lists.reverse(sorted)) { if (info.getProtocolVersion() > protocol && ProtocolVersion.isRegistered(protocol)) return protocol; } Via.getPlatform().getLogger().severe("Panic, no protocol id found for " + info.getProtocolVersion()); return info.getProtocolVersion(); }
@Subscribe public void onServerConnect(ServerConnectedEvent event) { UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null || setSettings == null) return; try { if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { PlayerSettings settings = event.getPlayer().getPlayerSettings(); if (user.has(EntityTracker.class)) { Object clientSettings = ReflectionUtil.get(settings, "settings", Object.class); ReflectionUtil.set(clientSettings, "mainHand", user.get(EntityTracker.class).getMainHand()); setSettings.invoke(event.getPlayer(), clientSettings); } } } catch (Exception e) { e.printStackTrace(); } } }