public static ProtocolVersion getProtocol(int id) { ProtocolVersion protocolVersion = versions.get(id); if (protocolVersion != null) { return protocolVersion; } else { return new ProtocolVersion(id, "Unknown (" + id + ")"); } }
public static void refreshVersions() { supportedVersions.clear(); supportedVersions.add(ProtocolRegistry.SERVER_PROTOCOL); for (ProtocolVersion versions : ProtocolVersion.getProtocols()) { List<Pair<Integer, Protocol>> paths = getProtocolPath(versions.getId(), ProtocolRegistry.SERVER_PROTOCOL); if (paths == null) continue; supportedVersions.add(versions.getId()); for (Pair<Integer, Protocol> path : paths) supportedVersions.add(path.getKey()); } }
if (!(entry.getValue() instanceof Integer)) { if (entry.getValue() instanceof String) { ProtocolVersion found = ProtocolVersion.getClosest((String) entry.getValue()); if (found != null) { servers.put(entry.getKey(), found.getId()); } else {
@Override public int getServerProtocol(UserConnection user) throws Exception { int playerVersion = user.get(ProtocolInfo.class).getProtocolVersion(); // Bungee supports it if (Collections.binarySearch(VELOCITY_PROTOCOLS, playerVersion) >= 0) return playerVersion; // Older than bungee supports, get the lowest version if (playerVersion < VELOCITY_PROTOCOLS.get(0)) { return VelocityViaInjector.getLowestSupportedProtocolVersion(); } // 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(VELOCITY_PROTOCOLS)) { if (playerVersion > protocol && ProtocolVersion.isRegistered(protocol)) return protocol; } Via.getPlatform().getLogger().severe("Panic, no protocol id found for " + playerVersion); return playerVersion; } }
@Override public boolean execute(ViaCommandSender sender, String[] args) { Map<ProtocolVersion, Set<String>> playerVersions = new TreeMap<>(new Comparator<ProtocolVersion>() { @Override public int compare(ProtocolVersion o1, ProtocolVersion o2) { return ProtocolVersion.getIndex(o2) - ProtocolVersion.getIndex(o1); } }); for (ViaCommandSender p : Via.getPlatform().getOnlinePlayers()) { int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID()); ProtocolVersion key = ProtocolVersion.getProtocol(playerVersion); if (!playerVersions.containsKey(key)) playerVersions.put(key, new HashSet<String>()); playerVersions.get(key).add(p.getName()); } for (Map.Entry<ProtocolVersion, Set<String>> entry : playerVersions.entrySet()) sendMessage(sender, "&8[&6%s&8] (&7%d&8): &b%s", entry.getKey().getName(), entry.getValue().size(), entry.getValue()); playerVersions.clear(); return true; } }
public static ProtocolVersion getClosest(String protocol) { for (ProtocolVersion version : versions.values()) { if (version.getName().equals(protocol)) return version; if (version.getName().equals(protocol + ".x")) return version; String[] parts = version.getName().split("-"); for (String part : parts) { if (part.equalsIgnoreCase(protocol)) { return version; } if (part.equals(protocol + ".x")) return version; } } return null; }
if (!(entry.getValue() instanceof Integer)) { if (entry.getValue() instanceof String) { ProtocolVersion found = ProtocolVersion.getClosest((String) entry.getValue()); if (found != null) { servers.put(entry.getKey(), found.getId()); } else {
@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.get(ProtocolInfo.class); // 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(); }
sendMessage(sender, "&8[&6%s&8]: &b%s", ProtocolVersion.getProtocol(entry.getKey()).getName(), entry.getValue()); sorted.clear(); return true;
public static void register(@NonNull ProtocolVersion protocol) { versions.put(protocol.getId(), protocol); versionList.add(protocol); }
default void init(ViaRewindConfig config) { ViaRewind.init(this, config); ProtocolRegistry.registerProtocol(new Protocol1_8TO1_9(), Collections.singletonList(ProtocolVersion.v1_8.getId()), ProtocolVersion.v1_9.getId()); ProtocolRegistry.registerProtocol(new Protocol1_7_6_10TO1_8(), Collections.singletonList(ProtocolVersion.v1_7_6.getId()), ProtocolVersion.v1_8.getId()); ProtocolRegistry.registerProtocol(new Protocol1_7_0_5to1_7_6_10(), Collections.singletonList(ProtocolVersion.v1_7_1.getId()), ProtocolVersion.v1_7_6.getId()); }
/** * Initialize ViaBackwards */ default void init() { ViaBackwards.init(this); if (!isOutdated()) { ProtocolRegistry.registerProtocol(new Protocol1_9_4To1_10(), Collections.singletonList(ProtocolVersion.v1_9_3.getId()), ProtocolVersion.v1_10.getId()); ProtocolRegistry.registerProtocol(new Protocol1_10To1_11(), Collections.singletonList(ProtocolVersion.v1_10.getId()), ProtocolVersion.v1_11.getId()); ProtocolRegistry.registerProtocol(new Protocol1_11To1_11_1(), Collections.singletonList(ProtocolVersion.v1_11.getId()), ProtocolVersion.v1_11_1.getId()); ProtocolRegistry.registerProtocol(new Protocol1_11_1To1_12(), Collections.singletonList(ProtocolVersion.v1_11_1.getId()), ProtocolVersion.v1_12.getId()); ProtocolRegistry.registerProtocol(new Protocol1_12To1_12_1(), Collections.singletonList(ProtocolVersion.v1_12.getId()), ProtocolVersion.v1_12_1.getId()); ProtocolRegistry.registerProtocol(new Protocol1_12_1To1_12_2(), Collections.singletonList(ProtocolVersion.v1_12_1.getId()), ProtocolVersion.v1_12_2.getId()); } }
private void sendPacket(UUID uuid, PacketWrapper wrapper) { if (!Via.getAPI().isPorted(uuid) || !(Via.getAPI().getPlayerVersion(uuid) >= ProtocolVersion.v1_9.getId())) { players.remove(uuid); return; } try { wrapper.send(Protocol1_9TO1_8.class); } catch (Exception e) { e.printStackTrace(); } }
this.windowClickPacketClass = NMSUtil.nms("PacketPlayInWindowClick"); int protocolId = ProtocolRegistry.SERVER_PROTOCOL; if (protocolId >= ProtocolVersion.v1_9.getId()) { Class<?> eclassz = NMSUtil.nms("InventoryClickType"); Object[] constants = eclassz.getEnumConstants();
public static Integer getProtocolId(String serverName) { // Step 1. Check Config Map<String, Integer> servers = ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols(); Integer protocol = servers.get(serverName); if (protocol != null) { return protocol; } // Step 2. Check Detected Integer detectedProtocol = detectedProtocolIds.get(serverName); if (detectedProtocol != null) { return detectedProtocol; } // Step 3. Use Default Integer defaultProtocol = servers.get("default"); if (defaultProtocol != null) { return defaultProtocol; } // Step 4: Use bungee lowest supported... *cries* try { return Via.getManager().getInjector().getServerProtocolVersion(); } catch (Exception e) { e.printStackTrace(); return ProtocolVersion.v1_8.getId(); } }
int protocolId = ProtocolRegistry.SERVER_PROTOCOL; if (protocolId == ProtocolVersion.v1_8.getId()) { return false;
if (protocolId == ProtocolVersion.v1_8.getId()) { if (tinvtype == InventoryType.BREWING) { ReflectionUtil.set(packet, "item", nmsItem); int protocolId = ProtocolRegistry.SERVER_PROTOCOL; if (protocolId == ProtocolVersion.v1_8.getId()) { ReflectionUtil.set(packet, "shift", 1); } else if (protocolId >= ProtocolVersion.v1_9.getId()) { // 1.9+ ReflectionUtil.set(packet, "shift", clickTypeEnum);