Skip to content

Commit

Permalink
fix: "attribute modifier already applied" error, close #348
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Jul 26, 2024
1 parent 8e9850d commit 83b5209
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ private static void applyAttribute(@Nullable AttributeInstance instance, @Nullab
instance.setBaseValue(attribute == null ? instance.getDefaultValue() : attribute.baseValue());
instance.getModifiers().forEach(instance::removeModifier);
if (attribute != null) {
attribute.modifiers().forEach(mod -> instance.addModifier(adapt(mod, plugin)));
attribute.modifiers().stream().distinct().forEach(mod -> instance.addModifier(adapt(mod, plugin)));
}
}

Expand Down
8 changes: 7 additions & 1 deletion common/src/main/java/net/william278/husksync/data/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,13 @@ public Modifier(@NotNull String name, double amount, int operationType, int equi

@Override
public boolean equals(Object obj) {
return obj instanceof Modifier modifier && modifier.uuid().equals(uuid());
if (obj instanceof Modifier other) {
if (uuid == null || other.uuid == null) {
return name.equals(other.name);
}
return uuid.equals(other.uuid);
}
return super.equals(obj);
}

public double modify(double value) {
Expand Down

0 comments on commit 83b5209

Please sign in to comment.