From d20dc74fefb38afaed8ad57cff8b26771057d65e Mon Sep 17 00:00:00 2001 From: ArikSquad <75741608+ArikSquad@users.noreply.github.com> Date: Fri, 9 Jan 2026 17:26:42 +0200 Subject: [PATCH] feat: proper ViaVersion --- .../net/swofty/commons/MinecraftVersion.java | 12 ++++++-- .../actions/ActionPlayerWarnCrossVersion.java | 29 ------------------- .../type/generic/user/HypixelPlayer.java | 3 -- .../commands/VersionCommand.java | 25 ---------------- .../net/swofty/velocity/SkyBlockVelocity.java | 26 +++++++++++++++++ .../command/ProtocolVersionCommand.java | 23 +++++++++++++++ .../provider/SkyBlockVersionProvider.java | 2 +- 7 files changed, 59 insertions(+), 61 deletions(-) delete mode 100644 type.generic/src/main/java/net/swofty/type/generic/event/actions/ActionPlayerWarnCrossVersion.java delete mode 100644 type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/commands/VersionCommand.java create mode 100644 velocity.extension/src/main/java/net/swofty/velocity/command/ProtocolVersionCommand.java diff --git a/commons/src/main/java/net/swofty/commons/MinecraftVersion.java b/commons/src/main/java/net/swofty/commons/MinecraftVersion.java index 56441f8ad..3bf3d1843 100644 --- a/commons/src/main/java/net/swofty/commons/MinecraftVersion.java +++ b/commons/src/main/java/net/swofty/commons/MinecraftVersion.java @@ -48,6 +48,14 @@ public enum MinecraftVersion { MINECRAFT_1_20_5(766, new String[]{"1.20.5", "1.20.6"}), MINECRAFT_1_21(767, new String[]{"1.21", "1.21.1"}), MINECRAFT_1_21_2(768, new String[]{"1.21.2", "1.21.3"}), + MINECRAFT_1_21_4(769, new String[]{"1.21.4"}), + MINECRAFT_1_21_5(770, new String[]{"1.21.5"}), + MINECRAFT_1_21_6(771, new String[]{"1.21.6"}), + MINECRAFT_1_21_7(772, new String[]{"1.21.7"}), + MINECRAFT_1_21_8(772, new String[]{"1.21.8"}), + MINECRAFT_1_21_9(773, new String[]{"1.21.9"}), + MINECRAFT_1_21_10(773, new String[]{"1.21.10"}), + MINECRAFT_1_21_11(774, new String[]{"1.21.11"}), ; private final int protocol; @@ -64,7 +72,5 @@ public static MinecraftVersion byProtocolId(int protocolID) { .findFirst() .orElse(null); } - public boolean isMoreRecentThan(MinecraftVersion version) { - return this.protocol > version.protocol; - } + } diff --git a/type.generic/src/main/java/net/swofty/type/generic/event/actions/ActionPlayerWarnCrossVersion.java b/type.generic/src/main/java/net/swofty/type/generic/event/actions/ActionPlayerWarnCrossVersion.java deleted file mode 100644 index 196fee7d6..000000000 --- a/type.generic/src/main/java/net/swofty/type/generic/event/actions/ActionPlayerWarnCrossVersion.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.swofty.type.generic.event.actions; - -import net.minestom.server.event.player.PlayerSpawnEvent; -import net.swofty.commons.MinecraftVersion; -import net.swofty.type.generic.event.EventNodes; -import net.swofty.type.generic.event.HypixelEvent; -import net.swofty.type.generic.event.HypixelEventClass; -import net.swofty.type.generic.user.HypixelPlayer; - -public class ActionPlayerWarnCrossVersion implements HypixelEventClass { - - @HypixelEvent(node = EventNodes.PLAYER, requireDataLoaded = true) - public void run(PlayerSpawnEvent event) { - HypixelPlayer player = (HypixelPlayer) event.getPlayer(); - - if (!player.getVersion().isMoreRecentThan(MinecraftVersion.MINECRAFT_1_20_2)) { - StringBuilder message = new StringBuilder(); - - message.append(" \n"); - message.append("§6§l----------- §cServer Notice §6§l-----------\n"); - message.append("§cAlthough we do support versions prior to §61.20.4§c, the experience may be buggy.\n"); - message.append("§cIf you experience a bug, please test if it also occurs on §61.20.4§c before reporting it.\n"); - message.append("§6§l---------------------------------\n"); - message.append(" \n"); - - player.sendMessage(message.toString()); - } - } -} diff --git a/type.generic/src/main/java/net/swofty/type/generic/user/HypixelPlayer.java b/type.generic/src/main/java/net/swofty/type/generic/user/HypixelPlayer.java index 22c2c6a3b..1b3e40305 100644 --- a/type.generic/src/main/java/net/swofty/type/generic/user/HypixelPlayer.java +++ b/type.generic/src/main/java/net/swofty/type/generic/user/HypixelPlayer.java @@ -32,9 +32,6 @@ public class HypixelPlayer extends Player { @Setter @Getter private ServerType originServer = ServerType.SKYBLOCK_HUB; - @Setter - @Getter - private MinecraftVersion version = MinecraftVersion.MINECRAFT_1_20_3; @Getter private boolean readyForEvents = false; @Getter diff --git a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/commands/VersionCommand.java b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/commands/VersionCommand.java deleted file mode 100644 index 23e94b2ce..000000000 --- a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/commands/VersionCommand.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.swofty.type.skyblockgeneric.commands; - -import net.swofty.commons.MinecraftVersion; -import net.swofty.type.generic.command.CommandParameters; -import net.swofty.type.generic.command.HypixelCommand; -import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer; -import net.swofty.type.generic.user.categories.Rank; - -@CommandParameters(description = "Tells the player their version", - usage = "/version", - permission = Rank.DEFAULT, - aliases = "playerversion", - allowsConsole = false) -public class VersionCommand extends HypixelCommand { - - @Override - public void registerUsage(MinestomCommand command) { - command.addSyntax((sender, context) -> { - if (!permissionCheck(sender)) return; - - MinecraftVersion playerVersion = ((SkyBlockPlayer) sender).getVersion(); - sender.sendMessage("§aYou are currently running §e" + playerVersion.name() + "§a!"); - }); - } -} diff --git a/velocity.extension/src/main/java/net/swofty/velocity/SkyBlockVelocity.java b/velocity.extension/src/main/java/net/swofty/velocity/SkyBlockVelocity.java index 55d35abea..ba51b9e98 100644 --- a/velocity.extension/src/main/java/net/swofty/velocity/SkyBlockVelocity.java +++ b/velocity.extension/src/main/java/net/swofty/velocity/SkyBlockVelocity.java @@ -13,8 +13,10 @@ import com.velocitypowered.api.event.player.KickedFromServerEvent; import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent; import com.velocitypowered.api.event.player.ServerConnectedEvent; +import com.velocitypowered.api.event.player.ServerPostConnectEvent; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.proxy.ProxyPingEvent; +import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.annotation.DataDirectory; @@ -37,6 +39,7 @@ import net.swofty.commons.ServerType; import net.swofty.commons.proxy.FromProxyChannels; import net.swofty.redisapi.api.RedisAPI; +import net.swofty.velocity.command.ProtocolVersionCommand; import net.swofty.velocity.command.ServerStatusCommand; import net.swofty.velocity.data.CoopDatabase; import net.swofty.velocity.data.ProfilesDatabase; @@ -174,6 +177,13 @@ public void onProxyInitialization(ProxyInitializeEvent event) { commandManager.register(statusCommandMeta, new ServerStatusCommand()); + CommandMeta protocolVersionMeta = commandManager.metaBuilder("protocolversion") + .aliases("protocol") + .plugin(this) + .build(); + + commandManager.register(protocolVersionMeta, new ProtocolVersionCommand()); + /** * Handle database @@ -339,6 +349,22 @@ public void onPing(ProxyPingEvent event) { )); } + @Subscribe + public void onPlayerConnect(ServerPostConnectEvent event) { + if (!(event.getPlayer().getProtocolVersion().getProtocol() >= ProtocolVersion.MAXIMUM_VERSION.getProtocol())) { + StringBuilder message = new StringBuilder(); + + message.append("\n"); + message.append("§6§l----------- §cServer Notice §6§l-----------\n"); + message.append("§cAlthough we do support versions prior to §6" + ProtocolVersion.MAXIMUM_VERSION.getVersionIntroducedIn() + "§c, the experience may be buggy.\n"); + message.append("§cIf you experience a bug, please test if it also occurs on §6" + ProtocolVersion.MAXIMUM_VERSION.getVersionIntroducedIn() + "§c before reporting it.\n"); + message.append("§6§l---------------------------------\n"); + message.append("\n"); + + event.getPlayer().sendMessage(Component.text(message.toString())); + } + } + public static Stream loopThroughPackage(String packageName, Class clazz) { Reflections reflections = new Reflections(packageName); Set> subTypes = reflections.getSubTypesOf(clazz); diff --git a/velocity.extension/src/main/java/net/swofty/velocity/command/ProtocolVersionCommand.java b/velocity.extension/src/main/java/net/swofty/velocity/command/ProtocolVersionCommand.java new file mode 100644 index 000000000..faa5923b6 --- /dev/null +++ b/velocity.extension/src/main/java/net/swofty/velocity/command/ProtocolVersionCommand.java @@ -0,0 +1,23 @@ +package net.swofty.velocity.command; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.api.proxy.Player; +import net.kyori.adventure.text.Component; + +import java.util.List; + +public class ProtocolVersionCommand implements SimpleCommand { + + @Override + public void execute(Invocation invocation) { + CommandSource source = invocation.source(); + if (!(source instanceof Player player)) { + return; + } + ProtocolVersion version = player.getProtocolVersion(); + List versionsSupportedBy = version.getVersionsSupportedBy(); + player.sendMessage(Component.text(version.getProtocol() + " §7(" + String.join(", ", versionsSupportedBy) + ")")); + } +} diff --git a/velocity.extension/src/main/java/net/swofty/velocity/viaversion/provider/SkyBlockVersionProvider.java b/velocity.extension/src/main/java/net/swofty/velocity/viaversion/provider/SkyBlockVersionProvider.java index 6dedd8069..c0cfa65c2 100644 --- a/velocity.extension/src/main/java/net/swofty/velocity/viaversion/provider/SkyBlockVersionProvider.java +++ b/velocity.extension/src/main/java/net/swofty/velocity/viaversion/provider/SkyBlockVersionProvider.java @@ -29,7 +29,7 @@ public ProtocolVersion getClosestServerProtocol(UserConnection user) throws Exce } private ProtocolVersion getBackProtocol(UserConnection user) { - return ProtocolVersion.v1_21_4; // backend server version + return ProtocolVersion.v1_21_11; // backend server version } private ProtocolVersion getFrontProtocol(UserConnection user) throws Exception {