mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-02 11:21:20 +01:00
Stat cleanup
This commit is contained in:
parent
5a007c2c1a
commit
e2967de8a6
@ -25,7 +25,6 @@ import net.Indyuce.mmoitems.api.util.AltChar;
|
||||
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
|
||||
import net.Indyuce.mmoitems.stat.data.GemSocketsData;
|
||||
import net.Indyuce.mmoitems.stat.data.StatData;
|
||||
import net.Indyuce.mmoitems.stat.data.StringListData;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import net.mmogroup.mmolib.api.item.ItemTag;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
@ -37,7 +36,7 @@ public class Gem_Sockets extends ItemStat {
|
||||
|
||||
@Override
|
||||
public void whenLoaded(MMOItem item, ConfigurationSection config) {
|
||||
item.setData(this, new GemSocketsData(new StringListData(config.getStringList("gem-sockets"))));
|
||||
item.setData(this, new GemSocketsData(config.getStringList("gem-sockets")));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,11 +6,12 @@ import org.bukkit.Color;
|
||||
import net.Indyuce.mmoitems.api.item.MMOItem;
|
||||
|
||||
public class ColorData extends StatData {
|
||||
private int red, green, blue;
|
||||
private final int red, green, blue;
|
||||
|
||||
public ColorData(MMOItem mmoitem, String string) {
|
||||
String[] split = string.split("\\ ");
|
||||
Validate.isTrue(split.length > 2, "Must specify 3 numbers for red, green and blue");
|
||||
|
||||
red = Math.min(255, Math.max(0, Integer.parseInt(split[0])));
|
||||
green = Math.min(255, Math.max(0, Integer.parseInt(split[1])));
|
||||
blue = Math.min(255, Math.max(0, Integer.parseInt(split[2])));
|
||||
@ -38,24 +39,6 @@ public class ColorData extends StatData {
|
||||
return blue;
|
||||
}
|
||||
|
||||
public void setRed(int value) {
|
||||
red = value;
|
||||
}
|
||||
|
||||
public void setGreen(int value) {
|
||||
green = value;
|
||||
}
|
||||
|
||||
public void setBlue(int value) {
|
||||
blue = value;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
red = color.getRed();
|
||||
green = color.getGreen();
|
||||
blue = color.getBlue();
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return Color.fromRGB(red, green, blue);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EffectListData extends StatData implements Mergeable {
|
||||
private List<PotionEffectData> effects = new ArrayList<>();
|
||||
private final List<PotionEffectData> effects = new ArrayList<>();
|
||||
|
||||
public EffectListData(PotionEffectData... effects) {
|
||||
add(effects);
|
||||
|
@ -17,28 +17,15 @@ import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.item.MMOItem;
|
||||
import net.Indyuce.mmoitems.stat.Abilities.AbilityListData;
|
||||
import net.Indyuce.mmoitems.stat.type.DoubleStat.DoubleData;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
|
||||
public class GemSocketsData extends StatData {
|
||||
private Set<GemstoneData> gems = new HashSet<>();
|
||||
private List<String> slots;
|
||||
private final Set<GemstoneData> gems = new HashSet<>();
|
||||
private final List<String> emptySlots;
|
||||
|
||||
/*
|
||||
* used when the MMOItem is generated. when the item has already been
|
||||
* generated, the direct item slot amount isloaded.
|
||||
*/
|
||||
private StringListData unloadedSlots;
|
||||
private boolean loaded;
|
||||
|
||||
public GemSocketsData(List<String> slots) {
|
||||
this.slots = slots;
|
||||
this.loaded = true;
|
||||
}
|
||||
|
||||
public GemSocketsData(StringListData unloadedSlots) {
|
||||
this.unloadedSlots = unloadedSlots;
|
||||
this.loaded = false;
|
||||
public GemSocketsData(List<String> emptySlots) {
|
||||
this.emptySlots = emptySlots;
|
||||
}
|
||||
|
||||
public boolean canReceive(String gem) {
|
||||
@ -46,7 +33,7 @@ public class GemSocketsData extends StatData {
|
||||
}
|
||||
|
||||
public String getEmptySocket(String gem) {
|
||||
for (String slot : slots)
|
||||
for (String slot : emptySlots)
|
||||
if (gem.equals("") || slot.equals(MMOItems.plugin.getConfig().getString("gem-sockets.uncolored")) || gem.equals(slot))
|
||||
return slot;
|
||||
return null;
|
||||
@ -57,12 +44,12 @@ public class GemSocketsData extends StatData {
|
||||
}
|
||||
|
||||
public void apply(String gem, GemstoneData gemstone) {
|
||||
slots.remove(getEmptySocket(gem));
|
||||
emptySlots.remove(getEmptySocket(gem));
|
||||
gems.add(gemstone);
|
||||
}
|
||||
|
||||
public List<String> getEmptySlots() {
|
||||
return loaded ? slots : unloadedSlots.getList();
|
||||
return emptySlots;
|
||||
}
|
||||
|
||||
public Set<GemstoneData> getGemstones() {
|
||||
@ -92,11 +79,11 @@ public class GemSocketsData extends StatData {
|
||||
}
|
||||
|
||||
public class GemstoneData {
|
||||
private Set<AbilityData> abilities = new HashSet<>();
|
||||
private List<PotionEffectData> effects = new ArrayList<>();
|
||||
private Map<ItemStat, Double> stats = new HashMap<>();
|
||||
private final Set<AbilityData> abilities = new HashSet<>();
|
||||
private final List<PotionEffectData> effects = new ArrayList<>();
|
||||
private final Map<ItemStat, Double> stats = new HashMap<>();
|
||||
// private ParticleData particle;
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
/*
|
||||
* This constructor is not really performance friendly. It should only
|
||||
@ -115,9 +102,9 @@ public class GemSocketsData extends StatData {
|
||||
|
||||
public GemstoneData(NBTItem nbtItem, MMOItem mmoitem) {
|
||||
if (mmoitem.hasData(ItemStat.ABILITIES))
|
||||
abilities = ((AbilityListData) mmoitem.getData(ItemStat.ABILITIES)).getAbilities();
|
||||
((AbilityListData) mmoitem.getData(ItemStat.ABILITIES)).getAbilities().forEach(data -> abilities.add(data));
|
||||
if (mmoitem.hasData(ItemStat.PERM_EFFECTS))
|
||||
effects = ((EffectListData) mmoitem.getData(ItemStat.PERM_EFFECTS)).getEffects();
|
||||
((EffectListData) mmoitem.getData(ItemStat.PERM_EFFECTS)).getEffects().forEach(data -> effects.add(data));
|
||||
for (ItemStat stat : MMOItems.plugin.getStats().getDoubleStats())
|
||||
if (mmoitem.hasData(stat))
|
||||
stats.put(stat, ((DoubleData) mmoitem.getData(stat)).getMin());
|
||||
|
@ -25,7 +25,7 @@ public class ParticleData extends StatData {
|
||||
private final Particle particle;
|
||||
private final Map<String, Double> modifiers = new HashMap<>();
|
||||
|
||||
private Color color;
|
||||
private final Color color;
|
||||
|
||||
public ParticleData(JsonObject object) {
|
||||
particle = Particle.valueOf(object.get("Particle").getAsString());
|
||||
@ -33,8 +33,9 @@ public class ParticleData extends StatData {
|
||||
|
||||
if (object.has("Color")) {
|
||||
JsonObject color = object.getAsJsonObject("Color");
|
||||
setColor(color.get("Red").getAsInt(), color.get("Green").getAsInt(), color.get("Blue").getAsInt());
|
||||
}
|
||||
this.color = Color.fromRGB(color.get("Red").getAsInt(), color.get("Green").getAsInt(), color.get("Blue").getAsInt());
|
||||
} else
|
||||
color = null;
|
||||
|
||||
object.getAsJsonObject("Modifiers").entrySet().forEach(entry -> setModifier(entry.getKey(), entry.getValue().getAsDouble()));
|
||||
}
|
||||
@ -48,17 +49,17 @@ public class ParticleData extends StatData {
|
||||
format = config.getString("particle").toUpperCase().replace("-", "_").replace(" ", "_");
|
||||
particle = Particle.valueOf(format);
|
||||
|
||||
for (String key : config.getKeys(false)) {
|
||||
if (key.equalsIgnoreCase("color"))
|
||||
setColor(config.getInt("color.red"), config.getInt("color.green"), config.getInt("color.blue"));
|
||||
else if (!key.equalsIgnoreCase("particle") && !key.equalsIgnoreCase("type"))
|
||||
color = config.contains("color") ? Color.fromRGB(config.getInt("color.red"), config.getInt("color.green"), config.getInt("color.blue")) : null;
|
||||
|
||||
for (String key : config.getKeys(false))
|
||||
if (!key.equalsIgnoreCase("particle") && !key.equalsIgnoreCase("type") && !key.equalsIgnoreCase("color"))
|
||||
setModifier(key, config.getDouble(key));
|
||||
}
|
||||
}
|
||||
|
||||
public ParticleData(ParticleType type, Particle particle) {
|
||||
this.type = type;
|
||||
this.particle = particle;
|
||||
this.color = null;
|
||||
}
|
||||
|
||||
public ParticleType getType() {
|
||||
@ -81,10 +82,6 @@ public class ParticleData extends StatData {
|
||||
return modifiers.keySet();
|
||||
}
|
||||
|
||||
public void setColor(int red, int green, int blue) {
|
||||
color = Color.fromRGB(red, green, blue);
|
||||
}
|
||||
|
||||
public void setModifier(String path, double value) {
|
||||
modifiers.put(path, value);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
|
||||
public class PotionEffectData {
|
||||
private PotionEffect effect;
|
||||
private final PotionEffect effect;
|
||||
|
||||
public PotionEffectData(PotionEffectType type, int level) {
|
||||
effect = new PotionEffect(type, MMOUtils.getEffectDuration(type), level - 1, true, false);
|
||||
|
@ -7,7 +7,7 @@ import java.util.List;
|
||||
import com.google.gson.JsonArray;
|
||||
|
||||
public class StringListData extends StatData {
|
||||
private List<String> list;
|
||||
private final List<String> list;
|
||||
|
||||
public StringListData() {
|
||||
this(new ArrayList<>());
|
||||
@ -19,6 +19,7 @@ public class StringListData extends StatData {
|
||||
|
||||
public StringListData(JsonArray array) {
|
||||
this();
|
||||
|
||||
array.forEach(str -> list.add(str.getAsString()));
|
||||
}
|
||||
|
||||
@ -29,8 +30,4 @@ public class StringListData extends StatData {
|
||||
public List<String> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<String> list) {
|
||||
this.list = list;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user