Skip to content

Commit d69ab59

Browse files
committed
Remove some code duplication and add a check for a potential error situation in which two feature generators of the same name are registered. This fixes the potential issue where the feature is in _features.json and the mod that added it has made the API calls that originally added it
1 parent b296d2c commit d69ab59

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,20 @@ public boolean hasFeature(String name) {
6464
public boolean hasFeature(IFeature feature) {
6565
return featuresInverse.containsKey(feature);
6666
}
67+
6768

6869
public void addFeature(JsonObject entry) {
69-
IFeature feature = getInstance(entry.get("class").getAsString());
70-
if( feature != null ) {
71-
features.put(entry.get("name").getAsString(), feature);
72-
featuresInverse.put(feature, entry.get("name").getAsString());
73-
}
70+
this.addFeature(entry.get("name").getAsString(), entry.get("class").getAsString());
7471
}
7572

7673
public void addFeature(String name, String className) {
7774
IFeature feature = getInstance(className);
7875
if( feature != null ) {
79-
features.put(name, feature);
80-
featuresInverse.put(feature, name);
76+
// the feature might already be registered
77+
if( !features.containsKey(name) ) {
78+
features.put(name, feature);
79+
featuresInverse.put(feature, name);
80+
}
8181
}
8282
}
8383

0 commit comments

Comments
 (0)