Small startup time improvements

This commit is contained in:
Nassim Jahnke 2023-03-16 11:21:47 +01:00
parent da7f8ea3b6
commit 4e844a0095
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
15 changed files with 119 additions and 74 deletions

View File

@ -131,4 +131,11 @@ public interface ViaManager {
* @param runnable runnable to be executed * @param runnable runnable to be executed
*/ */
void addEnableListener(Runnable runnable); void addEnableListener(Runnable runnable);
/**
* Returns whether the manager has been initialized (and protocols have been loaded).
*
* @return whether the manager has been initialized
*/
boolean isInitialized();
} }

View File

@ -256,6 +256,8 @@ public interface ViaVersionConfig {
*/ */
boolean is1_13TeamColourFix(); boolean is1_13TeamColourFix();
boolean shouldRegisterUserConnectionOnJoin();
/** /**
* Should we fix shift quick move action for 1.12 clients * Should we fix shift quick move action for 1.12 clients
* *

View File

@ -57,10 +57,12 @@ public class ViaBukkitListener extends ViaListener implements Listener {
*/ */
@Override @Override
public void register() { public void register() {
if (isRegistered()) return; if (isRegistered()) {
return;
}
plugin.getServer().getPluginManager().registerEvents(this, plugin);
setRegistered(true); setRegistered(true);
plugin.getServer().getPluginManager().registerEvents(this, plugin);
} }
public Plugin getPlugin() { public Plugin getPlugin() {

View File

@ -27,6 +27,7 @@ import com.viaversion.viaversion.api.platform.UnsupportedSoftware;
import com.viaversion.viaversion.api.platform.ViaPlatform; import com.viaversion.viaversion.api.platform.ViaPlatform;
import com.viaversion.viaversion.bukkit.commands.BukkitCommandHandler; import com.viaversion.viaversion.bukkit.commands.BukkitCommandHandler;
import com.viaversion.viaversion.bukkit.commands.BukkitCommandSender; import com.viaversion.viaversion.bukkit.commands.BukkitCommandSender;
import com.viaversion.viaversion.bukkit.listeners.JoinListener;
import com.viaversion.viaversion.bukkit.platform.BukkitViaAPI; import com.viaversion.viaversion.bukkit.platform.BukkitViaAPI;
import com.viaversion.viaversion.bukkit.platform.BukkitViaConfig; import com.viaversion.viaversion.bukkit.platform.BukkitViaConfig;
import com.viaversion.viaversion.bukkit.platform.BukkitViaInjector; import com.viaversion.viaversion.bukkit.platform.BukkitViaInjector;
@ -35,6 +36,7 @@ import com.viaversion.viaversion.bukkit.platform.BukkitViaTask;
import com.viaversion.viaversion.bukkit.platform.BukkitViaTaskTask; import com.viaversion.viaversion.bukkit.platform.BukkitViaTaskTask;
import com.viaversion.viaversion.bukkit.platform.PaperViaInjector; import com.viaversion.viaversion.bukkit.platform.PaperViaInjector;
import com.viaversion.viaversion.dump.PluginInfo; import com.viaversion.viaversion.dump.PluginInfo;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.unsupported.UnsupportedPlugin; import com.viaversion.viaversion.unsupported.UnsupportedPlugin;
import com.viaversion.viaversion.unsupported.UnsupportedServerSoftware; import com.viaversion.viaversion.unsupported.UnsupportedServerSoftware;
import com.viaversion.viaversion.util.GsonUtil; import com.viaversion.viaversion.util.GsonUtil;
@ -79,6 +81,15 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
// Config magic // Config magic
conf = new BukkitViaConfig(); conf = new BukkitViaConfig();
// Load a bunch of classes early with slow reflection and more classloading
Via.getManager().getScheduler().execute(() -> {
if (conf.shouldRegisterUserConnectionOnJoin()) {
JoinListener.init();
}
ChatRewriter.init();
});
} }
@Override @Override

View File

@ -42,13 +42,13 @@ public class JoinListener implements Listener {
private static final Field CHANNEL; private static final Field CHANNEL;
static { static {
Method gh = null; Method getHandleMethod = null;
Field conn = null, nm = null, ch = null; Field gamePacketListenerField = null, connectionField = null, channelField = null;
try { try {
gh = NMSUtil.obc("entity.CraftPlayer").getDeclaredMethod("getHandle"); getHandleMethod = NMSUtil.obc("entity.CraftPlayer").getDeclaredMethod("getHandle");
conn = findField(gh.getReturnType(), "PlayerConnection", "ServerGamePacketListenerImpl"); gamePacketListenerField = findField(getHandleMethod.getReturnType(), "PlayerConnection", "ServerGamePacketListenerImpl");
nm = findField(conn.getType(), "NetworkManager", "Connection"); connectionField = findField(gamePacketListenerField.getType(), "NetworkManager", "Connection");
ch = findField(nm.getType(), "Channel"); channelField = findField(connectionField.getType(), Class.forName("io.netty.channel.Channel"));
} catch (NoSuchMethodException | NoSuchFieldException | ClassNotFoundException e) { } catch (NoSuchMethodException | NoSuchFieldException | ClassNotFoundException e) {
Via.getPlatform().getLogger().log( Via.getPlatform().getLogger().log(
Level.WARNING, Level.WARNING,
@ -56,27 +56,47 @@ public class JoinListener implements Listener {
"Login race condition fixer will be disabled.\n" + "Login race condition fixer will be disabled.\n" +
" Some plugins that use ViaAPI on join event may work incorrectly.", e); " Some plugins that use ViaAPI on join event may work incorrectly.", e);
} }
GET_HANDLE = gh; GET_HANDLE = getHandleMethod;
CONNECTION = conn; CONNECTION = gamePacketListenerField;
NETWORK_MANAGER = nm; NETWORK_MANAGER = connectionField;
CHANNEL = ch; CHANNEL = channelField;
}
public static void init() {
} }
// Loosely search a field with any name, as long as it matches a type name. // Loosely search a field with any name, as long as it matches a type name.
private static Field findField(Class<?> cl, String... types) throws NoSuchFieldException { private static Field findField(Class<?> clazz, String... types) throws NoSuchFieldException {
for (Field field : cl.getDeclaredFields()) { for (Field field : clazz.getDeclaredFields()) {
String fieldTypeName = field.getType().getSimpleName();
for (String type : types) { for (String type : types) {
if (field.getType().getSimpleName().equals(type)) { if (!fieldTypeName.equals(type)) {
if (!Modifier.isPublic(field.getModifiers())) { continue;
field.setAccessible(true);
}
return field;
} }
if (!Modifier.isPublic(field.getModifiers())) {
field.setAccessible(true);
}
return field;
} }
} }
throw new NoSuchFieldException(types[0]); throw new NoSuchFieldException(types[0]);
} }
private static Field findField(Class<?> clazz, Class<?> fieldType) throws NoSuchFieldException {
for (Field field : clazz.getDeclaredFields()) {
if (field.getType() != fieldType) {
continue;
}
if (!Modifier.isPublic(field.getModifiers())) {
field.setAccessible(true);
}
return field;
}
throw new NoSuchFieldException(fieldType.getSimpleName());
}
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onJoin(PlayerJoinEvent e) { public void onJoin(PlayerJoinEvent e) {
if (CHANNEL == null) return; if (CHANNEL == null) return;

View File

@ -32,6 +32,7 @@ public class BukkitViaConfig extends AbstractViaConfig {
private boolean hitboxFix1_14; private boolean hitboxFix1_14;
private String blockConnectionMethod; private String blockConnectionMethod;
private boolean armorToggleFix; private boolean armorToggleFix;
private boolean registerUserConnectionOnJoin;
public BukkitViaConfig() { public BukkitViaConfig() {
super(new File(((Plugin) Via.getPlatform()).getDataFolder(), "config.yml")); super(new File(((Plugin) Via.getPlatform()).getDataFolder(), "config.yml"));
@ -41,6 +42,7 @@ public class BukkitViaConfig extends AbstractViaConfig {
@Override @Override
protected void loadFields() { protected void loadFields() {
super.loadFields(); super.loadFields();
registerUserConnectionOnJoin = getBoolean("register-userconnections-on-join", true);
quickMoveActionFix = getBoolean("quick-move-action-fix", false); quickMoveActionFix = getBoolean("quick-move-action-fix", false);
hitboxFix1_9 = getBoolean("change-1_9-hitbox", false); hitboxFix1_9 = getBoolean("change-1_9-hitbox", false);
hitboxFix1_14 = getBoolean("change-1_14-hitbox", false); hitboxFix1_14 = getBoolean("change-1_14-hitbox", false);
@ -52,6 +54,11 @@ public class BukkitViaConfig extends AbstractViaConfig {
protected void handleConfig(Map<String, Object> config) { protected void handleConfig(Map<String, Object> config) {
} }
@Override
public boolean shouldRegisterUserConnectionOnJoin() {
return registerUserConnectionOnJoin;
}
@Override @Override
public boolean is1_12QuickMoveActionFix() { public boolean is1_12QuickMoveActionFix() {
return quickMoveActionFix; return quickMoveActionFix;

View File

@ -187,7 +187,7 @@ public class BukkitViaInjector extends LegacyViaInjector {
@Override @Override
public boolean lateProtocolVersionSetting() { public boolean lateProtocolVersionSetting() {
return !PaperViaInjector.PAPER_PROTOCOL_METHOD && !HAS_SHARED_CONSTANTS; return !(PaperViaInjector.PAPER_PROTOCOL_METHOD || HAS_SHARED_CONSTANTS);
} }
public boolean isBinded() { public boolean isBinded() {

View File

@ -51,16 +51,13 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
public class BukkitViaLoader implements ViaPlatformLoader { public class BukkitViaLoader implements ViaPlatformLoader {
private final ViaVersionPlugin plugin;
private final Set<Listener> listeners = new HashSet<>();
private final Set<BukkitTask> tasks = new HashSet<>(); private final Set<BukkitTask> tasks = new HashSet<>();
private final ViaVersionPlugin plugin;
private HandItemCache handItemCache; private HandItemCache handItemCache;
public BukkitViaLoader(ViaVersionPlugin plugin) { public BukkitViaLoader(ViaVersionPlugin plugin) {
@ -68,21 +65,21 @@ public class BukkitViaLoader implements ViaPlatformLoader {
} }
public void registerListener(Listener listener) { public void registerListener(Listener listener) {
Bukkit.getPluginManager().registerEvents(storeListener(listener), plugin); plugin.getServer().getPluginManager().registerEvents(listener, plugin);
} }
@Deprecated/*(forRemoval = true)*/
public <T extends Listener> T storeListener(T listener) { public <T extends Listener> T storeListener(T listener) {
listeners.add(listener);
return listener; return listener;
} }
@Override @Override
public void load() { public void load() {
// Update Listener
registerListener(new UpdateListener()); registerListener(new UpdateListener());
// Login listener if (Via.getConfig().shouldRegisterUserConnectionOnJoin()) {
registerListener(new JoinListener()); registerListener(new JoinListener());
}
/* Base Protocol */ /* Base Protocol */
final ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion"); final ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
@ -92,13 +89,18 @@ public class BukkitViaLoader implements ViaPlatformLoader {
ProtocolSupportCompat.registerPSConnectListener(plugin); ProtocolSupportCompat.registerPSConnectListener(plugin);
} }
if (!Via.getAPI().getServerVersion().isKnown()) {
Via.getPlatform().getLogger().severe("Server version has not been loaded yet, cannot register additional listeners");
return;
}
int serverProtocolVersion = Via.getAPI().getServerVersion().lowestSupportedVersion(); int serverProtocolVersion = Via.getAPI().getServerVersion().lowestSupportedVersion();
/* 1.9 client to 1.8 server */ /* 1.9 client to 1.8 server */
if (serverProtocolVersion < ProtocolVersion.v1_9.getVersion()) { if (serverProtocolVersion < ProtocolVersion.v1_9.getVersion()) {
storeListener(new ArmorListener(plugin)).register(); new ArmorListener(plugin).register();
storeListener(new DeathListener(plugin)).register(); new DeathListener(plugin).register();
storeListener(new BlockListener(plugin)).register(); new BlockListener(plugin).register();
if (plugin.getConf().isItemCache()) { if (plugin.getConf().isItemCache()) {
handItemCache = new HandItemCache(); handItemCache = new HandItemCache();
@ -110,7 +112,7 @@ public class BukkitViaLoader implements ViaPlatformLoader {
boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && serverProtocolVersion < ProtocolVersion.v1_9.getVersion(); boolean use1_9Fix = plugin.getConf().is1_9HitboxFix() && serverProtocolVersion < ProtocolVersion.v1_9.getVersion();
if (use1_9Fix || plugin.getConf().is1_14HitboxFix()) { if (use1_9Fix || plugin.getConf().is1_14HitboxFix()) {
try { try {
storeListener(new PlayerSneakListener(plugin, use1_9Fix, plugin.getConf().is1_14HitboxFix())).register(); new PlayerSneakListener(plugin, use1_9Fix, plugin.getConf().is1_14HitboxFix()).register();
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
Via.getPlatform().getLogger().warning("Could not load hitbox fix - please report this on our GitHub"); Via.getPlatform().getLogger().warning("Could not load hitbox fix - please report this on our GitHub");
e.printStackTrace(); e.printStackTrace();
@ -121,7 +123,7 @@ public class BukkitViaLoader implements ViaPlatformLoader {
if (serverProtocolVersion < ProtocolVersion.v1_15.getVersion()) { if (serverProtocolVersion < ProtocolVersion.v1_15.getVersion()) {
try { try {
Class.forName("org.bukkit.event.entity.EntityToggleGlideEvent"); Class.forName("org.bukkit.event.entity.EntityToggleGlideEvent");
storeListener(new EntityToggleGlideListener(plugin)).register(); new EntityToggleGlideListener(plugin).register();
} catch (ClassNotFoundException ignored) { } catch (ClassNotFoundException ignored) {
} }
} }
@ -138,12 +140,12 @@ public class BukkitViaLoader implements ViaPlatformLoader {
} }
} }
if (paper) { if (paper) {
storeListener(new PaperPatch(plugin)).register(); new PaperPatch(plugin).register();
} }
} }
if (serverProtocolVersion < ProtocolVersion.v1_19_4.getVersion() && plugin.getConf().isArmorToggleFix()) { if (serverProtocolVersion < ProtocolVersion.v1_19_4.getVersion() && plugin.getConf().isArmorToggleFix()) {
storeListener(new ArmorToggleListener(plugin)).register(); new ArmorToggleListener(plugin).register();
} }
/* Providers */ /* Providers */
@ -189,16 +191,12 @@ public class BukkitViaLoader implements ViaPlatformLoader {
} }
if (serverProtocolVersion < ProtocolVersion.v1_19.getVersion()) { if (serverProtocolVersion < ProtocolVersion.v1_19.getVersion()) {
Via.getManager().getProviders().use(AckSequenceProvider.class, new BukkitAckSequenceProvider(plugin)); Via.getManager().getProviders().use(AckSequenceProvider.class, new BukkitAckSequenceProvider(plugin));
storeListener(new BlockBreakListener(plugin)).register(); new BlockBreakListener(plugin).register();
} }
} }
@Override @Override
public void unload() { public void unload() {
for (Listener listener : listeners) {
HandlerList.unregisterAll(listener);
}
listeners.clear();
for (BukkitTask task : tasks) { for (BukkitTask task : tasks) {
task.cancel(); task.cancel();
} }

View File

@ -63,6 +63,7 @@ public class ViaManagerImpl implements ViaManager {
private final Set<String> subPlatforms = new HashSet<>(); private final Set<String> subPlatforms = new HashSet<>();
private List<Runnable> enableListeners = new ArrayList<>(); private List<Runnable> enableListeners = new ArrayList<>();
private PlatformTask<?> mappingLoadingTask; private PlatformTask<?> mappingLoadingTask;
private boolean initialized;
public ViaManagerImpl(ViaPlatform<?> platform, ViaInjector injector, ViaCommandHandler commandHandler, ViaPlatformLoader loader) { public ViaManagerImpl(ViaPlatform<?> platform, ViaInjector injector, ViaCommandHandler commandHandler, ViaPlatformLoader loader) {
this.platform = platform; this.platform = platform;
@ -105,6 +106,8 @@ public class ViaManagerImpl implements ViaManager {
listener.run(); listener.run();
} }
enableListeners = null; enableListeners = null;
initialized = true;
} }
public void onServerLoaded() { public void onServerLoaded() {
@ -149,9 +152,6 @@ public class ViaManagerImpl implements ViaManager {
// Check for unsupported plugins/software // Check for unsupported plugins/software
unsupportedSoftwareWarning(); unsupportedSoftwareWarning();
// Load Listeners / Tasks
protocolManager.onServerLoaded();
// Load Platform // Load Platform
loader.load(); loader.load();
// Common tasks // Common tasks
@ -324,6 +324,11 @@ public class ViaManagerImpl implements ViaManager {
enableListeners.add(runnable); enableListeners.add(runnable);
} }
@Override
public boolean isInitialized() {
return initialized;
}
public static final class ViaManagerBuilder { public static final class ViaManagerBuilder {
private ViaPlatform<?> platform; private ViaPlatform<?> platform;
private ViaInjector injector; private ViaInjector injector;

View File

@ -383,6 +383,11 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
return nbtArrayFix; return nbtArrayFix;
} }
@Override
public boolean shouldRegisterUserConnectionOnJoin() {
return false;
}
@Override @Override
public boolean is1_12QuickMoveActionFix() { public boolean is1_12QuickMoveActionFix() {
return false; return false;

View File

@ -109,11 +109,10 @@ public class ProtocolManagerImpl implements ProtocolManager {
// Input Version -> Output Version & Protocol (Allows fast lookup) // Input Version -> Output Version & Protocol (Allows fast lookup)
private final Int2ObjectMap<Int2ObjectMap<Protocol>> registryMap = new Int2ObjectOpenHashMap<>(32); private final Int2ObjectMap<Int2ObjectMap<Protocol>> registryMap = new Int2ObjectOpenHashMap<>(32);
private final Map<Class<? extends Protocol>, Protocol<?, ?, ?, ?>> protocols = new HashMap<>(); private final Map<Class<? extends Protocol>, Protocol<?, ?, ?, ?>> protocols = new HashMap<>(64);
private final Map<ProtocolPathKey, List<ProtocolPathEntry>> pathCache = new ConcurrentHashMap<>(); private final Map<ProtocolPathKey, List<ProtocolPathEntry>> pathCache = new ConcurrentHashMap<>();
private final Set<Integer> supportedVersions = new HashSet<>(); private final Set<Integer> supportedVersions = new HashSet<>();
private final List<Pair<Range<Integer>, Protocol>> baseProtocols = Lists.newCopyOnWriteArrayList(); private final List<Pair<Range<Integer>, Protocol>> baseProtocols = Lists.newCopyOnWriteArrayList();
private final List<Protocol> registerList = new ArrayList<>();
private final ReadWriteLock mappingLoaderLock = new ReentrantReadWriteLock(); private final ReadWriteLock mappingLoaderLock = new ReentrantReadWriteLock();
private Map<Class<? extends Protocol>, CompletableFuture<Void>> mappingLoaderFutures = new HashMap<>(); private Map<Class<? extends Protocol>, CompletableFuture<Void>> mappingLoaderFutures = new HashMap<>();
@ -208,11 +207,9 @@ public class ProtocolManagerImpl implements ProtocolManager {
protocolMap.put(serverVersion, protocol); protocolMap.put(serverVersion, protocol);
} }
if (Via.getPlatform().isPluginEnabled()) { protocol.register(Via.getManager().getProviders());
protocol.register(Via.getManager().getProviders()); if (Via.getManager().isInitialized()) {
refreshVersions(); refreshVersions();
} else {
registerList.add(protocol);
} }
if (protocol.hasMappingDataToLoad()) { if (protocol.hasMappingDataToLoad()) {
@ -232,11 +229,9 @@ public class ProtocolManagerImpl implements ProtocolManager {
baseProtocol.initialize(); baseProtocol.initialize();
baseProtocols.add(new Pair<>(supportedProtocols, baseProtocol)); baseProtocols.add(new Pair<>(supportedProtocols, baseProtocol));
if (Via.getPlatform().isPluginEnabled()) { baseProtocol.register(Via.getManager().getProviders());
baseProtocol.register(Via.getManager().getProviders()); if (Via.getManager().isInitialized()) {
refreshVersions(); refreshVersions();
} else {
registerList.add(baseProtocol);
} }
} }
@ -498,16 +493,6 @@ public class ProtocolManagerImpl implements ProtocolManager {
return new PacketWrapperImpl(packetId, buf, connection); return new PacketWrapperImpl(packetId, buf, connection);
} }
/**
* Called when the server is enabled, to register any non-registered listeners.
*/
public void onServerLoaded() {
for (Protocol protocol : registerList) {
protocol.register(Via.getManager().getProviders());
}
registerList.clear();
}
public void shutdownLoaderExecutor() { public void shutdownLoaderExecutor() {
Preconditions.checkArgument(!mappingsLoaded); Preconditions.checkArgument(!mappingsLoaded);

View File

@ -28,6 +28,10 @@ import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.Leg
public final class ChatRewriter { public final class ChatRewriter {
public static final GsonComponentSerializer HOVER_GSON_SERIALIZER = GsonComponentSerializer.builder().emitLegacyHoverEvent().legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.get()).build(); public static final GsonComponentSerializer HOVER_GSON_SERIALIZER = GsonComponentSerializer.builder().emitLegacyHoverEvent().legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.get()).build();
public static final JsonElement EMPTY_COMPONENT = GsonComponentSerializer.gson().serializeToTree(Component.empty());
public static void init() {
}
public static String legacyTextToJsonString(String message, boolean itemData) { public static String legacyTextToJsonString(String message, boolean itemData) {
// Not used for chat messages, so no need for url extraction // Not used for chat messages, so no need for url extraction

View File

@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.type.types.version.Types1_19_4;
import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.libs.kyori.adventure.text.Component; import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3; import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3;
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3; import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3;
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.data.MappingData; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.data.MappingData;
@ -42,7 +43,6 @@ import java.util.Base64;
public final class Protocol1_19_4To1_19_3 extends AbstractProtocol<ClientboundPackets1_19_3, ClientboundPackets1_19_4, ServerboundPackets1_19_3, ServerboundPackets1_19_4> { public final class Protocol1_19_4To1_19_3 extends AbstractProtocol<ClientboundPackets1_19_3, ClientboundPackets1_19_4, ServerboundPackets1_19_3, ServerboundPackets1_19_4> {
public static final MappingData MAPPINGS = new MappingData(); public static final MappingData MAPPINGS = new MappingData();
private static final JsonElement EMPTY_COMPONENT = GsonComponentSerializer.gson().serializeToTree(Component.empty());
private final EntityPackets entityRewriter = new EntityPackets(this); private final EntityPackets entityRewriter = new EntityPackets(this);
private final InventoryPackets itemRewriter = new InventoryPackets(this); private final InventoryPackets itemRewriter = new InventoryPackets(this);
@ -60,7 +60,6 @@ public final class Protocol1_19_4To1_19_3 extends AbstractProtocol<ClientboundPa
soundRewriter.registerSound(ClientboundPackets1_19_3.ENTITY_SOUND); soundRewriter.registerSound(ClientboundPackets1_19_3.ENTITY_SOUND);
soundRewriter.register1_19_3Sound(ClientboundPackets1_19_3.SOUND); soundRewriter.register1_19_3Sound(ClientboundPackets1_19_3.SOUND);
new CommandRewriter<ClientboundPackets1_19_3>(this) { new CommandRewriter<ClientboundPackets1_19_3>(this) {
@Override @Override
public void handleArgument(final PacketWrapper wrapper, final String argumentType) throws Exception { public void handleArgument(final PacketWrapper wrapper, final String argumentType) throws Exception {
@ -78,7 +77,7 @@ public final class Protocol1_19_4To1_19_3 extends AbstractProtocol<ClientboundPa
if (element != null) { if (element != null) {
wrapper.write(Type.COMPONENT, element); wrapper.write(Type.COMPONENT, element);
} else { } else {
wrapper.write(Type.COMPONENT, EMPTY_COMPONENT); wrapper.write(Type.COMPONENT, ChatRewriter.EMPTY_COMPONENT);
} }
final String iconBase64 = wrapper.read(Type.OPTIONAL_STRING); final String iconBase64 = wrapper.read(Type.OPTIONAL_STRING);

View File

@ -53,13 +53,10 @@ public class InventoryPackets {
// Send 2 properties, splitting it into enchantID & level // Send 2 properties, splitting it into enchantID & level
final short level = (short) (value >> 8); final short level = (short) (value >> 8);
final short enchantID = (short) (value & 0xFF); final short enchantID = (short) (value & 0xFF);
wrapper.create(wrapper.getId(), new PacketHandler() { wrapper.create(wrapper.getId(), propertyPacket -> {
@Override propertyPacket.write(Type.UNSIGNED_BYTE, windowId);
public void handle(PacketWrapper wrapper) throws Exception { propertyPacket.write(Type.SHORT, property);
wrapper.write(Type.UNSIGNED_BYTE, windowId); propertyPacket.write(Type.SHORT, enchantID);
wrapper.write(Type.SHORT, property);
wrapper.write(Type.SHORT, enchantID);
}
}).scheduleSend(Protocol1_9To1_8.class); }).scheduleSend(Protocol1_9To1_8.class);
wrapper.set(Type.SHORT, 0, (short) (property + 3)); wrapper.set(Type.SHORT, 0, (short) (property + 3));

View File

@ -102,6 +102,9 @@ tracking-max-kick-msg: "You are sending too many packets, :("
# MULTIPLE VERSIONS OPTIONS # # MULTIPLE VERSIONS OPTIONS #
#----------------------------------------------------------# #----------------------------------------------------------#
# #
# Whether to make sure ViaVersion's UserConnection object is already available in the PlayerJoinEvent.
# You may disable this for faster startup/join time if you are 100% sure no plugin requires this.
register-userconnections-on-join: true
# Should we enable our hologram patch? # Should we enable our hologram patch?
# If they're in the wrong place enable this # If they're in the wrong place enable this
hologram-patch: false hologram-patch: false