/** * Get the UserConnection from an UUID * * @param uuid UUID object * @return The UserConnection */ protected UserConnection getUserConnection(@NonNull UUID uuid) { return Via.getManager().getConnection(uuid); }
@Override public BossBar addPlayer(UUID player) { if (!players.contains(player)) { players.add(player); if (visible) { UserConnection user = Via.getManager().getConnection(player); sendPacket(player, getPacket(CommonBoss.UpdateAction.ADD, user)); } } return this; }
@Override public BossBar removePlayer(UUID uuid) { if (players.contains(uuid)) { players.remove(uuid); UserConnection user = Via.getManager().getConnection(uuid); sendPacket(uuid, getPacket(UpdateAction.REMOVE, user)); } return this; }
private void sendPacket(UpdateAction action) { for (UUID uuid : new ArrayList<>(players)) { UserConnection connection = Via.getManager().getConnection(uuid); PacketWrapper wrapper = getPacket(action, connection); sendPacket(uuid, wrapper); } }
@Subscribe(order = PostOrder.LATE) public void connectedEvent(ServerConnectedEvent e) { UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId()); try { checkServerChange(e, Via.getManager().getConnection(e.getPlayer().getUniqueId())); } catch (Exception e1) { e1.printStackTrace(); } }
@EventHandler(priority = EventPriority.LOWEST) public void onServerConnected(ServerConnectedEvent e) { try { checkServerChange(e, Via.getManager().getConnection(e.getPlayer().getUniqueId())); } catch (Exception e1) { e1.printStackTrace(); } }
if (!playerVersions.containsKey(playerVersion)) playerVersions.put(playerVersion, new HashSet<String>()); UserConnection uc = Via.getManager().getConnection(p.getUUID()); if (uc != null && uc.getPacketsPerSecond() > -1) { playerVersions.get(playerVersion).add(p.getName() + " (" + uc.getPacketsPerSecond() + " PPS)");
@EventHandler public void onServerConnect(ServerConnectEvent event) { // Ignore if it doesn't exist (Like BungeeCord 1.8) if (setMainHand == null || getSettings == null) return; UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null) return; try { if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { Object settings = getSettings.invoke(event.getPlayer()); if (settings != null) { if (user.has(EntityTracker.class)) { setMainHand.invoke(settings, user.get(EntityTracker.class).getMainHand()); } } } } catch (Exception e) { e.printStackTrace(); } } }
@EventHandler(priority = EventPriority.HIGH) public void onServerConnected(ServerConnectedEvent event) { UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null) return; try { if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { int entityId = user.get(EntityTracker.class).getProvidedEntityId(); PacketWrapper wrapper = new PacketWrapper(0x39, null, user); wrapper.write(Type.VAR_INT, entityId); wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0))); wrapper.send(Protocol1_9TO1_8.class); } } catch (Exception e) { e.printStackTrace(); } } }
@Subscribe(order = PostOrder.LAST) public void onServerConnected(ServerConnectedEvent event) { UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null) return; try { if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { int entityId = user.get(EntityTracker.class).getProvidedEntityId(); PacketWrapper wrapper = new PacketWrapper(0x39, null, user); wrapper.write(Type.VAR_INT, entityId); wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0))); wrapper.send(Protocol1_9TO1_8.class); } } catch (Exception e) { e.printStackTrace(); } } }
@EventHandler public void onServerConnect(ServerConnectEvent e) { UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId()); if (user == null) return; if (!user.has(BungeeStorage.class)) { user.put(new BungeeStorage(user, e.getPlayer())); } int protocolId = ProtocolDetectorService.getProtocolId(e.getTarget().getName()); List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.get(ProtocolInfo.class).getProtocolVersion(), protocolId); // Check if ViaVersion can support that version try { //Object pendingConnection = getPendingConnection.invoke(e.getPlayer()); Object handshake = getHandshake.invoke(e.getPlayer().getPendingConnection()); setProtocol.invoke(handshake, protocols == null ? user.get(ProtocolInfo.class).getProtocolVersion() : protocolId); } catch (InvocationTargetException | IllegalAccessException e1) { e1.printStackTrace(); } }
@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(); } } }
@Subscribe public void preServerConnect(ServerPreConnectEvent e) { try { UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId()); if (user == null) return; if (!user.has(VelocityStorage.class)) { user.put(new VelocityStorage(user, e.getPlayer())); } int protocolId = ProtocolDetectorService.getProtocolId(e.getOriginalServer().getServerInfo().getName()); List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.get(ProtocolInfo.class).getProtocolVersion(), protocolId); // Check if ViaVersion can support that version Object connection = getMinecraftConnection.invoke(e.getPlayer()); setNextProtocolVersion.invoke(connection, ProtocolVersion.getProtocolVersion(protocols == null ? user.get(ProtocolInfo.class).getProtocolVersion() : protocolId)); } catch (IllegalAccessException | InvocationTargetException e1) { e1.printStackTrace(); } }