Register tasks in the right place

This commit is contained in:
Nassim Jahnke 2024-10-20 19:09:55 +02:00
parent 0827b6f6bb
commit 2ce11704ba
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
6 changed files with 14 additions and 17 deletions

View File

@ -36,19 +36,13 @@ public class BukkitPlugin extends JavaPlugin implements ViaBackwardsPlatform {
public BukkitPlugin() {
Via.getManager().addEnableListener(() -> init(new File(getDataFolder(), "config.yml")));
Via.getManager().addPostEnableListener(this::enable);
}
@Override
public void onEnable() {
if (Via.getManager().getInjector().lateProtocolVersionSetting()) {
// Enable in the next tick
Via.getPlatform().runSync(this::enable, 1);
} else {
enable();
}
}
public void enable() {
ViaBackwardsPlatform.super.enable();
private void enable() {
final ProtocolVersion protocolVersion = Via.getAPI().getServerVersion().highestSupportedProtocolVersion();
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_17)) {
new PlayerItemDropListener(this).register();

View File

@ -55,6 +55,7 @@ import com.viaversion.viabackwards.protocol.v1_20_3to1_20_2.Protocol1_20_3To1_20
import com.viaversion.viabackwards.protocol.v1_20_5to1_20_3.Protocol1_20_5To1_20_3;
import com.viaversion.viabackwards.protocol.v1_20_2to1_20.Protocol1_20_2To1_20;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.task.PlayerPacketsTickTask;
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5;
import com.viaversion.viabackwards.protocol.v1_9_3to1_9_1.Protocol1_9_3To1_9_1;
import com.viaversion.viabackwards.protocol.v1_10to1_9_3.Protocol1_10To1_9_3;
@ -145,6 +146,13 @@ public interface ViaBackwardsPlatform {
protocolManager.registerProtocol(new Protocol1_21_2To1_21(), ProtocolVersion.v1_21, ProtocolVersion.v1_21_2);
}
default void enable() {
final ProtocolVersion protocolVersion = Via.getAPI().getServerVersion().highestSupportedProtocolVersion();
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_21_2)) {
Via.getPlatform().runRepeatingSync(new PlayerPacketsTickTask(), 1L);
}
}
/**
* Logger provided by the platform.
*

View File

@ -28,11 +28,8 @@ import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryState
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.RecipeStorage;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.task.PlayerPacketsTickTask;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
@ -149,11 +146,6 @@ public final class Protocol1_21_2To1_21 extends BackwardsProtocol<ClientboundPac
wrapper.write(Types.VAR_INT, 0); // Particle status, assume 'all'
}
@Override
public void register(final ViaProviders providers) {
Via.getPlatform().runRepeatingSync(new PlayerPacketsTickTask(), 1L);
}
@Override
public void init(final UserConnection user) {
addEntityTracker(user, new EntityTrackerBase(user, EntityTypes1_20_5.PLAYER));

View File

@ -37,6 +37,7 @@ public final class PlayerPacketsTickTask implements Runnable {
if (user.getProtocolInfo().getClientState() != State.PLAY || !user.getProtocolInfo().getPipeline().contains(Protocol1_21_2To1_21.class)) {
continue;
}
final Channel channel = user.getChannel();
channel.eventLoop().submit(() -> {
if (!channel.isActive()) {

View File

@ -35,6 +35,7 @@ public class ViaFabricAddon implements ViaBackwardsPlatform, Runnable {
Path configDirPath = FabricLoader.getInstance().getConfigDir().resolve("ViaBackwards");
configDir = configDirPath.toFile();
this.init(new File(getDataFolder(), "config.yml"));
this.enable();
}
@Override

View File

@ -52,6 +52,7 @@ public class VelocityPlugin implements ViaBackwardsPlatform {
public void onProxyStart(ProxyInitializeEvent event) {
this.logger = new LoggerWrapper(loggerSlf4j);
Via.getManager().addEnableListener(() -> this.init(new File(getDataFolder(), "config.yml")));
Via.getManager().addPostEnableListener(this::enable);
}
@Override