mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-23 04:47:34 +01:00
Gem stones now keep the highest level req of both items
This commit is contained in:
parent
cbca4ab306
commit
8bb5764c5e
@ -4,21 +4,31 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.Indyuce.mmoitems.api.item.MMOItem;
|
||||
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
|
||||
import net.Indyuce.mmoitems.api.itemgen.RandomStatData;
|
||||
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||
import net.Indyuce.mmoitems.stat.data.DoubleData;
|
||||
import net.Indyuce.mmoitems.stat.data.RequiredLevelData;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomRequiredLevelData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
|
||||
import net.Indyuce.mmoitems.stat.type.DoubleStat;
|
||||
import net.Indyuce.mmoitems.stat.type.ProperStat;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
|
||||
import net.mmogroup.mmolib.api.item.ItemTag;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
import net.mmogroup.mmolib.version.VersionMaterial;
|
||||
|
||||
public class RequiredLevel extends DoubleStat implements ItemRestriction, ProperStat {
|
||||
public class RequiredLevel extends DoubleStat implements ItemRestriction {
|
||||
|
||||
/*
|
||||
* stat that uses a custom DoubleStatData because the merge algorithm is
|
||||
* slightly different. when merging two "required level", MMOItems should
|
||||
* only keep the highest levels of the two and not sum the two values
|
||||
*/
|
||||
public RequiredLevel() {
|
||||
super("REQUIRED_LEVEL", new ItemStack(VersionMaterial.EXPERIENCE_BOTTLE.toMaterial()), "Required Level", new String[] { "The level your item needs", "in order to be used." }, new String[] { "all" });
|
||||
super("REQUIRED_LEVEL", new ItemStack(VersionMaterial.EXPERIENCE_BOTTLE.toMaterial()), "Required Level",
|
||||
new String[] { "The level your item needs", "in order to be used." }, new String[] { "all" });
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,6 +39,22 @@ public class RequiredLevel extends DoubleStat implements ItemRestriction, Proper
|
||||
item.getLore().insert("required-level", format(lvl, "#", "" + lvl));
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatData whenInitialized(Object object) {
|
||||
return new RequiredLevelData(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomStatData whenInitializedGeneration(Object object) {
|
||||
return new RandomRequiredLevelData(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenLoaded(MMOItem mmoitem, NBTItem item) {
|
||||
if (item.hasTag(getNBTPath()))
|
||||
mmoitem.setData(this, new RequiredLevelData(item.getDouble(getNBTPath())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(RPGPlayer player, NBTItem item, boolean message) {
|
||||
int level = item.getInteger("MMOITEMS_REQUIRED_LEVEL");
|
||||
|
@ -29,11 +29,7 @@ public class DoubleData implements StatData, Mergeable {
|
||||
throw new IllegalArgumentException("Must specify a range or a number");
|
||||
}
|
||||
|
||||
public DoubleData(double value) {
|
||||
this(value, 0);
|
||||
}
|
||||
|
||||
private DoubleData(double min, double max) {
|
||||
public DoubleData(double min, double max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package net.Indyuce.mmoitems.stat.data;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
|
||||
public class RequiredLevelData extends DoubleData {
|
||||
public RequiredLevelData(Object object) {
|
||||
super(object);
|
||||
}
|
||||
|
||||
public RequiredLevelData(double min, double max) {
|
||||
super(min, max);
|
||||
}
|
||||
|
||||
/*
|
||||
* when a gem stone is applied on an item with a lower level requirement,
|
||||
* the item must save the HIGHEST level requirement so that newbies cannot
|
||||
* use over powered items
|
||||
*/
|
||||
@Override
|
||||
public void merge(StatData data) {
|
||||
Validate.isTrue(data instanceof RequiredLevelData, "Cannot merge two different stat data types");
|
||||
|
||||
setMin(Math.max(((DoubleData) data).getMin(), getMin()));
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package net.Indyuce.mmoitems.stat.data.random;
|
||||
|
||||
import net.Indyuce.mmoitems.api.itemgen.GeneratedItemBuilder;
|
||||
import net.Indyuce.mmoitems.api.itemgen.NumericStatFormula;
|
||||
import net.Indyuce.mmoitems.stat.data.RequiredLevelData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
|
||||
public class RandomRequiredLevelData extends NumericStatFormula {
|
||||
public RandomRequiredLevelData(Object object) {
|
||||
super(object);
|
||||
}
|
||||
|
||||
public RandomRequiredLevelData(double base, double scale, double spread, double maxSpread) {
|
||||
super(base, scale, spread, maxSpread);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatData randomize(GeneratedItemBuilder builder) {
|
||||
return new RequiredLevelData(calculate(builder.getLevel()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user