Skip to content

Commit

Permalink
Improve 1.21.2+ compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Dec 18, 2024
1 parent e94917e commit 80f24f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ repositories {
}

dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
implementation("com.github.thatsmusic99:ConfigurationMaster-API:v2.0.0-rc.2") {
exclude(group = "org.yaml", module = "snakeyaml")
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/cn/dreeam/surf/util/ItemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.cryptomorin.xseries.XMaterial;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Keyed;
import org.bukkit.Registry;
import org.bukkit.attribute.Attribute;
import org.bukkit.enchantments.Enchantment;
Expand Down Expand Up @@ -325,7 +326,7 @@ private static List<String> initIllegalItemFlags() {
private static List<String> initIllegalAttribute() {
List<String> list = new ArrayList<>();

for (Attribute attribute : getAttributes()) {
for (Object attribute : getAttributes()) {
list.add(attribute.toString());
}

Expand Down Expand Up @@ -412,17 +413,17 @@ private static Attribute getAttributeByName(String name) {
}
}

private static Attribute[] getAttributes() {
private static Object[] getAttributes() {
if (Util.isNewerThan(21, 1)) {
return Registry.ATTRIBUTE.stream().toArray(Attribute[]::new);
return Registry.ATTRIBUTE.stream().map(Keyed::getKey).toArray(Key[]::new);
}

try {
if (attributeValues == null) {
attributeValues = Attribute.class.getMethod("values");
}

return (Attribute[]) attributeValues.invoke(null);
return (Object[]) attributeValues.invoke(null);
} catch (ReflectiveOperationException e) {
Surf.LOGGER.error(e);
return null;
Expand Down

0 comments on commit 80f24f7

Please sign in to comment.