3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 16:12:42 +01:00

ProtocolRegistry -> ProtocolManager interface

Dieser Commit ist enthalten in:
KennyTV 2021-03-24 15:21:18 +01:00
Ursprung 210cae70fd
Commit 63356207a3
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
32 geänderte Dateien mit 536 neuen und 378 gelöschten Zeilen

Datei anzeigen

@ -22,55 +22,36 @@
*/
package us.myles.ViaVersion;
import org.jetbrains.annotations.Nullable;
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.ViaInjector;
import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
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.UUID;
public interface ViaManager {
Set<UserConnection> getConnections();
/**
* @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);
ProtocolManager getProtocolManager();
ViaPlatform<?> getPlatform();
ViaConnectionManager getConnectionManager();
ViaProviders getProviders();
boolean isDebug();
void setDebug(boolean debug);
ViaInjector getInjector();
ViaVersionCommand getCommandHandler();
ViaPlatformLoader getLoader();
boolean isDebug();
void setDebug(boolean debug);
/**
* 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.
@ -79,20 +60,10 @@ public interface ViaManager {
*/
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.
*
* @param runnable runnable to be executed
*/
void addEnableListener(Runnable runnable);
Protocol getBaseProtocol();
boolean isBaseProtocol(Protocol protocol);
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -47,7 +47,7 @@ public class ProtocolPipeline extends SimpleProtocol {
protected void registerPackets() {
protocolList = new CopyOnWriteArrayList<>();
// This is a pipeline so we register basic pipes
protocolList.add(Via.getManager().getBaseProtocol());
protocolList.add(Via.getManager().getProtocolManager().getBaseProtocol());
}
@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
List<Protocol> toMove = new ArrayList<>();
for (Protocol p : protocolList) {
if (Via.getManager().isBaseProtocol(p)) {
if (Via.getManager().getProtocolManager().isBaseProtocol(p)) {
toMove.add(p);
}
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

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

Datei anzeigen

@ -24,8 +24,8 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.Via;
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.bukkit.listeners.ViaBukkitListener;
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
if (ProtocolRegistry.SERVER_PROTOCOL >= ProtocolVersion.v1_9.getVersion()) {
if (Via.getAPI().getServerVersion() >= ProtocolVersion.v1_9.getVersion()) {
sneaking = new WeakHashMap<>();
useCache = true;
plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {

Datei anzeigen

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

Datei anzeigen

@ -27,7 +27,6 @@ import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item;
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.bukkit.classgenerator.ClassGenerator;
import us.myles.ViaVersion.bukkit.listeners.UpdateListener;
@ -88,7 +87,7 @@ public class BukkitViaLoader implements ViaPlatformLoader {
ClassGenerator.registerPSConnectListener(plugin);
/* 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 DeathListener(plugin)).register();
storeListener(new BlockListener(plugin)).register();
@ -99,8 +98,8 @@ public class BukkitViaLoader implements ViaPlatformLoader {
}
}
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_14.getVersion()) {
boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion();
if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_14.getVersion()) {
boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && Via.getAPI().getServerVersion() < ProtocolVersion.v1_9.getVersion();
if (use1_9Fix || plugin.getConf().is1_14HitboxFix()) {
try {
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 {
Class.forName("org.bukkit.event.entity.EntityToggleGlideEvent");
storeListener(new EntityToggleGlideListener(plugin)).register();
@ -122,13 +121,13 @@ public class BukkitViaLoader implements ViaPlatformLoader {
if ((Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("paper")
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("taco")
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("torch"))
&& ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_12.getVersion()) {
&& Via.getAPI().getServerVersion() < ProtocolVersion.v1_12.getVersion()) {
plugin.getLogger().info("Enabling Paper/TacoSpigot/Torch patch: Fixes block placement.");
storeListener(new PaperPatch(plugin)).register();
}
/* Providers */
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) {
if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_9.getVersion()) {
Via.getManager().getProviders().use(BulkChunkTranslatorProvider.class, new BukkitViaBulkChunkTranslator());
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()) {
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")) {
BukkitBlockConnectionProvider blockConnectionProvider = new BukkitBlockConnectionProvider();
Via.getManager().getProviders().use(BlockConnectionProvider.class, blockConnectionProvider);

Datei anzeigen

@ -24,7 +24,6 @@ import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import us.myles.ViaVersion.api.Via;
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.bukkit.tasks.protocol1_12to1_11_1.BukkitInventoryUpdateTask;
import us.myles.ViaVersion.bukkit.util.NMSUtil;
@ -71,7 +70,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
// windowId is always 0 for player inventory.
// This has almost definitely something to do with the offhand slot.
if (slotId >= 36 && slotId <= 44) {
int protocolId = ProtocolRegistry.SERVER_PROTOCOL;
int protocolId = Via.getAPI().getServerVersion();
// this seems to be working just fine.
if (protocolId == ProtocolVersion.v1_8.getVersion()) {
return false;
@ -103,7 +102,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
Inventory tinv = inv.getTopInventory();
InventoryType tinvtype = tinv == null ? null : tinv.getType(); // can this even be null?
if (tinvtype != null) {
int protocolId = ProtocolRegistry.SERVER_PROTOCOL;
int protocolId = Via.getAPI().getServerVersion();
if (protocolId == ProtocolVersion.v1_8.getVersion()) {
if (tinvtype == InventoryType.BREWING) {
// 1.9 added the blaze powder slot to brewing stand fix for 1.8 servers
@ -132,7 +131,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
ReflectionUtil.set(packet, "button", 0); // shift + left mouse click
ReflectionUtil.set(packet, "d", storage.getActionId());
ReflectionUtil.set(packet, "item", nmsItem);
int protocolId = ProtocolRegistry.SERVER_PROTOCOL;
int protocolId = Via.getAPI().getServerVersion();
if (protocolId == ProtocolVersion.v1_8.getVersion()) {
ReflectionUtil.set(packet, "shift", 1);
} else if (protocolId >= ProtocolVersion.v1_9.getVersion()) { // 1.9+
@ -171,7 +170,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
}
try {
this.windowClickPacketClass = NMSUtil.nms("PacketPlayInWindowClick");
int protocolId = ProtocolRegistry.SERVER_PROTOCOL;
int protocolId = Via.getAPI().getServerVersion();
if (protocolId >= ProtocolVersion.v1_9.getVersion()) {
Class<?> eclassz = NMSUtil.nms("InventoryClickType");
Object[] constants = eclassz.getEnumConstants();
@ -200,7 +199,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
}
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()) {
return true; // 1.8-1.11.2
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -40,7 +40,7 @@ public class ElytraPatch implements Listener {
@EventHandler(priority = EventPriority.HIGH)
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;
try {

Datei anzeigen

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

Datei anzeigen

@ -17,17 +17,15 @@
*/
package us.myles.ViaVersion;
import org.jetbrains.annotations.Nullable;
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.ViaConnectionManager;
import us.myles.ViaVersion.api.platform.ViaInjector;
import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolManager;
import us.myles.ViaVersion.api.protocol.ProtocolManagerImpl;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.commands.ViaCommandHandler;
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.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
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();
// Internals
private final ViaPlatform<?> platform;
private final ViaInjector injector;
private final ViaCommandHandler commandHandler;
private final ViaPlatformLoader loader;
@ -74,8 +71,8 @@ public class ViaManagerImpl implements ViaManager {
UpdateUtil.sendUpdateMessage();
}
// Force class load
ProtocolRegistry.init();
// Register protocols
protocolManager.registerProtocols();
// Inject
try {
@ -101,22 +98,22 @@ public class ViaManagerImpl implements ViaManager {
public void onServerLoaded() {
// Load Server Protocol
try {
ProtocolRegistry.SERVER_PROTOCOL = ProtocolVersion.getProtocol(injector.getServerProtocolVersion()).getVersion();
protocolManager.setServerProtocol(ProtocolVersion.getProtocol(injector.getServerProtocolVersion()).getVersion());
} catch (Exception e) {
platform.getLogger().severe("ViaVersion failed to get the server protocol!");
e.printStackTrace();
}
// Check if there are any pipes to this version
if (ProtocolRegistry.SERVER_PROTOCOL != -1) {
platform.getLogger().info("ViaVersion detected server version: " + ProtocolVersion.getProtocol(ProtocolRegistry.SERVER_PROTOCOL));
if (!ProtocolRegistry.isWorkingPipe() && !platform.isProxy()) {
if (protocolManager.getServerProtocol() != -1) {
platform.getLogger().info("ViaVersion detected server version: " + ProtocolVersion.getProtocol(protocolManager.getServerProtocol()));
if (!protocolManager.isWorkingPipe() && !platform.isProxy()) {
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("If you need support for older versions you may need to use one or more ViaVersion addons too.");
platform.getLogger().warning("In that case please read the ViaVersion resource page carefully or use https://jo0001.github.io/ViaSetup");
platform.getLogger().warning("and if you're still unsure, feel free to join our Discord-Server for further assistance.");
} else if (ProtocolRegistry.SERVER_PROTOCOL <= ProtocolVersion.v1_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. "
+ "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.");
@ -124,30 +121,30 @@ public class ViaManagerImpl implements ViaManager {
}
// Load Listeners / Tasks
ProtocolRegistry.onServerLoaded();
protocolManager.onServerLoaded();
// Load Platform
loader.load();
// Common tasks
mappingLoadingTask = Via.getPlatform().runRepeatingSync(() -> {
if (ProtocolRegistry.checkForMappingCompletion()) {
if (protocolManager.checkForMappingCompletion()) {
platform.cancelTask(mappingLoadingTask);
mappingLoadingTask = null;
}
}, 10L);
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) {
if (protocolManager.getServerProtocol() < ProtocolVersion.v1_9.getVersion()) {
if (Via.getConfig().isSimulatePlayerTick()) {
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) {
Via.getPlatform().runRepeatingSync(new TabCompleteThread(), 1L);
}
}
// Refresh Versions
ProtocolRegistry.refreshVersions();
protocolManager.refreshVersions();
}
public void destroy() {
@ -164,61 +161,47 @@ public class ViaManagerImpl implements ViaManager {
loader.unload();
}
public Set<UserConnection> getConnections() {
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);
}
@Override
public ViaPlatform<?> getPlatform() {
return platform;
}
@Override
public ViaConnectionManager getConnectionManager() {
return connectionManager;
}
@Override
public ProtocolManager getProtocolManager() {
return protocolManager;
}
@Override
public ViaProviders getProviders() {
return providers;
}
@Override
public boolean isDebug() {
return debug;
}
@Override
public void setDebug(boolean debug) {
this.debug = debug;
}
@Override
public ViaInjector getInjector() {
return injector;
}
@Override
public ViaCommandHandler getCommandHandler() {
return commandHandler;
}
@Override
public ViaPlatformLoader getLoader() {
return loader;
}
@ -233,14 +216,6 @@ public class ViaManagerImpl implements ViaManager {
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.
*
@ -250,16 +225,6 @@ public class ViaManagerImpl implements ViaManager {
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 {
private ViaPlatform<?> platform;
private ViaInjector injector;

Datei anzeigen

@ -19,7 +19,6 @@ package us.myles.ViaVersion.api;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import java.util.SortedSet;
import java.util.TreeSet;
@ -29,12 +28,12 @@ public abstract class ViaAPIBase<T> implements ViaAPI<T> {
@Override
public int getServerVersion() {
return ProtocolRegistry.SERVER_PROTOCOL;
return Via.getManager().getProtocolManager().getServerProtocol();
}
@Override
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;
}
@ -45,7 +44,7 @@ public abstract class ViaAPIBase<T> implements ViaAPI<T> {
@Override
public boolean isInjected(UUID playerUUID) {
return Via.getManager().isClientConnected(playerUUID);
return Via.getManager().getConnectionManager().isClientConnected(playerUUID);
}
@Override
@ -54,19 +53,19 @@ public abstract class ViaAPIBase<T> implements ViaAPI<T> {
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);
}
@Override
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());
return outputSet;
}
@Override
public SortedSet<Integer> getFullSupportedVersions() {
return ProtocolRegistry.getSupportedVersions();
return Via.getManager().getProtocolManager().getSupportedVersions();
}
}

Datei anzeigen

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

Datei anzeigen

@ -79,28 +79,32 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Function;
public class ProtocolRegistry {
public class ProtocolManagerImpl implements ProtocolManager {
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)
private static final Int2ObjectMap<Int2ObjectMap<Protocol>> registryMap = new Int2ObjectOpenHashMap<>(32);
private static final Map<Class<? extends Protocol>, Protocol> protocols = new HashMap<>();
private static final Map<Pair<Integer, Integer>, List<Pair<Integer, Protocol>>> pathCache = new ConcurrentHashMap<>();
private static final Set<Integer> supportedVersions = new HashSet<>();
private static final List<Pair<Range<Integer>, Protocol>> baseProtocols = Lists.newCopyOnWriteArrayList();
private static final List<Protocol> registerList = new ArrayList<>();
private final Int2ObjectMap<Int2ObjectMap<Protocol>> registryMap = new Int2ObjectOpenHashMap<>(32);
private final Map<Class<? extends Protocol>, Protocol> protocols = new HashMap<>();
private final Map<Pair<Integer, Integer>, List<Pair<Integer, Protocol>>> pathCache = new ConcurrentHashMap<>();
private final Set<Integer> supportedVersions = new HashSet<>();
private final List<Pair<Range<Integer>, Protocol>> baseProtocols = Lists.newCopyOnWriteArrayList();
private final List<Protocol> registerList = new ArrayList<>();
private static final ReadWriteLock MAPPING_LOADER_LOCK = new ReentrantReadWriteLock();
private static Map<Class<? extends Protocol>, CompletableFuture<Void>> mappingLoaderFutures = new HashMap<>();
private static ThreadPoolExecutor mappingLoaderExecutor;
private static boolean mappingsLoaded;
private final ReadWriteLock mappingLoaderLock = new ReentrantReadWriteLock();
private Map<Class<? extends Protocol>, CompletableFuture<Void>> mappingLoaderFutures = new HashMap<>();
private ThreadPoolExecutor mappingLoaderExecutor;
private boolean mappingsLoaded;
static {
private int maxProtocolPathSize = 50;
private int serverProtocol = -1;
public ProtocolManagerImpl() {
ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("Via-Mappingloader-%d").build();
mappingLoaderExecutor = new ThreadPoolExecutor(5, 16, 45L, TimeUnit.SECONDS, new SynchronousQueue<>(), threadFactory);
mappingLoaderExecutor.allowCoreThreadTimeOut(true);
}
public void registerProtocols() {
// Base Protocol
registerBaseProtocol(BASE_PROTOCOL, Range.lessThan(Integer.MIN_VALUE));
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);
}
public static void init() {
// Empty method to trigger static initializer once
}
/**
* 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) {
@Override
public 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) {
@Override
public void registerProtocol(Protocol protocol, List<Integer> supported, int output) {
// Clear cache as this may make new routes.
if (!pathCache.isEmpty()) {
pathCache.clear();
@ -197,15 +185,8 @@ public class ProtocolRegistry {
}
}
/**
* 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) {
@Override
public void registerBaseProtocol(Protocol baseProtocol, Range<Integer> supportedProtocols) {
baseProtocols.add(new Pair<>(supportedProtocols, baseProtocol));
if (Via.getPlatform().isPluginEnabled()) {
baseProtocol.register(Via.getManager().getProviders());
@ -215,12 +196,12 @@ public class ProtocolRegistry {
}
}
public static void refreshVersions() {
public void refreshVersions() {
supportedVersions.clear();
supportedVersions.add(ProtocolRegistry.SERVER_PROTOCOL);
supportedVersions.add(serverProtocol);
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;
supportedVersions.add(versions.getVersion());
for (Pair<Integer, Protocol> path : paths) {
@ -229,47 +210,34 @@ public class ProtocolRegistry {
}
}
/**
* Get the versions compatible with the server.
*
* @return Read-only set of the versions.
*/
public static SortedSet<Integer> getSupportedVersions() {
return Collections.unmodifiableSortedSet(new TreeSet<>(supportedVersions));
}
/**
* 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;
@Nullable
@Override
public List<Pair<Integer, Protocol>> getProtocolPath(int clientVersion, int serverVersion) {
Pair<Integer, Integer> protocolKey = new Pair<>(clientVersion, serverVersion);
// Check cache
List<Pair<Integer, Protocol>> protocolList = pathCache.get(protocolKey);
if (protocolList != null) {
return protocolList;
}
return false; // No destination for protocol
}
/**
* Called when the server is enabled, to register any non registered listeners.
*/
public static void onServerLoaded() {
for (Protocol protocol : registerList) {
protocol.register(Via.getManager().getProviders());
// 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);
}
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 clientVersion The current input version
* @param serverVersion The desired output version
* @return The path which has been generated, null if failed.
* @param current current items in the path
* @param clientVersion current input version
* @param serverVersion desired output version
* @return path that has been generated, null if failed
*/
@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 (current.size() > maxProtocolPathSize) return null; // Fail safe, protocol too complicated.
@ -312,42 +280,14 @@ public class ProtocolRegistry {
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
public static List<Pair<Integer, Protocol>> getProtocolPath(int clientVersion, int serverVersion) {
Pair<Integer, Integer> protocolKey = new Pair<>(clientVersion, serverVersion);
// 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) {
@Override
public Protocol getProtocol(Class<? extends Protocol> 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)) {
if (rangeProtocol.getKey().contains(serverVersion)) {
return rangeProtocol.getValue();
@ -356,7 +296,8 @@ public class ProtocolRegistry {
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) {
if (p.getValue() == protocol) {
return true;
@ -365,12 +306,46 @@ public class ProtocolRegistry {
return false;
}
/**
* Ensure that mapping data for that protocol has already been loaded, completes it otherwise.
*
* @param protocolClass protocol class
*/
public static void completeMappingDataLoading(Class<? extends Protocol> protocolClass) throws Exception {
@Override
public int getServerProtocol() {
return serverProtocol;
}
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;
CompletableFuture<Void> future = getMappingLoaderFuture(protocolClass);
@ -380,13 +355,9 @@ public class ProtocolRegistry {
}
}
/**
* Shuts down the executor and uncaches mappings if all futures have been completed.
*
* @return true if the executor has now been shut down
*/
public static boolean checkForMappingCompletion() {
MAPPING_LOADER_LOCK.readLock().lock();
@Override
public boolean checkForMappingCompletion() {
mappingLoaderLock.readLock().lock();
try {
if (mappingsLoaded) return false;
@ -400,66 +371,57 @@ public class ProtocolRegistry {
shutdownLoaderExecutor();
return true;
} finally {
MAPPING_LOADER_LOCK.readLock().unlock();
mappingLoaderLock.readLock().unlock();
}
}
/**
* 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
*/
public static void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Runnable runnable) {
@Override
public void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Runnable runnable) {
CompletableFuture<Void> future = CompletableFuture.runAsync(runnable, mappingLoaderExecutor).exceptionally(mappingLoaderThrowable(protocolClass));
MAPPING_LOADER_LOCK.writeLock().lock();
mappingLoaderLock.writeLock().lock();
try {
mappingLoaderFutures.put(protocolClass, future);
} finally {
MAPPING_LOADER_LOCK.writeLock().unlock();
mappingLoaderLock.writeLock().unlock();
}
}
/**
* 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
*/
public static void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Class<? extends Protocol> dependsOn, Runnable runnable) {
@Override
public void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Class<? extends Protocol> dependsOn, Runnable runnable) {
CompletableFuture<Void> future = getMappingLoaderFuture(dependsOn)
.whenCompleteAsync((v, throwable) -> runnable.run(), mappingLoaderExecutor).exceptionally(mappingLoaderThrowable(protocolClass));
MAPPING_LOADER_LOCK.writeLock().lock();
mappingLoaderLock.writeLock().lock();
try {
mappingLoaderFutures.put(protocolClass, future);
} 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.
* 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
* Called when the server is enabled, to register any non-registered listeners.
*/
@Nullable
public static CompletableFuture<Void> getMappingLoaderFuture(Class<? extends Protocol> protocolClass) {
MAPPING_LOADER_LOCK.readLock().lock();
try {
return mappingsLoaded ? null : mappingLoaderFutures.get(protocolClass);
} finally {
MAPPING_LOADER_LOCK.readLock().unlock();
public void onServerLoaded() {
for (Protocol protocol : registerList) {
protocol.register(Via.getManager().getProviders());
}
registerList.clear();
}
private static void shutdownLoaderExecutor() {
private void shutdownLoaderExecutor() {
Preconditions.checkArgument(!mappingsLoaded);
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 -> {
Via.getPlatform().getLogger().severe("Error during mapping loading of " + protocolClass.getSimpleName());
throwable.printStackTrace();

Datei anzeigen

@ -94,7 +94,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
@Override
public BossBar addPlayer(UUID player) {
return addConnection(Via.getManager().getConnection(player));
return addConnection(Via.getManager().getConnectionManager().getConnectedClient(player));
}
@Override
@ -107,7 +107,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
@Override
public BossBar removePlayer(UUID uuid) {
return removeConnection(Via.getManager().getConnection(uuid));
return removeConnection(Via.getManager().getConnectionManager().getConnectedClient(uuid));
}
@Override
@ -144,7 +144,7 @@ public abstract class CommonBoss<T> extends BossBar<T> {
@Override
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());
}

Datei anzeigen

@ -22,7 +22,6 @@ import com.google.gson.JsonObject;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.command.ViaCommandSender;
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.VersionInfo;
import us.myles.ViaVersion.util.GsonUtil;
@ -54,8 +53,8 @@ public class DumpSubCmd extends ViaSubCommand {
VersionInfo version = new VersionInfo(
System.getProperty("java.version"),
System.getProperty("os.name"),
ProtocolRegistry.SERVER_PROTOCOL,
ProtocolRegistry.getSupportedVersions(),
Via.getAPI().getServerVersion(),
Via.getManager().getProtocolManager().getSupportedVersions(),
Via.getPlatform().getPlatformName(),
Via.getPlatform().getPlatformVersion(),
Via.getPlatform().getPluginVersion(),

Datei anzeigen

@ -52,7 +52,7 @@ public class PPSSubCmd extends ViaSubCommand {
int playerVersion = Via.getAPI().getPlayerVersion(p.getUUID());
if (!playerVersions.containsKey(playerVersion))
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) {
playerVersions.get(playerVersion).add(p.getName() + " (" + uc.getPacketsPerSecond() + " PPS)");
totalPackets += uc.getPacketsPerSecond();

Datei anzeigen

@ -24,7 +24,6 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
import us.myles.ViaVersion.api.protocol.Protocol;
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.SimpleProtocol;
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)
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();
@ -73,7 +72,7 @@ public class BaseProtocol extends SimpleProtocol {
for (Pair<Integer, Protocol> prot : protocols) {
pipeline.add(prot.getValue());
// 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
@ -82,7 +81,7 @@ public class BaseProtocol extends SimpleProtocol {
}
// Add Base Protocol
pipeline.add(ProtocolRegistry.getBaseProtocol(serverProtocol));
pipeline.add(Via.getManager().getProtocolManager().getBaseProtocol(serverProtocol));
// Change state
if (state == 1) {

Datei anzeigen

@ -26,7 +26,7 @@ import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.Via;
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.SimpleProtocol;
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()));
}
if (ProtocolRegistry.SERVER_PROTOCOL == -1) { // Set the Server protocol if the detection on startup failed
ProtocolRegistry.SERVER_PROTOCOL = ProtocolVersion.getProtocol(protocolVersion).getVersion();
if (Via.getAPI().getServerVersion() == -1) { // Set the Server protocol if the detection on startup failed
ProtocolManagerImpl protocolManager = (ProtocolManagerImpl) Via.getManager().getProtocolManager();
protocolManager.setServerProtocol(ProtocolVersion.getProtocol(protocolVersion).getVersion());
}
// 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)
if (info.getProtocolVersion() >= protocol || Via.getPlatform().isOldClientsAllowed()) {
protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocol);
protocols = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), protocol);
}
if (protocols != null) {
@ -144,9 +145,9 @@ public class BaseProtocol1_7 extends SimpleProtocol {
String username = wrapper.passthrough(Type.STRING);
info.setUsername(username);
// 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);
}

Datei anzeigen

@ -17,13 +17,12 @@
*/
package us.myles.ViaVersion.protocols.base;
import us.myles.ViaVersion.api.Via;
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 int getServerProtocol(UserConnection connection) throws Exception {
return ProtocolRegistry.SERVER_PROTOCOL;
return Via.getAPI().getServerVersion();
}
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -22,9 +22,9 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import java.lang.reflect.Method;
@ -47,7 +47,7 @@ public class SpongeChannelInitializer extends ChannelInitializer<Channel> {
@Override
protected void initChannel(Channel channel) throws Exception {
// Ensure ViaVersion is loaded
if (ProtocolRegistry.SERVER_PROTOCOL != -1
if (Via.getAPI().getServerVersion() != -1
&& channel instanceof SocketChannel) { // channel can be LocalChannel on internal server
UserConnection info = new UserConnection((SocketChannel) channel);
// init protocol

Datei anzeigen

@ -24,7 +24,6 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.platform.TaskId;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider;
@ -67,7 +66,7 @@ public class SpongeViaLoader implements ViaPlatformLoader {
registerListener(new UpdateListener());
/* 1.9 client to 1.8 server */
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getVersion()) {
if (Via.getAPI().getServerVersion() < ProtocolVersion.v1_9.getVersion()) {
try {
Class.forName("org.spongepowered.api.event.entity.DisplaceEntityEvent");
storeListener(new Sponge4ArmorListener()).register();
@ -84,7 +83,7 @@ public class SpongeViaLoader implements ViaPlatformLoader {
}
/* 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(MovementTransmitterProvider.class, new SpongeViaMovementTransmitter());

Datei anzeigen

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

Datei anzeigen

@ -21,7 +21,6 @@ import com.velocitypowered.api.plugin.PluginContainer;
import us.myles.ViaVersion.VelocityPlugin;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.protocols.base.VersionProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider;
@ -38,7 +37,7 @@ public class VelocityViaLoader implements ViaPlatformLoader {
Object plugin = VelocityPlugin.PROXY.getPluginManager()
.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(BossBarProvider.class, new VelocityBossBarProvider());
}