mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
Added option to disallow using enchanted materials to repair items. (#4693)
This commit is contained in:
parent
ef714f98c9
commit
2ca3544741
@ -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); }
|
||||
|
@ -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;
|
||||
@ -128,6 +133,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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user