From 1ed52f3f4ea8f3d4eff586b05162acd8931981d9 Mon Sep 17 00:00:00 2001 From: booky10 Date: Sun, 20 Oct 2024 00:03:03 +0200 Subject: [PATCH] Fix versioned item type base components --- .../protocol/item/type/StaticItemType.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/com/github/retrooper/packetevents/protocol/item/type/StaticItemType.java b/api/src/main/java/com/github/retrooper/packetevents/protocol/item/type/StaticItemType.java index d3bd6e0fb..4c72e711d 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/protocol/item/type/StaticItemType.java +++ b/api/src/main/java/com/github/retrooper/packetevents/protocol/item/type/StaticItemType.java @@ -83,6 +83,10 @@ public Set getAttributes() { @Override public StaticComponentMap getComponents(ClientVersion version) { + if (!version.isRelease()) { + throw new IllegalArgumentException("Unsupported version for " + + "getting components of " + this.getName() + ": " + version); + } return this.components.getOrDefault(version, StaticComponentMap.SHARED_ITEM_COMPONENTS); } @@ -90,6 +94,9 @@ void setComponents(ClientVersion version, StaticComponentMap components) { if (this.components.containsKey(version)) { throw new IllegalStateException("Components are already defined for " + this.getName() + " in version " + version); + } else if (!version.isRelease()) { + throw new IllegalArgumentException("Unsupported version for " + + "setting components of " + this.getName() + ": " + version); } this.components.put(version, components); } @@ -98,14 +105,26 @@ void setComponents(ClientVersion version, StaticComponentMap components) { void fillComponents() { StaticComponentMap lastComponents = null; for (ClientVersion version : ClientVersion.values()) { + if (!version.isRelease()) { + continue; + } StaticComponentMap components = this.components.get(version); - if (components != null) { - lastComponents = components; + if (components == null) { + if (lastComponents != null) { + this.components.put(version, lastComponents); + } continue; } - if (lastComponents != null) { - this.components.put(version, lastComponents); + if (lastComponents == null) { + // also fill backwards + for (ClientVersion beforeVersion : ClientVersion.values()) { + if (beforeVersion == version) { + break; + } + this.components.put(beforeVersion, components); + } } + lastComponents = components; } } }