From 3a69f0398ed60e71af0d3ad10874d9cf709c8c6d Mon Sep 17 00:00:00 2001 From: langua Date: Fri, 30 Aug 2024 18:52:39 +0200 Subject: [PATCH] (fix #27) 1.20.4 compatibility --- .../mc/lockettepro/BlockPlayerListener.java | 6 +++- .../crafter/mc/lockettepro/LockettePro.java | 2 +- .../java/me/crafter/mc/lockettepro/Utils.java | 36 +++++++++++++++---- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/crafter/mc/lockettepro/BlockPlayerListener.java b/src/main/java/me/crafter/mc/lockettepro/BlockPlayerListener.java index 3bd7d8c..1cfcdb6 100644 --- a/src/main/java/me/crafter/mc/lockettepro/BlockPlayerListener.java +++ b/src/main/java/me/crafter/mc/lockettepro/BlockPlayerListener.java @@ -27,6 +27,10 @@ import java.util.List; public class BlockPlayerListener implements Listener { + Particle SMOKE_PARTICLE = Particle.valueOf( + Utils.isMinecraftVersionHigherThan(Utils.getCurrentMinecraftVersionString(), "1.20.4") ? + "SMOKE" : "SMOKE_NORMAL" + ); // SMOKE_NORMAL changed to SMOKE above 1.20.4 // Quick protect for chests @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -242,7 +246,7 @@ public void onAttemptChangeLockerSign(SignChangeEvent event) { sign.setWaxed(true); sign.update(); event.setCancelled(true); - block.getWorld().spawnParticle(Particle.SMOKE, block.getLocation(), 5); + block.getWorld().spawnParticle(SMOKE_PARTICLE, block.getLocation(), 5); } } diff --git a/src/main/java/me/crafter/mc/lockettepro/LockettePro.java b/src/main/java/me/crafter/mc/lockettepro/LockettePro.java index c800c00..5681795 100644 --- a/src/main/java/me/crafter/mc/lockettepro/LockettePro.java +++ b/src/main/java/me/crafter/mc/lockettepro/LockettePro.java @@ -2,7 +2,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.Material; +import org.bukkit.Particle; import org.bukkit.block.Block; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/src/main/java/me/crafter/mc/lockettepro/Utils.java b/src/main/java/me/crafter/mc/lockettepro/Utils.java index 8113c51..3510d90 100644 --- a/src/main/java/me/crafter/mc/lockettepro/Utils.java +++ b/src/main/java/me/crafter/mc/lockettepro/Utils.java @@ -7,9 +7,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.google.gson.JsonParser; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.json.JSONComponentSerializer; -import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -29,10 +26,7 @@ import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.concurrent.TimeUnit; public class Utils { @@ -342,6 +336,34 @@ public static String getSignLineFromUnknown(String json) { } } + public static String getCurrentMinecraftVersionString() { + return Bukkit.getVersion().split("-")[0]; + } + + public static List getMinecraftInList(String versionString) { + var list = new ArrayList(); + Arrays.stream(versionString.split("\\.")).forEach(s -> { + try { + list.add(Integer.parseInt(s)); + } catch (NumberFormatException ignored) { + } + }); + return list; + } + + public static boolean isMinecraftVersionHigherThan(String version,String compareTo) { + List versionInList = getMinecraftInList(version); + List compareToInList = getMinecraftInList(compareTo); + for (int i = 0; i < Math.min(versionInList.size(), compareToInList.size()); i++) { + if (versionInList.get(i) > compareToInList.get(i)) { + return true; + } else if (versionInList.get(i) < compareToInList.get(i)) { + return false; + } + } + return versionInList.size() > compareToInList.size(); + } + // trim string from "text" to text public static String trimNbtRawString(String rawString) {