Fixed ranges for a few stats when previewing items

This commit is contained in:
Jules 2023-10-28 01:48:00 +02:00
parent 68b4be0fdf
commit 3efb021798
11 changed files with 159 additions and 174 deletions

View File

@ -184,7 +184,6 @@ public class MMOItems extends JavaPlugin {
stationRecipeManager.reload();
// This ones are not implementing Reloadable
NumericStatFormula.reload();
MMOItemReforger.reload();
Bukkit.getPluginManager().registerEvents(entityManager, this);

View File

@ -1,6 +1,5 @@
package net.Indyuce.mmoitems.api.util;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
@ -218,14 +217,14 @@ public class NumericStatFormula implements RandomStatData<DoubleData>, Updatable
return max;
}
public static boolean RELATIVE_SPREAD;
public static boolean RELATIVE_SPREAD = false;
/**
* Applies the formula for a given input x.
*
* @param levelScalingFactor When choosing the mean of the distribution,
* the formula is <code>base + (scale*level)</code>.
* This is the <code>level</code>
* @param scaleFactor When choosing the mean of the distribution,
* the formula is <code>base + (scale*level)</code>.
* This is the <code>level</code>
* @return <b>Legacy formula: ???</b><br>
* Let A = {base} + {scale} * lvl, then the returned value is a
* random value taken in respect to a gaussian distribution
@ -237,10 +236,17 @@ public class NumericStatFormula implements RandomStatData<DoubleData>, Updatable
* The 'spread' is the standard deviation of the distribution. <br>
* 'Max Spread' constrains the result of this operation at <code>{mean}±{max spread}</code>
*/
public double calculate(double levelScalingFactor) {
public double calculate(double scaleFactor) {
// Calculate yes
return calculate(levelScalingFactor, uniform ? RANDOM.nextDouble() : RANDOM.nextGaussian());
return calculate(scaleFactor, FormulaInputType.RANDOM);
}
public double calculate(double scaleFactor, @NotNull FormulaInputType type) {
return calculate(scaleFactor,
type == FormulaInputType.RANDOM ? (uniform ? RANDOM.nextDouble() : RANDOM.nextGaussian()) :
type == FormulaInputType.UPPER_BOUND ? (uniform ? 1 : 2.5) :
type == FormulaInputType.LOWER_BOUND ? (uniform ? 0 : -2.5) : Double.NaN);
}
/**
@ -252,10 +258,13 @@ public class NumericStatFormula implements RandomStatData<DoubleData>, Updatable
*/
public double calculate(double scaleFactor, double random) {
double value;
if (uniform) {
value = min + (max - min) * random;
} else {
// Spread, max-spread and base are ignored
return scaleFactor * scale + min + (max - min) * random;
}
// Gausian
else {
// The mean, the center of the distribution
final double actualBase = base + (scale * scaleFactor);
@ -267,12 +276,29 @@ public class NumericStatFormula implements RandomStatData<DoubleData>, Updatable
*/
final double spreadCoef = Math.min(Math.max(random * spread, -maxSpread), maxSpread);
value = RELATIVE_SPREAD ? actualBase * (1 + spreadCoef) : actualBase + spreadCoef;
double value = RELATIVE_SPREAD ? actualBase * (1 + spreadCoef) : actualBase + spreadCoef;
if (hasMin) value = Math.max(min, value);
if (hasMax) value = Math.min(max, value);
return value;
}
}
return value;
public static enum FormulaInputType {
/**
* Upper bound of gaussian/uniform formula
*/
UPPER_BOUND,
/**
* Lower bound of gaussian/uniform formula
*/
LOWER_BOUND,
/**
* Random value, for stat value generation
*/
RANDOM;
}
@Override
@ -329,10 +355,6 @@ public class NumericStatFormula implements RandomStatData<DoubleData>, Updatable
+ (maxSpread != 0 ? ",Max=" + maxSpread : "") + "}";
}
public static void reload() {
RELATIVE_SPREAD = !MMOItems.plugin.getConfig().getBoolean("additive-spread-formula", false);
}
@NotNull
@SuppressWarnings("unchecked")
@Override

View File

@ -77,7 +77,6 @@ public class ReloadCommandTreeNode extends CommandTreeNode {
+ MMOItems.plugin.getUpgrades().getAll().size() + ChatColor.GRAY + " Upgrade Templates");
// This one is not implementing Reloadable
NumericStatFormula.reload();
MMOItemReforger.reload();
}

View File

@ -180,6 +180,8 @@ public class ConfigManager implements Reloadable {
levelSpread = MMOItems.plugin.getConfig().getDouble("item-level-spread");
disableRemovedItems = MMOItems.plugin.getConfig().getBoolean("disable-removed-items");
NumericStatFormula.RELATIVE_SPREAD = !MMOItems.plugin.getConfig().getBoolean("additive-spread-formula", false);
opStatsEnabled = MMOItems.plugin.getConfig().getBoolean("op-item-stats.enabled");
opStats.clear();
for (String key : MMOItems.plugin.getConfig().getStringList("op-item-stats.stats"))

View File

@ -21,6 +21,7 @@ import net.Indyuce.mmoitems.stat.type.Previewable;
import net.Indyuce.mmoitems.util.ElementStatType;
import net.Indyuce.mmoitems.util.Pair;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
@ -126,6 +127,14 @@ public class Elements extends ItemStat<RandomElementListData, ElementListData> i
return "elemental-damage";
}
@NotNull
private String formatForLore(Element element, ElementStatType statType) {
return statFormat.get(statType)
.replace("{color}", element.getColor())
.replace("{icon}", element.getLoreIcon())
.replace("{element}", element.getName());
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull ElementListData data) {
@ -133,10 +142,7 @@ public class Elements extends ItemStat<RandomElementListData, ElementListData> i
// Write Lore
for (Pair<Element, ElementStatType> pair : data.getKeys()) {
final String format = statFormat.get(pair.getValue())
.replace("{color}", pair.getKey().getColor())
.replace("{icon}", pair.getKey().getLoreIcon())
.replace("{element}", pair.getKey().getName());
final String format = formatForLore(pair.getKey(), pair.getValue());
final double value = data.getStat(pair.getKey(), pair.getValue());
lore.add(DoubleStat.formatPath("ELEMENTAL_STAT", format, true, value));
}
@ -216,26 +222,17 @@ public class Elements extends ItemStat<RandomElementListData, ElementListData> i
NumericStatFormula nsf = templateData.getStat(element, statType);
// Get Value
double techMinimum = nsf.calculate(0, -2.5);
double techMaximum = nsf.calculate(0, 2.5);
final double techMinimum = nsf.calculate(0, NumericStatFormula.FormulaInputType.LOWER_BOUND);
final double techMaximum = nsf.calculate(0, NumericStatFormula.FormulaInputType.UPPER_BOUND);
// Display if not ZERO
if (techMinimum != 0 || techMaximum != 0) {
// Get path
String builtRange;
if (SilentNumbers.round(techMinimum, 2) == SilentNumbers.round(techMaximum, 2)) {
builtRange = DoubleStat.formatPath(statType.getConcatenatedTagPath(element), statFormat.get(statType), true, techMinimum);
} else {
builtRange = DoubleStat.formatPath(statType.getConcatenatedTagPath(element), statFormat.get(statType), true, techMinimum, techMaximum);
}
// Just display normally
final String builtRange = DoubleStat.formatPath(statType.getConcatenatedTagPath(element), formatForLore(element, statType), true, techMinimum, techMaximum);
elementLore.add(builtRange);
}
}
if (!elementLore.isEmpty()) item.getLore().insert(getPath(), elementLore);
if (!elementLore.isEmpty()) item.getLore().insert("elements", elementLore);
// Add tags
item.addItemTag(getAppliedNBT(currentData));

View File

@ -1,67 +1,57 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import io.lumine.mythic.lib.api.item.ItemTag;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import io.lumine.mythic.lib.api.item.ItemTag;
import org.jetbrains.annotations.NotNull;
public class PickaxePower extends DoubleStat {
public PickaxePower() {
super("PICKAXE_POWER", Material.IRON_PICKAXE, "Pickaxe Power",
new String[] { "The breaking strength of the", "item when mining custom blocks." }, new String[] { "tool" });
}
public PickaxePower() {
super("PICKAXE_POWER", Material.IRON_PICKAXE, "Pickaxe Power", new String[]{"The breaking strength of the", "item when mining custom blocks."}, new String[]{"tool"});
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull DoubleData data) {
int pickPower = (int) data.getValue();
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull DoubleData data) {
int pickPower = (int) data.getValue();
item.addItemTag(new ItemTag("MMOITEMS_PICKAXE_POWER", pickPower));
item.getLore().insert("pickaxe-power", formatNumericStat(pickPower, "{value}", String.valueOf(pickPower)));
}
@Override
public void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull DoubleData currentData, @NotNull NumericStatFormula templateData) throws IllegalArgumentException {
Validate.isTrue(currentData instanceof DoubleData, "Current Data is not Double Data");
Validate.isTrue(templateData instanceof NumericStatFormula, "Template Data is not Numeric Stat Formula");
item.addItemTag(new ItemTag("MMOITEMS_PICKAXE_POWER", pickPower));
item.getLore().insert("pickaxe-power", DoubleStat.formatPath(getPath(), getGeneralStatFormat(), true, false, pickPower));
}
// Get Value
double techMinimum = ((NumericStatFormula) templateData).calculate(0, -2.5);
double techMaximum = ((NumericStatFormula) templateData).calculate(0, 2.5);
@Override
public void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull DoubleData currentData, @NotNull NumericStatFormula templateData) throws IllegalArgumentException {
Validate.isTrue(currentData instanceof DoubleData, "Current Data is not Double Data");
Validate.isTrue(templateData instanceof NumericStatFormula, "Template Data is not Numeric Stat Formula");
// Cancel if it its NEGATIVE and this doesn't support negative stats.
if (techMaximum < 0 && !handleNegativeStats()) {
return;
}
if (techMinimum < 0 && !handleNegativeStats()) {
techMinimum = 0;
}
if (techMinimum < ((NumericStatFormula) templateData).getBase() - ((NumericStatFormula) templateData).getMaxSpread()) {
techMinimum = ((NumericStatFormula) templateData).getBase() - ((NumericStatFormula) templateData).getMaxSpread();
}
if (techMaximum > ((NumericStatFormula) templateData).getBase() + ((NumericStatFormula) templateData).getMaxSpread()) {
techMaximum = ((NumericStatFormula) templateData).getBase() + ((NumericStatFormula) templateData).getMaxSpread();
}
// Get Value
double techMinimum = templateData.calculate(0, NumericStatFormula.FormulaInputType.LOWER_BOUND);
double techMaximum = templateData.calculate(0, NumericStatFormula.FormulaInputType.UPPER_BOUND);
// Add NBT Path
item.addItemTag(new ItemTag("MMOITEMS_PICKAXE_POWER", ((DoubleData) currentData).getValue()));
// Cancel if it its NEGATIVE and this doesn't support negative stats.
if (techMaximum < 0 && !handleNegativeStats()) {
return;
}
if (techMinimum < 0 && !handleNegativeStats()) {
techMinimum = 0;
}
if (techMinimum < ((NumericStatFormula) templateData).getBase() - ((NumericStatFormula) templateData).getMaxSpread()) {
techMinimum = ((NumericStatFormula) templateData).getBase() - ((NumericStatFormula) templateData).getMaxSpread();
}
if (techMaximum > ((NumericStatFormula) templateData).getBase() + ((NumericStatFormula) templateData).getMaxSpread()) {
techMaximum = ((NumericStatFormula) templateData).getBase() + ((NumericStatFormula) templateData).getMaxSpread();
}
// Display if not ZERO
if (techMinimum != 0 || techMaximum != 0) {
// Add NBT Path
item.addItemTag(new ItemTag("MMOITEMS_PICKAXE_POWER", currentData.getValue()));
String builtRange;
if (SilentNumbers.round(techMinimum, 2) == SilentNumbers.round(techMaximum, 2)) { builtRange = MythicLib.plugin.getMMOConfig().decimals.format(techMinimum); }
else { builtRange = MythicLib.plugin.getMMOConfig().decimals.format(techMinimum) + "-" + MythicLib.plugin.getMMOConfig().decimals.format(techMaximum); }
// Just display normally
item.getLore().insert("pickaxe-power", formatNumericStat(techMinimum, "{value}", builtRange));
}
}
// Display if not ZERO
if (techMinimum != 0 || techMaximum != 0) {
String builtRange = DoubleStat.formatPath(getPath(), getGeneralStatFormat(), true, false, Math.floor(techMinimum), Math.floor(techMaximum));
item.getLore().insert("pickaxe-power", builtRange);
}
}
}

View File

@ -3,7 +3,6 @@ package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
@ -41,7 +40,7 @@ public class RequiredLevel extends DoubleStat implements ItemRestriction {
// Lore Management
int lvl = (int) data.getValue();
item.getLore().insert(getPath(), formatNumericStat(lvl, "{value}", String.valueOf(lvl)));
item.getLore().insert(getPath(), DoubleStat.formatPath(getPath(), getGeneralStatFormat(), false, false, lvl));
// Insert NBT
item.addItemTag(getAppliedNBT(data));
@ -51,38 +50,18 @@ public class RequiredLevel extends DoubleStat implements ItemRestriction {
public void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull DoubleData currentData, @NotNull NumericStatFormula templateData) throws IllegalArgumentException {
// Get Value
double techMinimum = templateData.calculate(0, -2.5);
double techMaximum = templateData.calculate(0, 2.5);
// Cancel if it its NEGATIVE and this doesn't support negative stats.
if (techMaximum < 0 && !handleNegativeStats()) {
return;
}
if (techMinimum < 0 && !handleNegativeStats()) {
techMinimum = 0;
}
if (techMinimum < templateData.getBase() - templateData.getMaxSpread()) {
techMinimum = templateData.getBase() - templateData.getMaxSpread();
}
if (techMaximum > templateData.getBase() + templateData.getMaxSpread()) {
techMaximum = templateData.getBase() + templateData.getMaxSpread();
}
double techMinimum = templateData.calculate(0, NumericStatFormula.FormulaInputType.LOWER_BOUND);
double techMaximum = templateData.calculate(0, NumericStatFormula.FormulaInputType.UPPER_BOUND);
// Add NBT Path
item.addItemTag(getAppliedNBT(currentData));
// Display if not ZERO
if (techMinimum != 0 || techMaximum != 0) {
String builtRange;
if (SilentNumbers.round(techMinimum, 2) == SilentNumbers.round(techMaximum, 2)) {
builtRange = SilentNumbers.readableRounding(techMinimum, 0);
} else {
builtRange = SilentNumbers.removeDecimalZeros(String.valueOf(techMinimum)) + "-" + SilentNumbers.removeDecimalZeros(String.valueOf(techMaximum));
}
final String builtRange = DoubleStat.formatPath(getPath(), getGeneralStatFormat(), false, false, Math.floor(techMinimum), Math.floor(techMaximum));
// Just display normally
item.getLore().insert(getPath(), formatNumericStat(techMinimum, "{value}", builtRange));
item.getLore().insert(getPath(), builtRange);
}
}

View File

@ -22,7 +22,7 @@ public class SoulboundLevel extends DoubleStat {
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull DoubleData data) {
int value = (int) data.getValue();
item.addItemTag(new ItemTag("MMOITEMS_SOULBOUND_LEVEL", value));
item.getLore().insert("soulbound-level", formatNumericStat(value, "{value}", MMOUtils.intToRoman(value)));
item.getLore().insert("soulbound-level", getGeneralStatFormat().replace("{value}", MMOUtils.intToRoman(value)));
}
@Override

View File

@ -125,7 +125,7 @@ public class DoubleStat extends ItemStat<NumericStatFormula, DoubleData> impleme
if (value != 0 || upgradeShift != 0) {
String loreInsert = formatPath(getId(), getGeneralStatFormat(), moreIsBetter, value * multiplyWhenDisplaying());
if (upgradeShift != 0)
loreInsert += UpgradeTemplate.getUpgradeChangeSuffix(plus(upgradeShift * multiplyWhenDisplaying()) + (MythicLib.plugin.getMMOConfig().decimals.format(upgradeShift * multiplyWhenDisplaying())), !isGood(upgradeShift * multiplyWhenDisplaying()));
loreInsert += UpgradeTemplate.getUpgradeChangeSuffix(plus(true, upgradeShift * multiplyWhenDisplaying()) + (MythicLib.plugin.getMMOConfig().decimals.format(upgradeShift * multiplyWhenDisplaying())), !isGood(upgradeShift * multiplyWhenDisplaying()));
item.getLore().insert(getPath(), loreInsert);
}
@ -140,38 +140,62 @@ public class DoubleStat extends ItemStat<NumericStatFormula, DoubleData> impleme
}
}
@NotNull
@Deprecated
public static String formatPath(@NotNull String format, boolean moreIsBetter, double value) {
return formatPath("ATTACK_DAMAGE", format, moreIsBetter, value);
}
@NotNull
public static String formatPath(@NotNull String stat, @NotNull String format, boolean moreIsBetter, double value) {
final String valueFormatted = StatManager.format(stat, value);
final String colorPrefix = getColorPrefix(value < 0 && moreIsBetter);
return format
.replace("<plus>{value}", colorPrefix + (value > 0 ? "+" : "") + valueFormatted) // Replace conditional pluses with +value
.replace("{value}", colorPrefix + valueFormatted) // Replace loose pounds with the value
.replace("<plus>", (value > 0 ? "+" : "")); // Replace loose <plus>es
}
@NotNull
@Deprecated
public static String formatPath(@NotNull String format, boolean moreIsBetter, double min, double max) {
return formatPath("ATTACK_DAMAGE", format, moreIsBetter, min, max);
}
@NotNull
public static String formatPath(@NotNull String stat, @NotNull String format, boolean moreIsBetter, double value) {
return formatPath(stat, format, moreIsBetter, true, value);
}
@NotNull
public static String formatPath(@NotNull String stat, @NotNull String format, boolean moreIsBetter, boolean displayPlus, double value) {
final String valueFormatted = StatManager.format(stat, value);
final String colorPrefix = getColorPrefix(value < 0 && moreIsBetter);
return format
.replace("{value}", colorPrefix + valueFormatted) // Replace loose pounds with the value
.replace("<plus>", colorPrefix + plus(displayPlus, value)); // Replace loose <plus>es
}
@NotNull
public static String formatPath(@NotNull String stat, @NotNull String format, boolean moreIsBetter, double min, double max) {
final String minFormatted = StatManager.format(stat, min), maxFormatted = StatManager.format(stat, max);
return formatPath(stat, format, moreIsBetter, true, min, max);
}
@NotNull
public static String formatPath(@NotNull String stat, @NotNull String format, boolean moreIsBetter, boolean displayPlus, double min, double max) {
// For stat preview
if (SilentNumbers.round(min, 2) == SilentNumbers.round(max, 2))
return formatPath(stat, format, moreIsBetter, displayPlus, min);
final String minFormatted = plus(displayPlus, min) + StatManager.format(stat, min), maxFormatted = (displayPlus && min < 0 && max > 0 ? "+" : "") + StatManager.format(stat, max);
final String minPrefix = getColorPrefix(min < 0 && moreIsBetter), maxPrefix = getColorPrefix(max < 0 && moreIsBetter);
return format
.replace("<plus>", "")
.replace("<plus>", "") // Override plus
.replace("{value}",
minPrefix + (min > 0 ? "+" : "") + minFormatted
minPrefix + minFormatted
+ MMOItems.plugin.getConfig().getString("stats-displaying.range-dash", "") +
maxPrefix + (min < 0 && max > 0 ? "+" : "") + maxFormatted);
maxPrefix + maxFormatted);
}
@NotNull
private static String getColorPrefix(boolean isNegative) {
// Get the base
return MMOItems.plugin.getConfig().getString("stats-displaying.color-" + (isNegative ? "negative" : "positive"), "");
}
@NotNull
private static String plus(boolean displayPlus, double amount) {
return displayPlus && amount > 0 ? "+" : "";
}
@Override
@ -181,8 +205,8 @@ public class DoubleStat extends ItemStat<NumericStatFormula, DoubleData> impleme
// Get Value
//SPRD//MMOItems.log("\u00a7c༺\u00a77 Calulating deviations of \u00a7b" + item.getMMOItem().getType().toString() + " " + item.getMMOItem().getId() + "\u00a77's \u00a7e" + getId());
double techMinimum = templateData.calculate(0, -2.5);
double techMaximum = templateData.calculate(0, 2.5);
double techMinimum = templateData.calculate(0, NumericStatFormula.FormulaInputType.LOWER_BOUND);
double techMaximum = templateData.calculate(0, NumericStatFormula.FormulaInputType.UPPER_BOUND);
// Cancel if it its NEGATIVE and this doesn't support negative stats.
if (techMaximum < 0 && !handleNegativeStats()) {
@ -196,34 +220,11 @@ public class DoubleStat extends ItemStat<NumericStatFormula, DoubleData> impleme
// Display if not ZERO
if (techMinimum != 0 || techMaximum != 0) {
String builtRange;
if (SilentNumbers.round(techMinimum, 2) == SilentNumbers.round(techMaximum, 2)) {
builtRange = formatPath(getId(), getGeneralStatFormat(), moreIsBetter(), techMaximum * multiplyWhenDisplaying());
} else {
builtRange = formatPath(getId(), getGeneralStatFormat(), moreIsBetter(), techMinimum * multiplyWhenDisplaying(), techMaximum * multiplyWhenDisplaying());
}
// Just display normally
final String builtRange = formatPath(getId(), getGeneralStatFormat(), moreIsBetter(), techMinimum * multiplyWhenDisplaying(), techMaximum * multiplyWhenDisplaying());
item.getLore().insert(getPath(), builtRange);
}
}
@NotNull
public static String getColorPrefix(boolean isNegative) {
// Get the base
return Objects.requireNonNull(MMOItems.plugin.getConfig().getString("stats-displaying.color-" + (isNegative ? "negative" : "positive"), ""));
}
@NotNull
String plus(double amount) {
if (amount >= 0) {
return "+";
} else return "";
}
/**
* Usually, a greater magnitude of stat benefits the player (more health, more attack damage).
* <p>However, its not impossible for a stat to be evil instead, who knows?

View File

@ -187,7 +187,7 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
/**
* @return The stat ID
* @deprecated Use getId() instead. Type is no longer an util since they can
* now be registered from external plugins
* now be registered from external plugins
*/
@Deprecated
@NotNull
@ -205,8 +205,8 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
/**
* @return The NBT path used by the stat to save data in an item's NBTTags.
* The format is 'MMOITEMS_' followed by the stat name in capital
* letters only using _
* The format is 'MMOITEMS_' followed by the stat name in capital
* letters only using _
*/
@NotNull
public String getNBTPath() {
@ -248,6 +248,10 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
enabled = false;
}
/**
* @deprecated See {@link DoubleStat#formatPath(String, String, boolean, boolean, double, double)}
*/
@Deprecated
public String formatNumericStat(double value, String... replace) {
String format = getGeneralStatFormat().replace("<plus>", value > 0 ? "+" : "");
for (int j = 0; j < replace.length; j += 2)

View File

@ -23,7 +23,7 @@ import java.util.ArrayList;
* required skill levels.
*/
public abstract class RequiredLevelStat extends DoubleStat implements ItemRestriction, GemStoneStat {
private final String idKey;
// private final String idKey;
public RequiredLevelStat(String idKey, Material mat, String nameKey, String[] lore) {
super("REQUIRED_" + idKey,
@ -32,14 +32,14 @@ public abstract class RequiredLevelStat extends DoubleStat implements ItemRestri
lore,
new String[]{"!block", "all"});
this.idKey = idKey;
// this.idKey = idKey;
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull DoubleData data) {
// Lore Management
int lvl = (int) data.getValue();
int lvl = (int) data.getValue();
String format = getGeneralStatFormat().replace("{value}", String.valueOf(lvl));
item.getLore().insert(getPath(), format);
@ -51,8 +51,8 @@ public abstract class RequiredLevelStat extends DoubleStat implements ItemRestri
public void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull DoubleData currentData, @NotNull NumericStatFormula templateData) throws IllegalArgumentException {
// Get Value
double techMinimum = ((NumericStatFormula) templateData).calculate(0, -2.5);
double techMaximum = ((NumericStatFormula) templateData).calculate(0, 2.5);
double techMinimum = templateData.calculate(0, NumericStatFormula.FormulaInputType.LOWER_BOUND);
double techMaximum = templateData.calculate(0, NumericStatFormula.FormulaInputType.UPPER_BOUND);
// Cancel if it its NEGATIVE and this doesn't support negative stats.
if (techMaximum < 0 && !handleNegativeStats()) {
@ -73,16 +73,8 @@ public abstract class RequiredLevelStat extends DoubleStat implements ItemRestri
// Display if not ZERO
if (techMinimum != 0 || techMaximum != 0) {
String builtRange;
if (SilentNumbers.round(techMinimum, 2) == SilentNumbers.round(techMaximum, 2)) {
builtRange = SilentNumbers.readableRounding(techMinimum, 0);
} else {
builtRange = SilentNumbers.removeDecimalZeros(String.valueOf(techMinimum)) + "-" + SilentNumbers.removeDecimalZeros(String.valueOf(techMaximum));
}
// Just display normally
item.getLore().insert(getPath(), formatNumericStat(techMinimum, "{value}", builtRange));
final String builtRange = DoubleStat.formatPath(getPath(), getGeneralStatFormat(), false, false, Math.floor(techMinimum), Math.floor(techMaximum));
item.getLore().insert(getPath(), builtRange);
}
}