Fix ConflictBuilder copy not coping maxBeforeConflict

This commit is contained in:
alexcrea 2024-11-17 02:37:39 +01:00
parent 9458362453
commit 8acc136158
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
2 changed files with 34 additions and 32 deletions

View file

@ -148,7 +148,6 @@ public class ConflictAPI {
EnchantConflictGui conflictGui = EnchantConflictGui.getCurrentInstance(); EnchantConflictGui conflictGui = EnchantConflictGui.getCurrentInstance();
if (conflictGui != null) conflictGui.removeGeneric(conflict); if (conflictGui != null) conflictGui.removeGeneric(conflict);
return true; return true;
} }
@ -177,7 +176,6 @@ public class ConflictAPI {
reloadChangeTask = null; reloadChangeTask = null;
}); });
} }
static void logConflictOrigin(@NotNull ConflictBuilder builder) { static void logConflictOrigin(@NotNull ConflictBuilder builder) {

View file

@ -36,7 +36,7 @@ public class ConflictBuilder {
* @param maxBeforeConflict Maximum number of conflicting enchantment before conflict is active * @param maxBeforeConflict Maximum number of conflicting enchantment before conflict is active
* @param source The conflict source * @param source The conflict source
*/ */
public ConflictBuilder(@NotNull String name, int maxBeforeConflict, @Nullable Plugin source){ public ConflictBuilder(@NotNull String name, int maxBeforeConflict, @Nullable Plugin source) {
this.source = source; this.source = source;
this.name = name; this.name = name;
@ -54,7 +54,7 @@ public class ConflictBuilder {
* @param name The conflict name * @param name The conflict name
* @param source The conflict source * @param source The conflict source
*/ */
public ConflictBuilder(@NotNull String name, @Nullable Plugin source){ public ConflictBuilder(@NotNull String name, @Nullable Plugin source) {
this(name, 0, source); this(name, 0, source);
} }
@ -63,7 +63,7 @@ public class ConflictBuilder {
* *
* @param name The conflict name * @param name The conflict name
*/ */
public ConflictBuilder(@NotNull String name){ public ConflictBuilder(@NotNull String name) {
this(name, null); this(name, null);
} }
@ -84,7 +84,7 @@ public class ConflictBuilder {
*/ */
@NotNull @NotNull
public String getSourceName() { public String getSourceName() {
if(source == null) return "an unknown source"; if (source == null) return "an unknown source";
return source.getName(); return source.getName();
} }
@ -177,7 +177,7 @@ public class ConflictBuilder {
* @return This conflict builder instance. * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder addEnchantment(@NotNull String enchantmentName){ public ConflictBuilder addEnchantment(@NotNull String enchantmentName) {
enchantmentNames.add(enchantmentName); enchantmentNames.add(enchantmentName);
return this; return this;
} }
@ -189,7 +189,7 @@ public class ConflictBuilder {
* @return This conflict builder instance. * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder addEnchantment(@NotNull NamespacedKey enchantmentKey){ public ConflictBuilder addEnchantment(@NotNull NamespacedKey enchantmentKey) {
enchantmentKeys.add(enchantmentKey); enchantmentKeys.add(enchantmentKey);
return this; return this;
} }
@ -201,7 +201,7 @@ public class ConflictBuilder {
* @return This conflict builder instance. * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder addEnchantment(@NotNull CAEnchantment enchantment){ public ConflictBuilder addEnchantment(@NotNull CAEnchantment enchantment) {
addEnchantment(enchantment.getKey()); addEnchantment(enchantment.getKey());
return this; return this;
} }
@ -213,7 +213,7 @@ public class ConflictBuilder {
* @return This conflict builder instance. * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder removeEnchantment(@NotNull String enchantmentName){ public ConflictBuilder removeEnchantment(@NotNull String enchantmentName) {
enchantmentNames.remove(enchantmentName); enchantmentNames.remove(enchantmentName);
return this; return this;
} }
@ -225,7 +225,7 @@ public class ConflictBuilder {
* @return This conflict builder instance. * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder removeEnchantment(@NotNull NamespacedKey enchantmentKey){ public ConflictBuilder removeEnchantment(@NotNull NamespacedKey enchantmentKey) {
enchantmentKeys.remove(enchantmentKey); enchantmentKeys.remove(enchantmentKey);
return removeEnchantment(enchantmentKey.getKey()); return removeEnchantment(enchantmentKey.getKey());
} }
@ -237,7 +237,7 @@ public class ConflictBuilder {
* @return This conflict builder instance. * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder removeEnchantment(@NotNull CAEnchantment enchantment){ public ConflictBuilder removeEnchantment(@NotNull CAEnchantment enchantment) {
return removeEnchantment(enchantment.getKey()); return removeEnchantment(enchantment.getKey());
} }
@ -256,7 +256,7 @@ public class ConflictBuilder {
* @return This conflict builder instance. * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder addExcludedGroup(@NotNull String groupName){ public ConflictBuilder addExcludedGroup(@NotNull String groupName) {
excludedGroupNames.add(groupName); excludedGroupNames.add(groupName);
return this; return this;
} }
@ -276,7 +276,7 @@ public class ConflictBuilder {
* @return this conflict builder instance. * @return this conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder addExcludedGroup(@NotNull AbstractMaterialGroup group){ public ConflictBuilder addExcludedGroup(@NotNull AbstractMaterialGroup group) {
return addExcludedGroup(group.getName()); return addExcludedGroup(group.getName());
} }
@ -295,7 +295,7 @@ public class ConflictBuilder {
* @return This conflict builder instance. * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder removeExcludedGroup(@NotNull String groupName){ public ConflictBuilder removeExcludedGroup(@NotNull String groupName) {
excludedGroupNames.remove(groupName); excludedGroupNames.remove(groupName);
return this; return this;
} }
@ -315,7 +315,7 @@ public class ConflictBuilder {
* @return This conflict builder instance. * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder removeExcludedGroup(@NotNull AbstractMaterialGroup group){ public ConflictBuilder removeExcludedGroup(@NotNull AbstractMaterialGroup group) {
return removeExcludedGroup(group.getName()); return removeExcludedGroup(group.getName());
} }
@ -328,7 +328,7 @@ public class ConflictBuilder {
public ConflictBuilder copy() { public ConflictBuilder copy() {
ConflictBuilder copy = new ConflictBuilder(this.name, this.source); ConflictBuilder copy = new ConflictBuilder(this.name, this.source);
setMaxBeforeConflict(this.maxBeforeConflict); copy.setMaxBeforeConflict(this.maxBeforeConflict);
// Set Enchantments // Set Enchantments
for (NamespacedKey key : this.enchantmentKeys) { for (NamespacedKey key : this.enchantmentKeys) {
@ -345,11 +345,13 @@ public class ConflictBuilder {
return copy; return copy;
} }
/** /**
* Build a new Enchant conflict group by this builder. * Build a new Enchant conflict group by this builder.
*
* @return An Enchant conflict group with this builder parameters. * @return An Enchant conflict group with this builder parameters.
*/ */
public EnchantConflictGroup build(){ public EnchantConflictGroup build() {
AbstractMaterialGroup materials = extractGroups(); AbstractMaterialGroup materials = extractGroups();
EnchantConflictGroup conflict = new EnchantConflictGroup(getName(), materials, getMaxBeforeConflict()); EnchantConflictGroup conflict = new EnchantConflictGroup(getName(), materials, getMaxBeforeConflict());
appendEnchantments(conflict); appendEnchantments(conflict);
@ -360,18 +362,20 @@ public class ConflictBuilder {
/** /**
* Register this conflict if not yet registered. * Register this conflict if not yet registered.
* Equivalent to {@link ConflictAPI#addConflict(ConflictBuilder, boolean) ConflictAPI.addConflict(this, true)}} * Equivalent to {@link ConflictAPI#addConflict(ConflictBuilder, boolean) ConflictAPI.addConflict(this, true)}}
*
* @return True if successful. * @return True if successful.
*/ */
public boolean registerIfAbsent(){ public boolean registerIfAbsent() {
return ConflictAPI.addConflict(this, true); return ConflictAPI.addConflict(this, true);
} }
/** /**
* Register this conflict if not yet registered or deleted. * Register this conflict if not yet registered or deleted.
* Equivalent to {@link ConflictAPI#addConflict(ConflictBuilder) ConflictAPI.addConflict(this)} * Equivalent to {@link ConflictAPI#addConflict(ConflictBuilder) ConflictAPI.addConflict(this)}
*
* @return True if successful. * @return True if successful.
*/ */
public boolean registerIfNew(){ public boolean registerIfNew() {
return ConflictAPI.addConflict(this); return ConflictAPI.addConflict(this);
} }
@ -380,15 +384,15 @@ public class ConflictBuilder {
* *
* @param conflict The conflict target * @param conflict The conflict target
*/ */
protected void appendEnchantments(@NotNull EnchantConflictGroup conflict){ protected void appendEnchantments(@NotNull EnchantConflictGroup conflict) {
for (String enchantmentName : getEnchantmentNames()){ for (String enchantmentName : getEnchantmentNames()) {
if(appendEnchantments(conflict, EnchantmentApi.getListByName(enchantmentName)) == 0){ if (appendEnchantments(conflict, EnchantmentApi.getListByName(enchantmentName)) == 0) {
CustomAnvil.instance.getLogger().warning("Could not find enchantment " + enchantmentName + " for conflict " + getName()); CustomAnvil.instance.getLogger().warning("Could not find enchantment " + enchantmentName + " for conflict " + getName());
ConflictAPI.logConflictOrigin(this); ConflictAPI.logConflictOrigin(this);
} }
} }
for (NamespacedKey enchantmentKey : getEnchantmentKeys()){ for (NamespacedKey enchantmentKey : getEnchantmentKeys()) {
if(!appendEnchantment(conflict, EnchantmentApi.getByKey(enchantmentKey))){ if (!appendEnchantment(conflict, EnchantmentApi.getByKey(enchantmentKey))) {
CustomAnvil.instance.getLogger().warning("Could not find enchantment " + enchantmentKey + " for conflict " + getName()); CustomAnvil.instance.getLogger().warning("Could not find enchantment " + enchantmentKey + " for conflict " + getName());
ConflictAPI.logConflictOrigin(this); ConflictAPI.logConflictOrigin(this);
} }
@ -402,8 +406,8 @@ public class ConflictBuilder {
* @param enchantment The enchantment * @param enchantment The enchantment
* @return True if successful. * @return True if successful.
*/ */
protected static boolean appendEnchantment(@NotNull EnchantConflictGroup conflict, @Nullable CAEnchantment enchantment){ protected static boolean appendEnchantment(@NotNull EnchantConflictGroup conflict, @Nullable CAEnchantment enchantment) {
if(enchantment == null) if (enchantment == null)
return false; return false;
conflict.addEnchantment(enchantment); conflict.addEnchantment(enchantment);
return true; return true;
@ -416,10 +420,10 @@ public class ConflictBuilder {
* @param enchantments List of enchantment to add * @param enchantments List of enchantment to add
* @return Number of enchantment added * @return Number of enchantment added
*/ */
protected static int appendEnchantments(@NotNull EnchantConflictGroup conflict, @NotNull List<CAEnchantment> enchantments){ protected static int appendEnchantments(@NotNull EnchantConflictGroup conflict, @NotNull List<CAEnchantment> enchantments) {
int numberValid = 0; int numberValid = 0;
for (CAEnchantment enchantment : enchantments) { for (CAEnchantment enchantment : enchantments) {
if(appendEnchantment(conflict, enchantment)){ if (appendEnchantment(conflict, enchantment)) {
numberValid++; numberValid++;
} }
} }
@ -432,14 +436,14 @@ public class ConflictBuilder {
* *
* @return The abstract material group from the builder. * @return The abstract material group from the builder.
*/ */
protected AbstractMaterialGroup extractGroups(){ protected AbstractMaterialGroup extractGroups() {
ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager(); ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
IncludeGroup group = new IncludeGroup(EnchantConflictManager.DEFAULT_GROUP_NAME); IncludeGroup group = new IncludeGroup(EnchantConflictManager.DEFAULT_GROUP_NAME);
for (String groupName : getExcludedGroupNames()) { for (String groupName : getExcludedGroupNames()) {
AbstractMaterialGroup materialGroup = itemGroupManager.get(groupName); AbstractMaterialGroup materialGroup = itemGroupManager.get(groupName);
if(materialGroup == null){ if (materialGroup == null) {
CustomAnvil.instance.getLogger().warning("Material group " + groupName + " do not exist but is ask by conflict " + getName()); CustomAnvil.instance.getLogger().warning("Material group " + groupName + " do not exist but is ask by conflict " + getName());
ConflictAPI.logConflictOrigin(this); ConflictAPI.logConflictOrigin(this);
continue; continue;