Skip to content

Commit

Permalink
(fix #27) 1.20.4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Lori3f6 committed Aug 30, 2024
1 parent 1f9eecd commit 3a69f03
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/crafter/mc/lockettepro/LockettePro.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 29 additions & 7 deletions src/main/java/me/crafter/mc/lockettepro/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -342,6 +336,34 @@ public static String getSignLineFromUnknown(String json) {
}
}

public static String getCurrentMinecraftVersionString() {
return Bukkit.getVersion().split("-")[0];
}

public static List<Integer> getMinecraftInList(String versionString) {
var list = new ArrayList<Integer>();
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<Integer> versionInList = getMinecraftInList(version);
List<Integer> 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) {
Expand Down

0 comments on commit 3a69f03

Please sign in to comment.