Skip to content

Commit

Permalink
Fix versioned item type base components
Browse files Browse the repository at this point in the history
  • Loading branch information
booky10 committed Oct 19, 2024
1 parent 72a4464 commit 1ed52f3
Showing 1 changed file with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,20 @@ public Set<ItemAttribute> 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);
}

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);
}
Expand All @@ -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;
}
}
}

0 comments on commit 1ed52f3

Please sign in to comment.