Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Improve server version API
Dieser Commit ist enthalten in:
Ursprung
d918fd27b6
Commit
a63f2ab6fe
@ -26,6 +26,7 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import us.myles.ViaVersion.api.boss.BossBar;
|
import us.myles.ViaVersion.api.boss.BossBar;
|
||||||
import us.myles.ViaVersion.api.boss.BossColor;
|
import us.myles.ViaVersion.api.boss.BossColor;
|
||||||
import us.myles.ViaVersion.api.boss.BossStyle;
|
import us.myles.ViaVersion.api.boss.BossStyle;
|
||||||
|
import us.myles.ViaVersion.api.protocol.ServerProtocolVersion;
|
||||||
|
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -38,12 +39,11 @@ import java.util.UUID;
|
|||||||
public interface ViaAPI<T> {
|
public interface ViaAPI<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the server's protocol version.
|
* Returns the server's protocol version info.
|
||||||
* In the case of a proxy, this is the lowest supported version.
|
|
||||||
*
|
*
|
||||||
* @return the server's protocol version
|
* @return the server's protocol version info
|
||||||
*/
|
*/
|
||||||
int getServerVersion();
|
ServerProtocolVersion getServerVersion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get protocol version number from a player.
|
* Get protocol version number from a player.
|
||||||
|
@ -23,8 +23,11 @@
|
|||||||
package us.myles.ViaVersion.api.platform;
|
package us.myles.ViaVersion.api.platform;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSortedSets;
|
||||||
|
|
||||||
public interface ViaInjector {
|
public interface ViaInjector {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inject into the current Platform
|
* Inject into the current Platform
|
||||||
*
|
*
|
||||||
@ -40,13 +43,36 @@ public interface ViaInjector {
|
|||||||
void uninject() throws Exception;
|
void uninject() throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the server protocol version
|
* Returns true if the protocol version cannot be used in the early init.
|
||||||
|
* Namely, this returns true for forks of Vanilla without extra API to get the protocol version.
|
||||||
*
|
*
|
||||||
* @return The server protocol integer
|
* @return true if the protocol version cannot be used in the early init
|
||||||
* @throws Exception If there is an error with getting this info, eg. not binded.
|
*/
|
||||||
|
default boolean lateProtocolVersionSetting() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the server protocol version.
|
||||||
|
* For proxies, this returns the lowest supported protocol version.
|
||||||
|
*
|
||||||
|
* @return server protocol version
|
||||||
|
* @throws Exception if there is an error with getting this info, eg. not binded
|
||||||
|
* @see ViaPlatform#isProxy()
|
||||||
*/
|
*/
|
||||||
int getServerProtocolVersion() throws Exception;
|
int getServerProtocolVersion() throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the supported server protocol versions.
|
||||||
|
*
|
||||||
|
* @return server protocol versions
|
||||||
|
* @throws Exception if there is an error with getting this info, eg. not binded
|
||||||
|
* @see ViaPlatform#isProxy()
|
||||||
|
*/
|
||||||
|
default IntSortedSet getServerProtocolVersions() throws Exception {
|
||||||
|
return IntSortedSets.singleton(getServerProtocolVersion());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the encoder for then netty pipeline for this platform.
|
* Get the name of the encoder for then netty pipeline for this platform.
|
||||||
*
|
*
|
||||||
|
@ -32,12 +32,11 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
public interface ProtocolManager {
|
public interface ProtocolManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the server protocol version, or -1 if not set.
|
* Returns the server protocol version. Its methods will return -1 if not set yet.
|
||||||
* In the case of proxies, this returns the lowest supported protocol version.
|
|
||||||
*
|
*
|
||||||
* @return server protocol version, or -1 if not set
|
* @return server protocol version
|
||||||
*/
|
*/
|
||||||
int getServerProtocol();
|
ServerProtocolVersion getServerProtocolVersion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a protocol instance by its class.
|
* Returns a protocol instance by its class.
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2021 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package us.myles.ViaVersion.api.protocol;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
||||||
|
|
||||||
|
public interface ServerProtocolVersion {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the lowest supported protocol version by this server.
|
||||||
|
* This and {@link #highestSupportedVersion()} should only differ on proxy servers supporting multiple versions.
|
||||||
|
*
|
||||||
|
* @return lowest supported protocol version
|
||||||
|
*/
|
||||||
|
int lowestSupportedVersion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the lowest supported protocol version by this server.
|
||||||
|
* This and {@link #lowestSupportedVersion()} should only differ on proxy servers supporting multiple versions.
|
||||||
|
*
|
||||||
|
* @return highest supported protocol version
|
||||||
|
*/
|
||||||
|
int highestSupportedVersion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a sorted set of all supported protocol version by this server.
|
||||||
|
* For non-proxy servers, this should return a singleton set.
|
||||||
|
*
|
||||||
|
* @return sorted set of supported protocol versions
|
||||||
|
*/
|
||||||
|
IntSortedSet supportedVersions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the actual protocol version has not yet been identified.
|
||||||
|
* In that case, all methods above will returns -1.
|
||||||
|
*
|
||||||
|
* @return true if unset
|
||||||
|
*/
|
||||||
|
default boolean isKnown() {
|
||||||
|
return lowestSupportedVersion() != -1 && highestSupportedVersion() != -1;
|
||||||
|
}
|
||||||
|
}
|
@ -27,5 +27,11 @@ import us.myles.ViaVersion.api.platform.providers.Provider;
|
|||||||
|
|
||||||
public interface VersionProvider extends Provider {
|
public interface VersionProvider extends Provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the closest server protocol version to the user's protocol version.
|
||||||
|
*
|
||||||
|
* @param connection connection
|
||||||
|
* @return closest server protocol version to the user's protocol version
|
||||||
|
*/
|
||||||
int getServerProtocol(UserConnection connection) throws Exception;
|
int getServerProtocol(UserConnection connection) throws Exception;
|
||||||
}
|
}
|
||||||
|
@ -70,8 +70,6 @@ private fun ShadowJar.configureExcludes() {
|
|||||||
exclude("it/unimi/dsi/fastutil/*/*Char*")
|
exclude("it/unimi/dsi/fastutil/*/*Char*")
|
||||||
// Map types
|
// Map types
|
||||||
exclude("it/unimi/dsi/fastutil/*/*Custom*")
|
exclude("it/unimi/dsi/fastutil/*/*Custom*")
|
||||||
exclude("it/unimi/dsi/fastutil/*/*Linked*")
|
|
||||||
exclude("it/unimi/dsi/fastutil/*/*Sorted*")
|
|
||||||
exclude("it/unimi/dsi/fastutil/*/*Tree*")
|
exclude("it/unimi/dsi/fastutil/*/*Tree*")
|
||||||
exclude("it/unimi/dsi/fastutil/*/*Heap*")
|
exclude("it/unimi/dsi/fastutil/*/*Heap*")
|
||||||
exclude("it/unimi/dsi/fastutil/*/*Queue*")
|
exclude("it/unimi/dsi/fastutil/*/*Queue*")
|
||||||
|
@ -68,7 +68,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
|
// From 1.9 upwards the server hitbox is set in every entity tick, so we have to reset it everytime
|
||||||
if (Via.getAPI().getServerVersion() >= ProtocolVersion.v1_9.getVersion()) {
|
if (Via.getAPI().getServerVersion().lowestSupportedVersion() >= ProtocolVersion.v1_9.getVersion()) {
|
||||||
sneaking = new WeakHashMap<>();
|
sneaking = new WeakHashMap<>();
|
||||||
useCache = true;
|
useCache = true;
|
||||||
plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {
|
plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {
|
||||||
|
@ -179,6 +179,11 @@ public class BukkitViaInjector implements ViaInjector {
|
|||||||
injectedLists.clear();
|
injectedLists.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean lateProtocolVersionSetting() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getServerProtocolVersion() throws Exception {
|
public int getServerProtocolVersion() throws Exception {
|
||||||
try {
|
try {
|
||||||
|
@ -85,9 +85,10 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
|||||||
|
|
||||||
// Add ProtocolSupport ConnectListener if necessary.
|
// Add ProtocolSupport ConnectListener if necessary.
|
||||||
ClassGenerator.registerPSConnectListener(plugin);
|
ClassGenerator.registerPSConnectListener(plugin);
|
||||||
|
int serverProtocolVersion = Via.getAPI().getServerVersion().lowestSupportedVersion();
|
||||||
|
|
||||||
/* 1.9 client to 1.8 server */
|
/* 1.9 client to 1.8 server */
|
||||||
if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_9.getVersion()) {
|
if (serverProtocolVersion < ProtocolVersion.v1_9.getVersion()) {
|
||||||
storeListener(new ArmorListener(plugin)).register();
|
storeListener(new ArmorListener(plugin)).register();
|
||||||
storeListener(new DeathListener(plugin)).register();
|
storeListener(new DeathListener(plugin)).register();
|
||||||
storeListener(new BlockListener(plugin)).register();
|
storeListener(new BlockListener(plugin)).register();
|
||||||
@ -98,8 +99,8 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_14.getVersion()) {
|
if (serverProtocolVersion < ProtocolVersion.v1_14.getVersion()) {
|
||||||
boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && Via.getAPI().getServerVersion() < ProtocolVersion.v1_9.getVersion();
|
boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && serverProtocolVersion < ProtocolVersion.v1_9.getVersion();
|
||||||
if (use1_9Fix || plugin.getConf().is1_14HitboxFix()) {
|
if (use1_9Fix || plugin.getConf().is1_14HitboxFix()) {
|
||||||
try {
|
try {
|
||||||
storeListener(new PlayerSneakListener(plugin, use1_9Fix, plugin.getConf().is1_14HitboxFix())).register();
|
storeListener(new PlayerSneakListener(plugin, use1_9Fix, plugin.getConf().is1_14HitboxFix())).register();
|
||||||
@ -110,7 +111,7 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_15.getVersion()) {
|
if (serverProtocolVersion < ProtocolVersion.v1_15.getVersion()) {
|
||||||
try {
|
try {
|
||||||
Class.forName("org.bukkit.event.entity.EntityToggleGlideEvent");
|
Class.forName("org.bukkit.event.entity.EntityToggleGlideEvent");
|
||||||
storeListener(new EntityToggleGlideListener(plugin)).register();
|
storeListener(new EntityToggleGlideListener(plugin)).register();
|
||||||
@ -121,13 +122,13 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
|||||||
if ((Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("paper")
|
if ((Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("paper")
|
||||||
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("taco")
|
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("taco")
|
||||||
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("torch"))
|
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("torch"))
|
||||||
&& Via.getAPI().getServerVersion() < ProtocolVersion.v1_12.getVersion()) {
|
&& serverProtocolVersion < ProtocolVersion.v1_12.getVersion()) {
|
||||||
plugin.getLogger().info("Enabling Paper/TacoSpigot/Torch patch: Fixes block placement.");
|
plugin.getLogger().info("Enabling Paper/TacoSpigot/Torch patch: Fixes block placement.");
|
||||||
storeListener(new PaperPatch(plugin)).register();
|
storeListener(new PaperPatch(plugin)).register();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Providers */
|
/* Providers */
|
||||||
if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_9.getVersion()) {
|
if (serverProtocolVersion < ProtocolVersion.v1_9.getVersion()) {
|
||||||
Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new BukkitViaBulkChunkTranslator());
|
Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new BukkitViaBulkChunkTranslator());
|
||||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BukkitViaMovementTransmitter());
|
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BukkitViaMovementTransmitter());
|
||||||
|
|
||||||
@ -156,12 +157,12 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_12.getVersion()) {
|
if (serverProtocolVersion < ProtocolVersion.v1_12.getVersion()) {
|
||||||
if (plugin.getConf().is1_12QuickMoveActionFix()) {
|
if (plugin.getConf().is1_12QuickMoveActionFix()) {
|
||||||
Via.getManager().getProviders().use(InventoryQuickMoveProvider.class, new BukkitInventoryQuickMoveProvider());
|
Via.getManager().getProviders().use(InventoryQuickMoveProvider.class, new BukkitInventoryQuickMoveProvider());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_13.getVersion()) {
|
if (serverProtocolVersion < ProtocolVersion.v1_13.getVersion()) {
|
||||||
if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("world")) {
|
if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("world")) {
|
||||||
BukkitBlockConnectionProvider blockConnectionProvider = new BukkitBlockConnectionProvider();
|
BukkitBlockConnectionProvider blockConnectionProvider = new BukkitBlockConnectionProvider();
|
||||||
Via.getManager().getProviders().use(BlockConnectionProvider.class, blockConnectionProvider);
|
Via.getManager().getProviders().use(BlockConnectionProvider.class, blockConnectionProvider);
|
||||||
|
@ -70,7 +70,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
|
|||||||
// windowId is always 0 for player inventory.
|
// windowId is always 0 for player inventory.
|
||||||
// This has almost definitely something to do with the offhand slot.
|
// This has almost definitely something to do with the offhand slot.
|
||||||
if (slotId >= 36 && slotId <= 44) {
|
if (slotId >= 36 && slotId <= 44) {
|
||||||
int protocolId = Via.getAPI().getServerVersion();
|
int protocolId = Via.getAPI().getServerVersion().lowestSupportedVersion();
|
||||||
// this seems to be working just fine.
|
// this seems to be working just fine.
|
||||||
if (protocolId == ProtocolVersion.v1_8.getVersion()) {
|
if (protocolId == ProtocolVersion.v1_8.getVersion()) {
|
||||||
return false;
|
return false;
|
||||||
@ -102,7 +102,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
|
|||||||
Inventory tinv = inv.getTopInventory();
|
Inventory tinv = inv.getTopInventory();
|
||||||
InventoryType tinvtype = tinv == null ? null : tinv.getType(); // can this even be null?
|
InventoryType tinvtype = tinv == null ? null : tinv.getType(); // can this even be null?
|
||||||
if (tinvtype != null) {
|
if (tinvtype != null) {
|
||||||
int protocolId = Via.getAPI().getServerVersion();
|
int protocolId = Via.getAPI().getServerVersion().lowestSupportedVersion();
|
||||||
if (protocolId == ProtocolVersion.v1_8.getVersion()) {
|
if (protocolId == ProtocolVersion.v1_8.getVersion()) {
|
||||||
if (tinvtype == InventoryType.BREWING) {
|
if (tinvtype == InventoryType.BREWING) {
|
||||||
// 1.9 added the blaze powder slot to brewing stand fix for 1.8 servers
|
// 1.9 added the blaze powder slot to brewing stand fix for 1.8 servers
|
||||||
@ -131,7 +131,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
|
|||||||
ReflectionUtil.set(packet, "button", 0); // shift + left mouse click
|
ReflectionUtil.set(packet, "button", 0); // shift + left mouse click
|
||||||
ReflectionUtil.set(packet, "d", storage.getActionId());
|
ReflectionUtil.set(packet, "d", storage.getActionId());
|
||||||
ReflectionUtil.set(packet, "item", nmsItem);
|
ReflectionUtil.set(packet, "item", nmsItem);
|
||||||
int protocolId = Via.getAPI().getServerVersion();
|
int protocolId = Via.getAPI().getServerVersion().lowestSupportedVersion();
|
||||||
if (protocolId == ProtocolVersion.v1_8.getVersion()) {
|
if (protocolId == ProtocolVersion.v1_8.getVersion()) {
|
||||||
ReflectionUtil.set(packet, "shift", 1);
|
ReflectionUtil.set(packet, "shift", 1);
|
||||||
} else if (protocolId >= ProtocolVersion.v1_9.getVersion()) { // 1.9+
|
} else if (protocolId >= ProtocolVersion.v1_9.getVersion()) { // 1.9+
|
||||||
@ -170,7 +170,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.windowClickPacketClass = NMSUtil.nms("PacketPlayInWindowClick");
|
this.windowClickPacketClass = NMSUtil.nms("PacketPlayInWindowClick");
|
||||||
int protocolId = Via.getAPI().getServerVersion();
|
int protocolId = Via.getAPI().getServerVersion().lowestSupportedVersion();
|
||||||
if (protocolId >= ProtocolVersion.v1_9.getVersion()) {
|
if (protocolId >= ProtocolVersion.v1_9.getVersion()) {
|
||||||
Class<?> eclassz = NMSUtil.nms("InventoryClickType");
|
Class<?> eclassz = NMSUtil.nms("InventoryClickType");
|
||||||
Object[] constants = eclassz.getEnumConstants();
|
Object[] constants = eclassz.getEnumConstants();
|
||||||
@ -199,7 +199,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSupported() {
|
private boolean isSupported() {
|
||||||
int protocolId = Via.getAPI().getServerVersion();
|
int protocolId = Via.getAPI().getServerVersion().lowestSupportedVersion();
|
||||||
if (protocolId >= ProtocolVersion.v1_8.getVersion() && protocolId <= ProtocolVersion.v1_11_1.getVersion()) {
|
if (protocolId >= ProtocolVersion.v1_8.getVersion() && protocolId <= ProtocolVersion.v1_11_1.getVersion()) {
|
||||||
return true; // 1.8-1.11.2
|
return true; // 1.8-1.11.2
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class BungeePlugin extends Plugin implements ViaPlatform<ProxiedPlayer>,
|
|||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
try {
|
try {
|
||||||
ProtocolConstants.class.getField("MINECRAFT_1_16_3");
|
ProtocolConstants.class.getField("MINECRAFT_1_16_4");
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
getLogger().warning(" / \\");
|
getLogger().warning(" / \\");
|
||||||
getLogger().warning(" / \\");
|
getLogger().warning(" / \\");
|
||||||
|
@ -20,6 +20,8 @@ package us.myles.ViaVersion.bungee.platform;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.platform.ViaInjector;
|
import us.myles.ViaVersion.api.platform.ViaInjector;
|
||||||
import us.myles.ViaVersion.bungee.handlers.BungeeChannelInitializer;
|
import us.myles.ViaVersion.bungee.handlers.BungeeChannelInitializer;
|
||||||
@ -77,7 +79,16 @@ public class BungeeViaInjector implements ViaInjector {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getServerProtocolVersion() throws Exception {
|
public int getServerProtocolVersion() throws Exception {
|
||||||
return (int) ReflectionUtil.getStatic(Class.forName("net.md_5.bungee.protocol.ProtocolConstants"), "SUPPORTED_VERSION_IDS", List.class).get(0);
|
return getBungeeSupportedVersions().get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IntSortedSet getServerProtocolVersions() throws Exception {
|
||||||
|
return new IntLinkedOpenHashSet(getBungeeSupportedVersions());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Integer> getBungeeSupportedVersions() throws Exception {
|
||||||
|
return ReflectionUtil.getStatic(Class.forName("net.md_5.bungee.protocol.ProtocolConstants"), "SUPPORTED_VERSION_IDS", List.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,7 +65,7 @@ public class BungeeViaLoader implements ViaPlatformLoader {
|
|||||||
registerListener(new UpdateListener());
|
registerListener(new UpdateListener());
|
||||||
registerListener(new BungeeServerHandler());
|
registerListener(new BungeeServerHandler());
|
||||||
|
|
||||||
if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_9.getVersion()) {
|
if (Via.getAPI().getServerVersion().lowestSupportedVersion() < ProtocolVersion.v1_9.getVersion()) {
|
||||||
registerListener(new ElytraPatch());
|
registerListener(new ElytraPatch());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ public class BungeeViaLoader implements ViaPlatformLoader {
|
|||||||
Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider());
|
Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider());
|
||||||
Via.getManager().getProviders().use(EntityIdProvider.class, new BungeeEntityIdProvider());
|
Via.getManager().getProviders().use(EntityIdProvider.class, new BungeeEntityIdProvider());
|
||||||
|
|
||||||
if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_9.getVersion()) {
|
if (Via.getAPI().getServerVersion().lowestSupportedVersion() < ProtocolVersion.v1_9.getVersion()) {
|
||||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
|
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
|
||||||
Via.getManager().getProviders().use(BossBarProvider.class, new BungeeBossBarProvider());
|
Via.getManager().getProviders().use(BossBarProvider.class, new BungeeBossBarProvider());
|
||||||
Via.getManager().getProviders().use(MainHandProvider.class, new BungeeMainHandProvider());
|
Via.getManager().getProviders().use(MainHandProvider.class, new BungeeMainHandProvider());
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package us.myles.ViaVersion;
|
package us.myles.ViaVersion;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.platform.TaskId;
|
import us.myles.ViaVersion.api.platform.TaskId;
|
||||||
import us.myles.ViaVersion.api.platform.ViaConnectionManager;
|
import us.myles.ViaVersion.api.platform.ViaConnectionManager;
|
||||||
@ -27,12 +28,16 @@ import us.myles.ViaVersion.api.platform.providers.ViaProviders;
|
|||||||
import us.myles.ViaVersion.api.protocol.ProtocolManager;
|
import us.myles.ViaVersion.api.protocol.ProtocolManager;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolManagerImpl;
|
import us.myles.ViaVersion.api.protocol.ProtocolManagerImpl;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||||
|
import us.myles.ViaVersion.api.protocol.ServerProtocolVersion;
|
||||||
|
import us.myles.ViaVersion.api.protocol.ServerProtocolVersionRange;
|
||||||
|
import us.myles.ViaVersion.api.protocol.ServerProtocolVersionSingleton;
|
||||||
import us.myles.ViaVersion.commands.ViaCommandHandler;
|
import us.myles.ViaVersion.commands.ViaCommandHandler;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.TabCompleteThread;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.TabCompleteThread;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ViaIdleThread;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ViaIdleThread;
|
||||||
import us.myles.ViaVersion.update.UpdateUtil;
|
import us.myles.ViaVersion.update.UpdateUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -71,6 +76,11 @@ public class ViaManagerImpl implements ViaManager {
|
|||||||
UpdateUtil.sendUpdateMessage();
|
UpdateUtil.sendUpdateMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load supported protocol versions if we can
|
||||||
|
if (!injector.lateProtocolVersionSetting()) {
|
||||||
|
loadServerProtocol();
|
||||||
|
}
|
||||||
|
|
||||||
// Register protocols
|
// Register protocols
|
||||||
protocolManager.registerProtocols();
|
protocolManager.registerProtocols();
|
||||||
|
|
||||||
@ -96,24 +106,33 @@ public class ViaManagerImpl implements ViaManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onServerLoaded() {
|
public void onServerLoaded() {
|
||||||
// Load Server Protocol
|
if (!protocolManager.getServerProtocolVersion().isKnown()) {
|
||||||
try {
|
// Try again
|
||||||
protocolManager.setServerProtocol(ProtocolVersion.getProtocol(injector.getServerProtocolVersion()).getVersion());
|
loadServerProtocol();
|
||||||
} catch (Exception e) {
|
|
||||||
platform.getLogger().severe("ViaVersion failed to get the server protocol!");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if there are any pipes to this version
|
// Check if there are any pipes to this version
|
||||||
if (protocolManager.getServerProtocol() != -1) {
|
ServerProtocolVersion protocolVersion = protocolManager.getServerProtocolVersion();
|
||||||
platform.getLogger().info("ViaVersion detected server version: " + ProtocolVersion.getProtocol(protocolManager.getServerProtocol()));
|
if (protocolVersion.isKnown()) {
|
||||||
if (!protocolManager.isWorkingPipe() && !platform.isProxy()) {
|
if (platform.isProxy()) {
|
||||||
|
platform.getLogger().info("ViaVersion detected lowest supported versions by the proxy: "
|
||||||
|
+ ProtocolVersion.getProtocol(protocolVersion.lowestSupportedVersion())
|
||||||
|
+ "\nHighest supported version by the proxy: "
|
||||||
|
+ ProtocolVersion.getProtocol(protocolVersion.highestSupportedVersion()));
|
||||||
|
if (debug) {
|
||||||
|
platform.getLogger().info("Supported version range: " + Arrays.toString(protocolVersion.supportedVersions().toArray(new int[0])));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
platform.getLogger().info("ViaVersion detected server version: " + ProtocolVersion.getProtocol(protocolVersion.highestSupportedVersion()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!protocolManager.isWorkingPipe()) {
|
||||||
platform.getLogger().warning("ViaVersion does not have any compatible versions for this server version!");
|
platform.getLogger().warning("ViaVersion does not have any compatible versions for this server version!");
|
||||||
platform.getLogger().warning("Please remember that ViaVersion only adds support for versions newer than the server version.");
|
platform.getLogger().warning("Please remember that ViaVersion only adds support for versions newer than the server version.");
|
||||||
platform.getLogger().warning("If you need support for older versions you may need to use one or more ViaVersion addons too.");
|
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("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.");
|
platform.getLogger().warning("and if you're still unsure, feel free to join our Discord-Server for further assistance.");
|
||||||
} else if (protocolManager.getServerProtocol() <= ProtocolVersion.v1_12_2.getVersion() && !platform.isProxy()) {
|
} else if (protocolVersion.highestSupportedVersion() <= ProtocolVersion.v1_12_2.getVersion()) {
|
||||||
platform.getLogger().warning("This version of Minecraft is extremely outdated and support for it has reached its end of life. "
|
platform.getLogger().warning("This version of Minecraft is extremely outdated and support for it has reached its end of life. "
|
||||||
+ "You will still be able to run Via on this version, but we are unlikely to provide any further fixes or help with problems specific to legacy versions. "
|
+ "You will still be able to run Via on this version, but we are unlikely to provide any further fixes or help with problems specific to legacy versions. "
|
||||||
+ "Please consider updating to give your players a better experience and to avoid issues that have long been fixed.");
|
+ "Please consider updating to give your players a better experience and to avoid issues that have long been fixed.");
|
||||||
@ -132,12 +151,14 @@ public class ViaManagerImpl implements ViaManager {
|
|||||||
mappingLoadingTask = null;
|
mappingLoadingTask = null;
|
||||||
}
|
}
|
||||||
}, 10L);
|
}, 10L);
|
||||||
if (protocolManager.getServerProtocol() < ProtocolVersion.v1_9.getVersion()) {
|
|
||||||
|
int serverProtocolVersion = protocolManager.getServerProtocolVersion().lowestSupportedVersion();
|
||||||
|
if (serverProtocolVersion < ProtocolVersion.v1_9.getVersion()) {
|
||||||
if (Via.getConfig().isSimulatePlayerTick()) {
|
if (Via.getConfig().isSimulatePlayerTick()) {
|
||||||
Via.getPlatform().runRepeatingSync(new ViaIdleThread(), 1L);
|
Via.getPlatform().runRepeatingSync(new ViaIdleThread(), 1L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (protocolManager.getServerProtocol() < ProtocolVersion.v1_13.getVersion()) {
|
if (serverProtocolVersion < ProtocolVersion.v1_13.getVersion()) {
|
||||||
if (Via.getConfig().get1_13TabCompleteDelay() > 0) {
|
if (Via.getConfig().get1_13TabCompleteDelay() > 0) {
|
||||||
Via.getPlatform().runRepeatingSync(new TabCompleteThread(), 1L);
|
Via.getPlatform().runRepeatingSync(new TabCompleteThread(), 1L);
|
||||||
}
|
}
|
||||||
@ -147,6 +168,24 @@ public class ViaManagerImpl implements ViaManager {
|
|||||||
protocolManager.refreshVersions();
|
protocolManager.refreshVersions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadServerProtocol() {
|
||||||
|
try {
|
||||||
|
ProtocolVersion serverProtocolVersion = ProtocolVersion.getProtocol(injector.getServerProtocolVersion());
|
||||||
|
ServerProtocolVersion versionInfo;
|
||||||
|
if (platform.isProxy()) {
|
||||||
|
IntSortedSet supportedVersions = injector.getServerProtocolVersions();
|
||||||
|
versionInfo = new ServerProtocolVersionRange(supportedVersions.firstInt(), supportedVersions.lastInt(), supportedVersions);
|
||||||
|
} else {
|
||||||
|
versionInfo = new ServerProtocolVersionSingleton(serverProtocolVersion.getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
protocolManager.setServerProtocol(versionInfo);
|
||||||
|
} catch (Exception e) {
|
||||||
|
platform.getLogger().severe("ViaVersion failed to get the server protocol!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
// Uninject
|
// Uninject
|
||||||
platform.getLogger().info("ViaVersion is disabling, if this is a reload and you experience issues consider rebooting.");
|
platform.getLogger().info("ViaVersion is disabling, if this is a reload and you experience issues consider rebooting.");
|
||||||
|
@ -19,6 +19,7 @@ package us.myles.ViaVersion.api;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion.api.protocol.ServerProtocolVersion;
|
||||||
|
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
@ -27,8 +28,8 @@ import java.util.UUID;
|
|||||||
public abstract class ViaAPIBase<T> implements ViaAPI<T> {
|
public abstract class ViaAPIBase<T> implements ViaAPI<T> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getServerVersion() {
|
public ServerProtocolVersion getServerVersion() {
|
||||||
return Via.getManager().getProtocolManager().getServerProtocol();
|
return Via.getManager().getProtocolManager().getServerProtocolVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,8 +95,8 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
|||||||
private ThreadPoolExecutor mappingLoaderExecutor;
|
private ThreadPoolExecutor mappingLoaderExecutor;
|
||||||
private boolean mappingsLoaded;
|
private boolean mappingsLoaded;
|
||||||
|
|
||||||
|
private ServerProtocolVersion serverProtocolVersion = new ServerProtocolVersionSingleton(-1);
|
||||||
private int maxProtocolPathSize = 50;
|
private int maxProtocolPathSize = 50;
|
||||||
private int serverProtocol = -1;
|
|
||||||
|
|
||||||
public ProtocolManagerImpl() {
|
public ProtocolManagerImpl() {
|
||||||
ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("Via-Mappingloader-%d").build();
|
ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("Via-Mappingloader-%d").build();
|
||||||
@ -199,9 +199,9 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
|||||||
public void refreshVersions() {
|
public void refreshVersions() {
|
||||||
supportedVersions.clear();
|
supportedVersions.clear();
|
||||||
|
|
||||||
supportedVersions.add(serverProtocol);
|
supportedVersions.add(serverProtocolVersion.lowestSupportedVersion());
|
||||||
for (ProtocolVersion versions : ProtocolVersion.getProtocols()) {
|
for (ProtocolVersion versions : ProtocolVersion.getProtocols()) {
|
||||||
List<ProtocolPathEntry> paths = getProtocolPath(versions.getVersion(), serverProtocol);
|
List<ProtocolPathEntry> paths = getProtocolPath(versions.getVersion(), serverProtocolVersion.lowestSupportedVersion());
|
||||||
if (paths == null) continue;
|
if (paths == null) continue;
|
||||||
supportedVersions.add(versions.getVersion());
|
supportedVersions.add(versions.getVersion());
|
||||||
for (ProtocolPathEntry path : paths) {
|
for (ProtocolPathEntry path : paths) {
|
||||||
@ -309,19 +309,23 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getServerProtocol() {
|
public ServerProtocolVersion getServerProtocolVersion() {
|
||||||
return serverProtocol;
|
return serverProtocolVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServerProtocol(int serverProtocol) {
|
public void setServerProtocol(ServerProtocolVersion serverProtocolVersion) {
|
||||||
this.serverProtocol = serverProtocol;
|
this.serverProtocolVersion = serverProtocolVersion;
|
||||||
ProtocolRegistry.SERVER_PROTOCOL = serverProtocol;
|
ProtocolRegistry.SERVER_PROTOCOL = serverProtocolVersion.lowestSupportedVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWorkingPipe() {
|
public boolean isWorkingPipe() {
|
||||||
for (Int2ObjectMap<Protocol> map : registryMap.values()) {
|
for (Int2ObjectMap<Protocol> map : registryMap.values()) {
|
||||||
if (map.containsKey(serverProtocol)) return true;
|
for (int protocolVersion : serverProtocolVersion.supportedVersions()) {
|
||||||
|
if (map.containsKey(protocolVersion)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false; // No destination for protocol
|
return false; // No destination for protocol
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2021 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package us.myles.ViaVersion.api.protocol;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
||||||
|
|
||||||
|
public class ServerProtocolVersionRange implements ServerProtocolVersion {
|
||||||
|
private final int lowestSupportedVersion;
|
||||||
|
private final int highestSupportedVersion;
|
||||||
|
private final IntSortedSet supportedVersions;
|
||||||
|
|
||||||
|
public ServerProtocolVersionRange(int lowestSupportedVersion, int highestSupportedVersion, IntSortedSet supportedVersions) {
|
||||||
|
this.lowestSupportedVersion = lowestSupportedVersion;
|
||||||
|
this.highestSupportedVersion = highestSupportedVersion;
|
||||||
|
this.supportedVersions = supportedVersions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int lowestSupportedVersion() {
|
||||||
|
return lowestSupportedVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int highestSupportedVersion() {
|
||||||
|
return highestSupportedVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IntSortedSet supportedVersions() {
|
||||||
|
return supportedVersions;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2021 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package us.myles.ViaVersion.api.protocol;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSortedSets;
|
||||||
|
|
||||||
|
public class ServerProtocolVersionSingleton implements ServerProtocolVersion {
|
||||||
|
private final int protocolVersion;
|
||||||
|
|
||||||
|
public ServerProtocolVersionSingleton(int protocolVersion) {
|
||||||
|
this.protocolVersion = protocolVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int lowestSupportedVersion() {
|
||||||
|
return protocolVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int highestSupportedVersion() {
|
||||||
|
return protocolVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IntSortedSet supportedVersions() {
|
||||||
|
return IntSortedSets.singleton(protocolVersion);
|
||||||
|
}
|
||||||
|
}
|
@ -53,7 +53,7 @@ public class DumpSubCmd extends ViaSubCommand {
|
|||||||
VersionInfo version = new VersionInfo(
|
VersionInfo version = new VersionInfo(
|
||||||
System.getProperty("java.version"),
|
System.getProperty("java.version"),
|
||||||
System.getProperty("os.name"),
|
System.getProperty("os.name"),
|
||||||
Via.getAPI().getServerVersion(),
|
Via.getAPI().getServerVersion().lowestSupportedVersion(),
|
||||||
Via.getManager().getProtocolManager().getSupportedVersions(),
|
Via.getManager().getProtocolManager().getSupportedVersions(),
|
||||||
Via.getPlatform().getPlatformName(),
|
Via.getPlatform().getPlatformName(),
|
||||||
Via.getPlatform().getPlatformVersion(),
|
Via.getPlatform().getPlatformVersion(),
|
||||||
|
@ -27,6 +27,7 @@ import us.myles.ViaVersion.api.Via;
|
|||||||
import us.myles.ViaVersion.api.protocol.ProtocolManagerImpl;
|
import us.myles.ViaVersion.api.protocol.ProtocolManagerImpl;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolPathEntry;
|
import us.myles.ViaVersion.api.protocol.ProtocolPathEntry;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||||
|
import us.myles.ViaVersion.api.protocol.ServerProtocolVersionSingleton;
|
||||||
import us.myles.ViaVersion.api.protocol.SimpleProtocol;
|
import us.myles.ViaVersion.api.protocol.SimpleProtocol;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
@ -80,9 +81,9 @@ public class BaseProtocol1_7 extends SimpleProtocol {
|
|||||||
version.add("supportedVersions", GsonUtil.getGson().toJsonTree(Via.getAPI().getSupportedVersions()));
|
version.add("supportedVersions", GsonUtil.getGson().toJsonTree(Via.getAPI().getSupportedVersions()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Via.getAPI().getServerVersion() == -1) { // Set the Server protocol if the detection on startup failed
|
if (!Via.getAPI().getServerVersion().isKnown()) { // Set the Server protocol if the detection on startup failed
|
||||||
ProtocolManagerImpl protocolManager = (ProtocolManagerImpl) Via.getManager().getProtocolManager();
|
ProtocolManagerImpl protocolManager = (ProtocolManagerImpl) Via.getManager().getProtocolManager();
|
||||||
protocolManager.setServerProtocol(ProtocolVersion.getProtocol(protocolVersion).getVersion());
|
protocolManager.setServerProtocol(new ServerProtocolVersionSingleton(ProtocolVersion.getProtocol(protocolVersion).getVersion()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the server has a version provider
|
// Ensure the server has a version provider
|
||||||
@ -92,16 +93,14 @@ public class BaseProtocol1_7 extends SimpleProtocol {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int protocol = versionProvider.getServerProtocol(wrapper.user());
|
int closestServerProtocol = versionProvider.getServerProtocol(wrapper.user());
|
||||||
List<ProtocolPathEntry> protocols = null;
|
List<ProtocolPathEntry> protocols = null;
|
||||||
|
if (info.getProtocolVersion() >= closestServerProtocol || Via.getPlatform().isOldClientsAllowed()) {
|
||||||
// Only allow newer clients or (1.9.2 on 1.9.4 server if the server supports it)
|
protocols = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), closestServerProtocol);
|
||||||
if (info.getProtocolVersion() >= protocol || Via.getPlatform().isOldClientsAllowed()) {
|
|
||||||
protocols = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), protocol);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (protocols != null) {
|
if (protocols != null) {
|
||||||
if (protocolVersion == protocol || protocolVersion == 0) { // Fix ServerListPlus
|
if (protocolVersion == closestServerProtocol || protocolVersion == 0) { // Fix ServerListPlus
|
||||||
ProtocolVersion prot = ProtocolVersion.getProtocol(info.getProtocolVersion());
|
ProtocolVersion prot = ProtocolVersion.getProtocol(info.getProtocolVersion());
|
||||||
version.addProperty("protocol", prot.getOriginalVersion());
|
version.addProperty("protocol", prot.getOriginalVersion());
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,6 @@ import us.myles.ViaVersion.api.data.UserConnection;
|
|||||||
public class BaseVersionProvider implements VersionProvider {
|
public class BaseVersionProvider implements VersionProvider {
|
||||||
|
|
||||||
public int getServerProtocol(UserConnection connection) throws Exception {
|
public int getServerProtocol(UserConnection connection) throws Exception {
|
||||||
return Via.getAPI().getServerVersion();
|
return Via.getAPI().getServerVersion().lowestSupportedVersion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ public class SpongeChannelInitializer extends ChannelInitializer<Channel> {
|
|||||||
@Override
|
@Override
|
||||||
protected void initChannel(Channel channel) throws Exception {
|
protected void initChannel(Channel channel) throws Exception {
|
||||||
// Ensure ViaVersion is loaded
|
// Ensure ViaVersion is loaded
|
||||||
if (Via.getAPI().getServerVersion() != -1
|
if (Via.getAPI().getServerVersion().isKnown()
|
||||||
&& channel instanceof SocketChannel) { // channel can be LocalChannel on internal server
|
&& channel instanceof SocketChannel) { // channel can be LocalChannel on internal server
|
||||||
UserConnection info = new UserConnection((SocketChannel) channel);
|
UserConnection info = new UserConnection((SocketChannel) channel);
|
||||||
// init protocol
|
// init protocol
|
||||||
|
@ -120,6 +120,11 @@ public class SpongeViaInjector implements ViaInjector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean lateProtocolVersionSetting() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uninject() {
|
public void uninject() {
|
||||||
// TODO: Uninject from players currently online
|
// TODO: Uninject from players currently online
|
||||||
|
@ -66,7 +66,7 @@ public class SpongeViaLoader implements ViaPlatformLoader {
|
|||||||
registerListener(new UpdateListener());
|
registerListener(new UpdateListener());
|
||||||
|
|
||||||
/* 1.9 client to 1.8 server */
|
/* 1.9 client to 1.8 server */
|
||||||
if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_9.getVersion()) {
|
if (Via.getAPI().getServerVersion().lowestSupportedVersion() < ProtocolVersion.v1_9.getVersion()) {
|
||||||
try {
|
try {
|
||||||
Class.forName("org.spongepowered.api.event.entity.DisplaceEntityEvent");
|
Class.forName("org.spongepowered.api.event.entity.DisplaceEntityEvent");
|
||||||
storeListener(new Sponge4ArmorListener()).register();
|
storeListener(new Sponge4ArmorListener()).register();
|
||||||
@ -83,7 +83,7 @@ public class SpongeViaLoader implements ViaPlatformLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Providers */
|
/* Providers */
|
||||||
if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_9.getVersion()) {
|
if (Via.getAPI().getServerVersion().lowestSupportedVersion() < ProtocolVersion.v1_9.getVersion()) {
|
||||||
Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new SpongeViaBulkChunkTranslator());
|
Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new SpongeViaBulkChunkTranslator());
|
||||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new SpongeViaMovementTransmitter());
|
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new SpongeViaMovementTransmitter());
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ package us.myles.ViaVersion.velocity.platform;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSortedSet;
|
||||||
import us.myles.ViaVersion.VelocityPlugin;
|
import us.myles.ViaVersion.VelocityPlugin;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.platform.ViaInjector;
|
import us.myles.ViaVersion.api.platform.ViaInjector;
|
||||||
@ -44,7 +46,7 @@ public class VelocityViaInjector implements ViaInjector {
|
|||||||
private ChannelInitializer getInitializer() throws Exception {
|
private ChannelInitializer getInitializer() throws Exception {
|
||||||
Object connectionManager = ReflectionUtil.get(VelocityPlugin.PROXY, "cm", Object.class);
|
Object connectionManager = ReflectionUtil.get(VelocityPlugin.PROXY, "cm", Object.class);
|
||||||
Object channelInitializerHolder = ReflectionUtil.invoke(connectionManager, "getServerChannelInitializer");
|
Object channelInitializerHolder = ReflectionUtil.invoke(connectionManager, "getServerChannelInitializer");
|
||||||
return (ChannelInitializer) ReflectionUtil.invoke(channelInitializerHolder, "get");
|
return (ChannelInitializer) ReflectionUtil.invoke(channelInitializerHolder, "get");
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChannelInitializer getBackendInitializer() throws Exception {
|
private ChannelInitializer getBackendInitializer() throws Exception {
|
||||||
@ -65,7 +67,7 @@ public class VelocityViaInjector implements ViaInjector {
|
|||||||
Object backendInitializerHolder = ReflectionUtil.invoke(connectionManager, "getBackendChannelInitializer");
|
Object backendInitializerHolder = ReflectionUtil.invoke(connectionManager, "getBackendChannelInitializer");
|
||||||
ChannelInitializer backendInitializer = getBackendInitializer();
|
ChannelInitializer backendInitializer = getBackendInitializer();
|
||||||
backendInitializerHolder.getClass().getMethod("set", ChannelInitializer.class)
|
backendInitializerHolder.getClass().getMethod("set", ChannelInitializer.class)
|
||||||
.invoke(backendInitializerHolder, new VelocityChannelInitializer(backendInitializer, true));
|
.invoke(backendInitializerHolder, new VelocityChannelInitializer(backendInitializer, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -79,11 +81,26 @@ public class VelocityViaInjector implements ViaInjector {
|
|||||||
return getLowestSupportedProtocolVersion();
|
return getLowestSupportedProtocolVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IntSortedSet getServerProtocolVersions() throws Exception {
|
||||||
|
int lowestSupportedProtocolVersion = getLowestSupportedProtocolVersion();
|
||||||
|
|
||||||
|
IntSortedSet set = new IntLinkedOpenHashSet();
|
||||||
|
for (com.velocitypowered.api.network.ProtocolVersion version : com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS) {
|
||||||
|
if (version.getProtocol() >= lowestSupportedProtocolVersion) {
|
||||||
|
set.add(version.getProtocol());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
public static int getLowestSupportedProtocolVersion() {
|
public static int getLowestSupportedProtocolVersion() {
|
||||||
try {
|
try {
|
||||||
if (getPlayerInfoForwardingMode != null
|
if (getPlayerInfoForwardingMode != null
|
||||||
&& ((Enum<?>) getPlayerInfoForwardingMode.invoke(VelocityPlugin.PROXY.getConfiguration()))
|
&& ((Enum<?>) getPlayerInfoForwardingMode.invoke(VelocityPlugin.PROXY.getConfiguration()))
|
||||||
.name().equals("MODERN")) return ProtocolVersion.v1_13.getVersion();
|
.name().equals("MODERN")) {
|
||||||
|
return ProtocolVersion.v1_13.getVersion();
|
||||||
|
}
|
||||||
} catch (IllegalAccessException | InvocationTargetException ignored) {
|
} catch (IllegalAccessException | InvocationTargetException ignored) {
|
||||||
}
|
}
|
||||||
return com.velocitypowered.api.network.ProtocolVersion.MINIMUM_VERSION.getProtocol();
|
return com.velocitypowered.api.network.ProtocolVersion.MINIMUM_VERSION.getProtocol();
|
||||||
|
@ -37,7 +37,7 @@ public class VelocityViaLoader implements ViaPlatformLoader {
|
|||||||
Object plugin = VelocityPlugin.PROXY.getPluginManager()
|
Object plugin = VelocityPlugin.PROXY.getPluginManager()
|
||||||
.getPlugin("viaversion").flatMap(PluginContainer::getInstance).get();
|
.getPlugin("viaversion").flatMap(PluginContainer::getInstance).get();
|
||||||
|
|
||||||
if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_9.getVersion()) {
|
if (Via.getAPI().getServerVersion().lowestSupportedVersion() < ProtocolVersion.v1_9.getVersion()) {
|
||||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new VelocityMovementTransmitter());
|
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new VelocityMovementTransmitter());
|
||||||
Via.getManager().getProviders().use(BossBarProvider.class, new VelocityBossBarProvider());
|
Via.getManager().getProviders().use(BossBarProvider.class, new VelocityBossBarProvider());
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren