Skip to content

Commit

Permalink
Add support for Minecraft 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
EpiCanard committed Jun 16, 2024
1 parent f60160d commit f669c9b
Show file tree
Hide file tree
Showing 5 changed files with 1,712 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<spigot.version>1.20.6-R0.1-SNAPSHOT</spigot.version>
<duckconfig.version>1.2.0</duckconfig.version>
<lombok.version>1.18.20</lombok.version>
<lombok.version>1.18.32</lombok.version>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Utils {
* Prevent loading config issues for versions not fully supported by the plugin
*/
@Getter
private static final String lastSupportedVersion = "1.19";
private static final String lastSupportedVersion = "1.21";

static {
fullVersion = GlobalMarketChest.plugin.getServer().getBukkitVersion().substring(0, 6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,6 @@ public Object getRegistryItem(Object registry, Object minecraftKey)
return registry.getClass().getMethod("a", minecraftKey.getClass()).invoke(registry, minecraftKey);
}

@Version(name = "getMinecraftKeyClass", versions = { "1.12", "1.13", "1.14", "1.15", "1.16" })
public Class<?> getMinecraftKeyClass_old() throws ClassNotFoundException {
return Path.MINECRAFT_SERVER.getClass("MinecraftKey");
}

@Version(name = "getMinecraftKeyClass")
public Class<?> getMinecraftKeyClass_latest() throws ClassNotFoundException {
return Path.MINECRAFT_RESOURCES.getClass("MinecraftKey");
}

@Version(name = "getMinecraftKey", versions = { "1.12" })
public Object getMinecraftKey_1_12(Object registry, Object nmsItemStack)
throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
Expand Down Expand Up @@ -314,6 +304,21 @@ public void setTagLatest(Object nmsItemStack, Object tagCompound) {
}
}

@Version(name = "newMinecraftKey", versions = { "1.12", "1.13", "1.14", "1.15", "1.16" })
public Object newMinecraftKey_old(String name) throws Exception {
return Path.MINECRAFT_SERVER.getClass("MinecraftKey").getConstructor(String.class).newInstance(name);
}

@Version(name = "newMinecraftKey", versions = { "1.17", "1.18", "1.19", "1.20" })
public Object newMinecraftKey_1_17(String name) throws Exception {
return Path.MINECRAFT_RESOURCES.getClass("MinecraftKey").getConstructor(String.class).newInstance(name);
}

@Version(name = "newMinecraftKey")
public Object newMinecraftKey_latest(String name) throws Exception {
return Path.MINECRAFT_RESOURCES.getClass("MinecraftKey").getMethod("a", String.class).invoke(null, name);
}

// ======= SPECIFIC METHOD ===========

/**
Expand All @@ -324,8 +329,7 @@ public void setTagLatest(Object nmsItemStack, Object tagCompound) {
*/
public ItemStack getItemStack(String name) {
try {
Class<?> minecraftKeyClass = call("getMinecraftKeyClass", this);
Object minecraftKey = minecraftKeyClass.getConstructor(String.class).newInstance(name);
Object minecraftKey = call("newMinecraftKey", this, name);;

Object registry = getRegistry();
Object item = call("getRegistryItem", this, registry, minecraftKey);
Expand Down
Loading

0 comments on commit f669c9b

Please sign in to comment.