Search in sources :

Example 1 with VelocityServerConnection

use of com.velocitypowered.proxy.connection.backend.VelocityServerConnection in project LimboAPI by Elytrium.

the class PlayerListItemHook method handle.

@Override
public boolean handle(MinecraftSessionHandler handler) {
    if (handler instanceof BackendPlaySessionHandler) {
        try {
            List<Item> items = this.getItems();
            for (int i = 0; i < items.size(); ++i) {
                Item item = items.get(i);
                ConnectedPlayer player = ((VelocityServerConnection) serverConnField.get(handler)).getPlayer();
                UUID initialID = this.plugin.getInitialID(player);
                if (player.getUniqueId().equals(item.getUuid())) {
                    items.set(i, new Item(initialID).setDisplayName(item.getDisplayName()).setGameMode(item.getGameMode()).setLatency(item.getLatency()).setName(item.getName()).setProperties(item.getProperties()));
                }
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    return super.handle(handler);
}
Also used : PlayerListItem(com.velocitypowered.proxy.protocol.packet.PlayerListItem) BackendPlaySessionHandler(com.velocitypowered.proxy.connection.backend.BackendPlaySessionHandler) VelocityServerConnection(com.velocitypowered.proxy.connection.backend.VelocityServerConnection) ConnectedPlayer(com.velocitypowered.proxy.connection.client.ConnectedPlayer) UUID(java.util.UUID)

Example 2 with VelocityServerConnection

use of com.velocitypowered.proxy.connection.backend.VelocityServerConnection in project InteractiveChat by LOOHP.

the class InteractiveChatVelocity method onServerConnected.

@Subscribe
public void onServerConnected(ServerPostConnectEvent event) {
    Player player = event.getPlayer();
    RegisteredServer to = player.getCurrentServer().get().getServer();
    UUID uuid = player.getUniqueId();
    if (!placeholderList.containsKey(to.getServerInfo().getName())) {
        try {
            PluginMessageSendingVelocity.requestPlaceholderList(to);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    try {
        PluginMessageSendingVelocity.sendPlayerListData();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    long universalTime = playerCooldownManager.getPlayerUniversalLastTimestamp(uuid);
    if (universalTime >= 0) {
        try {
            PluginMessageSendingVelocity.sendPlayerUniversalCooldown(to, uuid, universalTime);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    List<ICPlaceholder> placeholders = placeholderList.get(to.getServerInfo().getName());
    if (placeholders != null) {
        for (ICPlaceholder placeholder : placeholders) {
            long placeholderTime = playerCooldownManager.getPlayerPlaceholderLastTimestamp(uuid, placeholder.getInternalId());
            if (placeholderTime >= 0) {
                try {
                    PluginMessageSendingVelocity.sendPlayerPlaceholderCooldown(to, uuid, placeholder, placeholderTime);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    proxyServer.getScheduler().buildTask(plugin, () -> {
        try {
            PluginMessageSendingVelocity.sendDelayAndScheme();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }).schedule();
    proxyServer.getScheduler().buildTask(plugin, () -> {
        if (event.getPlayer().getUsername().equals("LOOHP") || event.getPlayer().getUsername().equals("AppLEskakE")) {
            sendMessage(event.getPlayer(), Component.text(TextColor.GOLD + "InteractiveChat (Velocity) " + getDescription().getVersion() + " is running!"));
        }
    }).delay(100, TimeUnit.MILLISECONDS).schedule();
    VelocityServerConnection serverConnection = ((ConnectedPlayer) event.getPlayer()).getConnectedServer();
    ChannelPipeline pipeline = serverConnection.ensureConnected().getChannel().pipeline();
    pipeline.addBefore(Connections.HANDLER, "interactivechat_interceptor", new ChannelDuplexHandler() {

        @Override
        public void write(ChannelHandlerContext channelHandlerContext, Object obj, ChannelPromise channelPromise) throws Exception {
            try {
                if (obj instanceof Chat) {
                    Chat packet = (Chat) obj;
                    UUID uuid = player.getUniqueId();
                    String message = packet.getMessage();
                    byte position = packet.getType();
                    if ((position == 0 || position == 1) && uuid != null && message != null) {
                        Map<String, Long> list = forwardedMessages.get(uuid);
                        if (list != null) {
                            list.put(message, System.currentTimeMillis());
                        }
                    }
                }
            } catch (Throwable e) {
                e.printStackTrace();
            }
            super.write(channelHandlerContext, obj, channelPromise);
        }
    });
}
Also used : ConnectedPlayer(com.velocitypowered.proxy.connection.client.ConnectedPlayer) ParsePlayer(com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer) Player(com.velocitypowered.api.proxy.Player) VelocityServerConnection(com.velocitypowered.proxy.connection.backend.VelocityServerConnection) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise) IOException(java.io.IOException) ConnectedPlayer(com.velocitypowered.proxy.connection.client.ConnectedPlayer) ChannelPipeline(io.netty.channel.ChannelPipeline) ParseException(org.json.simple.parser.ParseException) IOException(java.io.IOException) ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) Chat(com.velocitypowered.proxy.protocol.packet.Chat) JSONObject(org.json.simple.JSONObject) UUID(java.util.UUID) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 3 with VelocityServerConnection

use of com.velocitypowered.proxy.connection.backend.VelocityServerConnection in project LimboAPI by Elytrium.

the class LimboImpl method spawnPlayer.

@Override
public void spawnPlayer(Player apiPlayer, LimboSessionHandler handler) {
    ConnectedPlayer player = (ConnectedPlayer) apiPlayer;
    MinecraftConnection connection = player.getConnection();
    Class<? extends LimboSessionHandler> handlerClass = handler.getClass();
    if (this.limboName == null) {
        this.limboName = handlerClass.getSimpleName();
    }
    connection.eventLoop().execute(() -> {
        ChannelPipeline pipeline = connection.getChannel().pipeline();
        if (Settings.IMP.MAIN.LOGGING_ENABLED) {
            this.plugin.getLogger().info(player.getUsername() + " (" + player.getRemoteAddress() + ") has connected to the " + this.limboName + " Limbo");
        }
        if (!pipeline.names().contains("prepared-encoder")) {
            // and an error occurs that "minecraft-encoder" doesn't exist.
            if (!pipeline.names().contains(Connections.MINECRAFT_ENCODER)) {
                connection.close();
                return;
            }
            pipeline.addAfter(Connections.MINECRAFT_ENCODER, "prepared-encoder", new PreparedPacketEncoder(connection.getProtocolVersion()));
        }
        RegisteredServer previousServer = null;
        if (connection.getState() != LimboProtocol.getLimboRegistry()) {
            connection.setState(LimboProtocol.getLimboRegistry());
            VelocityServerConnection server = player.getConnectedServer();
            if (server != null) {
                server.disconnect();
                player.setConnectedServer(null);
                previousServer = server.getServer();
                this.plugin.setLimboJoined(player);
            }
        }
        if (this.plugin.isLimboJoined(player)) {
            if (connection.getType() == ConnectionTypes.LEGACY_FORGE) {
                connection.delayedWrite(this.safeRejoinPackets);
            } else {
                connection.delayedWrite(this.fastRejoinPackets);
            }
        } else {
            connection.delayedWrite(this.joinPackets);
        }
        connection.delayedWrite(this.postJoinPackets);
        connection.delayedWrite(this.getBrandMessage(handlerClass));
        this.plugin.setLimboJoined(player);
        LimboSessionHandlerImpl sessionHandler = new LimboSessionHandlerImpl(this.plugin, player, handler, connection.getSessionHandler(), previousServer, () -> this.limboName);
        connection.setSessionHandler(sessionHandler);
        connection.flush();
        if (connection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_18_2) >= 0) {
            this.plugin.getServer().getScheduler().buildTask(this.plugin, () -> connection.eventLoop().execute(() -> this.proceed(player, sessionHandler))).delay(Settings.IMP.MAIN.RECEIVER_LEVEL_1_18_2_FIXER_DELAY, TimeUnit.MILLISECONDS).schedule();
        } else {
            this.proceed(player, sessionHandler);
        }
    });
}
Also used : PreparedPacketEncoder(net.elytrium.limboapi.injection.packet.PreparedPacketEncoder) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) VelocityServerConnection(com.velocitypowered.proxy.connection.backend.VelocityServerConnection) MinecraftConnection(com.velocitypowered.proxy.connection.MinecraftConnection) ConnectedPlayer(com.velocitypowered.proxy.connection.client.ConnectedPlayer) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

VelocityServerConnection (com.velocitypowered.proxy.connection.backend.VelocityServerConnection)3 ConnectedPlayer (com.velocitypowered.proxy.connection.client.ConnectedPlayer)3 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)2 ChannelPipeline (io.netty.channel.ChannelPipeline)2 UUID (java.util.UUID)2 ParsePlayer (com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer)1 ICPlaceholder (com.loohp.interactivechat.objectholders.ICPlaceholder)1 Subscribe (com.velocitypowered.api.event.Subscribe)1 Player (com.velocitypowered.api.proxy.Player)1 MinecraftConnection (com.velocitypowered.proxy.connection.MinecraftConnection)1 BackendPlaySessionHandler (com.velocitypowered.proxy.connection.backend.BackendPlaySessionHandler)1 Chat (com.velocitypowered.proxy.protocol.packet.Chat)1 PlayerListItem (com.velocitypowered.proxy.protocol.packet.PlayerListItem)1 ChannelDuplexHandler (io.netty.channel.ChannelDuplexHandler)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelPromise (io.netty.channel.ChannelPromise)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1