Java Code Examples for us.myles.ViaVersion.api.data.UserConnection#getProtocolInfo()

The following examples show how to use us.myles.ViaVersion.api.data.UserConnection#getProtocolInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BungeePlugin.java    From ViaBackwards with MIT License 6 votes vote down vote up
@EventHandler(priority = -110) // Slightly later than VV
public void serverConnected(ServerConnectedEvent event) {
    ProxiedPlayer player = event.getPlayer();
    if (player.getServer() == null) return;

    UserConnection connection = Via.getManager().getConnection(player.getUniqueId());
    if (connection == null) return;

    ProtocolInfo info = connection.getProtocolInfo();
    if (info == null || !info.getPipeline().contains(Protocol1_15_2To1_16.class)) return;

    // Need to send a dummy respawn with a different dimension before the actual respawn
    // We also don't know what dimension it's sent to, so just send 2 dummies :>
    sendRespawn(connection, -1);
    sendRespawn(connection, 0);
}
 
Example 2
Source File: BukkitInventoryQuickMoveProvider.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public boolean registerQuickMoveAction(short windowId, short slotId, short actionId, UserConnection userConnection) {
    if (!supported) {
        return false;
    }
    if (slotId < 0) { // clicked out of inv slot
        return false;
    }
    if (windowId == 0) {
        /**
         * windowId is always 0 for player inventory.
         * This has almost definitely something to do with the offhand slot.
         */
        if (slotId >= 36 && slotId <= 44) {
            int protocolId = ProtocolRegistry.SERVER_PROTOCOL;
            // this seems to be working just fine.
            if (protocolId == ProtocolVersion.v1_8.getId()) {
                return false;
            }
        }
    }
    ProtocolInfo info = userConnection.getProtocolInfo();
    UUID uuid = info.getUuid();
    BukkitInventoryUpdateTask updateTask = updateTasks.get(uuid);
    final boolean registered = updateTask != null;
    if (!registered) {
        updateTask = new BukkitInventoryUpdateTask(this, uuid);
        updateTasks.put(uuid, updateTask);
    }
    // http://wiki.vg/index.php?title=Protocol&oldid=13223#Click_Window
    updateTask.addItem(windowId, slotId, actionId);
    if (!registered) {
        Via.getPlatform().runSync(updateTask, 5L);
    }
    return true;
}
 
Example 3
Source File: PlayerSneakListener.java    From ViaVersion with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void playerToggleSneak(PlayerToggleSneakEvent event) {
    Player player = event.getPlayer();
    UserConnection userConnection = getUserConnection(player);
    if (userConnection == null) return;
    ProtocolInfo info = userConnection.getProtocolInfo();
    if (info == null) return;

    int protocolVersion = info.getProtocolVersion();
    if (is1_14Fix && protocolVersion >= ProtocolVersion.v1_14.getId()) {
        setHeight(player, event.isSneaking() ? HEIGHT_1_14 : STANDING_HEIGHT);
        if (event.isSneaking())
            sneakingUuids.add(player.getUniqueId());
        else
            sneakingUuids.remove(player.getUniqueId());

        if (!useCache) return;
        if (event.isSneaking())
            sneaking.put(player, true);
        else
            sneaking.remove(player);
    } else if (is1_9Fix && protocolVersion >= ProtocolVersion.v1_9.getId()) {
        setHeight(player, event.isSneaking() ? HEIGHT_1_9 : STANDING_HEIGHT);
        if (!useCache) return;
        if (event.isSneaking())
            sneaking.put(player, false);
        else
            sneaking.remove(player);
    }
}
 
Example 4
Source File: BungeeVersionProvider.java    From ViaVersion with MIT License 5 votes vote down vote up
@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.getProtocolInfo();

    // 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();
}
 
Example 5
Source File: BungeeMainHandProvider.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void setMainHand(UserConnection user, int hand) {
    ProtocolInfo info = user.getProtocolInfo();
    if (info == null || info.getUuid() == null) return;
    ProxiedPlayer player = ProxyServer.getInstance().getPlayer(info.getUuid());
    if (player == null) return;
    try {
        Object settings = getSettings.invoke(player);
        if (settings != null) {
            setMainHand.invoke(settings, hand);
        }
    } catch (IllegalAccessException | InvocationTargetException e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: ViaConnectionManager.java    From ViaVersion with MIT License 5 votes vote down vote up
/**
 * Returns the UUID from the frontend connection to this proxy server
 * Returns null when there isn't a server or this connection isn't frontend or it doesn't have an id
 * When ViaVersion is reloaded, this method may not return some players.
 * May not return ProtocolSupport players.
 * <p>
 * Note that connections are removed as soon as their channel is closed,
 * so avoid using this method during player quits for example.
 */
@Nullable
public UUID getConnectedClientId(UserConnection conn) {
    if (conn.getProtocolInfo() == null) return null;
    UUID uuid = conn.getProtocolInfo().getUuid();
    UserConnection client = clients.get(uuid);
    if (client != null && client.equals(conn)) {
        // This is frontend
        return uuid;
    }
    return null;
}
 
Example 7
Source File: ViaIdleThread.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void run() {
    for (UserConnection info : Via.getManager().getConnections()) {
        ProtocolInfo protocolInfo = info.getProtocolInfo();
        if (protocolInfo != null && protocolInfo.getPipeline().contains(Protocol1_9To1_8.class)) {
            long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket();
            if (nextIdleUpdate <= System.currentTimeMillis()) {
                if (info.getChannel().isOpen()) {
                    Via.getManager().getProviders().get(MovementTransmitterProvider.class).sendPlayer(info);
                }
            }
        }
    }
}
 
Example 8
Source File: TabCompleteThread.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void run() {
    for (UserConnection info : Via.getManager().getConnections()) {
        if (info.getProtocolInfo() == null) continue;
        if (info.getProtocolInfo().getPipeline().contains(Protocol1_13To1_12_2.class)) {
            if (info.getChannel().isOpen()) {
                info.get(TabCompleteTracker.class).sendPacketToServer();
            }
        }
    }
}
 
Example 9
Source File: GlassConnectionHandler.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
protected byte getStates(UserConnection user, Position position, int blockState) {
    byte states = super.getStates(user, position, blockState);
    if (states != 0) return states;

    ProtocolInfo protocolInfo = user.getProtocolInfo();
    return protocolInfo.getServerProtocolVersion() <= 47
            && protocolInfo.getServerProtocolVersion() != -1 ? 0xF : states;
}
 
Example 10
Source File: CommonBoss.java    From ViaVersion with MIT License 5 votes vote down vote up
private void sendPacketConnection(UserConnection conn, PacketWrapper wrapper) {
    if (conn.getProtocolInfo() == null || !conn.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
        connections.remove(conn);
        return;
    }
    try {
        wrapper.send(Protocol1_9To1_8.class);
    } catch (Exception e) {
        e.printStackTrace();
    }
}