ProtocolRegistry -> ProtocolManager interface

This commit is contained in:
KennyTV 2021-03-24 15:21:18 +01:00
parent 210cae70fd
commit 63356207a3
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
32 changed files with 536 additions and 378 deletions

View File

@ -22,55 +22,36 @@
*/ */
package us.myles.ViaVersion; package us.myles.ViaVersion;
import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.command.ViaVersionCommand; import us.myles.ViaVersion.api.command.ViaVersionCommand;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.ViaConnectionManager; import us.myles.ViaVersion.api.platform.ViaConnectionManager;
import us.myles.ViaVersion.api.platform.ViaInjector; import us.myles.ViaVersion.api.platform.ViaInjector;
import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader; import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
import us.myles.ViaVersion.api.platform.providers.ViaProviders; import us.myles.ViaVersion.api.platform.providers.ViaProviders;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.ProtocolManager;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID;
public interface ViaManager { public interface ViaManager {
Set<UserConnection> getConnections(); ProtocolManager getProtocolManager();
/**
* @deprecated use getConnectedClients()
*/
@Deprecated
Map<UUID, UserConnection> getPortedPlayers();
Map<UUID, UserConnection> getConnectedClients();
UUID getConnectedClientId(UserConnection conn);
/**
* @see ViaConnectionManager#isClientConnected(UUID)
*/
boolean isClientConnected(UUID player);
void handleLoginSuccess(UserConnection info);
ViaPlatform<?> getPlatform(); ViaPlatform<?> getPlatform();
ViaConnectionManager getConnectionManager();
ViaProviders getProviders(); ViaProviders getProviders();
boolean isDebug();
void setDebug(boolean debug);
ViaInjector getInjector(); ViaInjector getInjector();
ViaVersionCommand getCommandHandler(); ViaVersionCommand getCommandHandler();
ViaPlatformLoader getLoader(); ViaPlatformLoader getLoader();
boolean isDebug();
void setDebug(boolean debug);
/** /**
* Returns a mutable set of self-added subplatform version strings. * Returns a mutable set of self-added subplatform version strings.
* This set is expanded by the subplatform itself (e.g. ViaBackwards), and may not contain all running ones. * This set is expanded by the subplatform itself (e.g. ViaBackwards), and may not contain all running ones.
@ -79,20 +60,10 @@ public interface ViaManager {
*/ */
Set<String> getSubPlatforms(); Set<String> getSubPlatforms();
/**
* @see ViaConnectionManager#getConnectedClient(UUID)
*/
@Nullable
UserConnection getConnection(UUID playerUUID);
/** /**
* Adds a runnable to be executed when ViaVersion has finished its init before the full server load. * Adds a runnable to be executed when ViaVersion has finished its init before the full server load.
* *
* @param runnable runnable to be executed * @param runnable runnable to be executed
*/ */
void addEnableListener(Runnable runnable); void addEnableListener(Runnable runnable);
Protocol getBaseProtocol();
boolean isBaseProtocol(Protocol protocol);
} }

View File

@ -27,7 +27,6 @@ import us.myles.ViaVersion.ViaManager;
import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.api.platform.ViaPlatform;
public class Via { public class Via {
private static ViaPlatform platform;
private static ViaManager manager; private static ViaManager manager;
/** /**
@ -37,19 +36,17 @@ public class Via {
*/ */
public static void init(ViaManager viaManager) { public static void init(ViaManager viaManager) {
Preconditions.checkArgument(manager == null, "ViaManager is already set"); Preconditions.checkArgument(manager == null, "ViaManager is already set");
Via.platform = viaManager.getPlatform();
Via.manager = viaManager; Via.manager = viaManager;
} }
/** /**
* Get the API associated with the current platform. * Returns the API associated with the current platform.
* *
* @return API instance * @return API instance
*/ */
public static ViaAPI getAPI() { public static ViaAPI getAPI() {
Preconditions.checkArgument(platform != null, "ViaVersion has not loaded the Platform"); Preconditions.checkArgument(manager != null, "ViaVersion has not loaded the platform yet");
return Via.platform.getApi(); return manager.getPlatform().getApi();
} }
/** /**
@ -58,12 +55,12 @@ public class Via {
* @return Config instance * @return Config instance
*/ */
public static ViaVersionConfig getConfig() { public static ViaVersionConfig getConfig() {
Preconditions.checkArgument(platform != null, "ViaVersion has not loaded the Platform"); Preconditions.checkArgument(manager != null, "ViaVersion has not loaded the platform yet");
return Via.platform.getConf(); return manager.getPlatform().getConf();
} }
public static ViaPlatform getPlatform() { public static ViaPlatform getPlatform() {
return platform; return manager.getPlatform();
} }
public static ViaManager getManager() { public static ViaManager getManager() {

View File

@ -23,6 +23,8 @@
package us.myles.ViaVersion.api.platform; package us.myles.ViaVersion.api.platform;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import us.myles.ViaVersion.ViaManager;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaAPI; import us.myles.ViaVersion.api.ViaAPI;
import us.myles.ViaVersion.api.ViaVersionConfig; import us.myles.ViaVersion.api.ViaVersionConfig;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
@ -216,9 +218,10 @@ public interface ViaPlatform<T> {
boolean isOldClientsAllowed(); boolean isOldClientsAllowed();
/** /**
* Returns the connection manager holding and managing user connections. * @deprecated use {@link ViaManager#getConnectionManager()}
*
* @return connection manager
*/ */
ViaConnectionManager getConnectionManager(); @Deprecated
default ViaConnectionManager getConnectionManager() {
return Via.getManager().getConnectionManager();
}
} }

View File

@ -0,0 +1,166 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package us.myles.ViaVersion.api.protocol;
import com.google.common.collect.Range;
import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.Pair;
import java.util.List;
import java.util.SortedSet;
import java.util.concurrent.CompletableFuture;
public interface ProtocolManager {
/**
* Returns the server protocol version, or -1 if not set.
* In the case of proxies, this returns the lowest supported protocol version.
*
* @return server protocol version, or -1 if not set
*/
int getServerProtocol();
/**
* Returns a protocol instance by its class.
*
* @param protocolClass class of the protocol
* @return protocol if present
*/
@Nullable
Protocol getProtocol(Class<? extends Protocol> protocolClass);
Protocol getBaseProtocol();
Protocol getBaseProtocol(int serverVersion);
boolean isBaseProtocol(Protocol protocol);
/**
* Register a protocol.
*
* @param protocol protocol to register
* @param supported supported client versions
* @param output output server version the protocol converts to
*/
void registerProtocol(Protocol protocol, ProtocolVersion supported, ProtocolVersion output);
/**
* Register a protocol.
*
* @param protocol protocol to register
* @param supported supported client versions
* @param output output server version the protocol converts to
*/
void registerProtocol(Protocol protocol, List<Integer> supported, int output);
/**
* Registers a base protocol. Base Protocols registered later have higher priority.
* Only base protocol will always be added to pipeline.
*
* @param baseProtocol base protocol to register
* @param supportedProtocols versions supported by the base protocol
*/
void registerBaseProtocol(Protocol baseProtocol, Range<Integer> supportedProtocols);
/**
* Calculates a path from a client version to server version.
*
* @param clientVersion input client version
* @param serverVersion desired output server version
* @return path it generated, null if it failed
*/
@Nullable
List<Pair<Integer, Protocol>> getProtocolPath(int clientVersion, int serverVersion);
/**
* Returns the maximum protocol path size applied to {@link #getProtocolPath(int, int)}.
*
* @return maximum protocol path size
*/
int getMaxProtocolPathSize();
/**
* Sets the maximum protocol path size applied to {@link #getProtocolPath(int, int)}.
* Its default it 50.
*
* @param maxProtocolPathSize maximum protocol path size
*/
void setMaxProtocolPathSize(int maxProtocolPathSize);
/**
* Returns the versions compatible with the server.
*
* @return sorted, immutable set of supported versions
*/
SortedSet<Integer> getSupportedVersions();
/**
* Check if this plugin is useful to the server.
*
* @return true if there is a useful pipe
*/
boolean isWorkingPipe();
/**
* Ensure that mapping data for that protocol has already been loaded, completes it otherwise.
*
* @param protocolClass protocol class
*/
void completeMappingDataLoading(Class<? extends Protocol> protocolClass) throws Exception;
/**
* Shuts down the executor and uncaches mappings if all futures have been completed.
*
* @return true if the executor has now been shut down
*/
boolean checkForMappingCompletion();
/**
* Executes the given runnable asynchronously, adding a {@link CompletableFuture}
* to the list of data to load bound to their protocols.
*
* @param protocolClass protocol class
* @param runnable runnable to be executed asynchronously
*/
void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Runnable runnable);
/**
* Executes the given runnable asynchronously after the other protocol has finished its data loading,
* adding a {@link CompletableFuture} to the list of data to load bound to their protocols.
*
* @param protocolClass protocol class
* @param dependsOn class of the protocol that the data loading depends on
* @param runnable runnable to be executed asynchronously
*/
void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Class<? extends Protocol> dependsOn, Runnable runnable);
/**
* Returns the data loading future bound to the protocol, or null if all loading is complete.
* The future may or may not have already been completed.
*
* @param protocolClass protocol class
* @return data loading future bound to the protocol, or null if all loading is complete
*/
@Nullable
CompletableFuture<Void> getMappingLoaderFuture(Class<? extends Protocol> protocolClass);
}

View File

@ -47,7 +47,7 @@ public class ProtocolPipeline extends SimpleProtocol {
protected void registerPackets() { protected void registerPackets() {
protocolList = new CopyOnWriteArrayList<>(); protocolList = new CopyOnWriteArrayList<>();
// This is a pipeline so we register basic pipes // This is a pipeline so we register basic pipes
protocolList.add(Via.getManager().getBaseProtocol()); protocolList.add(Via.getManager().getProtocolManager().getBaseProtocol());
} }
@Override @Override
@ -78,7 +78,7 @@ public class ProtocolPipeline extends SimpleProtocol {
// Move base Protocols to the end, so the login packets can be modified by other protocols // Move base Protocols to the end, so the login packets can be modified by other protocols
List<Protocol> toMove = new ArrayList<>(); List<Protocol> toMove = new ArrayList<>();
for (Protocol p : protocolList) { for (Protocol p : protocolList) {
if (Via.getManager().isBaseProtocol(p)) { if (Via.getManager().getProtocolManager().isBaseProtocol(p)) {
toMove.add(p); toMove.add(p);
} }
} }

View File

@ -0,0 +1,128 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package us.myles.ViaVersion.api.protocol;
import com.google.common.collect.Range;
import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.ViaManager;
import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.Via;
import java.util.Collections;
import java.util.List;
import java.util.SortedSet;
/**
* @see ViaManager#getProtocolManager()
* @deprecated use {@link ProtocolManager}
*/
@Deprecated
public class ProtocolRegistry {
@Deprecated
public static int SERVER_PROTOCOL = -1;
@Deprecated
public static int maxProtocolPathSize = 50;
/**
* Register a protocol
*
* @param protocol The protocol to register.
* @param supported Supported client versions.
* @param output The output server version it converts to.
*/
public static void registerProtocol(Protocol protocol, ProtocolVersion supported, ProtocolVersion output) {
registerProtocol(protocol, Collections.singletonList(supported.getVersion()), output.getVersion());
}
/**
* Register a protocol
*
* @param protocol The protocol to register.
* @param supported Supported client versions.
* @param output The output server version it converts to.
*/
public static void registerProtocol(Protocol protocol, List<Integer> supported, int output) {
Via.getManager().getProtocolManager().registerProtocol(protocol, supported, output);
}
/**
* Registers a base protocol.
* Base Protocols registered later have higher priority
* Only one base protocol will be added to pipeline
*
* @param baseProtocol Base Protocol to register
* @param supportedProtocols Versions that baseProtocol supports
*/
public static void registerBaseProtocol(Protocol baseProtocol, Range<Integer> supportedProtocols) {
Via.getManager().getProtocolManager().registerBaseProtocol(baseProtocol, supportedProtocols);
}
/**
* Get the versions compatible with the server.
*
* @return Read-only set of the versions.
*/
public static SortedSet<Integer> getSupportedVersions() {
return Via.getManager().getProtocolManager().getSupportedVersions();
}
/**
* Check if this plugin is useful to the server.
*
* @return True if there is a useful pipe
*/
public static boolean isWorkingPipe() {
return Via.getManager().getProtocolManager().isWorkingPipe();
}
/**
* Calculate a path from a client version to server version.
*
* @param clientVersion The input client version
* @param serverVersion The desired output server version
* @return The path it generated, null if it failed.
*/
@Nullable
public static List<Pair<Integer, Protocol>> getProtocolPath(int clientVersion, int serverVersion) {
return Via.getManager().getProtocolManager().getProtocolPath(clientVersion, serverVersion);
}
/**
* Returns a protocol instance by its class.
*
* @param protocolClass class of the protocol
* @return protocol if present
*/
@Nullable
public static Protocol getProtocol(Class<? extends Protocol> protocolClass) {
return Via.getManager().getProtocolManager().getProtocol(protocolClass);
}
public static Protocol getBaseProtocol(int serverVersion) {
return Via.getManager().getProtocolManager().getBaseProtocol(serverVersion);
}
public static boolean isBaseProtocol(Protocol protocol) {
return Via.getManager().getProtocolManager().isBaseProtocol(protocol);
}
}

View File

@ -29,7 +29,6 @@ import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider; import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
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.ViaPlatform; import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator; import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator;
import us.myles.ViaVersion.bukkit.commands.BukkitCommandHandler; import us.myles.ViaVersion.bukkit.commands.BukkitCommandHandler;
@ -50,7 +49,6 @@ import java.util.UUID;
public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player> { public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player> {
private static ViaVersionPlugin instance; private static ViaVersionPlugin instance;
private final ViaConnectionManager connectionManager = new ViaConnectionManager();
private final BukkitCommandHandler commandHandler; private final BukkitCommandHandler commandHandler;
private final BukkitViaConfig conf; private final BukkitViaConfig conf;
private final ViaAPI<Player> api = new BukkitViaAPI(this); private final ViaAPI<Player> api = new BukkitViaAPI(this);
@ -311,9 +309,4 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
public static ViaVersionPlugin getInstance() { public static ViaVersionPlugin getInstance() {
return instance; return instance;
} }
@Override
public ViaConnectionManager getConnectionManager() {
return connectionManager;
}
} }

View File

@ -24,8 +24,8 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSneakEvent;
import us.myles.ViaVersion.ViaVersionPlugin; import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener; import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
@ -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 (ProtocolRegistry.SERVER_PROTOCOL >= ProtocolVersion.v1_9.getVersion()) { if (Via.getAPI().getServerVersion() >= 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() {

View File

@ -46,7 +46,7 @@ public class BukkitViaAPI extends ViaAPIBase<Player> {
@Override @Override
public int getPlayerVersion(UUID uuid) { public int getPlayerVersion(UUID uuid) {
UserConnection connection = Via.getManager().getConnection(uuid); UserConnection connection = Via.getManager().getConnectionManager().getConnectedClient(uuid);
if (connection == null) { if (connection == null) {
Player player = Bukkit.getPlayer(uuid); Player player = Bukkit.getPlayer(uuid);
if (player != null && isProtocolSupport()) { if (player != null && isProtocolSupport()) {

View File

@ -27,7 +27,6 @@ import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader; 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.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator; import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator;
import us.myles.ViaVersion.bukkit.listeners.UpdateListener; import us.myles.ViaVersion.bukkit.listeners.UpdateListener;
@ -88,7 +87,7 @@ public class BukkitViaLoader implements ViaPlatformLoader {
ClassGenerator.registerPSConnectListener(plugin); ClassGenerator.registerPSConnectListener(plugin);
/* 1.9 client to 1.8 server */ /* 1.9 client to 1.8 server */
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) { if (Via.getAPI().getServerVersion() < 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();
@ -99,8 +98,8 @@ public class BukkitViaLoader implements ViaPlatformLoader {
} }
} }
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_14.getVersion()) { if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_14.getVersion()) {
boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion(); boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && Via.getAPI().getServerVersion() < 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();
@ -111,7 +110,7 @@ public class BukkitViaLoader implements ViaPlatformLoader {
} }
} }
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_15.getVersion()) { if (Via.getAPI().getServerVersion() < 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();
@ -122,13 +121,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"))
&& ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_12.getVersion()) { && Via.getAPI().getServerVersion() < 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 (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) { if (Via.getAPI().getServerVersion() < 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());
@ -157,12 +156,12 @@ public class BukkitViaLoader implements ViaPlatformLoader {
}); });
} }
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_12.getVersion()) { if (Via.getAPI().getServerVersion() < 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 (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_13.getVersion()) { if (Via.getAPI().getServerVersion() < 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);

View File

@ -24,7 +24,6 @@ import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.bukkit.tasks.protocol1_12to1_11_1.BukkitInventoryUpdateTask; import us.myles.ViaVersion.bukkit.tasks.protocol1_12to1_11_1.BukkitInventoryUpdateTask;
import us.myles.ViaVersion.bukkit.util.NMSUtil; import us.myles.ViaVersion.bukkit.util.NMSUtil;
@ -71,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 = ProtocolRegistry.SERVER_PROTOCOL; int protocolId = Via.getAPI().getServerVersion();
// 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;
@ -103,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 = ProtocolRegistry.SERVER_PROTOCOL; int protocolId = Via.getAPI().getServerVersion();
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
@ -132,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 = ProtocolRegistry.SERVER_PROTOCOL; int protocolId = Via.getAPI().getServerVersion();
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+
@ -171,7 +170,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
} }
try { try {
this.windowClickPacketClass = NMSUtil.nms("PacketPlayInWindowClick"); this.windowClickPacketClass = NMSUtil.nms("PacketPlayInWindowClick");
int protocolId = ProtocolRegistry.SERVER_PROTOCOL; int protocolId = Via.getAPI().getServerVersion();
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();
@ -200,7 +199,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
} }
private boolean isSupported() { private boolean isSupported() {
int protocolId = ProtocolRegistry.SERVER_PROTOCOL; int protocolId = Via.getAPI().getServerVersion();
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
} }

View File

@ -29,7 +29,6 @@ import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider; import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
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.ViaPlatform; import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.bungee.commands.BungeeCommand; import us.myles.ViaVersion.bungee.commands.BungeeCommand;
import us.myles.ViaVersion.bungee.commands.BungeeCommandHandler; import us.myles.ViaVersion.bungee.commands.BungeeCommandHandler;
@ -51,7 +50,6 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class BungeePlugin extends Plugin implements ViaPlatform<ProxiedPlayer>, Listener { public class BungeePlugin extends Plugin implements ViaPlatform<ProxiedPlayer>, Listener {
private final ViaConnectionManager connectionManager = new ViaConnectionManager();
private BungeeViaAPI api; private BungeeViaAPI api;
private BungeeViaConfig config; private BungeeViaConfig config;
@ -216,9 +214,4 @@ public class BungeePlugin extends Plugin implements ViaPlatform<ProxiedPlayer>,
public boolean isOldClientsAllowed() { public boolean isOldClientsAllowed() {
return true; return true;
} }
@Override
public ViaConnectionManager getConnectionManager() {
return connectionManager;
}
} }

View File

@ -33,7 +33,6 @@ import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.bungee.service.ProtocolDetectorService; import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
@ -86,14 +85,14 @@ public class BungeeServerHandler implements Listener {
return; return;
} }
UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId()); UserConnection user = Via.getManager().getConnectionManager().getConnectedClient(e.getPlayer().getUniqueId());
if (user == null) return; if (user == null) return;
if (!user.has(BungeeStorage.class)) { if (!user.has(BungeeStorage.class)) {
user.put(new BungeeStorage(user, e.getPlayer())); user.put(new BungeeStorage(user, e.getPlayer()));
} }
int protocolId = ProtocolDetectorService.getProtocolId(e.getTarget().getName()); int protocolId = ProtocolDetectorService.getProtocolId(e.getTarget().getName());
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.getProtocolInfo().getProtocolVersion(), protocolId); List<Pair<Integer, Protocol>> protocols = Via.getManager().getProtocolManager().getProtocolPath(user.getProtocolInfo().getProtocolVersion(), protocolId);
// Check if ViaVersion can support that version // Check if ViaVersion can support that version
try { try {
@ -108,7 +107,7 @@ public class BungeeServerHandler implements Listener {
@EventHandler(priority = -120) @EventHandler(priority = -120)
public void onServerConnected(ServerConnectedEvent e) { public void onServerConnected(ServerConnectedEvent e) {
try { try {
checkServerChange(e, Via.getManager().getConnection(e.getPlayer().getUniqueId())); checkServerChange(e, Via.getManager().getConnectionManager().getConnectedClient(e.getPlayer().getUniqueId()));
} catch (Exception e1) { } catch (Exception e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
@ -117,7 +116,7 @@ public class BungeeServerHandler implements Listener {
@EventHandler(priority = -120) @EventHandler(priority = -120)
public void onServerSwitch(ServerSwitchEvent e) { public void onServerSwitch(ServerSwitchEvent e) {
// Update entity id // Update entity id
UserConnection userConnection = Via.getManager().getConnection(e.getPlayer().getUniqueId()); UserConnection userConnection = Via.getManager().getConnectionManager().getConnectedClient(e.getPlayer().getUniqueId());
if (userConnection == null) return; if (userConnection == null) return;
int playerId; int playerId;
try { try {
@ -176,7 +175,7 @@ public class BungeeServerHandler implements Listener {
int previousServerProtocol = info.getServerProtocolVersion(); int previousServerProtocol = info.getServerProtocolVersion();
// Refresh the pipes // Refresh the pipes
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId); List<Pair<Integer, Protocol>> protocols = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), protocolId);
ProtocolPipeline pipeline = user.getProtocolInfo().getPipeline(); ProtocolPipeline pipeline = user.getProtocolInfo().getPipeline();
user.clearStoredObjects(); user.clearStoredObjects();
pipeline.cleanPipes(); pipeline.cleanPipes();
@ -191,7 +190,7 @@ public class BungeeServerHandler implements Listener {
info.setServerProtocolVersion(protocolId); info.setServerProtocolVersion(protocolId);
// Add version-specific base Protocol // Add version-specific base Protocol
pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId)); pipeline.add(Via.getManager().getProtocolManager().getBaseProtocol(protocolId));
// Workaround 1.13 server change // Workaround 1.13 server change
Object relayMessages = getRelayMessages.invoke(e.getPlayer().getPendingConnection()); Object relayMessages = getRelayMessages.invoke(e.getPlayer().getPendingConnection());

View File

@ -40,7 +40,7 @@ public class ElytraPatch implements Listener {
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onServerConnected(ServerConnectedEvent event) { public void onServerConnected(ServerConnectedEvent event) {
UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); UserConnection user = Via.getManager().getConnectionManager().getConnectedClient(event.getPlayer().getUniqueId());
if (user == null) return; if (user == null) return;
try { try {

View File

@ -23,12 +23,15 @@ import net.md_5.bungee.api.scheduler.ScheduledTask;
import us.myles.ViaVersion.BungeePlugin; import us.myles.ViaVersion.BungeePlugin;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader; 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.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.bungee.handlers.BungeeServerHandler; import us.myles.ViaVersion.bungee.handlers.BungeeServerHandler;
import us.myles.ViaVersion.bungee.listeners.ElytraPatch; import us.myles.ViaVersion.bungee.listeners.ElytraPatch;
import us.myles.ViaVersion.bungee.listeners.UpdateListener; import us.myles.ViaVersion.bungee.listeners.UpdateListener;
import us.myles.ViaVersion.bungee.providers.*; import us.myles.ViaVersion.bungee.providers.BungeeBossBarProvider;
import us.myles.ViaVersion.bungee.providers.BungeeEntityIdProvider;
import us.myles.ViaVersion.bungee.providers.BungeeMainHandProvider;
import us.myles.ViaVersion.bungee.providers.BungeeMovementTransmitter;
import us.myles.ViaVersion.bungee.providers.BungeeVersionProvider;
import us.myles.ViaVersion.bungee.service.ProtocolDetectorService; import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
import us.myles.ViaVersion.protocols.base.VersionProvider; import us.myles.ViaVersion.protocols.base.VersionProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider;
@ -62,7 +65,7 @@ public class BungeeViaLoader implements ViaPlatformLoader {
registerListener(new UpdateListener()); registerListener(new UpdateListener());
registerListener(new BungeeServerHandler()); registerListener(new BungeeServerHandler());
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) { if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_9.getVersion()) {
registerListener(new ElytraPatch()); registerListener(new ElytraPatch());
} }
@ -70,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 (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) { if (Via.getAPI().getServerVersion() < 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());

View File

@ -17,17 +17,15 @@
*/ */
package us.myles.ViaVersion; package us.myles.ViaVersion;
import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
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;
import us.myles.ViaVersion.api.platform.ViaInjector; import us.myles.ViaVersion.api.platform.ViaInjector;
import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader; import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
import us.myles.ViaVersion.api.platform.providers.ViaProviders; import us.myles.ViaVersion.api.platform.providers.ViaProviders;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.ProtocolManager;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry; 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.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;
@ -37,14 +35,13 @@ import us.myles.ViaVersion.update.UpdateUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID;
public class ViaManagerImpl implements ViaManager { public class ViaManagerImpl implements ViaManager {
private final ViaPlatform<?> platform; private final ProtocolManagerImpl protocolManager = new ProtocolManagerImpl();
private final ViaConnectionManager connectionManager = new ViaConnectionManager();
private final ViaProviders providers = new ViaProviders(); private final ViaProviders providers = new ViaProviders();
// Internals private final ViaPlatform<?> platform;
private final ViaInjector injector; private final ViaInjector injector;
private final ViaCommandHandler commandHandler; private final ViaCommandHandler commandHandler;
private final ViaPlatformLoader loader; private final ViaPlatformLoader loader;
@ -74,8 +71,8 @@ public class ViaManagerImpl implements ViaManager {
UpdateUtil.sendUpdateMessage(); UpdateUtil.sendUpdateMessage();
} }
// Force class load // Register protocols
ProtocolRegistry.init(); protocolManager.registerProtocols();
// Inject // Inject
try { try {
@ -101,22 +98,22 @@ public class ViaManagerImpl implements ViaManager {
public void onServerLoaded() { public void onServerLoaded() {
// Load Server Protocol // Load Server Protocol
try { try {
ProtocolRegistry.SERVER_PROTOCOL = ProtocolVersion.getProtocol(injector.getServerProtocolVersion()).getVersion(); protocolManager.setServerProtocol(ProtocolVersion.getProtocol(injector.getServerProtocolVersion()).getVersion());
} catch (Exception e) { } catch (Exception e) {
platform.getLogger().severe("ViaVersion failed to get the server protocol!"); platform.getLogger().severe("ViaVersion failed to get the server protocol!");
e.printStackTrace(); e.printStackTrace();
} }
// Check if there are any pipes to this version // Check if there are any pipes to this version
if (ProtocolRegistry.SERVER_PROTOCOL != -1) { if (protocolManager.getServerProtocol() != -1) {
platform.getLogger().info("ViaVersion detected server version: " + ProtocolVersion.getProtocol(ProtocolRegistry.SERVER_PROTOCOL)); platform.getLogger().info("ViaVersion detected server version: " + ProtocolVersion.getProtocol(protocolManager.getServerProtocol()));
if (!ProtocolRegistry.isWorkingPipe() && !platform.isProxy()) { if (!protocolManager.isWorkingPipe() && !platform.isProxy()) {
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 (ProtocolRegistry.SERVER_PROTOCOL <= ProtocolVersion.v1_12_2.getVersion() && !platform.isProxy()) { } else if (protocolManager.getServerProtocol() <= ProtocolVersion.v1_12_2.getVersion() && !platform.isProxy()) {
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.");
@ -124,30 +121,30 @@ public class ViaManagerImpl implements ViaManager {
} }
// Load Listeners / Tasks // Load Listeners / Tasks
ProtocolRegistry.onServerLoaded(); protocolManager.onServerLoaded();
// Load Platform // Load Platform
loader.load(); loader.load();
// Common tasks // Common tasks
mappingLoadingTask = Via.getPlatform().runRepeatingSync(() -> { mappingLoadingTask = Via.getPlatform().runRepeatingSync(() -> {
if (ProtocolRegistry.checkForMappingCompletion()) { if (protocolManager.checkForMappingCompletion()) {
platform.cancelTask(mappingLoadingTask); platform.cancelTask(mappingLoadingTask);
mappingLoadingTask = null; mappingLoadingTask = null;
} }
}, 10L); }, 10L);
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) { if (protocolManager.getServerProtocol() < 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 (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_13.getVersion()) { if (protocolManager.getServerProtocol() < 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);
} }
} }
// Refresh Versions // Refresh Versions
ProtocolRegistry.refreshVersions(); protocolManager.refreshVersions();
} }
public void destroy() { public void destroy() {
@ -164,61 +161,47 @@ public class ViaManagerImpl implements ViaManager {
loader.unload(); loader.unload();
} }
public Set<UserConnection> getConnections() { @Override
return platform.getConnectionManager().getConnections();
}
/**
* @deprecated use getConnectedClients()
*/
@Deprecated
public Map<UUID, UserConnection> getPortedPlayers() {
return getConnectedClients();
}
public Map<UUID, UserConnection> getConnectedClients() {
return platform.getConnectionManager().getConnectedClients();
}
public UUID getConnectedClientId(UserConnection conn) {
return platform.getConnectionManager().getConnectedClientId(conn);
}
/**
* @see ViaConnectionManager#isClientConnected(UUID)
*/
public boolean isClientConnected(UUID player) {
return platform.getConnectionManager().isClientConnected(player);
}
public void handleLoginSuccess(UserConnection info) {
platform.getConnectionManager().onLoginSuccess(info);
}
public ViaPlatform<?> getPlatform() { public ViaPlatform<?> getPlatform() {
return platform; return platform;
} }
@Override
public ViaConnectionManager getConnectionManager() {
return connectionManager;
}
@Override
public ProtocolManager getProtocolManager() {
return protocolManager;
}
@Override
public ViaProviders getProviders() { public ViaProviders getProviders() {
return providers; return providers;
} }
@Override
public boolean isDebug() { public boolean isDebug() {
return debug; return debug;
} }
@Override
public void setDebug(boolean debug) { public void setDebug(boolean debug) {
this.debug = debug; this.debug = debug;
} }
@Override
public ViaInjector getInjector() { public ViaInjector getInjector() {
return injector; return injector;
} }
@Override
public ViaCommandHandler getCommandHandler() { public ViaCommandHandler getCommandHandler() {
return commandHandler; return commandHandler;
} }
@Override
public ViaPlatformLoader getLoader() { public ViaPlatformLoader getLoader() {
return loader; return loader;
} }
@ -233,14 +216,6 @@ public class ViaManagerImpl implements ViaManager {
return subPlatforms; return subPlatforms;
} }
/**
* @see ViaConnectionManager#getConnectedClient(UUID)
*/
@Nullable
public UserConnection getConnection(UUID playerUUID) {
return platform.getConnectionManager().getConnectedClient(playerUUID);
}
/** /**
* Adds a runnable to be executed when ViaVersion has finished its init before the full server load. * Adds a runnable to be executed when ViaVersion has finished its init before the full server load.
* *
@ -250,16 +225,6 @@ public class ViaManagerImpl implements ViaManager {
enableListeners.add(runnable); enableListeners.add(runnable);
} }
@Override
public Protocol getBaseProtocol() {
return ProtocolRegistry.BASE_PROTOCOL;
}
@Override
public boolean isBaseProtocol(Protocol protocol) {
return ProtocolRegistry.isBaseProtocol(protocol);
}
public static final class ViaManagerBuilder { public static final class ViaManagerBuilder {
private ViaPlatform<?> platform; private ViaPlatform<?> platform;
private ViaInjector injector; private ViaInjector injector;

View File

@ -19,7 +19,6 @@ 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.ProtocolRegistry;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
@ -29,12 +28,12 @@ public abstract class ViaAPIBase<T> implements ViaAPI<T> {
@Override @Override
public int getServerVersion() { public int getServerVersion() {
return ProtocolRegistry.SERVER_PROTOCOL; return Via.getManager().getProtocolManager().getServerProtocol();
} }
@Override @Override
public int getPlayerVersion(UUID uuid) { public int getPlayerVersion(UUID uuid) {
UserConnection connection = Via.getManager().getConnection(uuid); UserConnection connection = Via.getManager().getConnectionManager().getConnectedClient(uuid);
return connection != null ? connection.getProtocolInfo().getProtocolVersion() : -1; return connection != null ? connection.getProtocolInfo().getProtocolVersion() : -1;
} }
@ -45,7 +44,7 @@ public abstract class ViaAPIBase<T> implements ViaAPI<T> {
@Override @Override
public boolean isInjected(UUID playerUUID) { public boolean isInjected(UUID playerUUID) {
return Via.getManager().isClientConnected(playerUUID); return Via.getManager().getConnectionManager().isClientConnected(playerUUID);
} }
@Override @Override
@ -54,19 +53,19 @@ public abstract class ViaAPIBase<T> implements ViaAPI<T> {
throw new IllegalArgumentException("This player is not controlled by ViaVersion!"); throw new IllegalArgumentException("This player is not controlled by ViaVersion!");
} }
UserConnection user = Via.getManager().getConnection(uuid); UserConnection user = Via.getManager().getConnectionManager().getConnectedClient(uuid);
user.sendRawPacket(packet); user.sendRawPacket(packet);
} }
@Override @Override
public SortedSet<Integer> getSupportedVersions() { public SortedSet<Integer> getSupportedVersions() {
SortedSet<Integer> outputSet = new TreeSet<>(ProtocolRegistry.getSupportedVersions()); SortedSet<Integer> outputSet = new TreeSet<>(Via.getManager().getProtocolManager().getSupportedVersions());
outputSet.removeAll(Via.getPlatform().getConf().getBlockedProtocols()); outputSet.removeAll(Via.getPlatform().getConf().getBlockedProtocols());
return outputSet; return outputSet;
} }
@Override @Override
public SortedSet<Integer> getFullSupportedVersions() { public SortedSet<Integer> getFullSupportedVersions() {
return ProtocolRegistry.getSupportedVersions(); return Via.getManager().getProtocolManager().getSupportedVersions();
} }
} }

View File

@ -39,7 +39,7 @@ public abstract class ViaListener {
*/ */
@Nullable @Nullable
protected UserConnection getUserConnection(UUID uuid) { protected UserConnection getUserConnection(UUID uuid) {
return Via.getManager().getConnection(uuid); return Via.getManager().getConnectionManager().getConnectedClient(uuid);
} }
/** /**

View File

@ -79,28 +79,32 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Function; import java.util.function.Function;
public class ProtocolRegistry { public class ProtocolManagerImpl implements ProtocolManager {
public static final Protocol BASE_PROTOCOL = new BaseProtocol(); public static final Protocol BASE_PROTOCOL = new BaseProtocol();
public static int SERVER_PROTOCOL = -1;
public static int maxProtocolPathSize = 50;
// Input Version -> Output Version & Protocol (Allows fast lookup) // Input Version -> Output Version & Protocol (Allows fast lookup)
private static final Int2ObjectMap<Int2ObjectMap<Protocol>> registryMap = new Int2ObjectOpenHashMap<>(32); private final Int2ObjectMap<Int2ObjectMap<Protocol>> registryMap = new Int2ObjectOpenHashMap<>(32);
private static final Map<Class<? extends Protocol>, Protocol> protocols = new HashMap<>(); private final Map<Class<? extends Protocol>, Protocol> protocols = new HashMap<>();
private static final Map<Pair<Integer, Integer>, List<Pair<Integer, Protocol>>> pathCache = new ConcurrentHashMap<>(); private final Map<Pair<Integer, Integer>, List<Pair<Integer, Protocol>>> pathCache = new ConcurrentHashMap<>();
private static final Set<Integer> supportedVersions = new HashSet<>(); private final Set<Integer> supportedVersions = new HashSet<>();
private static final List<Pair<Range<Integer>, Protocol>> baseProtocols = Lists.newCopyOnWriteArrayList(); private final List<Pair<Range<Integer>, Protocol>> baseProtocols = Lists.newCopyOnWriteArrayList();
private static final List<Protocol> registerList = new ArrayList<>(); private final List<Protocol> registerList = new ArrayList<>();
private static final ReadWriteLock MAPPING_LOADER_LOCK = new ReentrantReadWriteLock(); private final ReadWriteLock mappingLoaderLock = new ReentrantReadWriteLock();
private static Map<Class<? extends Protocol>, CompletableFuture<Void>> mappingLoaderFutures = new HashMap<>(); private Map<Class<? extends Protocol>, CompletableFuture<Void>> mappingLoaderFutures = new HashMap<>();
private static ThreadPoolExecutor mappingLoaderExecutor; private ThreadPoolExecutor mappingLoaderExecutor;
private static boolean mappingsLoaded; private boolean mappingsLoaded;
static { private int maxProtocolPathSize = 50;
private int serverProtocol = -1;
public ProtocolManagerImpl() {
ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("Via-Mappingloader-%d").build(); ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("Via-Mappingloader-%d").build();
mappingLoaderExecutor = new ThreadPoolExecutor(5, 16, 45L, TimeUnit.SECONDS, new SynchronousQueue<>(), threadFactory); mappingLoaderExecutor = new ThreadPoolExecutor(5, 16, 45L, TimeUnit.SECONDS, new SynchronousQueue<>(), threadFactory);
mappingLoaderExecutor.allowCoreThreadTimeOut(true); mappingLoaderExecutor.allowCoreThreadTimeOut(true);
}
public void registerProtocols() {
// Base Protocol // Base Protocol
registerBaseProtocol(BASE_PROTOCOL, Range.lessThan(Integer.MIN_VALUE)); registerBaseProtocol(BASE_PROTOCOL, Range.lessThan(Integer.MIN_VALUE));
registerBaseProtocol(new BaseProtocol1_7(), Range.lessThan(ProtocolVersion.v1_16.getVersion())); registerBaseProtocol(new BaseProtocol1_7(), Range.lessThan(ProtocolVersion.v1_16.getVersion()));
@ -144,29 +148,13 @@ public class ProtocolRegistry {
registerProtocol(new Protocol1_17To1_16_4(), ProtocolVersion.v1_17, ProtocolVersion.v1_16_4); registerProtocol(new Protocol1_17To1_16_4(), ProtocolVersion.v1_17, ProtocolVersion.v1_16_4);
} }
public static void init() { @Override
// Empty method to trigger static initializer once public void registerProtocol(Protocol protocol, ProtocolVersion supported, ProtocolVersion output) {
}
/**
* Register a protocol
*
* @param protocol The protocol to register.
* @param supported Supported client versions.
* @param output The output server version it converts to.
*/
public static void registerProtocol(Protocol protocol, ProtocolVersion supported, ProtocolVersion output) {
registerProtocol(protocol, Collections.singletonList(supported.getVersion()), output.getVersion()); registerProtocol(protocol, Collections.singletonList(supported.getVersion()), output.getVersion());
} }
/** @Override
* Register a protocol public void registerProtocol(Protocol protocol, List<Integer> supported, int output) {
*
* @param protocol The protocol to register.
* @param supported Supported client versions.
* @param output The output server version it converts to.
*/
public static void registerProtocol(Protocol protocol, List<Integer> supported, int output) {
// Clear cache as this may make new routes. // Clear cache as this may make new routes.
if (!pathCache.isEmpty()) { if (!pathCache.isEmpty()) {
pathCache.clear(); pathCache.clear();
@ -197,15 +185,8 @@ public class ProtocolRegistry {
} }
} }
/** @Override
* Registers a base protocol. public void registerBaseProtocol(Protocol baseProtocol, Range<Integer> supportedProtocols) {
* Base Protocols registered later have higher priority
* Only one base protocol will be added to pipeline
*
* @param baseProtocol Base Protocol to register
* @param supportedProtocols Versions that baseProtocol supports
*/
public static void registerBaseProtocol(Protocol baseProtocol, Range<Integer> supportedProtocols) {
baseProtocols.add(new Pair<>(supportedProtocols, baseProtocol)); baseProtocols.add(new Pair<>(supportedProtocols, baseProtocol));
if (Via.getPlatform().isPluginEnabled()) { if (Via.getPlatform().isPluginEnabled()) {
baseProtocol.register(Via.getManager().getProviders()); baseProtocol.register(Via.getManager().getProviders());
@ -215,12 +196,12 @@ public class ProtocolRegistry {
} }
} }
public static void refreshVersions() { public void refreshVersions() {
supportedVersions.clear(); supportedVersions.clear();
supportedVersions.add(ProtocolRegistry.SERVER_PROTOCOL); supportedVersions.add(serverProtocol);
for (ProtocolVersion versions : ProtocolVersion.getProtocols()) { for (ProtocolVersion versions : ProtocolVersion.getProtocols()) {
List<Pair<Integer, Protocol>> paths = getProtocolPath(versions.getVersion(), ProtocolRegistry.SERVER_PROTOCOL); List<Pair<Integer, Protocol>> paths = getProtocolPath(versions.getVersion(), serverProtocol);
if (paths == null) continue; if (paths == null) continue;
supportedVersions.add(versions.getVersion()); supportedVersions.add(versions.getVersion());
for (Pair<Integer, Protocol> path : paths) { for (Pair<Integer, Protocol> path : paths) {
@ -229,47 +210,34 @@ public class ProtocolRegistry {
} }
} }
/** @Nullable
* Get the versions compatible with the server. @Override
* public List<Pair<Integer, Protocol>> getProtocolPath(int clientVersion, int serverVersion) {
* @return Read-only set of the versions. Pair<Integer, Integer> protocolKey = new Pair<>(clientVersion, serverVersion);
*/ // Check cache
public static SortedSet<Integer> getSupportedVersions() { List<Pair<Integer, Protocol>> protocolList = pathCache.get(protocolKey);
return Collections.unmodifiableSortedSet(new TreeSet<>(supportedVersions)); if (protocolList != null) {
} return protocolList;
/**
* Check if this plugin is useful to the server.
*
* @return True if there is a useful pipe
*/
public static boolean isWorkingPipe() {
for (Int2ObjectMap<Protocol> map : registryMap.values()) {
if (map.containsKey(SERVER_PROTOCOL)) return true;
} }
return false; // No destination for protocol // Generate path
} List<Pair<Integer, Protocol>> outputPath = getProtocolPath(new ArrayList<>(), clientVersion, serverVersion);
// If it found a path, cache it.
/** if (outputPath != null) {
* Called when the server is enabled, to register any non registered listeners. pathCache.put(protocolKey, outputPath);
*/
public static void onServerLoaded() {
for (Protocol protocol : registerList) {
protocol.register(Via.getManager().getProviders());
} }
registerList.clear(); return outputPath;
} }
/** /**
* Calculate a path to get from an input protocol to the servers protocol. * Calculates a path to get from an input protocol to the server's protocol.
* *
* @param current The current items in the path * @param current current items in the path
* @param clientVersion The current input version * @param clientVersion current input version
* @param serverVersion The desired output version * @param serverVersion desired output version
* @return The path which has been generated, null if failed. * @return path that has been generated, null if failed
*/ */
@Nullable @Nullable
private static List<Pair<Integer, Protocol>> getProtocolPath(List<Pair<Integer, Protocol>> current, int clientVersion, int serverVersion) { private List<Pair<Integer, Protocol>> getProtocolPath(List<Pair<Integer, Protocol>> current, int clientVersion, int serverVersion) {
if (clientVersion == serverVersion) return null; // We're already there if (clientVersion == serverVersion) return null; // We're already there
if (current.size() > maxProtocolPathSize) return null; // Fail safe, protocol too complicated. if (current.size() > maxProtocolPathSize) return null; // Fail safe, protocol too complicated.
@ -312,42 +280,14 @@ public class ProtocolRegistry {
return shortest; // null if none found return shortest; // null if none found
} }
/**
* Calculate a path from a client version to server version.
*
* @param clientVersion The input client version
* @param serverVersion The desired output server version
* @return The path it generated, null if it failed.
*/
@Nullable @Nullable
public static List<Pair<Integer, Protocol>> getProtocolPath(int clientVersion, int serverVersion) { @Override
Pair<Integer, Integer> protocolKey = new Pair<>(clientVersion, serverVersion); public Protocol getProtocol(Class<? extends Protocol> protocolClass) {
// Check cache
List<Pair<Integer, Protocol>> protocolList = pathCache.get(protocolKey);
if (protocolList != null) {
return protocolList;
}
// Generate path
List<Pair<Integer, Protocol>> outputPath = getProtocolPath(new ArrayList<>(), clientVersion, serverVersion);
// If it found a path, cache it.
if (outputPath != null) {
pathCache.put(protocolKey, outputPath);
}
return outputPath;
}
/**
* Returns a protocol instance by its class.
*
* @param protocolClass class of the protocol
* @return protocol if present
*/
@Nullable
public static Protocol getProtocol(Class<? extends Protocol> protocolClass) {
return protocols.get(protocolClass); return protocols.get(protocolClass);
} }
public static Protocol getBaseProtocol(int serverVersion) { @Override
public Protocol getBaseProtocol(int serverVersion) {
for (Pair<Range<Integer>, Protocol> rangeProtocol : Lists.reverse(baseProtocols)) { for (Pair<Range<Integer>, Protocol> rangeProtocol : Lists.reverse(baseProtocols)) {
if (rangeProtocol.getKey().contains(serverVersion)) { if (rangeProtocol.getKey().contains(serverVersion)) {
return rangeProtocol.getValue(); return rangeProtocol.getValue();
@ -356,7 +296,8 @@ public class ProtocolRegistry {
throw new IllegalStateException("No Base Protocol for " + serverVersion); throw new IllegalStateException("No Base Protocol for " + serverVersion);
} }
public static boolean isBaseProtocol(Protocol protocol) { @Override
public boolean isBaseProtocol(Protocol protocol) {
for (Pair<Range<Integer>, Protocol> p : baseProtocols) { for (Pair<Range<Integer>, Protocol> p : baseProtocols) {
if (p.getValue() == protocol) { if (p.getValue() == protocol) {
return true; return true;
@ -365,12 +306,46 @@ public class ProtocolRegistry {
return false; return false;
} }
/** @Override
* Ensure that mapping data for that protocol has already been loaded, completes it otherwise. public int getServerProtocol() {
* return serverProtocol;
* @param protocolClass protocol class }
*/
public static void completeMappingDataLoading(Class<? extends Protocol> protocolClass) throws Exception { public void setServerProtocol(int serverProtocol) {
this.serverProtocol = serverProtocol;
ProtocolRegistry.SERVER_PROTOCOL = serverProtocol;
}
@Override
public boolean isWorkingPipe() {
for (Int2ObjectMap<Protocol> map : registryMap.values()) {
if (map.containsKey(serverProtocol)) return true;
}
return false; // No destination for protocol
}
@Override
public SortedSet<Integer> getSupportedVersions() {
return Collections.unmodifiableSortedSet(new TreeSet<>(supportedVersions));
}
@Override
public int getMaxProtocolPathSize() {
return maxProtocolPathSize;
}
@Override
public void setMaxProtocolPathSize(int maxProtocolPathSize) {
this.maxProtocolPathSize = maxProtocolPathSize;
}
@Override
public Protocol getBaseProtocol() {
return BASE_PROTOCOL;
}
@Override
public void completeMappingDataLoading(Class<? extends Protocol> protocolClass) throws Exception {
if (mappingsLoaded) return; if (mappingsLoaded) return;
CompletableFuture<Void> future = getMappingLoaderFuture(protocolClass); CompletableFuture<Void> future = getMappingLoaderFuture(protocolClass);
@ -380,13 +355,9 @@ public class ProtocolRegistry {
} }
} }
/** @Override
* Shuts down the executor and uncaches mappings if all futures have been completed. public boolean checkForMappingCompletion() {
* mappingLoaderLock.readLock().lock();
* @return true if the executor has now been shut down
*/
public static boolean checkForMappingCompletion() {
MAPPING_LOADER_LOCK.readLock().lock();
try { try {
if (mappingsLoaded) return false; if (mappingsLoaded) return false;
@ -400,66 +371,57 @@ public class ProtocolRegistry {
shutdownLoaderExecutor(); shutdownLoaderExecutor();
return true; return true;
} finally { } finally {
MAPPING_LOADER_LOCK.readLock().unlock(); mappingLoaderLock.readLock().unlock();
} }
} }
/** @Override
* Executes the given runnable asynchronously, adding a {@link CompletableFuture} public void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Runnable runnable) {
* to the list of data to load bound to their protocols.
*
* @param protocolClass protocol class
* @param runnable runnable to be executed asynchronously
*/
public static void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Runnable runnable) {
CompletableFuture<Void> future = CompletableFuture.runAsync(runnable, mappingLoaderExecutor).exceptionally(mappingLoaderThrowable(protocolClass)); CompletableFuture<Void> future = CompletableFuture.runAsync(runnable, mappingLoaderExecutor).exceptionally(mappingLoaderThrowable(protocolClass));
MAPPING_LOADER_LOCK.writeLock().lock(); mappingLoaderLock.writeLock().lock();
try { try {
mappingLoaderFutures.put(protocolClass, future); mappingLoaderFutures.put(protocolClass, future);
} finally { } finally {
MAPPING_LOADER_LOCK.writeLock().unlock(); mappingLoaderLock.writeLock().unlock();
} }
} }
/** @Override
* Executes the given runnable asynchronously after the other protocol has finished its data loading, public void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Class<? extends Protocol> dependsOn, Runnable runnable) {
* adding a {@link CompletableFuture} to the list of data to load bound to their protocols.
*
* @param protocolClass protocol class
* @param dependsOn class of the protocol that the data loading depends on
* @param runnable runnable to be executed asynchronously
*/
public static void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Class<? extends Protocol> dependsOn, Runnable runnable) {
CompletableFuture<Void> future = getMappingLoaderFuture(dependsOn) CompletableFuture<Void> future = getMappingLoaderFuture(dependsOn)
.whenCompleteAsync((v, throwable) -> runnable.run(), mappingLoaderExecutor).exceptionally(mappingLoaderThrowable(protocolClass)); .whenCompleteAsync((v, throwable) -> runnable.run(), mappingLoaderExecutor).exceptionally(mappingLoaderThrowable(protocolClass));
MAPPING_LOADER_LOCK.writeLock().lock(); mappingLoaderLock.writeLock().lock();
try { try {
mappingLoaderFutures.put(protocolClass, future); mappingLoaderFutures.put(protocolClass, future);
} finally { } finally {
MAPPING_LOADER_LOCK.writeLock().unlock(); mappingLoaderLock.writeLock().unlock();
}
}
@Nullable
@Override
public CompletableFuture<Void> getMappingLoaderFuture(Class<? extends Protocol> protocolClass) {
mappingLoaderLock.readLock().lock();
try {
return mappingsLoaded ? null : mappingLoaderFutures.get(protocolClass);
} finally {
mappingLoaderLock.readLock().unlock();
} }
} }
/** /**
* Returns the data loading future bound to the protocol, or null if all loading is complete. * Called when the server is enabled, to register any non-registered listeners.
* The future may or may not have already been completed.
*
* @param protocolClass protocol class
* @return data loading future bound to the protocol, or null if all loading is complete
*/ */
@Nullable public void onServerLoaded() {
public static CompletableFuture<Void> getMappingLoaderFuture(Class<? extends Protocol> protocolClass) { for (Protocol protocol : registerList) {
MAPPING_LOADER_LOCK.readLock().lock(); protocol.register(Via.getManager().getProviders());
try {
return mappingsLoaded ? null : mappingLoaderFutures.get(protocolClass);
} finally {
MAPPING_LOADER_LOCK.readLock().unlock();
} }
registerList.clear();
} }
private static void shutdownLoaderExecutor() { private void shutdownLoaderExecutor() {
Preconditions.checkArgument(!mappingsLoaded); Preconditions.checkArgument(!mappingsLoaded);
Via.getPlatform().getLogger().info("Finished mapping loading, shutting down loader executor!"); Via.getPlatform().getLogger().info("Finished mapping loading, shutting down loader executor!");
@ -473,7 +435,7 @@ public class ProtocolRegistry {
} }
} }
private static Function<Throwable, Void> mappingLoaderThrowable(Class<? extends Protocol> protocolClass) { private Function<Throwable, Void> mappingLoaderThrowable(Class<? extends Protocol> protocolClass) {
return throwable -> { return throwable -> {
Via.getPlatform().getLogger().severe("Error during mapping loading of " + protocolClass.getSimpleName()); Via.getPlatform().getLogger().severe("Error during mapping loading of " + protocolClass.getSimpleName());
throwable.printStackTrace(); throwable.printStackTrace();

View File

@ -94,7 +94,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
@Override @Override
public BossBar addPlayer(UUID player) { public BossBar addPlayer(UUID player) {
return addConnection(Via.getManager().getConnection(player)); return addConnection(Via.getManager().getConnectionManager().getConnectedClient(player));
} }
@Override @Override
@ -107,7 +107,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
@Override @Override
public BossBar removePlayer(UUID uuid) { public BossBar removePlayer(UUID uuid) {
return removeConnection(Via.getManager().getConnection(uuid)); return removeConnection(Via.getManager().getConnectionManager().getConnectedClient(uuid));
} }
@Override @Override
@ -144,7 +144,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
@Override @Override
public Set<UUID> getPlayers() { public Set<UUID> getPlayers() {
return connections.stream().map(conn -> Via.getManager().getConnectedClientId(conn)).filter(Objects::nonNull) return connections.stream().map(conn -> Via.getManager().getConnectionManager().getConnectedClientId(conn)).filter(Objects::nonNull)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }

View File

@ -22,7 +22,6 @@ import com.google.gson.JsonObject;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.command.ViaSubCommand; import us.myles.ViaVersion.api.command.ViaSubCommand;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.dump.DumpTemplate; import us.myles.ViaVersion.dump.DumpTemplate;
import us.myles.ViaVersion.dump.VersionInfo; import us.myles.ViaVersion.dump.VersionInfo;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
@ -54,8 +53,8 @@ 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"),
ProtocolRegistry.SERVER_PROTOCOL, Via.getAPI().getServerVersion(),
ProtocolRegistry.getSupportedVersions(), Via.getManager().getProtocolManager().getSupportedVersions(),
Via.getPlatform().getPlatformName(), Via.getPlatform().getPlatformName(),
Via.getPlatform().getPlatformVersion(), Via.getPlatform().getPlatformVersion(),
Via.getPlatform().getPluginVersion(), Via.getPlatform().getPluginVersion(),

View File

@ -52,7 +52,7 @@ public class PPSSubCmd extends ViaSubCommand {
int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID()); int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID());
if (!playerVersions.containsKey(playerVersion)) if (!playerVersions.containsKey(playerVersion))
playerVersions.put(playerVersion, new HashSet<String>()); playerVersions.put(playerVersion, new HashSet<String>());
UserConnection uc = Via.getManager().getConnection(p.getUUID()); UserConnection uc = Via.getManager().getConnectionManager().getConnectedClient(p.getUUID());
if (uc != null && uc.getPacketsPerSecond() > -1) { if (uc != null && uc.getPacketsPerSecond() > -1) {
playerVersions.get(playerVersion).add(p.getName() + " (" + uc.getPacketsPerSecond() + " PPS)"); playerVersions.get(playerVersion).add(p.getName() + " (" + uc.getPacketsPerSecond() + " PPS)");
totalPackets += uc.getPacketsPerSecond(); totalPackets += uc.getPacketsPerSecond();

View File

@ -24,7 +24,6 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.providers.ViaProviders; import us.myles.ViaVersion.api.platform.providers.ViaProviders;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion; import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.api.protocol.SimpleProtocol; import us.myles.ViaVersion.api.protocol.SimpleProtocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
@ -65,7 +64,7 @@ public class BaseProtocol extends SimpleProtocol {
// Only allow newer clients or (1.9.2 on 1.9.4 server if the server supports it) // Only allow newer clients or (1.9.2 on 1.9.4 server if the server supports it)
if (info.getProtocolVersion() >= serverProtocol || Via.getPlatform().isOldClientsAllowed()) { if (info.getProtocolVersion() >= serverProtocol || Via.getPlatform().isOldClientsAllowed()) {
protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), serverProtocol); protocols = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), serverProtocol);
} }
ProtocolPipeline pipeline = wrapper.user().getProtocolInfo().getPipeline(); ProtocolPipeline pipeline = wrapper.user().getProtocolInfo().getPipeline();
@ -73,7 +72,7 @@ public class BaseProtocol extends SimpleProtocol {
for (Pair<Integer, Protocol> prot : protocols) { for (Pair<Integer, Protocol> prot : protocols) {
pipeline.add(prot.getValue()); pipeline.add(prot.getValue());
// Ensure mapping data has already been loaded // Ensure mapping data has already been loaded
ProtocolRegistry.completeMappingDataLoading(prot.getValue().getClass()); Via.getManager().getProtocolManager().completeMappingDataLoading(prot.getValue().getClass());
} }
// Set the original snapshot version if present // Set the original snapshot version if present
@ -82,7 +81,7 @@ public class BaseProtocol extends SimpleProtocol {
} }
// Add Base Protocol // Add Base Protocol
pipeline.add(ProtocolRegistry.getBaseProtocol(serverProtocol)); pipeline.add(Via.getManager().getProtocolManager().getBaseProtocol(serverProtocol));
// Change state // Change state
if (state == 1) { if (state == 1) {

View File

@ -26,7 +26,7 @@ import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry; 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.SimpleProtocol; import us.myles.ViaVersion.api.protocol.SimpleProtocol;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;
@ -81,8 +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 (ProtocolRegistry.SERVER_PROTOCOL == -1) { // Set the Server protocol if the detection on startup failed if (Via.getAPI().getServerVersion() == -1) { // Set the Server protocol if the detection on startup failed
ProtocolRegistry.SERVER_PROTOCOL = ProtocolVersion.getProtocol(protocolVersion).getVersion(); ProtocolManagerImpl protocolManager = (ProtocolManagerImpl) Via.getManager().getProtocolManager();
protocolManager.setServerProtocol(ProtocolVersion.getProtocol(protocolVersion).getVersion());
} }
// Ensure the server has a version provider // Ensure the server has a version provider
@ -97,7 +98,7 @@ public class BaseProtocol1_7 extends SimpleProtocol {
// Only allow newer clients or (1.9.2 on 1.9.4 server if the server supports it) // Only allow newer clients or (1.9.2 on 1.9.4 server if the server supports it)
if (info.getProtocolVersion() >= protocol || Via.getPlatform().isOldClientsAllowed()) { if (info.getProtocolVersion() >= protocol || Via.getPlatform().isOldClientsAllowed()) {
protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocol); protocols = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), protocol);
} }
if (protocols != null) { if (protocols != null) {
@ -144,9 +145,9 @@ public class BaseProtocol1_7 extends SimpleProtocol {
String username = wrapper.passthrough(Type.STRING); String username = wrapper.passthrough(Type.STRING);
info.setUsername(username); info.setUsername(username);
// Add to ported clients // Add to ported clients
Via.getManager().handleLoginSuccess(wrapper.user()); Via.getManager().getConnectionManager().onLoginSuccess(wrapper.user());
if (info.getPipeline().pipes().stream().allMatch(ProtocolRegistry::isBaseProtocol)) { // Only base protocol if (info.getPipeline().pipes().stream().allMatch(Via.getManager().getProtocolManager()::isBaseProtocol)) { // Only base protocol
wrapper.user().setActive(false); wrapper.user().setActive(false);
} }

View File

@ -17,13 +17,12 @@
*/ */
package us.myles.ViaVersion.protocols.base; package us.myles.ViaVersion.protocols.base;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.providers.Provider;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
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 ProtocolRegistry.SERVER_PROTOCOL; return Via.getAPI().getServerVersion();
} }
} }

View File

@ -24,7 +24,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.TabCompleteTra
public class TabCompleteThread implements Runnable { public class TabCompleteThread implements Runnable {
@Override @Override
public void run() { public void run() {
for (UserConnection info : Via.getManager().getConnections()) { for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
if (info.getProtocolInfo() == null) continue; if (info.getProtocolInfo() == null) continue;
if (info.getProtocolInfo().getPipeline().contains(Protocol1_13To1_12_2.class)) { if (info.getProtocolInfo().getPipeline().contains(Protocol1_13To1_12_2.class)) {
if (info.getChannel().isOpen()) { if (info.getChannel().isOpen()) {

View File

@ -27,7 +27,7 @@ public class ViaIdleThread implements Runnable {
@Override @Override
public void run() { public void run() {
for (UserConnection info : Via.getManager().getConnections()) { for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
ProtocolInfo protocolInfo = info.getProtocolInfo(); ProtocolInfo protocolInfo = info.getProtocolInfo();
if (protocolInfo == null || !protocolInfo.getPipeline().contains(Protocol1_9To1_8.class)) continue; if (protocolInfo == null || !protocolInfo.getPipeline().contains(Protocol1_9To1_8.class)) continue;

View File

@ -35,7 +35,6 @@ import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider; import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
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.ViaPlatform; import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.dump.PluginInfo; import us.myles.ViaVersion.dump.PluginInfo;
import us.myles.ViaVersion.sponge.commands.SpongeCommandHandler; import us.myles.ViaVersion.sponge.commands.SpongeCommandHandler;
@ -72,7 +71,6 @@ public class SpongePlugin implements ViaPlatform<Player> {
private File spongeConfig; private File spongeConfig;
public static final LegacyComponentSerializer COMPONENT_SERIALIZER = LegacyComponentSerializer.builder().character('§').extractUrls().build(); public static final LegacyComponentSerializer COMPONENT_SERIALIZER = LegacyComponentSerializer.builder().character('§').extractUrls().build();
private final ViaConnectionManager connectionManager = new ViaConnectionManager();
private final SpongeViaAPI api = new SpongeViaAPI(); private final SpongeViaAPI api = new SpongeViaAPI();
private SpongeViaConfig conf; private SpongeViaConfig conf;
private Logger logger; private Logger logger;
@ -243,11 +241,6 @@ public class SpongePlugin implements ViaPlatform<Player> {
return true; return true;
} }
@Override
public ViaConnectionManager getConnectionManager() {
return connectionManager;
}
@Override @Override
public SpongeViaAPI getApi() { public SpongeViaAPI getApi() {
return api; return api;

View File

@ -22,9 +22,9 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToByteEncoder;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline; import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -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 (ProtocolRegistry.SERVER_PROTOCOL != -1 if (Via.getAPI().getServerVersion() != -1
&& 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

View File

@ -24,7 +24,6 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.platform.TaskId; import us.myles.ViaVersion.api.platform.TaskId;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader; 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.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider; 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.HandItemProvider;
@ -67,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 (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) { if (Via.getAPI().getServerVersion() < 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();
@ -84,7 +83,7 @@ public class SpongeViaLoader implements ViaPlatformLoader {
} }
/* Providers */ /* Providers */
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) { if (Via.getAPI().getServerVersion() < 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());

View File

@ -34,7 +34,6 @@ import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider; import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
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.ViaPlatform; import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.dump.PluginInfo; import us.myles.ViaVersion.dump.PluginInfo;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
@ -79,7 +78,6 @@ public class VelocityPlugin implements ViaPlatform<Player> {
private VelocityViaAPI api; private VelocityViaAPI api;
private java.util.logging.Logger logger; private java.util.logging.Logger logger;
private VelocityViaConfig conf; private VelocityViaConfig conf;
private ViaConnectionManager connectionManager;
@Subscribe @Subscribe
public void onProxyInit(ProxyInitializeEvent e) { public void onProxyInit(ProxyInitializeEvent e) {
@ -89,7 +87,6 @@ public class VelocityPlugin implements ViaPlatform<Player> {
api = new VelocityViaAPI(); api = new VelocityViaAPI();
conf = new VelocityViaConfig(configDir.toFile()); conf = new VelocityViaConfig(configDir.toFile());
logger = new LoggerWrapper(loggerslf4j); logger = new LoggerWrapper(loggerslf4j);
connectionManager = new ViaConnectionManager();
Via.init(ViaManagerImpl.builder() Via.init(ViaManagerImpl.builder()
.platform(this) .platform(this)
.commandHandler(commandHandler) .commandHandler(commandHandler)
@ -240,9 +237,4 @@ public class VelocityPlugin implements ViaPlatform<Player> {
public java.util.logging.Logger getLogger() { public java.util.logging.Logger getLogger() {
return logger; return logger;
} }
@Override
public ViaConnectionManager getConnectionManager() {
return connectionManager;
}
} }

View File

@ -21,7 +21,6 @@ import com.velocitypowered.api.plugin.PluginContainer;
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.ViaPlatformLoader; 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.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.protocols.base.VersionProvider; import us.myles.ViaVersion.protocols.base.VersionProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider;
@ -38,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 (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) { if (Via.getAPI().getServerVersion() < 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());
} }