us.myles.ViaVersion.protocols.base.ProtocolInfo Java Examples

The following examples show how to use us.myles.ViaVersion.protocols.base.ProtocolInfo. 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: MixinDebugHud.java    From ViaFabric with MIT License 5 votes vote down vote up
@Inject(at = @At("RETURN"), method = "getLeftText")
protected void getLeftText(CallbackInfoReturnable<List<String>> info) {
    info.getReturnValue().add("[ViaFabric] Injected: " + Via.getManager().getConnections().size() + " ("
            + Via.getManager().getConnectedClients().size() + " frontend)");
    ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
            .getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
    if (viaDecoder instanceof VRDecodeHandler) {
        ProtocolInfo protocol = ((VRDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
        if (protocol != null) {
            ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
            String inactive = "";
            if (!protocol.getUser().isActive()) {
                inactive = " (inactive)";
            }
            info.getReturnValue().add("[ViaFabric] Client injected: "
                    + serverVer.getName() + " (" + serverVer.getId() + ") server" + inactive);
        }
    }
}
 
Example #3
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 #4
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 #5
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 #6
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 #7
Source File: ProtocolPipeline.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void init(UserConnection userConnection) {
    this.userConnection = userConnection;

    ProtocolInfo protocolInfo = new ProtocolInfo(userConnection);
    protocolInfo.setPipeline(this);

    userConnection.setProtocolInfo(protocolInfo);

    /* Init through all our pipes */
    for (Protocol protocol : protocolList) {
        protocol.init(userConnection);
    }
}
 
Example #8
Source File: UserConnection.java    From ViaVersion with MIT License 5 votes vote down vote up
public void setProtocolInfo(@Nullable ProtocolInfo protocolInfo) {
    this.protocolInfo = protocolInfo;
    if (protocolInfo != null) {
        storedObjects.put(ProtocolInfo.class, protocolInfo);
    } else {
        storedObjects.remove(ProtocolInfo.class);
    }
}
 
Example #9
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 #10
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 #11
Source File: WitherBossBar.java    From ViaRewind with MIT License 4 votes vote down vote up
@Override
public Set<UUID> getPlayers() {
	return Collections.singleton(connection.get(ProtocolInfo.class).getUuid());
}
 
Example #12
Source File: Utils.java    From ViaRewind with MIT License 4 votes vote down vote up
public static UUID getUUID(UserConnection user) {
	return user.get(ProtocolInfo.class).getUuid();
}
 
Example #13
Source File: UserConnection.java    From ViaVersion with MIT License 4 votes vote down vote up
@Nullable
public ProtocolInfo getProtocolInfo() {
    return protocolInfo;
}