Added option to disallow using enchanted materials to repair items. (#4693)

This commit is contained in:
JeBobs 2021-12-27 14:29:54 -05:00 committed by GitHub
parent ef714f98c9
commit 2ca3544741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -680,6 +680,7 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
/* REPAIR */
public double getRepairMasteryMaxBonus() { return config.getDouble("Skills.Repair.RepairMastery.MaxBonusPercentage", 200.0D); }
public int getRepairMasteryMaxLevel() { return config.getInt("Skills.Repair.RepairMastery.MaxBonusLevel", 100); }
public boolean getAllowEnchantedRepairMaterials() { return config.getBoolean("Skills.Repair.Use_Enchanted_Materials", false); }
public boolean getArcaneForgingEnchantLossEnabled() { return config.getBoolean("Skills.Repair.ArcaneForging.May_Lose_Enchants", true); }
public double getArcaneForgingKeepEnchantsChance(int rank) { return config.getDouble("Skills.Repair.ArcaneForging.Keep_Enchants_Chance.Rank_" + rank); }

View File

@ -28,8 +28,13 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import java.util.Arrays;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collector;
import java.util.stream.Collectors;
public class RepairManager extends SkillManager {
private boolean placedAnvil;
@ -129,6 +134,35 @@ public class RepairManager extends SkillManager {
// toRemove should be refreshed before the event call.
toRemove = inventory.getItem(inventory.first(repairMaterial)).clone();
// Check if we allow enchanted materials to be used to repair objects.
// (Servers may provide enchanted items that don't follow their intended use)
if (!mcMMO.p.getAdvancedConfig().getAllowEnchantedRepairMaterials()) {
// See if our proposed item is even enchanted in the first place.
if (toRemove.getEnchantments().size() > 0) {
// Lots of array sorting to find a potential non-enchanted candidate item.
Optional<ItemStack> possibleMaterial = Arrays.stream(inventory.getContents())
.filter(Objects::nonNull)
.filter(p -> p.getType() == repairMaterial)
.filter(p -> p.getEnchantments().isEmpty())
.findFirst();
// Fail out with "you need material" if we don't find a suitable alternative.
if (possibleMaterial.isEmpty()) {
String prettyName = repairable.getRepairMaterialPrettyName() == null ? StringUtils.getPrettyItemString(repairMaterial) : repairable.getRepairMaterialPrettyName();
String materialsNeeded = "";
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Skills.NeedMore.Extra", prettyName, materialsNeeded);
return;
}
// Update our toRemove item to our suggested possible material.
toRemove = possibleMaterial.get().clone();
}
}
// Call event
if (EventUtils.callRepairCheckEvent(player, (short) (startDurability - newDurability), toRemove, item).isCancelled()) {
return;