Minor ProtocolVersion refactor

This commit is contained in:
KennyTV 2020-10-16 18:21:45 +02:00
parent 6cb2837d77
commit 7d96efc645
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
19 changed files with 148 additions and 166 deletions

View File

@ -51,7 +51,7 @@ public class PlayerSneakListener extends ViaBukkitListener {
// From 1.9 upwards the server hitbox is set in every entity tick, so we have to reset it everytime
if (ProtocolRegistry.SERVER_PROTOCOL >= ProtocolVersion.v1_9.getId()) {
if (ProtocolRegistry.SERVER_PROTOCOL >= ProtocolVersion.v1_9.getVersion()) {
sneaking = new WeakHashMap<>();
useCache = true;
plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {
@ -79,7 +79,7 @@ public class PlayerSneakListener extends ViaBukkitListener {
if (info == null) return;
int protocolVersion = info.getProtocolVersion();
if (is1_14Fix && protocolVersion >= ProtocolVersion.v1_14.getId()) {
if (is1_14Fix && protocolVersion >= ProtocolVersion.v1_14.getVersion()) {
setHeight(player, event.isSneaking() ? HEIGHT_1_14 : STANDING_HEIGHT);
if (event.isSneaking())
sneakingUuids.add(player.getUniqueId());
@ -91,7 +91,7 @@ public class PlayerSneakListener extends ViaBukkitListener {
sneaking.put(player, true);
else
sneaking.remove(player);
} else if (is1_9Fix && protocolVersion >= ProtocolVersion.v1_9.getId()) {
} else if (is1_9Fix && protocolVersion >= ProtocolVersion.v1_9.getVersion()) {
setHeight(player, event.isSneaking() ? HEIGHT_1_9 : STANDING_HEIGHT);
if (!useCache) return;
if (event.isSneaking())

View File

@ -25,7 +25,6 @@ import us.myles.ViaVersion.bukkit.providers.BukkitBlockConnectionProvider;
import us.myles.ViaVersion.bukkit.providers.BukkitInventoryQuickMoveProvider;
import us.myles.ViaVersion.bukkit.providers.BukkitViaBulkChunkTranslator;
import us.myles.ViaVersion.bukkit.providers.BukkitViaMovementTransmitter;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider;
@ -72,7 +71,7 @@ public class BukkitViaLoader implements ViaPlatformLoader {
ClassGenerator.registerPSConnectListener(plugin);
/* 1.9 client to 1.8 server */
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) {
storeListener(new ArmorListener(plugin)).register();
storeListener(new DeathListener(plugin)).register();
storeListener(new BlockListener(plugin)).register();
@ -83,8 +82,8 @@ public class BukkitViaLoader implements ViaPlatformLoader {
}
}
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_14.getId()) {
boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId();
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_14.getVersion()) {
boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion();
if (use1_9Fix || plugin.getConf().is1_14HitboxFix()) {
try {
storeListener(new PlayerSneakListener(plugin, use1_9Fix, plugin.getConf().is1_14HitboxFix())).register();
@ -95,7 +94,7 @@ public class BukkitViaLoader implements ViaPlatformLoader {
}
}
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_15.getId()) {
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_15.getVersion()) {
try {
Class.forName("org.bukkit.event.entity.EntityToggleGlideEvent");
storeListener(new EntityToggleGlideListener(plugin)).register();
@ -106,13 +105,13 @@ public class BukkitViaLoader implements ViaPlatformLoader {
if ((Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("paper")
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("taco")
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("torch"))
&& ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_12.getId()) {
&& ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_12.getVersion()) {
plugin.getLogger().info("Enabling Paper/TacoSpigot/Torch patch: Fixes block placement.");
storeListener(new PaperPatch(plugin)).register();
}
/* Providers */
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) {
Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new BukkitViaBulkChunkTranslator());
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BukkitViaMovementTransmitter());
@ -141,12 +140,12 @@ public class BukkitViaLoader implements ViaPlatformLoader {
});
}
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_12.getId()) {
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_12.getVersion()) {
if (plugin.getConf().is1_12QuickMoveActionFix()) {
Via.getManager().getProviders().use(InventoryQuickMoveProvider.class, new BukkitInventoryQuickMoveProvider());
}
}
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_13.getId()) {
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_13.getVersion()) {
if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("world")) {
BukkitBlockConnectionProvider blockConnectionProvider = new BukkitBlockConnectionProvider();
Via.getManager().getProviders().use(BlockConnectionProvider.class, blockConnectionProvider);

View File

@ -58,7 +58,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
if (slotId >= 36 && slotId <= 44) {
int protocolId = ProtocolRegistry.SERVER_PROTOCOL;
// this seems to be working just fine.
if (protocolId == ProtocolVersion.v1_8.getId()) {
if (protocolId == ProtocolVersion.v1_8.getVersion()) {
return false;
}
}
@ -89,7 +89,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
InventoryType tinvtype = tinv == null ? null : tinv.getType(); // can this even be null?
if (tinvtype != null) {
int protocolId = ProtocolRegistry.SERVER_PROTOCOL;
if (protocolId == ProtocolVersion.v1_8.getId()) {
if (protocolId == ProtocolVersion.v1_8.getVersion()) {
if (tinvtype == InventoryType.BREWING) {
// 1.9 added the blaze powder slot to brewing stand fix for 1.8 servers
if (slotId >= 5 && slotId <= 40) {
@ -118,9 +118,9 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
ReflectionUtil.set(packet, "d", storage.getActionId());
ReflectionUtil.set(packet, "item", nmsItem);
int protocolId = ProtocolRegistry.SERVER_PROTOCOL;
if (protocolId == ProtocolVersion.v1_8.getId()) {
if (protocolId == ProtocolVersion.v1_8.getVersion()) {
ReflectionUtil.set(packet, "shift", 1);
} else if (protocolId >= ProtocolVersion.v1_9.getId()) { // 1.9+
} else if (protocolId >= ProtocolVersion.v1_9.getVersion()) { // 1.9+
ReflectionUtil.set(packet, "shift", clickTypeEnum);
}
} catch (Exception e) {
@ -157,7 +157,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
try {
this.windowClickPacketClass = NMSUtil.nms("PacketPlayInWindowClick");
int protocolId = ProtocolRegistry.SERVER_PROTOCOL;
if (protocolId >= ProtocolVersion.v1_9.getId()) {
if (protocolId >= ProtocolVersion.v1_9.getVersion()) {
Class<?> eclassz = NMSUtil.nms("InventoryClickType");
Object[] constants = eclassz.getEnumConstants();
this.clickTypeEnum = constants[1]; // QUICK_MOVE
@ -186,7 +186,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
private boolean isSupported() {
int protocolId = ProtocolRegistry.SERVER_PROTOCOL;
if (protocolId >= ProtocolVersion.v1_8.getId() && protocolId <= ProtocolVersion.v1_11_1.getId()) {
if (protocolId >= ProtocolVersion.v1_8.getVersion() && protocolId <= ProtocolVersion.v1_11_1.getVersion()) {
return true; // 1.8-1.11.2
}
// this is not needed on 1.12+ servers

View File

@ -7,7 +7,6 @@ import net.md_5.bungee.api.event.ServerSwitchEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.score.Team;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
import net.md_5.bungee.protocol.packet.PluginMessage;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Pair;
@ -140,7 +139,7 @@ public class BungeeServerHandler implements Listener {
int protocolId = ProtocolDetectorService.getProtocolId(serverName);
if (protocolId <= ProtocolVersion.v1_8.getId()) { // 1.8 doesn't have BossBar packet
if (protocolId <= ProtocolVersion.v1_8.getVersion()) { // 1.8 doesn't have BossBar packet
if (storage.getBossbar() != null) {
// TODO: Verify whether this packet needs to be sent when 1.8 -> 1.9 protocol isn't present in the pipeline
// This ensures we can encode it properly as only the 1.9 protocol is currently implemented.
@ -182,7 +181,7 @@ public class BungeeServerHandler implements Listener {
for (Object message : (List) relayMessages) {
PluginMessage plMsg = (PluginMessage) message;
String channel = plMsg.getTag();
int id1_13 = ProtocolVersion.v1_13.getId();
int id1_13 = ProtocolVersion.v1_13.getVersion();
if (previousServerProtocol != -1) {
String oldChannel = channel;
if (previousServerProtocol < id1_13 && protocolId >= id1_13) {

View File

@ -47,7 +47,7 @@ public class BungeeViaConfig extends AbstractViaConfig {
if (entry.getValue() instanceof String) {
ProtocolVersion found = ProtocolVersion.getClosest((String) entry.getValue());
if (found != null) {
servers.put(entry.getKey(), found.getId());
servers.put(entry.getKey(), found.getVersion());
} else {
servers.remove(entry.getKey()); // Remove!
}

View File

@ -45,7 +45,7 @@ public class BungeeViaLoader implements ViaPlatformLoader {
registerListener(new UpdateListener());
registerListener(new BungeeServerHandler());
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) {
registerListener(new ElytraPatch());
}
@ -53,7 +53,7 @@ public class BungeeViaLoader implements ViaPlatformLoader {
Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider());
Via.getManager().getProviders().use(EntityIdProvider.class, new BungeeEntityIdProvider());
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) {
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
Via.getManager().getProviders().use(BossBarProvider.class, new BungeeBossBarProvider());
Via.getManager().getProviders().use(MainHandProvider.class, new BungeeMainHandProvider());

View File

@ -83,7 +83,7 @@ public class ViaManager {
public void onServerLoaded() {
// Load Server Protocol
try {
ProtocolRegistry.SERVER_PROTOCOL = ProtocolVersion.getProtocol(injector.getServerProtocolVersion()).getId();
ProtocolRegistry.SERVER_PROTOCOL = ProtocolVersion.getProtocol(injector.getServerProtocolVersion()).getVersion();
} catch (Exception e) {
platform.getLogger().severe("ViaVersion failed to get the server protocol!");
e.printStackTrace();
@ -97,7 +97,7 @@ public class ViaManager {
platform.getLogger().warning("If you need support for older versions you may need to use one or more ViaVersion addons too.");
platform.getLogger().warning("In that case please read the ViaVersion resource page carefully or use https://jo0001.github.io/ViaSetup");
platform.getLogger().warning("and if you're still unsure, feel free to join our Discord-Server for further assistance.");
} else if (ProtocolRegistry.SERVER_PROTOCOL == ProtocolVersion.v1_8.getId() && !platform.isProxy()) {
} else if (ProtocolRegistry.SERVER_PROTOCOL == ProtocolVersion.v1_8.getVersion() && !platform.isProxy()) {
platform.getLogger().warning("This version of Minecraft is over half a decade old and support for it will be fully dropped eventually. "
+ "Please upgrade to a newer version to avoid encountering bugs and stability issues that have long been fixed.");
}
@ -114,12 +114,12 @@ public class ViaManager {
mappingLoadingTask = null;
}
}, 10L);
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) {
if (Via.getConfig().isSimulatePlayerTick()) {
Via.getPlatform().runRepeatingSync(new ViaIdleThread(), 1L);
}
}
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_13.getId()) {
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_13.getVersion()) {
if (Via.getConfig().get1_13TabCompleteDelay() > 0) {
Via.getPlatform().runRepeatingSync(new TabCompleteThread(), 1L);
}

View File

@ -81,15 +81,15 @@ public class ProtocolRegistry {
// Base Protocol
registerBaseProtocol(BASE_PROTOCOL, Range.lessThan(Integer.MIN_VALUE));
registerBaseProtocol(new BaseProtocol1_7(), Range.lessThan(ProtocolVersion.v1_16.getId()));
registerBaseProtocol(new BaseProtocol1_16(), Range.atLeast(ProtocolVersion.v1_16.getId()));
registerBaseProtocol(new BaseProtocol1_7(), Range.lessThan(ProtocolVersion.v1_16.getVersion()));
registerBaseProtocol(new BaseProtocol1_16(), Range.atLeast(ProtocolVersion.v1_16.getVersion()));
registerProtocol(new Protocol1_9To1_8(), ProtocolVersion.v1_9, ProtocolVersion.v1_8);
registerProtocol(new Protocol1_9_1To1_9(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9.getId());
registerProtocol(new Protocol1_9_1To1_9(), Arrays.asList(ProtocolVersion.v1_9_1.getVersion(), ProtocolVersion.v1_9_2.getVersion()), ProtocolVersion.v1_9.getVersion());
registerProtocol(new Protocol1_9_3To1_9_1_2(), ProtocolVersion.v1_9_3, ProtocolVersion.v1_9_2);
registerProtocol(new Protocol1_9To1_9_1(), ProtocolVersion.v1_9, ProtocolVersion.v1_9_2);
registerProtocol(new Protocol1_9_1_2To1_9_3_4(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9_3.getId());
registerProtocol(new Protocol1_9_1_2To1_9_3_4(), Arrays.asList(ProtocolVersion.v1_9_1.getVersion(), ProtocolVersion.v1_9_2.getVersion()), ProtocolVersion.v1_9_3.getVersion());
registerProtocol(new Protocol1_10To1_9_3_4(), ProtocolVersion.v1_10, ProtocolVersion.v1_9_3);
registerProtocol(new Protocol1_11To1_10(), ProtocolVersion.v1_11, ProtocolVersion.v1_10);
@ -132,7 +132,7 @@ public class ProtocolRegistry {
* @param output The output server version it converts to.
*/
public static void registerProtocol(Protocol protocol, ProtocolVersion supported, ProtocolVersion output) {
registerProtocol(protocol, Collections.singletonList(supported.getId()), output.getId());
registerProtocol(protocol, Collections.singletonList(supported.getVersion()), output.getVersion());
}
/**
@ -196,9 +196,9 @@ public class ProtocolRegistry {
supportedVersions.add(ProtocolRegistry.SERVER_PROTOCOL);
for (ProtocolVersion versions : ProtocolVersion.getProtocols()) {
List<Pair<Integer, Protocol>> paths = getProtocolPath(versions.getId(), ProtocolRegistry.SERVER_PROTOCOL);
List<Pair<Integer, Protocol>> paths = getProtocolPath(versions.getVersion(), ProtocolRegistry.SERVER_PROTOCOL);
if (paths == null) continue;
supportedVersions.add(versions.getId());
supportedVersions.add(versions.getVersion());
for (Pair<Integer, Protocol> path : paths) {
supportedVersions.add(path.getKey());
}

View File

@ -3,6 +3,7 @@ package us.myles.ViaVersion.api.protocol;
import com.google.common.base.Preconditions;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
@ -12,101 +13,65 @@ public class ProtocolVersion {
private static final Int2ObjectMap<ProtocolVersion> versions = new Int2ObjectOpenHashMap<>();
private static final List<ProtocolVersion> versionList = new ArrayList<>();
public static final ProtocolVersion v1_4_6;
public static final ProtocolVersion v1_5_1;
public static final ProtocolVersion v1_5_2;
public static final ProtocolVersion v_1_6_1;
public static final ProtocolVersion v_1_6_2;
public static final ProtocolVersion v_1_6_3;
public static final ProtocolVersion v_1_6_4;
public static final ProtocolVersion v1_7_1;
public static final ProtocolVersion v1_7_6;
public static final ProtocolVersion v1_8;
public static final ProtocolVersion v1_9;
public static final ProtocolVersion v1_9_1;
public static final ProtocolVersion v1_9_2;
public static final ProtocolVersion v1_9_3;
public static final ProtocolVersion v1_10;
public static final ProtocolVersion v1_11;
public static final ProtocolVersion v1_11_1;
public static final ProtocolVersion v1_12;
public static final ProtocolVersion v1_12_1;
public static final ProtocolVersion v1_12_2;
public static final ProtocolVersion v1_13;
public static final ProtocolVersion v1_13_1;
public static final ProtocolVersion v1_13_2;
public static final ProtocolVersion v1_14;
public static final ProtocolVersion v1_14_1;
public static final ProtocolVersion v1_14_2;
public static final ProtocolVersion v1_14_3;
public static final ProtocolVersion v1_14_4;
public static final ProtocolVersion v1_15;
public static final ProtocolVersion v1_15_1;
public static final ProtocolVersion v1_15_2;
public static final ProtocolVersion v1_16;
public static final ProtocolVersion v1_16_1;
public static final ProtocolVersion v1_16_2;
public static final ProtocolVersion v1_16_3;
public static final ProtocolVersion v1_16_4;
public static final ProtocolVersion unknown;
// Before the Netty rewrite
public static final ProtocolVersion v1_4_6 = register(51, "1.4.6");
public static final ProtocolVersion v1_5_1 = register(60, "1.5.1");
public static final ProtocolVersion v1_5_2 = register(61, "1.5.2");
public static final ProtocolVersion v_1_6_1 = register(73, "1.6.1");
public static final ProtocolVersion v_1_6_2 = register(74, "1.6.2");
public static final ProtocolVersion v_1_6_3 = register(77, "1.6.3");
public static final ProtocolVersion v_1_6_4 = register(78, "1.6.4");
// After the Netty rewrite
public static final ProtocolVersion v1_7_1 = register(4, "1.7-1.7.5");
public static final ProtocolVersion v1_7_6 = register(5, "1.7.6-1.7.10");
public static final ProtocolVersion v1_8 = register(47, "1.8.x");
public static final ProtocolVersion v1_9 = register(107, "1.9");
public static final ProtocolVersion v1_9_1 = register(108, "1.9.1");
public static final ProtocolVersion v1_9_2 = register(109, "1.9.2");
public static final ProtocolVersion v1_9_3 = register(110, "1.9.3/4");
public static final ProtocolVersion v1_10 = register(210, "1.10");
public static final ProtocolVersion v1_11 = register(315, "1.11");
public static final ProtocolVersion v1_11_1 = register(316, "1.11.1");
public static final ProtocolVersion v1_12 = register(335, "1.12");
public static final ProtocolVersion v1_12_1 = register(338, "1.12.1");
public static final ProtocolVersion v1_12_2 = register(340, "1.12.2");
public static final ProtocolVersion v1_13 = register(393, "1.13");
public static final ProtocolVersion v1_13_1 = register(401, "1.13.1");
public static final ProtocolVersion v1_13_2 = register(404, "1.13.2");
public static final ProtocolVersion v1_14 = register(477, "1.14");
public static final ProtocolVersion v1_14_1 = register(480, "1.14.1");
public static final ProtocolVersion v1_14_2 = register(485, "1.14.2");
public static final ProtocolVersion v1_14_3 = register(490, "1.14.3");
public static final ProtocolVersion v1_14_4 = register(498, "1.14.4");
public static final ProtocolVersion v1_15 = register(573, "1.15");
public static final ProtocolVersion v1_15_1 = register(575, "1.15.1");
public static final ProtocolVersion v1_15_2 = register(578, "1.15.2");
public static final ProtocolVersion v1_16 = register(735, "1.16");
public static final ProtocolVersion v1_16_1 = register(736, "1.16.1");
public static final ProtocolVersion v1_16_2 = register(751, "1.16.2");
public static final ProtocolVersion v1_16_3 = register(753, "1.16.3");
public static final ProtocolVersion v1_16_4 = register(754, 1, "1.16.4");
public static final ProtocolVersion unknown = register(-1, "UNKNOWN");
static {
// Before netty rewrite
register(v1_4_6 = new ProtocolVersion(51, "1.4.6"));
register(v1_5_1 = new ProtocolVersion(60, "1.5.1"));
register(v1_5_2 = new ProtocolVersion(61, "1.5.2"));
register(v_1_6_1 = new ProtocolVersion(73, "1.6.1"));
register(v_1_6_2 = new ProtocolVersion(74, "1.6.2"));
register(v_1_6_3 = new ProtocolVersion(77, "1.6.3"));
register(v_1_6_4 = new ProtocolVersion(78, "1.6.4"));
// After netty rewrite
register(v1_7_1 = new ProtocolVersion(4, "1.7-1.7.5"));
register(v1_7_6 = new ProtocolVersion(5, "1.7.6-1.7.10"));
register(v1_8 = new ProtocolVersion(47, "1.8.x"));
register(v1_9 = new ProtocolVersion(107, "1.9"));
register(v1_9_1 = new ProtocolVersion(108, "1.9.1"));
register(v1_9_2 = new ProtocolVersion(109, "1.9.2"));
register(v1_9_3 = new ProtocolVersion(110, "1.9.3/4"));
register(v1_10 = new ProtocolVersion(210, "1.10"));
register(v1_11 = new ProtocolVersion(315, "1.11"));
register(v1_11_1 = new ProtocolVersion(316, "1.11.1"));
register(v1_12 = new ProtocolVersion(335, "1.12"));
register(v1_12_1 = new ProtocolVersion(338, "1.12.1"));
register(v1_12_2 = new ProtocolVersion(340, "1.12.2"));
register(v1_13 = new ProtocolVersion(393, "1.13"));
register(v1_13_1 = new ProtocolVersion(401, "1.13.1"));
register(v1_13_2 = new ProtocolVersion(404, "1.13.2"));
register(v1_14 = new ProtocolVersion(477, "1.14"));
register(v1_14_1 = new ProtocolVersion(480, "1.14.1"));
register(v1_14_2 = new ProtocolVersion(485, "1.14.2"));
register(v1_14_3 = new ProtocolVersion(490, "1.14.3"));
register(v1_14_4 = new ProtocolVersion(498, "1.14.4"));
register(v1_15 = new ProtocolVersion(573, "1.15"));
register(v1_15_1 = new ProtocolVersion(575, "1.15.1"));
register(v1_15_2 = new ProtocolVersion(578, "1.15.2"));
register(v1_16 = new ProtocolVersion(735, "1.16"));
register(v1_16_1 = new ProtocolVersion(736, "1.16.1"));
register(v1_16_2 = new ProtocolVersion(751, "1.16.2"));
register(v1_16_3 = new ProtocolVersion(753, "1.16.3"));
register(v1_16_4 = new ProtocolVersion(754, 1, "1.16.4"));
register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
public static ProtocolVersion register(int version, String name) {
return register(version, -1, name);
}
public static void register(ProtocolVersion protocol) {
Preconditions.checkNotNull(protocol);
versions.put(protocol.id, protocol);
if (protocol.isSnapshot()) {
versions.put(protocol.getFullSnapshotId(), protocol);
}
public static ProtocolVersion register(int version, int snapshotVersion, String name) {
ProtocolVersion protocol = new ProtocolVersion(version, snapshotVersion, name);
versionList.add(protocol);
versions.put(protocol.version, protocol);
if (protocol.isSnapshot()) {
versions.put(protocol.getFullSnapshotVersion(), protocol);
}
return protocol;
}
public static boolean isRegistered(int id) {
return versions.containsKey(id);
}
@NotNull
public static ProtocolVersion getProtocol(int id) {
ProtocolVersion protocolVersion = versions.get(id);
if (protocolVersion != null) {
@ -143,40 +108,61 @@ public class ProtocolVersion {
return null;
}
private final int id;
private final int snapshotId;
private final int version;
private final int snapshotVersion;
private final String name;
public ProtocolVersion(int id, String name) {
this(id, -1, name);
public ProtocolVersion(int version, String name) {
this(version, -1, name);
}
public ProtocolVersion(int id, int snapshotId, String name) {
this.id = id;
this.snapshotId = snapshotId;
public ProtocolVersion(int version, int snapshotVersion, String name) {
this.version = version;
this.snapshotVersion = snapshotVersion;
this.name = name;
}
/**
* @return release version
*/
public int getVersion() {
return version;
}
/**
* @return snapshot protocol version without the snapshot indicator bit
* @throws IllegalArgumentException if the version if not a snapshot version
* @see #isSnapshot()
*/
public int getSnapshotVersion() {
Preconditions.checkArgument(isSnapshot());
return snapshotVersion;
}
/**
* @return snapshot protocol version with the snapshot indicator bit
* @throws IllegalArgumentException if the version if not a snapshot version
* @see #isSnapshot()
*/
public int getFullSnapshotVersion() {
Preconditions.checkArgument(isSnapshot());
return (1 << 30) | snapshotVersion; // Bit indicating snapshot versions
}
/**
* @return release version if release, snapshot version (with the snapshot indicator bit) if snapshot
*/
public int getOriginalVersion() {
return snapshotVersion == -1 ? version : ((1 << 30) | snapshotVersion);
}
/**
* @return release version
* @deprecated ambiguous, see {@link #getOriginalVersion()} ()}, {@link #getVersion()} ()}, and {@link #getSnapshotVersion()}
*/
@Deprecated
public int getId() {
return id;
}
public int getOriginalId() {
return snapshotId == -1 ? id : ((1 << 30) | snapshotId);
}
/**
* @return snapshot protocol version without the snapshot indicator bit, -1 if not a snapshot
*/
public int getSnapshotId() {
return snapshotId;
}
/**
* @return snapshot protocol version with the hight bit indicating its snapshot status, -1 if not a snapshot
*/
public int getFullSnapshotId() {
return id == -1 ? -1 : (1 << 30) | snapshotId; // Bit indicating snapshot versions
return version;
}
public String getName() {
@ -184,7 +170,7 @@ public class ProtocolVersion {
}
public boolean isSnapshot() {
return snapshotId != -1;
return snapshotVersion != -1;
}
public boolean isRange() {
@ -197,16 +183,16 @@ public class ProtocolVersion {
if (o == null || getClass() != o.getClass()) return false;
ProtocolVersion that = (ProtocolVersion) o;
return id == that.id;
return version == that.version;
}
@Override
public int hashCode() {
return id;
return version;
}
@Override
public String toString() {
return String.format("%s(%d)", this.name, this.id);
return String.format("%s(%d)", this.name, this.version);
}
}

View File

@ -61,7 +61,7 @@ public class BaseProtocol extends SimpleProtocol {
// Set the original snapshot version if present
ProtocolVersion protocol = ProtocolVersion.getProtocol(serverProtocol);
wrapper.set(Type.VAR_INT, 0, protocol.getOriginalId());
wrapper.set(Type.VAR_INT, 0, protocol.getOriginalVersion());
}
// Add Base Protocol

View File

@ -65,7 +65,7 @@ public class BaseProtocol1_7 extends SimpleProtocol {
}
if (ProtocolRegistry.SERVER_PROTOCOL == -1) { // Set the Server protocol if the detection on startup failed
ProtocolRegistry.SERVER_PROTOCOL = ProtocolVersion.getProtocol(protocolVersion).getId();
ProtocolRegistry.SERVER_PROTOCOL = ProtocolVersion.getProtocol(protocolVersion).getVersion();
}
// Ensure the server has a version provider
@ -86,7 +86,7 @@ public class BaseProtocol1_7 extends SimpleProtocol {
if (protocols != null) {
if (protocolVersion == protocol || protocolVersion == 0) { // Fix ServerListPlus
ProtocolVersion prot = ProtocolVersion.getProtocol(info.getProtocolVersion());
version.addProperty("protocol", prot.getOriginalId());
version.addProperty("protocol", prot.getOriginalVersion());
}
} else {
// not compatible :(, *plays very sad violin*

View File

@ -35,7 +35,7 @@ public class ProtocolInfo extends StoredObject {
public void setProtocolVersion(int protocolVersion) {
// Map snapshot versions to the higher/orderer release version
ProtocolVersion protocol = ProtocolVersion.getProtocol(protocolVersion);
this.protocolVersion = protocol.getId();
this.protocolVersion = protocol.getVersion();
}
public int getServerProtocolVersion() {
@ -44,7 +44,7 @@ public class ProtocolInfo extends StoredObject {
public void setServerProtocolVersion(int serverProtocolVersion) {
ProtocolVersion protocol = ProtocolVersion.getProtocol(serverProtocolVersion);
this.serverProtocolVersion = protocol.getId();
this.serverProtocolVersion = protocol.getVersion();
}
public String getUsername() {

View File

@ -4,7 +4,6 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.BlockFace;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import java.util.HashMap;
import java.util.HashSet;
@ -44,7 +43,7 @@ public abstract class AbstractFenceConnectionHandler extends ConnectionHandler {
protected byte getStates(UserConnection user, Position position, int blockState) {
byte states = 0;
boolean pre1_12 = user.getProtocolInfo().getServerProtocolVersion() < ProtocolVersion.v1_12.getId();
boolean pre1_12 = user.getProtocolInfo().getServerProtocolVersion() < ProtocolVersion.v1_12.getVersion();
if (connects(BlockFace.EAST, getBlockData(user, position.getRelative(BlockFace.EAST)), pre1_12)) states |= 1;
if (connects(BlockFace.NORTH, getBlockData(user, position.getRelative(BlockFace.NORTH)), pre1_12)) states |= 2;
if (connects(BlockFace.SOUTH, getBlockData(user, position.getRelative(BlockFace.SOUTH)), pre1_12)) states |= 4;

View File

@ -9,7 +9,6 @@ import us.myles.ViaVersion.api.platform.TaskId;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
@ -51,7 +50,7 @@ public class SpongeViaLoader implements ViaPlatformLoader {
registerListener(new UpdateListener());
/* 1.9 client to 1.8 server */
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) {
try {
Class.forName("org.spongepowered.api.event.entity.DisplaceEntityEvent");
storeListener(new Sponge4ArmorListener()).register();
@ -68,7 +67,7 @@ public class SpongeViaLoader implements ViaPlatformLoader {
}
/* Providers */
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) {
Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new SpongeViaBulkChunkTranslator());
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new SpongeViaMovementTransmitter());

View File

@ -46,7 +46,7 @@ public class VelocityViaConfig extends AbstractViaConfig {
if (entry.getValue() instanceof String) {
ProtocolVersion found = ProtocolVersion.getClosest((String) entry.getValue());
if (found != null) {
servers.put(entry.getKey(), found.getId());
servers.put(entry.getKey(), found.getVersion());
} else {
servers.remove(entry.getKey()); // Remove!
}

View File

@ -54,7 +54,7 @@ public class VelocityViaInjector implements ViaInjector {
try {
if (getPlayerInfoForwardingMode != null
&& ((Enum<?>) getPlayerInfoForwardingMode.invoke(VelocityPlugin.PROXY.getConfiguration()))
.name().equals("MODERN")) return ProtocolVersion.v1_13.getId();
.name().equals("MODERN")) return ProtocolVersion.v1_13.getVersion();
} catch (IllegalAccessException | InvocationTargetException ignored) {
}
return com.velocitypowered.api.network.ProtocolVersion.MINIMUM_VERSION.getProtocol();

View File

@ -23,7 +23,7 @@ public class VelocityViaLoader implements ViaPlatformLoader {
Object plugin = VelocityPlugin.PROXY.getPluginManager()
.getPlugin("viaversion").flatMap(PluginContainer::getInstance).get();
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) {
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new VelocityMovementTransmitter());
Via.getManager().getProviders().use(BossBarProvider.class, new VelocityBossBarProvider());
VelocityPlugin.PROXY.getEventManager().register(plugin, new ElytraPatch());

View File

@ -23,7 +23,7 @@ public class VelocityVersionProvider extends VersionProvider {
if (VelocityViaInjector.getPlayerInfoForwardingMode != null
&& ((Enum<?>) VelocityViaInjector.getPlayerInfoForwardingMode.invoke(VelocityPlugin.PROXY.getConfiguration()))
.name().equals("MODERN")) {
versions = versions.filter(ver -> ver >= ProtocolVersion.v1_13.getId());
versions = versions.filter(ver -> ver >= ProtocolVersion.v1_13.getVersion());
}
int[] compatibleProtocols = versions.toArray();

View File

@ -37,10 +37,10 @@ public class ProtocolDetectorService implements Runnable {
}
// Step 4: Use bungee lowest supported... *cries*
try {
return ProtocolVersion.getProtocol(Via.getManager().getInjector().getServerProtocolVersion()).getId();
return ProtocolVersion.getProtocol(Via.getManager().getInjector().getServerProtocolVersion()).getVersion();
} catch (Exception e) {
e.printStackTrace();
return ProtocolVersion.v1_8.getId();
return ProtocolVersion.v1_8.getVersion();
}
}