Implements some necessary code for the scrapper
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
Implements ignored salvage Implements salvage-able items Adds some TODOs Implements salvage fail chance Moves several methods to ItemHelper Adds option for allowing extended salvage
This commit is contained in:
@ -4,13 +4,19 @@ import net.citizensnpcs.api.util.DataKey;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import net.knarcraft.blacksmith.config.TraitSettings;
|
||||
import net.knarcraft.blacksmith.util.ConfigHelper;
|
||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
|
||||
|
||||
private final Map<ScrapperSetting, Object> currentValues = new HashMap<>();
|
||||
private final GlobalScrapperSettings globalScrapperSettings;
|
||||
private final List<Material> salvageAbleItems = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Instantiates a new scrapper NPC settings object
|
||||
@ -59,6 +65,20 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
|
||||
} else {
|
||||
currentValues.put(setting, newValue);
|
||||
}
|
||||
if (setting == ScrapperSetting.SALVAGE_ABLE_ITEMS) {
|
||||
updateSalvageAbleItems();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the reforge-able items according to the current value of the setting
|
||||
*/
|
||||
private void updateSalvageAbleItems() {
|
||||
this.salvageAbleItems.clear();
|
||||
List<String> materialStrings = ConfigHelper.asStringList(getValue(ScrapperSetting.SALVAGE_ABLE_ITEMS));
|
||||
if (materialStrings != null) {
|
||||
this.salvageAbleItems.addAll(ItemHelper.getItems(materialStrings, !extendedSalvageEnabled()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,14 +107,23 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message to display when a blacksmith has successfully repaired an item
|
||||
* Gets the message to display when a scrapper has successfully scrapped an item
|
||||
*
|
||||
* @return <p>The reforge success message</p>
|
||||
* @return <p>The salvage success message</p>
|
||||
*/
|
||||
public String getSuccessMessage() {
|
||||
return asString(ScrapperSetting.SUCCESS_SALVAGE_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message to display when a scrapper fails to salvage an item
|
||||
*
|
||||
* @return <p>The salvage fail message</p>
|
||||
*/
|
||||
public String getFailMessage() {
|
||||
return asString(ScrapperSetting.FAIL_SALVAGE_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCoolDownUnexpiredMessage() {
|
||||
return asString(ScrapperSetting.COOL_DOWN_UNEXPIRED_MESSAGE);
|
||||
@ -157,6 +186,15 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
|
||||
return asInt(ScrapperSetting.MAX_SALVAGE_DELAY) <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chance of a salvaging to fail
|
||||
*
|
||||
* @return <p>The chance of a salvaging to fail</p>
|
||||
*/
|
||||
public int getFailChance() {
|
||||
return asInt(ScrapperSetting.FAIL_SALVAGE_CHANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the given value as an integer
|
||||
*
|
||||
@ -201,4 +239,51 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all item types this NPC is able to salvage
|
||||
*
|
||||
* @return <p>All salvageable items</p>
|
||||
*/
|
||||
public List<Material> getSalvageAbleItems() {
|
||||
Object currentValue = currentValues.get(ScrapperSetting.SALVAGE_ABLE_ITEMS);
|
||||
if (currentValue == null || String.valueOf(currentValue).isEmpty()) {
|
||||
return globalScrapperSettings.getSalvageAbleItems();
|
||||
} else {
|
||||
return new ArrayList<>(this.salvageAbleItems);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether extended salvaging is enabled
|
||||
*
|
||||
* <p>When not extended, only repairable items can be salvaged. When extended, any item produced using a crafting
|
||||
* recipe or a smithing transformation can be salvaged. This does not include smelting or similar.</p>
|
||||
*
|
||||
* @return <p>True if extended salvaging is enabled</p>
|
||||
*/
|
||||
public boolean extendedSalvageEnabled() {
|
||||
return ConfigHelper.asBoolean(getValue(ScrapperSetting.EXTENDED_SALVAGE_ENABLED));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the title of this scrapper NPC
|
||||
*
|
||||
* <p>The title is used to specify scrapper sub-types in order to make it clear which items a scrapper can salvage.
|
||||
* For example, an armor-scrapper would only be able to salvage armor pieces.</p>
|
||||
*
|
||||
* @return <p>The title of this scrapper NPC</p>
|
||||
*/
|
||||
public String getScrapperTitle() {
|
||||
return asString(ScrapperSetting.SCRAPPER_TITLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message to display if this NPC is given an item it cannot salvage
|
||||
*
|
||||
* @return <p>The message to display</p>
|
||||
*/
|
||||
public String getInvalidItemMessage() {
|
||||
return asString(ScrapperSetting.INVALID_ITEM_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user