Search in sources :

Example 1 with ConnectedPlayer

use of com.velocitypowered.proxy.connection.client.ConnectedPlayer in project LimboAPI by Elytrium.

the class LimboImpl method respawnPlayer.

@Override
public void respawnPlayer(Player player) {
    MinecraftConnection connection = ((ConnectedPlayer) player).getConnection();
    connection.write(this.spawnPosition);
    if (this.chunks != null) {
        connection.write(this.chunks);
    }
}
Also used : MinecraftConnection(com.velocitypowered.proxy.connection.MinecraftConnection) ConnectedPlayer(com.velocitypowered.proxy.connection.client.ConnectedPlayer)

Example 2 with ConnectedPlayer

use of com.velocitypowered.proxy.connection.client.ConnectedPlayer 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 3 with ConnectedPlayer

use of com.velocitypowered.proxy.connection.client.ConnectedPlayer in project LimboAPI by Elytrium.

the class LoginListener method hookPlaySession.

@Subscribe
public void hookPlaySession(ServerConnectedEvent event) {
    ConnectedPlayer player = (ConnectedPlayer) event.getPlayer();
    MinecraftConnection connection = player.getConnection();
    connection.eventLoop().execute(() -> {
        if (!(connection.getSessionHandler() instanceof ClientPlaySessionHandler)) {
            ClientPlaySessionHandler playHandler = new ClientPlaySessionHandler(this.server, player);
            try {
                spawned.set(playHandler, this.plugin.isLimboJoined(player));
            } catch (IllegalAccessException ex) {
                this.plugin.getLogger().error("Exception while hooking into ClientPlaySessionHandler of {}", player, ex);
            }
            connection.setSessionHandler(playHandler);
        }
    });
}
Also used : ClientPlaySessionHandler(com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler) ClosedMinecraftConnection(net.elytrium.limboapi.injection.dummy.ClosedMinecraftConnection) MinecraftConnection(com.velocitypowered.proxy.connection.MinecraftConnection) ConnectedPlayer(com.velocitypowered.proxy.connection.client.ConnectedPlayer) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 4 with ConnectedPlayer

use of com.velocitypowered.proxy.connection.client.ConnectedPlayer in project LimboAPI by Elytrium.

the class LoginListener method hookLoginSession.

public void hookLoginSession(GameProfileRequestEvent event) throws IllegalAccessException {
    // Changing mcConnection to the closed one. For what? To break the "initializePlayer"
    // method (which checks mcConnection.isActive()) and to override it. :)
    InitialInboundConnection inbound = (InitialInboundConnection) delegate.get(event.getConnection());
    MinecraftConnection connection = inbound.getConnection();
    LoginSessionHandler handler = (LoginSessionHandler) connection.getSessionHandler();
    loginConnectionField.set(handler, closed);
    if (connection.isClosed()) {
        return;
    }
    connection.eventLoop().execute(() -> {
        try {
            // Initiate a regular connection and move over to it.
            ConnectedPlayer player = ctor.newInstance(this.server, event.getGameProfile(), connection, event.getConnection().getVirtualHost().orElse(null), this.onlineMode.contains(event.getUsername()));
            if (!this.server.canRegisterConnection(player)) {
                player.disconnect0(Component.translatable("velocity.error.already-connected-proxy", NamedTextColor.RED), true);
                return;
            }
            if (connection.isClosed()) {
                return;
            }
            // Completing the Login process
            int threshold = this.server.getConfiguration().getCompressionThreshold();
            if (threshold >= 0 && connection.getProtocolVersion().compareTo(MINECRAFT_1_8) >= 0) {
                connection.write(new SetCompression(threshold));
                if (connection.isClosed()) {
                    return;
                }
                connection.setCompressionThreshold(threshold);
            }
            VelocityConfiguration configuration = this.server.getConfiguration();
            UUID playerUniqueId = player.getUniqueId();
            if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) {
                playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername());
            }
            ServerLoginSuccess success = new ServerLoginSuccess();
            success.setUsername(player.getUsername());
            success.setUuid(playerUniqueId);
            connection.write(success);
            this.plugin.setInitialID(player, playerUniqueId);
            connection.setState(StateRegistry.PLAY);
            this.server.getEventManager().fire(new LoginLimboRegisterEvent(player)).thenAcceptAsync(limboEvent -> {
                LoginTasksQueue queue = new LoginTasksQueue(this.plugin, handler, this.server, player, inbound, limboEvent.getCallbacks());
                this.plugin.addLoginQueue(player, queue);
                queue.next();
            }, connection.eventLoop());
        } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
    });
}
Also used : LoginSessionHandler(com.velocitypowered.proxy.connection.client.LoginSessionHandler) ServerLoginSuccess(com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess) ClosedMinecraftConnection(net.elytrium.limboapi.injection.dummy.ClosedMinecraftConnection) MinecraftConnection(com.velocitypowered.proxy.connection.MinecraftConnection) ConnectedPlayer(com.velocitypowered.proxy.connection.client.ConnectedPlayer) InvocationTargetException(java.lang.reflect.InvocationTargetException) VelocityConfiguration(com.velocitypowered.proxy.config.VelocityConfiguration) LoginLimboRegisterEvent(net.elytrium.limboapi.api.event.LoginLimboRegisterEvent) SetCompression(com.velocitypowered.proxy.protocol.packet.SetCompression) InitialInboundConnection(com.velocitypowered.proxy.connection.client.InitialInboundConnection) UUID(java.util.UUID)

Example 5 with ConnectedPlayer

use of com.velocitypowered.proxy.connection.client.ConnectedPlayer 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)

Aggregations

ConnectedPlayer (com.velocitypowered.proxy.connection.client.ConnectedPlayer)9 Subscribe (com.velocitypowered.api.event.Subscribe)4 Player (com.velocitypowered.api.proxy.Player)4 MinecraftConnection (com.velocitypowered.proxy.connection.MinecraftConnection)4 VelocityServerConnection (com.velocitypowered.proxy.connection.backend.VelocityServerConnection)4 ChannelPipeline (io.netty.channel.ChannelPipeline)4 UUID (java.util.UUID)4 ParsePlayer (com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer)3 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)3 Chat (com.velocitypowered.proxy.protocol.packet.Chat)3 ChannelDuplexHandler (io.netty.channel.ChannelDuplexHandler)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 ChannelPromise (io.netty.channel.ChannelPromise)3 IOException (java.io.IOException)3 JSONObject (org.json.simple.JSONObject)3 ParseException (org.json.simple.parser.ParseException)3 ICPlaceholder (com.loohp.interactivechat.objectholders.ICPlaceholder)2 BackendInteractiveChatData (com.loohp.interactivechat.proxy.objectholders.BackendInteractiveChatData)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2