Add custom_item_support config file to optionally disable repair/salvage on items with custom models

This commit is contained in:
nossr50
2024-04-06 14:26:57 -07:00
parent 0363ee2e90
commit ffc6061f8b
8 changed files with 79 additions and 35 deletions

View File

@ -0,0 +1,23 @@
package com.gmail.nossr50.config;
import java.io.File;
public class CustomItemSupportConfig extends BukkitConfig {
public CustomItemSupportConfig(File dataFolder) {
super("custom_item_support.yml", dataFolder);
validate();
}
@Override
protected void loadKeys() {
}
public boolean isCustomRepairAllowed() {
return config.getBoolean("Custom_Item_Support.Repair.Allow_Repair_On_Items_With_Custom_Model_Data", true);
}
public boolean isCustomSalvageAllowed() {
return config.getBoolean("Custom_Item_Support.Salvage.Allow_Salvage_On_Items_With_Custom_Model_Data", true);
}
}

View File

@ -140,6 +140,7 @@ public class mcMMO extends JavaPlugin {
private GeneralConfig generalConfig;
private AdvancedConfig advancedConfig;
private PartyConfig partyConfig;
private CustomItemSupportConfig customItemSupportConfig;
private FoliaLib foliaLib;
private PartyManager partyManager;
@ -185,6 +186,7 @@ public class mcMMO extends JavaPlugin {
//Init configs
advancedConfig = new AdvancedConfig(getDataFolder());
partyConfig = new PartyConfig(getDataFolder());
customItemSupportConfig = new CustomItemSupportConfig(getDataFolder());
//Store this value so other plugins can check it
isRetroModeEnabled = generalConfig.getIsRetroMode();
@ -806,6 +808,10 @@ public class mcMMO extends JavaPlugin {
return partyManager;
}
public CustomItemSupportConfig getCustomItemSupportConfig() {
return customItemSupportConfig;
}
public @NotNull FoliaLib getFoliaLib() {
return foliaLib;
}

View File

@ -65,10 +65,19 @@ public class RepairManager extends SkillManager {
public void handleRepair(ItemStack item) {
Player player = getPlayer();
Repairable repairable = mcMMO.getRepairableManager().getRepairable(item.getType());
if (item.getItemMeta() != null) {
if(item.getItemMeta().hasCustomModelData()) {
if(!mcMMO.p.getCustomItemSupportConfig().isCustomRepairAllowed()) {
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED,
"Anvil.Repair.Reject.CustomModelData");
return;
}
}
if (item.getItemMeta().isUnbreakable()) {
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Anvil.Unbreakable");
return;
if (item.getItemMeta().isUnbreakable()) {
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Anvil.Unbreakable");
return;
}
}
// Permissions checks on material and item types

View File

@ -62,14 +62,19 @@ public class SalvageManager extends SkillManager {
}
public void handleSalvage(Location location, ItemStack item) {
Player player = getPlayer();
final Player player = getPlayer();
Salvageable salvageable = mcMMO.getSalvageableManager().getSalvageable(item.getType());
ItemMeta meta = item.getItemMeta();
if (meta != null && meta.isUnbreakable()) {
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Anvil.Unbreakable");
return;
final Salvageable salvageable = mcMMO.getSalvageableManager().getSalvageable(item.getType());
final ItemMeta meta = item.getItemMeta();
if (meta != null) {
if (meta.hasCustomModelData() && !mcMMO.p.getCustomItemSupportConfig().isCustomSalvageAllowed()) {
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Anvil.Salvage.Reject.CustomModelData");
return;
}
if (meta.isUnbreakable()) {
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Anvil.Unbreakable");
return;
}
}
// Permissions checks on material and item types
@ -190,30 +195,6 @@ public class SalvageManager extends SkillManager {
return RankUtils.getRank(getPlayer(), SubSkillType.SALVAGE_ARCANE_SALVAGE);
}
/*public double getExtractFullEnchantChance() {
int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.getExtractFullEnchantChance();
}
}
return 0;
}
public double getExtractPartialEnchantChance() {
int skillLevel = getSkillLevel();
for (Tier tier : Tier.values()) {
if (skillLevel >= tier.getLevel()) {
return tier.getExtractPartialEnchantChance();
}
}
return 0;
}*/
public double getExtractFullEnchantChance() {
if(Permissions.hasSalvageEnchantBypassPerk(getPlayer()))
return 100.0D;

View File

@ -0,0 +1,11 @@
# This is meant to be a general config for allowing mcMMO to allow interaction with custom items.
# In the future, I would like to add configs to be specific about certain custom items.
# For now, support is generalized to whether the custom item has a custom model.
# This is an easy solution to implement for now, but not the most ideal.
Custom_Item_Support:
Repair:
# Turn this off to disable repair on any items with custom model data
Allow_Repair_On_Items_With_Custom_Model_Data: true
Salvage:
# Turn this off to disable salvage on any items with custom model data
Allow_Salvage_On_Items_With_Custom_Model_Data: true

View File

@ -423,6 +423,8 @@ Salvage.Skills.Lottery.Perfect=&a&lPerfect!&r&6 You salvaged &3{1}&6 effortlessl
Salvage.Skills.Lottery.Untrained=&7You aren't properly trained in salvaging. You were only able to recover &c{0}&7 materials from &a{1}&7.
#Anvil (Shared between SALVAGE and REPAIR)
Anvil.Unbreakable=This item is unbreakable!
Anvil.Repair.Reject.CustomModelData=A mysterious force prevents you from repairing this item...
Anvil.Salvage.Reject.CustomModelData=A mysterious force prevents you from salvaging this item...
#CROSSBOWS
Crossbows.SkillName=CROSSBOWS
Crossbows.Ability.Lower=&7You lower your crossbow.