Skip to content

Commit

Permalink
Add custom_item_support config file to optionally disable repair/salv…
Browse files Browse the repository at this point in the history
…age on items with custom models
  • Loading branch information
nossr50 committed Apr 6, 2024
1 parent 0363ee2 commit ffc6061
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 36 deletions.
12 changes: 12 additions & 0 deletions Changelog.txt
@@ -1,3 +1,15 @@
Version 2.2.006
Added new config custom_item_support.yml
Added setting to disable repair on items with custom models, this is not on by default
Added new locale entry 'Anvil.Repair.Reject.CustomModelData'
Added new locale entry 'Anvil.Salvage.Reject.CustomModelData'

NOTES:
Let me know in detail what kind of support you'd like to see in mcMMO regarding custom items, I'm open to suggestions.
This update adds a new config file to allow server owners to disable repair or salvage on items with custom models,
This prevention mechanism is not enabled by default, change the settings in custom_item_support.yml if you want to enable it.
This feature is off by default for now to keep compatibility with existing servers, but it may be enabled by default in the future if feedback suggests it should be.

Version 2.2.005
Fixed a bug where certain skills such as Dodge/Arrow Deflect had no skill cap and would continue improving forever
Reduced messages on startup for SQL DB
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.2.005</version>
<version>2.2.006-SNAPSHOT</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm>
Expand Down
@@ -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);
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/gmail/nossr50/mcMMO.java
Expand Up @@ -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;
Expand Down Expand Up @@ -185,6 +186,7 @@ public void onEnable() {
//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();
Expand Down Expand Up @@ -806,6 +808,10 @@ public PartyManager getPartyManager() {
return partyManager;
}

public CustomItemSupportConfig getCustomItemSupportConfig() {
return customItemSupportConfig;
}

public @NotNull FoliaLib getFoliaLib() {
return foliaLib;
}
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java
Expand Up @@ -65,10 +65,19 @@ public void placedAnvilCheck() {
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
Expand Down
45 changes: 13 additions & 32 deletions src/main/java/com/gmail/nossr50/skills/salvage/SalvageManager.java
Expand Up @@ -62,14 +62,19 @@ public void placedAnvilCheck() {
}

public void handleSalvage(Location location, ItemStack item) {
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 Player player = getPlayer();

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
Expand Down Expand Up @@ -190,30 +195,6 @@ public int getArcaneSalvageRank() {
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;
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/custom_item_support.yml
@@ -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
2 changes: 2 additions & 0 deletions src/main/resources/locale/locale_en_US.properties
Expand Up @@ -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.
Expand Down

0 comments on commit ffc6061

Please sign in to comment.