Basic component API stuff

This commit is contained in:
Jules 2024-10-26 03:19:43 +02:00
parent 5bda049802
commit ef1a1e7cd5
131 changed files with 2372 additions and 669 deletions

View File

@ -209,7 +209,7 @@ public class ItemStats {
UPGRADE = new UpgradeStat(),
DOWNGRADE_ON_BREAK = new BooleanStat("BREAK_DOWNGRADE", Material.DAMAGED_ANVIL, "Downgrade when Broken", new String[]{"If this item's durability reaches 0,", "it will be fully repaired but also", "downgraded by one level.", "", "&cIt will only break if it cannot be", "&cdowngraded further", "", "Requires to define an &6Upgrade Template", "Required to define &6Custom Durability"}, new String[]{"equipment"}).setCategory(StatCategories.UPGRADING),
DOWNGRADE_ON_DEATH = new BooleanStat("DEATH_DOWNGRADE", Material.DAMAGED_ANVIL, "Downgrade on Death", new String[]{"If the wearer of this item dies, it may", "downgrade (based on &6Death Downgrade", "&6Chance &7stat)", "", "Required to define an &6Upgrade Template", "Requires keep-inventory gamerule. "}, new String[]{"equipment"}).setCategory(StatCategories.UPGRADING),
DOWNGRADE_ON_DEATH_CHANCE = new DoubleStat("DEATH_DOWNGRADE_CHANCE", Material.SKELETON_SKULL, "Death Downgrade Chance", new String[]{"Probability that an item with &cDowngrade ", "&con Death&7 will be downgraded when the", "player dies. ", "", "Exceeding 100% will for sure downgrade", "one item, and roll again to downgrade", "another (with the excess probability).", "&6The same item wont be downgraded twice."}, new String[]{"equipment"}, false).setCategory(StatCategories.UPGRADING),
DOWNGRADE_ON_DEATH_CHANCE = new DoubleStat("DEATH_DOWNGRADE_CHANCE", Material.SKELETON_SKULL, "Death Downgrade Chance", "Probability that an item with &cDowngrade on Death &7will be downgraded when the player dies.\n\n Exceeding 100% will for sure downgrade one item, and roll again to downgrade another (with the excess probability). The same item won't be downgraded twice.", new String[]{"equipment"}, false).setCategory(StatCategories.UPGRADING),
// Unique Item Stats
DYE_COLOR = new DyeColor(),

View File

@ -4,7 +4,7 @@ import net.Indyuce.mmoitems.api.event.PlayerDataEvent;
import net.Indyuce.mmoitems.api.interaction.Consumable;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.stat.type.PlayerConsumable;
import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

View File

@ -12,8 +12,8 @@ import net.Indyuce.mmoitems.api.event.item.ConsumableConsumedEvent;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.item.util.LoreUpdate;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.type.PlayerConsumable;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;

View File

@ -14,7 +14,7 @@ import net.Indyuce.mmoitems.stat.data.GemSocketsData;
import net.Indyuce.mmoitems.stat.data.GemstoneData;
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.stat.type.StatHistory;
import net.Indyuce.mmoitems.util.MMOUtils;

View File

@ -3,7 +3,7 @@ package net.Indyuce.mmoitems.api.player;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.ChatColor;
import org.bukkit.Sound;

View File

@ -1,6 +1,9 @@
package net.Indyuce.mmoitems.api.util;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import net.Indyuce.mmoitems.stat.component.builtin.DoubleComponent;
import net.Indyuce.mmoitems.stat.component.model.Model;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.random.UpdatableRandomStatData;

View File

@ -8,7 +8,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.type.InternalStat;
import net.Indyuce.mmoitems.stat.behaviour.InternalStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.Material;

View File

@ -6,7 +6,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.type.InternalStat;
import net.Indyuce.mmoitems.stat.behaviour.InternalStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.advancedplugins.ae.api.AEAPI;
import org.apache.commons.lang.Validate;

View File

@ -7,7 +7,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringStat;
import org.bukkit.ChatColor;
import org.bukkit.Material;

View File

@ -22,7 +22,7 @@ import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.category.StatCategory;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.stat.type.RequiredLevelStat;
import org.apache.commons.lang.Validate;

View File

@ -1,10 +1,23 @@
package net.Indyuce.mmoitems.gui.edition;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.util.Lazy;
import io.lumine.mythic.lib.version.VersionUtils;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.stat.type.InternalStat;
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.gui.edition.newedit.ItemFactory;
import net.Indyuce.mmoitems.stat.behaviour.InternalStat;
import net.Indyuce.mmoitems.stat.category.StatCategory;
import net.Indyuce.mmoitems.stat.component.LoreWrapper;
import net.Indyuce.mmoitems.stat.component.builtin.MaterialComponent;
import net.Indyuce.mmoitems.stat.component.builtin.StringComponent;
import net.Indyuce.mmoitems.stat.component.model.Model;
import net.Indyuce.mmoitems.stat.component.model.builtin.ArrayModel;
import net.Indyuce.mmoitems.stat.component.model.builtin.DoubleModel;
import net.Indyuce.mmoitems.stat.component.type.ComponentType;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.ChatColor;
@ -16,18 +29,26 @@ import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
public class ItemEdition extends EditionInventory {
private static final int[] slots = {19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43};
private static final NamespacedKey STAT_ID_KEY = new NamespacedKey(MMOItems.plugin, "StatId");
private static final int[] SLOTS = {19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43, 46, 47, 48, 49, 50, 51, 52};
private static final NamespacedKey COMPONENT_KEY = new NamespacedKey(MMOItems.plugin, "component_key");
private Stack<Entry> explored = new Stack<>();
Map<ItemStat<?, ?>, Model<?>> sampleItem = new HashMap<>();
public ItemEdition(Player player, MMOItemTemplate template) {
super(player, template);
super(player, template, false);
// TODO replace by getting info from the item
sampleItem.put(ItemStats.ATTACK_DAMAGE, new DoubleModel(new NumericStatFormula(10)));
sampleItem.put(ItemStats.MATERIAL, new MaterialComponent(Material.IRON_SWORD));
sampleItem.put(ItemStats.NAME, new StringComponent("Super Duper Item"));
sampleItem.put(ItemStats.LORE, new ArrayModel<>());
}
@Override
@ -35,71 +56,120 @@ public class ItemEdition extends EditionInventory {
return "Item Edition: " + getEdited().getId();
}
private static class Entry {
final String key;
final StatCategory category;
final ComponentType ctype;
final Model<?> model;
private Entry(String key, StatCategory category, ComponentType<?, ?> ctype, Model<?> model) {
this.key = key;
this.category = category;
this.ctype = ctype;
this.model = model;
}
}
@Override
@SuppressWarnings({"unchecked"})
public void arrangeInventory() {
int min = (page - 1) * slots.length;
int max = page * slots.length;
int n = 0;
/*
* it has to determine what stats can be applied first because otherwise
* the for loop will just let some slots empty
*/
List<ItemStat> appliable = new ArrayList<>(getEdited().getType().getAvailableStats()).stream()
.filter(stat -> stat.hasValidMaterial(getCachedItem()) && !(stat instanceof InternalStat)).collect(Collectors.toList());
Entry topmost = explored.isEmpty() ? null : explored.peek();
for (int j = min; j < Math.min(appliable.size(), max); j++) {
ItemStat stat = appliable.get(j);
ItemStack item = new ItemStack(stat.getDisplayMaterial());
// TODO define visiting object/array. and let some of these visit() impls throw RuntimeExcption
List<Entry> entries = topmost != null ?
// Explore current component
((ComponentType<?, ?>) topmost.ctype).getSubcomponents().stream()
.map(pair -> new Entry(pair.getKey(), null, pair.getValue(), topmost.model == null ? null : topmost.model.getModel(pair.getKey())))
.collect(Collectors.toList()) :
// Explore stats
new ArrayList<>(getEdited().getType().getAvailableStats()).stream()
.filter(stat -> stat.getComponentType() != null)
.filter(stat -> stat.hasValidMaterial(getCachedItem()) && !(stat instanceof InternalStat))
// TODO sample item
.map(stat -> new Entry(stat.getId().toLowerCase(), stat.getCategory(), stat.getComponentType(), sampleItem.get(stat)))
.collect(Collectors.toList());
// Bounds and counter
int min = (page - 1) * SLOTS.length;
int max = Math.min(page * SLOTS.length, entries.size());
int slotc = 0;
for (int j = min; j < max; j++) {
Entry entry = entries.get(j);
ItemStack item = entry.ctype.provideIcon(entry.model);
ItemMeta meta = item.getItemMeta();
meta.addItemFlags(ItemFlag.values());
VersionUtils.addEmptyAttributeModifier(meta);
meta.setDisplayName(ChatColor.GREEN + stat.getName());
List<String> lore = MythicLib.plugin.parseColors(Arrays.stream(stat.getLore()).map(s -> ChatColor.GRAY + s).collect(Collectors.toList()));
lore.add("");
if (stat.getCategory() != null) {
meta.setDisplayName(ChatColor.GREEN + entry.ctype.provideName(entry.model));
List<String> lore = new ArrayList<>();
// Display stat category
if (entry.category != null) {
lore.add(0, "");
lore.add(0, ChatColor.BLUE + stat.getCategory().getLoreTag());
lore.add(0, ChatColor.BLUE + entry.category.getLoreTag());
}
stat.whenDisplayed(lore, getEventualStatData(stat));
// Display component type lore
List<String> statDesc = (List<String>) entry.ctype.provideDescription(entry.model);
if (statDesc != null) {
lore.addAll(MythicLib.plugin.parseColors(statDesc.stream().map(s -> ChatColor.GRAY + s).collect(Collectors.toList())));
lore.add("");
}
// Display current value of main stat component
try {
entry.ctype.editionUiDisplay(new LoreWrapper(lore), entry.model);
lore.add("");
} catch (Exception ignored) {
// Pass
}
// Lore action tags
for (String loreActionTag : (List<String>) entry.ctype.getActionLoreTags())
lore.add(ChatColor.YELLOW + AltChar.listDash + " " + loreActionTag);
// Set NBT tag for exploration and edition
meta.getPersistentDataContainer().set(COMPONENT_KEY, PersistentDataType.STRING, entry.key);
meta.getPersistentDataContainer().set(STAT_ID_KEY, PersistentDataType.STRING, stat.getId());
meta.setLore(lore);
item.setItemMeta(meta);
inventory.setItem(slots[n++], item);
inventory.setItem(SLOTS[slotc++], item);
}
ItemStack glass = new ItemStack(Material.GRAY_STAINED_GLASS_PANE);
ItemMeta glassMeta = glass.getItemMeta();
glassMeta.setDisplayName(ChatColor.RED + "- No Item Stat -");
glass.setItemMeta(glassMeta);
ItemStack next = new ItemStack(Material.ARROW);
ItemMeta nextMeta = next.getItemMeta();
nextMeta.setDisplayName(ChatColor.GREEN + "Next Page");
next.setItemMeta(nextMeta);
ItemStack previous = new ItemStack(Material.ARROW);
ItemMeta previousMeta = previous.getItemMeta();
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
previous.setItemMeta(previousMeta);
while (n < slots.length)
inventory.setItem(slots[n++], glass);
inventory.setItem(27, page > 1 ? previous : null);
inventory.setItem(35, appliable.size() > max ? next : null);
while (slotc < SLOTS.length) inventory.setItem(SLOTS[slotc++], NO_COMPONENT.get());
inventory.setItem(6, topmost != null ? BACK.get() : null);
inventory.setItem(27, page > 1 ? PREVIOUS_PAGE.get() : null);
inventory.setItem(35, entries.size() > max ? NEXT_PAGE.get() : null);
}
private static Lazy<ItemStack>
PREVIOUS_PAGE = Lazy.of(() -> ItemFactory.of(Material.ARROW).name("&aPrevious Page").build()),
NEXT_PAGE = Lazy.of(() -> ItemFactory.of(Material.ARROW).name("&aNext Page").build()),
BACK = Lazy.of(() -> ItemFactory.of(Material.BARRIER).name("&aBack").build()),
NO_COMPONENT = Lazy.of(() -> ItemFactory.of(Material.GRAY_STAINED_GLASS_PANE).name("&c- No Item Stat").build());
/*
private String pathSoFar() {
StringBuilder s = new StringBuilder();
for (TypedComponent comp : this.explored) {
if (!s.isEmpty()) s.append(".");
s.append(comp.path);
}
return s.toString();
}
*/
@Override
public void whenClicked(InventoryClickEvent event) {
event.setCancelled(true);
if (event.getInventory() != event.getClickedInventory())
return;
if (event.getInventory() != event.getClickedInventory()) return;
ItemStack item = event.getCurrentItem();
if (!MMOUtils.isMetaItem(item, false) || event.getInventory().getItem(4) == null)
return;
if (!MMOUtils.isMetaItem(item, false) || event.getInventory().getItem(4) == null) return;
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Next Page")) {
page++;
@ -111,9 +181,25 @@ public class ItemEdition extends EditionInventory {
refreshInventory();
}
final String tag = item.getItemMeta().getPersistentDataContainer().get(STAT_ID_KEY, PersistentDataType.STRING);
if (tag == null || tag.isEmpty()) return;
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Back")) {
explored.pop();
refreshInventory();
}
// Check tag
final String tag = item.getItemMeta().getPersistentDataContainer().get(COMPONENT_KEY, PersistentDataType.STRING);
if (tag == null) return;
// Explore stat
if (explored.isEmpty()) {
ItemStat<?, ?> stat = Objects.requireNonNull(MMOItems.plugin.getStats().get(tag.toUpperCase()), "No stat found with ID '" + tag + "'");
@Nullable Model<?> model = sampleItem.get(stat);
//Validate.notNull(component, "Component is null"); // TODO exception handling
explored.push(new Entry(stat.getId().toLowerCase(), null, stat.getComponentType(), model));
refreshInventory();
}
/*
// Check for OP stats
final ItemStat edited = MMOItems.plugin.getStats().get(tag);
if (MMOItems.plugin.hasPermissions() && MMOItems.plugin.getLanguage().opStatsEnabled
@ -123,7 +209,9 @@ public class ItemEdition extends EditionInventory {
return;
}
edited.whenClicked(this, event);
*/
}
@Deprecated

View File

@ -0,0 +1,59 @@
package net.Indyuce.mmoitems.gui.edition.newedit;
import io.lumine.mythic.lib.MythicLib;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Arrays;
import java.util.List;
public class ItemFactory {
private ItemStack item;
private ItemMeta meta;
/**
* @see #of(Material)
*/
private ItemFactory() {
// Private constructor
}
public ItemFactory material(Material material) {
this.item = new ItemStack(material);
this.meta = item.getItemMeta();
return this;
}
private void validateMaterial() {
Validate.notNull(meta, "No material or invalid material");
}
public ItemFactory name(String name) {
validateMaterial();
meta.setDisplayName(MythicLib.plugin.parseColors(name));
return this;
}
public ItemFactory lore(String... lore) {
return lore(Arrays.asList(lore));
}
public ItemFactory lore(List<String> lore) {
validateMaterial();
meta.setLore(lore);
return this;
}
public ItemStack build() {
validateMaterial();
item.setItemMeta(meta);
return item;
}
public static ItemFactory of(Material mat) {
return new ItemFactory().material(mat);
}
}

View File

@ -19,6 +19,7 @@ import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
// TODO implement navigators
public class GuiListener implements Listener {
@EventHandler

View File

@ -9,7 +9,12 @@ import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.StatCategories;
import net.Indyuce.mmoitems.api.ConfigFile;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.stat.Elements;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction;
import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable;
import net.Indyuce.mmoitems.stat.category.StatCategory;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.legacy.LegacyConfigAdapter;
@ -103,6 +108,8 @@ public class StatManager {
// Register elemental stats
registerElementStats();
Elements.updateComponentType();
// Load stat translation objects (nothing to do with stats)
final ConfigurationSection statOptions = new ConfigFile("/language", "stats").getConfig();
for (ItemStat<?, ?> stat : getAll())

View File

@ -17,6 +17,9 @@ import net.Indyuce.mmoitems.gui.edition.AbilityListEdition;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.skill.RegisteredSkill;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.component.builtin.AbilityComponent;
import net.Indyuce.mmoitems.stat.component.type.builtin.ArrayComponentType;
import net.Indyuce.mmoitems.stat.component.type.builtin.ObjectComponentType;
import net.Indyuce.mmoitems.stat.data.AbilityData;
import net.Indyuce.mmoitems.stat.data.AbilityListData;
import net.Indyuce.mmoitems.stat.data.random.RandomAbilityData;
@ -37,10 +40,22 @@ import java.util.Optional;
@HasCategory(cat = "abilities")
public class Abilities extends ItemStat<RandomAbilityListData, AbilityListData> {
public Abilities() {
super("ABILITY", Material.BLAZE_POWDER, "Item Abilities",
new String[]{"Make your item cast amazing abilities", "to kill monsters or buff yourself."}, new String[]{"!block", "all"});
}
super("ABILITY", new String[]{"!block", "all"});
/*
ObjectComponentType abilityType = ObjectComponentType.object()
.addField("ability", AbilityComponent.type().build())
.addField("modifiers", ObjectComponentType.object().build())
.setFlattened(true)
.build();
setComponentType(ArrayComponentType.arrayOf(abilityType)
.setActionLoreTags("Left click to edit abilities.", "Right click to remove all abilities.")
.setIcon(Material.FIRE_CHARGE)
.setName("Abilities")
.setLoreTrimmed("Make your item cast amazing abilities to kill monsters or buff yourself. Abilities can be actively cast, set on a timer or triggered by specific world events. Custom abilities can be created using MythicLib, MythicMobs, Fabled...")
.build());
*/
}
@Override
public RandomAbilityListData whenInitialized(Object object) {
Validate.isTrue(object instanceof ConfigurationSection, "Must specify a valid config section");

View File

@ -8,8 +8,8 @@ import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction;
import net.Indyuce.mmoitems.util.StatChoice;
import org.bukkit.Material;
import org.bukkit.block.Block;

View File

@ -1,6 +1,7 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.component.type.builtin.DoubleComponentType;
import net.Indyuce.mmoitems.stat.type.AttackWeaponStat;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
@ -13,5 +14,12 @@ public class AttackDamage extends AttackWeaponStat {
"Attack Damage",
new String[]{"The amount of damage your weapon deals."},
Attribute.GENERIC_ATTACK_DAMAGE);
setComponentType(DoubleComponentType.numeric()
.moreIsBetter(true)
.setIcon(Material.IRON_SWORD)
.setName("Attack Damage")
.trimLore("The amount of damage dealt by melee or ranged weapon attacks.")
.build());
}
}

View File

@ -20,7 +20,7 @@ import net.Indyuce.mmoitems.api.interaction.Consumable;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import io.lumine.mythic.lib.api.item.NBTItem;
import org.jetbrains.annotations.NotNull;

View File

@ -18,7 +18,7 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.ParticleData;
import net.Indyuce.mmoitems.stat.data.SkullTextureData;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;

View File

@ -16,7 +16,7 @@ import net.Indyuce.mmoitems.api.item.util.identify.IdentifiedItem;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import io.lumine.mythic.lib.api.item.NBTItem;
import org.jetbrains.annotations.NotNull;

View File

@ -14,7 +14,7 @@ import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.data.GemSocketsData;
import net.Indyuce.mmoitems.stat.data.GemstoneData;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.util.Pair;
import org.bukkit.ChatColor;
import org.bukkit.Material;

View File

@ -1,8 +1,7 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringStat;
import net.Indyuce.mmoitems.stat.type.TemplateOption;
import org.bukkit.Material;

View File

@ -4,9 +4,8 @@ import io.lumine.mythic.lib.api.item.ItemTag;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.InternalStat;
import net.Indyuce.mmoitems.stat.behaviour.InternalStat;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;

View File

@ -6,10 +6,9 @@ import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import io.lumine.mythic.lib.api.item.ItemTag;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;

View File

@ -16,9 +16,9 @@ import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.gui.edition.SoundsEdition;
import net.Indyuce.mmoitems.stat.data.SoundData;
import net.Indyuce.mmoitems.stat.data.SoundListData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.stat.type.PlayerConsumable;
import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Material;

View File

@ -10,7 +10,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.NameData;
import net.Indyuce.mmoitems.stat.type.StatHistory;
import net.Indyuce.mmoitems.stat.type.StringStat;

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringStat;
import org.bukkit.Material;

View File

@ -9,6 +9,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.component.type.builtin.ObjectComponentType;
import net.Indyuce.mmoitems.stat.data.ColorData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
@ -30,9 +31,14 @@ import java.util.Optional;
@HasCategory(cat = "item")
public class DyeColor extends ItemStat<ColorData, ColorData> {
public DyeColor() {
super("DYE_COLOR", Material.RED_DYE, "Dye Color",
new String[] { "The color of your item", "(for dyeable items).", "In RGB." }, new String[0], Material.LEATHER_HELMET,
Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, Material.LEATHER_BOOTS, Material.LEATHER_HORSE_ARMOR);
super("DYE_COLOR",
null, Material.LEATHER_HELMET, Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, Material.LEATHER_BOOTS, Material.LEATHER_HORSE_ARMOR);
setComponentType(ObjectComponentType.color()
.setIcon(Material.RED_DYE)
.setName("Dye Color")
.trimLore("Sets the dye color of leather player armor and leather horse armor, in RGB (red, green, blue) format.")
.build());
}
@Override
@ -100,7 +106,9 @@ public class DyeColor extends ItemStat<ColorData, ColorData> {
StatData data = getLoadedNBT(relevantTags);
// Put if nonull
if (data != null) { mmoitem.setData(this, data); }
if (data != null) {
mmoitem.setData(this, data);
}
}
}

View File

@ -23,7 +23,7 @@ import net.Indyuce.mmoitems.stat.data.random.RandomPotionEffectData;
import net.Indyuce.mmoitems.stat.data.random.RandomPotionEffectListData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.stat.type.PlayerConsumable;
import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
@ -12,6 +13,8 @@ import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.gui.edition.ElementsEdition;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.component.type.builtin.DoubleComponentType;
import net.Indyuce.mmoitems.stat.component.type.builtin.ObjectComponentType;
import net.Indyuce.mmoitems.stat.data.ElementListData;
import net.Indyuce.mmoitems.stat.data.random.RandomElementListData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
@ -34,10 +37,31 @@ import java.util.*;
@HasCategory(cat = "elements")
public class Elements extends ItemStat<RandomElementListData, ElementListData> implements Previewable<RandomElementListData, ElementListData> {
public Elements() {
super("ELEMENT", Material.SLIME_BALL, "Elements", new String[]{"The elements of your item."},
super("ELEMENT",
new String[]{"equipment", "ornament", "gem_stone"});
}
@Deprecated
public static void updateComponentType() {
ItemStat<?, ?> stat = MMOItems.plugin.getStats().get("ELEMENT");
ObjectComponentType.Builder builder = ObjectComponentType.object();
for (Element element : MythicLib.plugin.getElements().getAll())
for (ElementStatType statType : ElementStatType.values())
builder.addField(statType.getConcatenatedTagPath(element).toLowerCase(), DoubleComponentType.numeric()
.setIcon(element.getIcon())
.setName(element.getName() + " " + statType.getName())
.build());
stat.setComponentType(builder
.setIcon(Material.MAGMA_CREAM)
.setName("Elemental Stats")
.trimLore("Have the weapon deal on-hit elemental damage, reduce or increase incoming elemental damage.")
.setActionLoreTags("Click to edit elemental stats.", "Right click to reset elements")
.build());
}
@Override
public RandomElementListData whenInitialized(Object object) {
Validate.isTrue(object instanceof ConfigurationSection, "Must specify a config section");

View File

@ -4,7 +4,7 @@ import io.lumine.mythic.lib.api.item.ItemTag;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringStat;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;

View File

@ -3,7 +3,7 @@ package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.util.StatChoice;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;

View File

@ -8,7 +8,7 @@ import net.Indyuce.mmoitems.api.edition.StatEdition;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringListStat;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;

View File

@ -8,7 +8,7 @@ import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import org.bukkit.Material;
import org.bukkit.inventory.meta.Damageable;
import org.jetbrains.annotations.NotNull;

View File

@ -9,7 +9,7 @@ import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.InternalStat;
import net.Indyuce.mmoitems.stat.behaviour.InternalStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.Material;

View File

@ -7,7 +7,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringStat;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;

View File

@ -2,7 +2,7 @@ package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
@ -10,7 +10,6 @@ import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ItemTier;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.StringStat;
import io.lumine.mythic.lib.api.item.ItemTag;
import org.jetbrains.annotations.NotNull;

View File

@ -9,7 +9,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringListStat;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;

View File

@ -6,7 +6,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringStat;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;

View File

@ -10,7 +10,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringStat;
import org.bukkit.Material;
import org.bukkit.event.inventory.InventoryAction;

View File

@ -4,7 +4,7 @@ import io.lumine.mythic.lib.api.item.ItemTag;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringStat;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;

View File

@ -9,8 +9,8 @@ import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
import net.Indyuce.mmoitems.stat.type.PlayerConsumable;
import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction;
import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;

View File

@ -12,6 +12,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.component.builtin.MaterialComponent;
import net.Indyuce.mmoitems.stat.data.MaterialData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.md_5.bungee.api.ChatColor;
@ -32,6 +33,12 @@ import java.util.Optional;
public class MaterialStat extends ItemStat<MaterialData, MaterialData> {
public MaterialStat() {
super("MATERIAL", VMaterial.GRASS_BLOCK.get(), "Material", new String[] { "Your item material." }, new String[0]);
setComponentType(MaterialComponent.Type.init()
.setIcon(org.bukkit.Material.GRASS_BLOCK)
.setName("Item Material")
.trimLore("The material of your item. This option determines quite a lot of properties of your item, like durability, interactions with blocks etc. Therefore, you should use a material that makes sense with your item use case.")
.build());
}
@Override

View File

@ -9,7 +9,7 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.annotation.VersionDependant;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;

View File

@ -9,7 +9,7 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.annotation.VersionDependant;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;

View File

@ -12,8 +12,8 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.MaterialData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction;
import net.Indyuce.mmoitems.stat.type.Upgradable;
import org.bukkit.ChatColor;
import org.bukkit.Material;

View File

@ -14,7 +14,7 @@ import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction;
import net.Indyuce.mmoitems.stat.type.StringListStat;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;

View File

@ -9,6 +9,7 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.component.type.builtin.ObjectComponentType;
import net.Indyuce.mmoitems.stat.data.ColorData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import org.apache.commons.lang.NotImplementedException;
@ -29,9 +30,15 @@ import java.util.Optional;
@HasCategory(cat = "item")
public class PotionColor extends ItemStat<ColorData, ColorData> {
public PotionColor() {
super("POTION_COLOR", Material.POTION, "Potion Color",
new String[] { "The color of your potion.", "(Doesn't impact the effects)." }, new String[0], Material.POTION,
Material.SPLASH_POTION, Material.LINGERING_POTION, Material.TIPPED_ARROW);
super("POTION_COLOR",
new String[0],
Material.POTION, Material.SPLASH_POTION, Material.LINGERING_POTION, Material.TIPPED_ARROW);
setComponentType(ObjectComponentType.color()
.setName("Potion Color")
.setIcon(Material.POTION)
.trimLore("The potion of your color. It is purely a cosmetic option and has no effect whatsoever on the potion effects.")
.build());
}
@Override
@ -97,7 +104,7 @@ public class PotionColor extends ItemStat<ColorData, ColorData> {
@NotNull
@Override
public ColorData getClearStatData() {
return new ColorData(0,0,0);
return new ColorData(0, 0, 0);
}
@Override

View File

@ -16,9 +16,8 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.data.GemSocketsData;
import net.Indyuce.mmoitems.stat.data.GemstoneData;
import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.StatHistory;
import net.Indyuce.mmoitems.util.MMOUtils;
import net.Indyuce.mmoitems.util.Pair;
import org.bukkit.Bukkit;

View File

@ -10,7 +10,7 @@ import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.listener.CustomSoundListener;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.util.MMOUtils;
import net.Indyuce.mmoitems.util.RepairUtils;

View File

@ -6,7 +6,7 @@ import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.interaction.Consumable;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import org.bukkit.Material;
import org.bukkit.event.inventory.InventoryClickEvent;

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringStat;
import org.bukkit.Material;

View File

@ -3,13 +3,11 @@ 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 net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction;
import net.Indyuce.mmoitems.stat.type.StringListStat;
import org.bukkit.Material;

View File

@ -14,8 +14,8 @@ import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction;
import net.Indyuce.mmoitems.stat.type.StringListStat;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;

View File

@ -7,7 +7,7 @@ import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.PlayerConsumable;
import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.Material;
import org.bukkit.entity.Player;

View File

@ -5,7 +5,7 @@ import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.PlayerConsumable;
import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.Material;
import org.bukkit.entity.Player;

View File

@ -6,7 +6,7 @@ import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.PlayerConsumable;
import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

View File

@ -7,7 +7,7 @@ import net.Indyuce.mmoitems.util.MMOUtils;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.PlayerConsumable;
import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

View File

@ -6,7 +6,7 @@ import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.PlayerConsumable;
import net.Indyuce.mmoitems.stat.behaviour.PlayerConsumable;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

View File

@ -11,7 +11,7 @@ import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.gui.edition.RevisionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.DoubleData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import org.bukkit.ChatColor;
import org.bukkit.Material;

View File

@ -12,7 +12,7 @@ import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.SoulboundData;
import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.Bukkit;

View File

@ -12,7 +12,7 @@ import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.SoulboundData;
import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.Bukkit;

View File

@ -16,8 +16,8 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.SoulboundData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.InternalStat;
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
import net.Indyuce.mmoitems.stat.behaviour.InternalStat;
import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.apache.commons.lang.NotImplementedException;

View File

@ -8,8 +8,8 @@ import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StoredTagsData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.InternalStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.InternalStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.Material;

View File

@ -4,7 +4,7 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import org.bukkit.Material;
import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
@HasCategory(cat = "gem_stones")
public class SuccessRate extends DoubleStat implements GemStoneStat {

View File

@ -8,7 +8,7 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.tooltip.TooltipTexture;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.StringStat;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;

View File

@ -5,7 +5,7 @@ import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.util.StatChoice;
import net.Indyuce.mmoitems.stat.annotation.VersionDependant;
import org.bukkit.Material;

View File

@ -5,7 +5,7 @@ import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.util.StatChoice;
import net.Indyuce.mmoitems.stat.annotation.VersionDependant;
import org.bukkit.Material;

View File

@ -23,7 +23,7 @@ import net.Indyuce.mmoitems.gui.edition.UpgradingEdition;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.UpgradeData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.apache.commons.lang.Validate;

View File

@ -0,0 +1,8 @@
package net.Indyuce.mmoitems.stat.annotation;
public class TerminalComponentException extends RuntimeException {
public TerminalComponentException() {
super("Terminal component type");
}
}

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmoitems.stat.type;
package net.Indyuce.mmoitems.stat.behaviour;
import org.bukkit.event.inventory.InventoryClickEvent;

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmoitems.stat.type;
package net.Indyuce.mmoitems.stat.behaviour;
/**
* Statistics which must NOT be applied onto an item when socketing the gem
@ -7,4 +7,5 @@ package net.Indyuce.mmoitems.stat.type;
*
* @author indyuce
*/
public interface GemStoneStat { }
public interface GemStoneStat {
}

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmoitems.stat.type;
package net.Indyuce.mmoitems.stat.behaviour;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;

View File

@ -0,0 +1,39 @@
package net.Indyuce.mmoitems.stat.behaviour;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import io.lumine.mythic.lib.api.item.NBTItem;
/**
* Stats which implement an item restriction. They are automatically collected
* in a list when registered in the StatManager. Lets other plugins implement
* stats which rely on item restrictions without having to use Bukkit events!
*
* @author cympe
*/
public interface ItemRestriction {
/**
* @param player Player trying to use an item
* @param item The item being checked
* @param message Difference between an active and a passive check: if the
* check is active (message boolean set to true), the plugin
* should send a message to the player if he can't use the
* item for eg when he tries to equip the item. If the check
* is passive, no message needs to be sent (when the plugin
* internally needs some similar check)
* @return False if the item cannot be used
*/
boolean canUse(RPGPlayer player, NBTItem item, boolean message);
/**
* Usually, item restrictions are checked <i>when equipping</i>
* an item, and prevent the item being equipped if they fail that moment.
* <p></p>
* Setting this to <code>true</code> will allow items equip anyway
* and check with every use that the conditions for their usage
* are met.
*/
default boolean isDynamic() {
return false;
}
}

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmoitems.stat.type;
package net.Indyuce.mmoitems.stat.behaviour;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import org.bukkit.entity.Player;
@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
* <br>
* Any food is a self consumable, since you eat them to
* restore hunger or health or whatever, while upgrading
* consumables are not self consumables, as the are used
* consumables are not self consumables, as they are used
* on other items and cannot be consumed by themselves.
*
* @author Gunging

View File

@ -1,14 +0,0 @@
package net.Indyuce.mmoitems.stat.component;
public class DoubleComponent extends StatComponent implements Mergeable<DoubleComponent> {
private double value;
public DoubleComponent() {
}
@Override
public void merge(DoubleComponent component) {
value += component.value;
}
}

View File

@ -1,14 +0,0 @@
package net.Indyuce.mmoitems.stat.component;
public class IntegerComponent extends StatComponent implements Mergeable<IntegerComponent> {
private int value;
public IntegerComponent() {
}
@Override
public void merge(IntegerComponent component) {
value += component.value;
}
}

View File

@ -0,0 +1,27 @@
package net.Indyuce.mmoitems.stat.component;
import org.bukkit.ChatColor;
import java.util.List;
public class LoreWrapper {
private final List<String> lore;
private final String prefix = String.valueOf(ChatColor.GRAY);
public LoreWrapper(List<String> lore) {
this.lore = lore;
}
@Deprecated
public void addLines(String... lines) {
for (String line : lines) addLine(line);
}
public void addLine(String line) {
lore.add(prefix + ChatColor.translateAlternateColorCodes('&', line));
}
public void addLines(Iterable<String> lines) {
for (String line : lines) addLine(line);
}
}

View File

@ -1,8 +1,10 @@
package net.Indyuce.mmoitems.stat.component;
import io.lumine.mythic.lib.util.annotation.NotUsed;
import net.Indyuce.mmoitems.stat.component.type.ComponentType;
public interface Mergeable<T extends StatComponent> {
@NotUsed
public interface Mergeable<C extends ComponentType<?, T>, T extends StatComponent> {
public void merge(T t);
public void merge(C componentType, T t);
}

View File

@ -1,49 +0,0 @@
package net.Indyuce.mmoitems.stat.component;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
public class ObjectComponent extends StatComponent {
private final Map<String, StatComponent> components = new HashMap<>();
public ObjectComponent() {
}
@Nullable
public StatComponent getComponent(String path) {
return components.get(path);
}
public void forEachComponent(Consumer<StatComponent> action) {
for (StatComponent component : components.values())
action.accept(component);
}
public Set<String> getComponentKeys() {
return components.keySet();
}
/*
@Nullable
public StatComponent findComponent(String path) {
String[] split = path.split("\\.");
ObjectComponent current = this;
int n = split.length - 1;
for (int i = 0; i < n; i++) {
StatComponent next = getComponent(split[i]);
if (next == null || !(next instanceof ObjectComponent))
return null;
current = (ObjectComponent) next;
}
return current.getComponent(split[n]);
}
*/
}

View File

@ -1,5 +1,30 @@
package net.Indyuce.mmoitems.stat.component;
import net.Indyuce.mmoitems.stat.component.builtin.ObjectComponent;
import org.apache.commons.lang.Validate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class StatComponent {
@Nullable
public StatComponent get(@NotNull String key) {
throw new RuntimeException("No subcomponent for " + getClass().getSimpleName());
}
@Nullable
@Deprecated
public StatComponent findComponent(String path) {
String[] split = path.split("\\.");
ObjectComponent current = (ObjectComponent) this;
int n = split.length - 1;
for (int i = 0; i < n; i++) {
StatComponent next = current.get(split[i]);
Validate.notNull(next, "Could not find component " + path);
current = (ObjectComponent) next;
}
return current.get(split[n]);
}
}

View File

@ -0,0 +1,61 @@
package net.Indyuce.mmoitems.stat.component.builtin;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.skill.RegisteredSkill;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import net.Indyuce.mmoitems.stat.component.model.Model;
import net.Indyuce.mmoitems.stat.component.type.ComponentType;
import org.apache.commons.lang.NotImplementedException;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
public class AbilityComponent extends StatComponent implements Model<AbilityComponent> {
private RegisteredSkill ability;
@NotNull
public RegisteredSkill getValue() {
return ability;
}
@NotNull
public static Type.Builder type() {
return new Type().new Builder();
}
@Override
public AbilityComponent randomizeComponent(MMOItemBuilder builder) {
return this;
}
public static class Type extends ComponentType<AbilityComponent, AbilityComponent> {
@NotNull
@Override
public List<String> editionUiFormat(AbilityComponent data) {
return Collections.singletonList(data.getValue().getName());
/*
List<String> format = new ArrayList<>(1 + data.getComponentKeys().size());
format.add("Ability: " + data.getAbility().getName());
data.forEachModifier((key, comp) -> format.add(key + ": " + comp.getValue()));
return format;
*/
}
@Override
public AbilityComponent initialize(@NotNull Object object) {
throw new NotImplementedException();
}
public class Builder extends ComponentType<AbilityComponent, AbilityComponent>.Builder {
public Builder() {
setActionLoreTagHint("ability");
}
public Type build() {
return (Type) super.build();
}
}
}
}

View File

@ -0,0 +1,28 @@
package net.Indyuce.mmoitems.stat.component.builtin;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
public class ArrayComponent<C extends StatComponent> extends StatComponent {
private final List<C> components = new ArrayList<>();
@Nullable
public C getComponent(int index) {
return components.get(index);
}
public void forEachComponent(Consumer<C> action) {
for (C component : components)
action.accept(component);
}
@NotNull
public List<C> getComponents() {
return components;
}
}

View File

@ -0,0 +1,37 @@
package net.Indyuce.mmoitems.stat.component.builtin;
import net.Indyuce.mmoitems.stat.component.Mergeable;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import net.Indyuce.mmoitems.stat.component.type.builtin.BooleanComponentType;
public class BooleanComponent extends StatComponent implements Mergeable<BooleanComponentType, BooleanComponent> {
private boolean value;
public BooleanComponent(boolean value) {
this.value = value;
}
public boolean getValue() {
return value;
}
public void setValue(boolean value) {
this.value = value;
}
@Override
public void merge(BooleanComponentType componentType, BooleanComponent component) {
switch (componentType.mergeMecanism) {
case OR:
value |= component.value;
break;
case AND:
value &= component.value;
break;
case XOR:
value ^= component.value;
break;
}
}
}

View File

@ -0,0 +1,28 @@
package net.Indyuce.mmoitems.stat.component.builtin;
import net.Indyuce.mmoitems.stat.component.Mergeable;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import net.Indyuce.mmoitems.stat.component.type.builtin.DoubleComponentType;
public class DoubleComponent extends StatComponent implements Mergeable<DoubleComponentType, DoubleComponent> {
private double value;
public DoubleComponent(double value) {
this.value = value;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
@Override
public void merge(DoubleComponentType componentType, DoubleComponent component) {
value += component.value;
// TODO merge mecanisms
}
}

View File

@ -0,0 +1,33 @@
package net.Indyuce.mmoitems.stat.component.builtin;
import net.Indyuce.mmoitems.stat.component.Mergeable;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import net.Indyuce.mmoitems.stat.component.type.builtin.IntegerComponentType;
public class IntegerComponent extends StatComponent implements Mergeable<IntegerComponentType, IntegerComponent> {
private int value;
public IntegerComponent(int value) {
this.value = value;
}
public int getValue() {
return value;
}
@Override
public void merge(IntegerComponentType componentType, IntegerComponent component) {
switch (componentType.mergeMecanism) {
case SUM:
value += component.value;
break;
case HIGHEST:
value = Math.max(value, component.value);
break;
case LOWEST:
value = Math.min(value, component.value);
break;
}
}
}

View File

@ -0,0 +1,225 @@
package net.Indyuce.mmoitems.stat.component.builtin;
import io.lumine.mythic.lib.util.annotation.NotUsed;
import net.Indyuce.mmoitems.skill.RegisteredSkill;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
@NotUsed
@Deprecated
public class ItemAbilityComponent extends ObjectComponent {
private AbilityComponent ability;
private Map<String, DoubleComponent> modifiers;
/*
public NewAbilityData(@NotNull JsonObject object) {
super(MMOUtils.backwardsCompatibleTriggerType(object.get("CastMode").getAsString()));
ability = MMOItems.plugin.getSkills().getSkill(object.get("Id").getAsString());
JsonObject modifiers = object.getAsJsonObject("Modifiers");
modifiers.entrySet().forEach(entry -> setModifier(entry.getKey(), entry.getValue().getAsDouble()));
}
public NewAbilityData(@NotNull ConfigurationSection config) {
super(MMOUtils.backwardsCompatibleTriggerType(UtilityMethods.enumName(Objects.requireNonNull(config.getString("mode"), "Ability is missing mode"))));
Validate.isTrue(config.contains("type"), "Ability is missing type");
String abilityFormat = UtilityMethods.enumName(config.getString("type"));
Validate.isTrue(MMOItems.plugin.getSkills().hasSkill(abilityFormat), "Could not find ability called '" + abilityFormat + "'");
ability = MMOItems.plugin.getSkills().getSkill(abilityFormat);
for (String key : config.getKeys(false))
if (!key.equalsIgnoreCase("mode") && !key.equalsIgnoreCase("type") && ability.getHandler().getModifiers().contains(key))
modifiers.put(key, config.getDouble(key));
}
public NewAbilityData(RegisteredSkill ability, TriggerType triggerType) {
super(triggerType);
this.ability = ability;
}
*/
@NotNull
public RegisteredSkill getAbility() {
return ability.getValue();
}
@NotNull
public Set<String> getModifiers() {
return modifiers.keySet();
}
public void forEachModifier(BiConsumer<String, DoubleComponent> action) {
modifiers.forEach(action);
}
public void setModifier(String modifier, double value) {
modifiers.put(modifier, new DoubleComponent(value));
}
public boolean hasModifier(String modifier) {
return modifiers.containsKey(modifier);
}
@Override
public void set(@NotNull String key, @NotNull StatComponent component) {
}
@Nullable
@Override
public StatComponent get(@NotNull String key) {
return null;
}
@Override
public void forEachComponent(@NotNull BiConsumer<String, StatComponent> action) {
}
@NotNull
@Override
public Collection<String> getComponentKeys() {
return Arrays.asList("ability", "modifiers");
}
/*
@Override
public boolean getResult(SkillMetadata meta) {
PlayerData playerData = PlayerData.get(meta.getCaster().getPlayer());
RPGPlayer rpgPlayer = playerData.getRPG();
Player player = meta.getCaster().getPlayer();
// Check for cooldown
if (meta.getCaster().getData().getCooldownMap().isOnCooldown(this)) {
CooldownInfo info = playerData.getMMOPlayerData().getCooldownMap().getInfo(this);
if (!getTrigger().isSilent()) {
StringBuilder progressBar = new StringBuilder(ChatColor.YELLOW + "");
double progress = (double) (info.getInitialCooldown() - info.getRemaining()) / info.getInitialCooldown() * 10;
String barChar = MMOItems.plugin.getConfig().getString("cooldown-progress-bar-char");
for (int j = 0; j < 10; j++)
progressBar.append(progress >= j ? ChatColor.GREEN : ChatColor.WHITE).append(barChar);
Message.SPELL_ON_COOLDOWN.format(ChatColor.RED, "#left#", MythicLib.plugin.getMMOConfig().decimal.format(info.getRemaining() / 1000d), "#progress#", progressBar.toString(), "#s#", (info.getRemaining() > 1999 ? "s" : "")).send(player);
}
return false;
}
// Check for permission
if (MMOItems.plugin.getConfig().getBoolean("permissions.abilities") && !player.hasPermission("mmoitems.ability." + getHandler().getLowerCaseId()) && !player.hasPermission("mmoitems.bypass.ability"))
return false;
// Check for mana cost
if (hasModifier("mana") && rpgPlayer.getMana() < meta.getParameter("mana")) {
Message.NOT_ENOUGH_MANA.format(ChatColor.RED).send(player);
return false;
}
// Check for stamina cost
if (hasModifier("stamina") && rpgPlayer.getStamina() < meta.getParameter("stamina")) {
Message.NOT_ENOUGH_STAMINA.format(ChatColor.RED).send(player);
return false;
}
return true;
}
@Override
public void whenCast(SkillMetadata meta) {
PlayerData playerData = PlayerData.get(meta.getCaster().getPlayer());
RPGPlayer rpgPlayer = playerData.getRPG();
// Apply mana cost
if (hasModifier("mana")) rpgPlayer.giveMana(-meta.getParameter("mana"));
// Apply stamina cost
if (hasModifier("stamina")) rpgPlayer.giveStamina(-meta.getParameter("stamina"));
// Apply cooldown
double cooldown = meta.getParameter("cooldown") * (1 - Math.min(.8, meta.getCaster().getStat("COOLDOWN_REDUCTION") / 100));
if (cooldown > 0) meta.getCaster().getData().getCooldownMap().applyCooldown(this, cooldown);
}
@Override
public SkillHandler getHandler() {
return ability.getHandler();
}
@Override
public double getParameter(String path) {
return modifiers.getOrDefault(path, ability.getDefaultModifier(path));
}
public JsonObject toJson() {
JsonObject object = new JsonObject();
object.addProperty("Id", ability.getHandler().getId());
object.addProperty("CastMode", getTrigger().name());
JsonObject modifiers = new JsonObject();
this.modifiers.keySet().forEach(modifier -> modifiers.addProperty(modifier, getParameter(modifier)));
object.add("Modifiers", modifiers);
return object;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AbilityDataImpl that = (AbilityDataImpl) o;
return ability.equals(that.ability) && getTrigger().equals(that.getTrigger()) && modifiers.equals(that.modifiers);
}
@Override
public String toString() {
return "AbilityData{" +
"ability=" + ability +
", modifiers=" + modifiers +
'}';
}
@Override
public int hashCode() {
return Objects.hash(ability, modifiers);
}
@NotNull
public static Type.Builder type() {
return new Type().new Builder();
}
public static class Type extends ComponentType<ItemAbilityComponent> {
@NotNull
@Override
public List<String> editionUiFormat(ItemAbilityComponent data) {
List<String> format = new ArrayList<>(1 + data.getComponentKeys().size());
format.add("Ability: " + data.getAbility().getName());
data.forEachModifier((key, comp) -> format.add(key + ": " + comp.getValue()));
return format;
}
public class Builder extends ComponentType<ItemAbilityComponent>.Builder {
public Builder() {
setActionLoreTagHint("ability");
}
public Type build() {
return (Type) super.build();
}
}
}*/
}

View File

@ -0,0 +1,68 @@
package net.Indyuce.mmoitems.stat.component.builtin;
import io.lumine.mythic.lib.UtilityMethods;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import net.Indyuce.mmoitems.stat.component.model.Model;
import net.Indyuce.mmoitems.stat.component.type.ComponentType;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
public class MaterialComponent extends StatComponent implements Model<MaterialComponent> {
private Material mat;
public MaterialComponent(@Nullable Material mat) {
this.mat = mat;
}
public Material getMaterial() {
return mat;
}
@Override
public MaterialComponent randomizeComponent(MMOItemBuilder builder) {
return this;
}
/*
@Override
public void merge(MaterialComponent component) {
value += component.value;
}
*/
public static class Type extends ComponentType<MaterialComponent, MaterialComponent> {
@NotNull
@Override
public List<String> editionUiFormat(MaterialComponent data) {
return Collections.singletonList(data.getMaterial().name());
}
@Override
public MaterialComponent initialize(@NotNull Object object) {
return new MaterialComponent(Material.valueOf(UtilityMethods.enumName(object.toString())));
}
@NotNull
public static Builder init() {
return new Type().new Builder();
}
public class Builder extends ComponentType<MaterialComponent, MaterialComponent>.Builder {
public Builder() {
setActionLoreTags("Left click to edit this material.", "Right click to remove this option.");
setTerminal(true);
}
public Type build() {
return (Type) super.build();
}
}
}
}

View File

@ -0,0 +1,38 @@
package net.Indyuce.mmoitems.stat.component.builtin;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import net.Indyuce.mmoitems.stat.component.model.Model;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.function.BiConsumer;
/**
* Allows both implementations of abstract objects for user-end
* fully customizable stat components, and builtin hard-coded
* implementations of components like abilities, elements for
* performance.
* <p>
* Components for built-in stats like abilities or elements
* have specific implementations for performance to avoid the
* abstraction overhead.
*/
public abstract class ObjectComponent extends StatComponent implements Model<ObjectComponent> {
public abstract void set(@NotNull String key, @NotNull StatComponent component);
@Nullable
public abstract StatComponent get(@NotNull String key);
public abstract void forEachComponent(@NotNull BiConsumer<String, StatComponent> action);
@NotNull
public abstract Collection<String> getComponentKeys();
@Override
public ObjectComponent randomizeComponent(MMOItemBuilder builder) {
return this;
}
}

View File

@ -0,0 +1,36 @@
package net.Indyuce.mmoitems.stat.component.builtin;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
public class ObjectComponentImpl extends ObjectComponent {
private final Map<String, StatComponent> components = new HashMap<>();
@Override
public void set(@NotNull String key, @NotNull StatComponent component) {
components.put(key, component);
}
@Nullable
@Override
public StatComponent get(@NotNull String key) {
return components.get(key);
}
@Override
public void forEachComponent(@NotNull BiConsumer<String, StatComponent> action) {
components.forEach(action);
}
@NotNull
@Override
public Set<String> getComponentKeys() {
return components.keySet();
}
}

View File

@ -0,0 +1,32 @@
package net.Indyuce.mmoitems.stat.component.builtin;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import net.Indyuce.mmoitems.stat.component.model.Model;
import org.jetbrains.annotations.Nullable;
public class StringComponent extends StatComponent implements Model<StringComponent> {
private String value;
public StringComponent(@Nullable String value) {
this.value = value;
}
public String getValue() {
return value;
}
@Override
public StringComponent randomizeComponent(MMOItemBuilder builder) {
return this;
}
/*
@Override
public void merge(StringComponent component) {
// By default, mere replacement, but can depend on options configured in the config section!!
value = component.value;
}
*/
}

View File

@ -0,0 +1,23 @@
package net.Indyuce.mmoitems.stat.component.model;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.stat.annotation.TerminalComponentException;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface Model<C extends StatComponent> {
/**
* @param builder The builder of the random item being generated
* @return A random stat data instance which will then be merged onto the
* base item template
*/
C randomizeComponent(MMOItemBuilder builder);
// TODO change name
@Nullable
default Model<?> getModel(@NotNull String key) {
throw new TerminalComponentException();
}
}

View File

@ -0,0 +1,24 @@
package net.Indyuce.mmoitems.stat.component.model.builtin;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import net.Indyuce.mmoitems.stat.component.builtin.ArrayComponent;
import net.Indyuce.mmoitems.stat.component.model.Model;
import org.apache.commons.lang.NotImplementedException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
// TODO merge with component?
public class ArrayModel<C extends StatComponent> implements Model<ArrayComponent<C>> {
@Override
public ArrayComponent<C> randomizeComponent(MMOItemBuilder builder) {
throw new NotImplementedException();
}
@Nullable
@Override
public Model<?> getModel(@NotNull String key) {
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,49 @@
package net.Indyuce.mmoitems.stat.component.model.builtin;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.stat.component.builtin.BooleanComponent;
import net.Indyuce.mmoitems.stat.component.model.Model;
import org.apache.commons.lang.Validate;
import java.util.Random;
public class BooleanModel implements Model<BooleanComponent> {
private final double chance;
private final Boolean value;
// TODO add string expression
private static final Random RANDOM = new Random();
public BooleanModel(Object object) {
// Boolean value
if (object instanceof Boolean) {
this.value = (boolean) object;
this.chance = 0;
}
// Flat nb
else if (object instanceof Number) {
this.value = null;
this.chance = Double.parseDouble(object.toString());
Validate.isTrue(chance >= 0 && chance <= 1, "Chance must be between 0 and 1");
}
throw new IllegalArgumentException("Must be a number or boolean value");
}
public double getChance() {
return chance;
}
public Boolean getValue() {
return value;
}
@Override
public BooleanComponent randomizeComponent(MMOItemBuilder builder) {
boolean value = this.value != null ? this.value : chance < RANDOM.nextDouble();
return new BooleanComponent(value);
}
}

View File

@ -0,0 +1,27 @@
package net.Indyuce.mmoitems.stat.component.model.builtin;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.stat.annotation.TerminalComponentException;
import net.Indyuce.mmoitems.stat.component.builtin.DoubleComponent;
import net.Indyuce.mmoitems.stat.component.model.Model;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class DoubleModel implements Model<DoubleComponent> {
private final NumericStatFormula formula;
// TODO add string expression
public DoubleModel(NumericStatFormula formula) {
this.formula = formula;
}
public NumericStatFormula getFormula() {
return formula;
}
@Override
public DoubleComponent randomizeComponent(MMOItemBuilder builder) {
return new DoubleComponent(formula.calculate(builder.getLevel()));
}
}

View File

@ -0,0 +1,25 @@
package net.Indyuce.mmoitems.stat.component.model.builtin;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.api.util.NumericStatFormula;
import net.Indyuce.mmoitems.stat.component.builtin.IntegerComponent;
import net.Indyuce.mmoitems.stat.component.model.Model;
public class IntegerModel implements Model<IntegerComponent> {
private final NumericStatFormula formula;
public IntegerModel(NumericStatFormula formula) {
this.formula = formula;
}
public NumericStatFormula getFormula() {
return formula;
}
@Override
public IntegerComponent randomizeComponent(MMOItemBuilder builder) {
// TODO add rule for round/ceil/floor?
// TODO make this function require a componentType as argument. cannot save it inside of models/components!
return new IntegerComponent((int) Math.round(formula.calculate(builder.getLevel())));
}
}

View File

@ -0,0 +1,36 @@
package net.Indyuce.mmoitems.stat.component.model.builtin;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.stat.component.builtin.ObjectComponent;
import net.Indyuce.mmoitems.stat.component.builtin.ObjectComponentImpl;
import net.Indyuce.mmoitems.stat.component.model.Model;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
// TODO merge with component?
public class ObjectModel implements Model<ObjectComponent> {
private final Map<String, Model<?>> components = new HashMap<>();
public Map<String, Model<?>> getComponents() {
return components;
}
@Override
public ObjectComponent randomizeComponent(MMOItemBuilder builder) {
ObjectComponentImpl comp = new ObjectComponentImpl();
for (Map.Entry<String, Model<?>> entry : this.components.entrySet())
comp.set(entry.getKey(), entry.getValue().randomizeComponent(builder));
return comp;
}
@Nullable
@Override
public Model<?> getModel(@NotNull String key) {
return components.get(key);
}
}

View File

@ -1,4 +1,197 @@
package net.Indyuce.mmoitems.stat.component.type;
public class ComponentType {
import net.Indyuce.mmoitems.stat.component.LoreWrapper;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import net.Indyuce.mmoitems.stat.component.model.Model;
import net.Indyuce.mmoitems.util.MMOUtils;
import net.Indyuce.mmoitems.util.Pair;
import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
public abstract class ComponentType<M extends Model<C>, C extends StatComponent> {
/**
* A terminal component type is the type for a component
* which holds a terminal value like a string, integer,
* double, boolean, or even custom object types like abilities,
* ...
* <p>
* Such terminal components can be directly edited by the player
* by clicking on that component in the editor UI. No further sub-UI
* can be opened to access its subcomponents.
*/
private boolean terminal;
private Function<M, ItemStack> icon;
private Function<M, String> name;
private Function<M, List<String>> description;
private List<String> actionLoreTags = Arrays.asList("Left click to change this value.", "Right click to reset this value.");
public boolean isTerminal() {
return terminal;
}
@NotNull
public ItemStack provideIcon(@Nullable M model) {
return icon.apply(model);
}
public String provideName(@Nullable M model) {
return name.apply(model);
}
@Nullable
public List<String> provideDescription(@Nullable M model) {
return description == null ? null : description.apply(model);
}
public List<String> getActionLoreTags() {
return actionLoreTags;
}
/*
public void flatten(@NotNull List<Pair<ComponentType<?>, StatComponent>> list, @Nullable S statComponent) {
Validate.isTrue(terminal, "Basic impl for terminal components");
list.add(Pair.of(this, statComponent));
}
*/
/**
* @deprecated TODO adapt to arrays
*/
@NotNull
@Deprecated
public List<Pair<String, ComponentType<?, ?>>> getSubcomponents() {
throw new NotImplementedException();
}
public static final String NO_VALUE = ChatColor.RED + "---";
public static final String CURRENT_VALUE = "Current Value: ";
public void editionUiDisplay(LoreWrapper lore, @Nullable M model) {
// Display nothing
if (model == null) {
lore.addLine(CURRENT_VALUE + NO_VALUE);
return;
}
// Error handling
List<String> disp;
try {
disp = editionUiFormat(model);
} catch (Exception exception) {
lore.addLine(CURRENT_VALUE + NO_VALUE);
// TODO improve error handling lore.addLine(ChatColor.RED + "Error: " + exception.getMessage());
return;
}
// Display it
if (disp.size() == 1) lore.addLine("Current Value: " + ChatColor.GREEN + disp.getFirst());
else {
lore.addLine("Current Value:");
lore.addLines(disp);
}
}
// TODO remove overhead of using intermediate List<String>
@NotNull
public abstract List<String> editionUiFormat(M model);
public abstract M initialize(@NotNull Object object);
public class Builder {
public Builder setTerminal(boolean terminal) {
ComponentType.this.terminal = terminal;
return this;
}
public Builder setIcon(@NotNull Material material) {
return setIcon(ignored -> new ItemStack(material));
}
public Builder setIcon(@NotNull ItemStack icon) {
return setIcon(ignored -> icon);
}
public Builder setIcon(@NotNull Function<M, ItemStack> material) {
ComponentType.this.icon = material;
return this;
}
public Builder setActionLoreTags(@NotNull String... tags) {
ComponentType.this.actionLoreTags = Arrays.asList(tags);
return this;
}
public Builder setActionLoreTagHint(@NotNull String hint) {
return setActionLoreTags("Left click to edit this " + hint + ".", "Right click to remove this " + hint + ".");
}
public Builder setName(@NotNull String name) {
return setName(ignored -> name);
}
public Builder setName(@NotNull Function<M, String> name) {
ComponentType.this.name = name;
return this;
}
public Builder setLore(@NotNull String... lore) {
return setLore(Arrays.asList(lore));
}
public Builder setLore(@NotNull List<String> lore) {
return setLore(ignored -> lore);
}
public Builder setLore(@NotNull Function<M, List<String>> lore) {
ComponentType.this.description = lore;
return this;
}
public Builder fromConfig(@NotNull ConfigurationSection config) {
setName(config.getString("name", "{no_stat_name}"));
Object lore = config.get("lore");
if (lore == null) setLore(Collections.singletonList("{no_stat_description}"));
else if (lore instanceof String) trimLore(lore.toString());
else if (lore instanceof List) setLore((List<String>) lore);
setIcon(MMOUtils.readIcon(config.getString("icon")));
// TODO
return this;
}
public Builder trimLore(@NotNull String lore) {
return setLore(MMOUtils.trimString(40, lore));
}
/**
* Should return an exception if one of the fields is not correct
*
* @return Built component type
*/
public ComponentType<M, C> build() {
// TODO infer data instead of throwing an error
Validate.notNull(icon, "Icon cannot be null");
Validate.notNull(name, "Name cannot be null");
//Validate.notNull(description, "Lore cannot be null");
//Validate.notNull(actionLoreTags, "Action lore tags cannot be null");
return ComponentType.this;
}
}
}

View File

@ -1,11 +0,0 @@
package net.Indyuce.mmoitems.stat.component.type;
public class DoubleComponentType extends ComponentType {
/**
* Are higher values of this component better or worse? Debuff stats
* should set this to false, otherwise should be true by default for
* most stats.
*/
boolean moreIsBetter = true;
}

View File

@ -1,16 +0,0 @@
package net.Indyuce.mmoitems.stat.component.type;
public class IntegerComponentType {
/**
* Are higher values of this component better or worse? Debuff stats
* should set this to false, otherwise should be true by default for
* most stats.
*/
boolean moreIsBetter = true;
/**
* Should components be displayed using roman integer format.
*/
boolean useRoman;
}

Some files were not shown because too many files have changed in this diff Show More