From 3d1047deb85083c4ea9558462ef235897e4f09a3 Mon Sep 17 00:00:00 2001 From: Patrick Miller Date: Sat, 3 Feb 2024 12:34:22 -0500 Subject: [PATCH] Fix loading on Spigot versions older than 1.18 (#6399) --- .../java/ch/njol/skript/aliases/AliasesProvider.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/aliases/AliasesProvider.java b/src/main/java/ch/njol/skript/aliases/AliasesProvider.java index 1c6e73184c4..c4fc7b4204a 100644 --- a/src/main/java/ch/njol/skript/aliases/AliasesProvider.java +++ b/src/main/java/ch/njol/skript/aliases/AliasesProvider.java @@ -21,10 +21,12 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Set; import java.util.List; import java.util.Map; +import ch.njol.skript.Skript; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -42,6 +44,9 @@ * Provides aliases on Bukkit/Spigot platform. */ public class AliasesProvider { + + // not supported on Spigot versions older than 1.18 + private static final boolean FASTER_SET_SUPPORTED = Skript.classExists("it.unimi.dsi.fastutil.objects.ObjectOpenHashSet"); /** * When an alias is not found, it will requested from this provider. @@ -173,7 +178,12 @@ public AliasesProvider(int expectedCount, @Nullable AliasesProvider parent) { this.aliases = new HashMap<>(expectedCount); this.variations = new HashMap<>(expectedCount / 20); this.aliasesMap = new AliasesMap(); - this.materials = new ObjectOpenHashSet<>(); + + if (FASTER_SET_SUPPORTED) { + this.materials = new ObjectOpenHashSet<>(); + } else { + this.materials = new HashSet<>(); + } this.gson = new Gson(); }