From 9b3a6717c9df369ef621f9cc979a45a575f73d7d Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Wed, 6 Mar 2024 14:43:14 +0100 Subject: [PATCH] Compile against VV master --- build.gradle | 2 +- .../viarewind/legacysupport/BukkitPlugin.java | 10 ++++----- .../injector/BoundingBoxFixer.java | 21 ++++++++++--------- .../listener/AreaEffectCloudListener.java | 2 +- .../listener/BounceListener.java | 2 +- .../listener/BrewingListener.java | 4 ++-- .../listener/ElytraListener.java | 2 +- .../listener/EnchantingListener.java | 4 ++-- .../legacysupport/listener/SoundListener.java | 4 ++-- 9 files changed, 26 insertions(+), 25 deletions(-) diff --git a/build.gradle b/build.gradle index 9e9f53e..4c199ba 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ version = project.maven_version group = project.maven_group dependencies { - compileOnly "com.viaversion:viaversion-api:4.10.0-24w09a-SNAPSHOT" + compileOnly "com.viaversion:viaversion-api:4.9.3" compileOnly "org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT" } diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/BukkitPlugin.java b/src/main/java/com/viaversion/viarewind/legacysupport/BukkitPlugin.java index 616f7e8..09fc059 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/BukkitPlugin.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/BukkitPlugin.java @@ -49,18 +49,18 @@ public class BukkitPlugin extends JavaPlugin { @Override public void run() { - final ProtocolVersion serverProtocol = Via.getAPI().getServerVersion().lowestSupportedProtocolVersion(); - if (!serverProtocol.isKnown()) return; + final int serverProtocol = Via.getAPI().getServerVersion().lowestSupportedVersion(); + if (serverProtocol == -1) return; cancel(); - if (serverProtocol.newerThanOrEqualTo(ProtocolVersion.v1_8)) { + if (serverProtocol >= ProtocolVersion.v1_8.getVersion()) { if (config.getBoolean("enchanting-gui-fix")) Bukkit.getPluginManager().registerEvents(new EnchantingListener(), BukkitPlugin.this); if (config.getBoolean("slime-fix")) Bukkit.getPluginManager().registerEvents(new BounceListener(), BukkitPlugin.this); } - if (serverProtocol.newerThanOrEqualTo(ProtocolVersion.v1_9)) { + if (serverProtocol >= ProtocolVersion.v1_9.getVersion()) { if (config.getBoolean("sound-fix")) Bukkit.getPluginManager().registerEvents(new SoundListener(BukkitPlugin.this), BukkitPlugin.this); @@ -79,7 +79,7 @@ public class BukkitPlugin extends JavaPlugin { if (config.getBoolean("lily-pad-fix")) // 15w44b BoundingBoxFixer.fixLilyPad(getLogger(), serverProtocol); } - if (serverProtocol.newerThanOrEqualTo(ProtocolVersion.v1_14_4) && config.getBoolean("carpet-fix")) { + if (serverProtocol >= ProtocolVersion.v1_14_4.getVersion() && config.getBoolean("carpet-fix")) { BoundingBoxFixer.fixCarpet(getLogger(), serverProtocol); } diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/injector/BoundingBoxFixer.java b/src/main/java/com/viaversion/viarewind/legacysupport/injector/BoundingBoxFixer.java index 8ca425f..fd5a663 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/injector/BoundingBoxFixer.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/injector/BoundingBoxFixer.java @@ -30,9 +30,10 @@ import java.util.logging.Logger; public class BoundingBoxFixer { - public static void fixLilyPad(final Logger logger, final ProtocolVersion serverVersion) { + public static void fixLilyPad(final Logger logger, final int serverVersion) { try { - final Field boundingBoxField = ReflectionAPI.getFieldAccessible(NMSReflection.getNMSBlock("BlockWaterLily"), serverVersion.olderThanOrEqualTo(ProtocolVersion.v1_20_2) ? "a" : "b"); + final Field boundingBoxField = ReflectionAPI.getFieldAccessible(NMSReflection.getNMSBlock("BlockWaterLily"), + serverVersion <= ProtocolVersion.v1_20_2.getVersion() ? "a" : "b"); setBoundingBox(boundingBoxField.get(null), 0.0625, 0.0, 0.0625, 0.9375, 0.015625, 0.9375); } catch (Exception ex) { @@ -40,23 +41,23 @@ public class BoundingBoxFixer { } } - public static void fixCarpet(final Logger logger, final ProtocolVersion serverVersion) { + public static void fixCarpet(final Logger logger, final int serverVersion) { try { - final Class blockCarpetClass = serverVersion.olderThanOrEqualTo(ProtocolVersion.v1_16_4) ? NMSReflection.getNMSBlock("BlockCarpet") : NMSReflection.getNMSBlock("CarpetBlock"); + final Class blockCarpetClass = serverVersion <= ProtocolVersion.v1_16_4.getVersion() ? NMSReflection.getNMSBlock("BlockCarpet") : NMSReflection.getNMSBlock("CarpetBlock"); - final Field boundingBoxField = ReflectionAPI.getFieldAccessible(blockCarpetClass, serverVersion.olderThanOrEqualTo(ProtocolVersion.v1_20_2) ? "a" : "b"); + final Field boundingBoxField = ReflectionAPI.getFieldAccessible(blockCarpetClass, serverVersion <= ProtocolVersion.v1_20_2.getVersion() ? "a" : "b"); setBoundingBox(boundingBoxField.get(0), 0.0D, -0.0000001D, 0.0D, 1.0D, 0.0000001D, 1.0D); } catch (Exception ex) { logger.log(Level.SEVERE, "Could not fix carpet bounding box.", ex); } } - public static void fixLadder(final Logger logger, final ProtocolVersion serverVersion) { + public static void fixLadder(final Logger logger, final int serverVersion) { try { - final boolean pre1_12_2 = serverVersion.olderThanOrEqualTo(ProtocolVersion.v1_12_2); - final boolean pre1_13_2 = serverVersion.olderThanOrEqualTo(ProtocolVersion.v1_13_2); - final boolean pre1_16_4 = serverVersion.olderThanOrEqualTo(ProtocolVersion.v1_16_4); - final boolean pre1_20_2 = serverVersion.olderThanOrEqualTo(ProtocolVersion.v1_20_2); + final boolean pre1_12_2 = serverVersion <= ProtocolVersion.v1_12_2.getVersion(); + final boolean pre1_13_2 = serverVersion <= ProtocolVersion.v1_13_2.getVersion(); + final boolean pre1_16_4 = serverVersion <= ProtocolVersion.v1_16_4.getVersion(); + final boolean pre1_20_2 = serverVersion <= ProtocolVersion.v1_20_2.getVersion(); final Class blockLadderClass = NMSReflection.getNMSBlock("BlockLadder"); diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/listener/AreaEffectCloudListener.java b/src/main/java/com/viaversion/viarewind/legacysupport/listener/AreaEffectCloudListener.java index 1c6e492..6967a8c 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/listener/AreaEffectCloudListener.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/listener/AreaEffectCloudListener.java @@ -41,7 +41,7 @@ public class AreaEffectCloudListener implements Listener { public AreaEffectCloudListener(final BukkitPlugin plugin) { Bukkit.getScheduler().runTaskTimer(plugin, () -> { - final Set affectedPlayers = Bukkit.getOnlinePlayers().stream().filter(p -> Via.getAPI().getPlayerProtocolVersion(p).newerThanOrEqualTo(ProtocolVersion.v1_8)).collect(Collectors.toSet()); + final Set affectedPlayers = Bukkit.getOnlinePlayers().stream().filter(p -> Via.getAPI().getPlayerVersion(p) >= ProtocolVersion.v1_8.getVersion()).collect(Collectors.toSet()); effectClouds.removeIf(e -> !e.isValid()); effectClouds.forEach(cloud -> { final Location location = cloud.getLocation(); diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/listener/BounceListener.java b/src/main/java/com/viaversion/viarewind/legacysupport/listener/BounceListener.java index 4181118..3ac9a02 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/listener/BounceListener.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/listener/BounceListener.java @@ -36,7 +36,7 @@ public class BounceListener implements Listener { if (e.getTo().getY() >= e.getFrom().getY()) return; // Only check upwards motion final Player player = e.getPlayer(); - if (Via.getAPI().getPlayerProtocolVersion(player).newerThanOrEqualTo(ProtocolVersion.v1_8)) return; // Only apply for 1.7 and below players + if (Via.getAPI().getPlayerVersion(player) >= ProtocolVersion.v1_8.getVersion()) return; // Only apply for 1.7 and below players if (Math.floor(e.getTo().getY()) + 0.01 < e.getTo().getY()) return; if (player.isSneaking()) return; diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/listener/BrewingListener.java b/src/main/java/com/viaversion/viarewind/legacysupport/listener/BrewingListener.java index e6012ef..437cd85 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/listener/BrewingListener.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/listener/BrewingListener.java @@ -38,8 +38,8 @@ public class BrewingListener implements Listener { public void onPlayerInteract(PlayerInteractEvent e) { if (!e.hasBlock() || e.getClickedBlock().getType() != Material.BREWING_STAND) return; Player player = e.getPlayer(); - ProtocolVersion version = Via.getAPI().getPlayerProtocolVersion(player); - if (version.newerThan(ProtocolVersion.v1_9)) return; + int version = Via.getAPI().getPlayerVersion(player); + if (version > ProtocolVersion.v1_9.getVersion()) return; ItemStack blazePowder = new ItemStack(Material.BLAZE_POWDER); ItemStack playerItem = e.getItem(); if (playerItem == null) playerItem = new ItemStack(Material.AIR); diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/listener/ElytraListener.java b/src/main/java/com/viaversion/viarewind/legacysupport/listener/ElytraListener.java index 38b3285..9b9366b 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/listener/ElytraListener.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/listener/ElytraListener.java @@ -34,7 +34,7 @@ public class ElytraListener implements Listener { public void onPlayerMove(PlayerMoveEvent e) { final Player player = e.getPlayer(); - if (Via.getAPI().getPlayerProtocolVersion(player).newerThanOrEqualTo(ProtocolVersion.v1_9)) return; // Only apply for 1.8 and below players + if (Via.getAPI().getPlayerVersion(player) >= ProtocolVersion.v1_9.getVersion()) return; // Only apply for 1.8 and below players if (!player.isGliding()) return; // Only apply if the player is gliding final Vector direction = player.getLocation().getDirection(); diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/listener/EnchantingListener.java b/src/main/java/com/viaversion/viarewind/legacysupport/listener/EnchantingListener.java index 97dde4a..29788eb 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/listener/EnchantingListener.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/listener/EnchantingListener.java @@ -54,7 +54,7 @@ public class EnchantingListener implements Listener { if (!(e.getInventory() instanceof EnchantingInventory)) return; final Player player = (Player) e.getPlayer(); - if (Via.getAPI().getPlayerProtocolVersion(player).newerThanOrEqualTo(ProtocolVersion.v1_8)) return; + if (Via.getAPI().getPlayerVersion(player) >= ProtocolVersion.v1_8.getVersion()) return; final PlayerInventory inv = player.getInventory(); final ItemStack lapis = newMaterialNames ? new ItemStack(lapisMaterial) : new ItemStack(lapisMaterial, 1, (short) 4); @@ -89,7 +89,7 @@ public class EnchantingListener implements Listener { if (!(e.getInventory() instanceof EnchantingInventory)) return; final Player player = (Player) e.getPlayer(); - if (Via.getAPI().getPlayerProtocolVersion(player).newerThanOrEqualTo(ProtocolVersion.v1_8)) return; + if (Via.getAPI().getPlayerVersion(player) >= ProtocolVersion.v1_8.getVersion()) return; final PlayerInventory inv = player.getInventory(); final EnchantingInventory replacement = (EnchantingInventory) e.getInventory(); diff --git a/src/main/java/com/viaversion/viarewind/legacysupport/listener/SoundListener.java b/src/main/java/com/viaversion/viarewind/legacysupport/listener/SoundListener.java index c6639ee..ad4298c 100644 --- a/src/main/java/com/viaversion/viarewind/legacysupport/listener/SoundListener.java +++ b/src/main/java/com/viaversion/viarewind/legacysupport/listener/SoundListener.java @@ -83,9 +83,9 @@ public class SoundListener implements Listener { @EventHandler public void onBlockPlace(BlockPlaceEvent e) { final Player player = e.getPlayer(); - if (Via.getAPI().getPlayerProtocolVersion(player).newerThanOrEqualTo(ProtocolVersion.v1_9)) return; + if (Via.getAPI().getPlayerVersion(player) >= ProtocolVersion.v1_9.getVersion()) return; - if (Via.getAPI().getServerVersion().lowestSupportedProtocolVersion().newerThanOrEqualTo(ProtocolVersion.v1_17)) { + if (Via.getAPI().getServerVersion().lowestSupportedVersion() >= ProtocolVersion.v1_17.getVersion()) { player.playSound(e.getBlockPlaced().getLocation(), e.getBlock().getBlockData().getSoundGroup().getPlaceSound(), 1.0f, 0.8f); } else { playBlockPlaceSoundNMS(player, e.getBlock());