mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-24 09:51:21 +01:00
Extra display options for abilities in lore
This commit is contained in:
parent
4a38952310
commit
c4ded8355c
@ -79,18 +79,16 @@ public class ConfigFile {
|
||||
|
||||
public void registerTemplateEdition(ItemReference ref) {
|
||||
|
||||
/*
|
||||
* saves the changes before asking for a template update
|
||||
*/
|
||||
// Saves the changes before asking for a template update
|
||||
save();
|
||||
|
||||
/*
|
||||
* goes for a template update once the change has been saved. this
|
||||
* Goes for a template update once the change has been saved. this
|
||||
* simply unloads the currently saved template and reloads it
|
||||
*/
|
||||
MMOItems.plugin.getTemplates().requestTemplateUpdate(ref.getType(), ref.getId());
|
||||
|
||||
/* update the database UUID for the dynamic item updater
|
||||
/* Update the database UUID for the dynamic item updater
|
||||
if (MMOItems.plugin.getUpdater().hasData(ref))
|
||||
MMOItems.plugin.getUpdater().getData(ref).setUniqueId(UUID.randomUUID());*/
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public class Consumable extends UseItem {
|
||||
/**
|
||||
* This dynamically updates the item lore
|
||||
*/
|
||||
final String format = MythicLib.inst().parseColors(MMOItems.plugin.getLanguage().getStatFormat("max-consume"));
|
||||
final String format = MythicLib.inst().parseColors(ItemStats.MAX_CONSUME.getGeneralStatFormat());
|
||||
final String old = format.replace("{value}", String.valueOf(usesLeft + 1));
|
||||
final String replaced = format.replace("{value}", String.valueOf(usesLeft));
|
||||
ItemStack newItem = new LoreUpdate(nbtItem.toItem(), old, replaced).updateLore();
|
||||
|
@ -243,7 +243,7 @@ public class DurabilityItem {
|
||||
ItemStack item = nbtItem.toItem();
|
||||
|
||||
// Item lore update
|
||||
final String format = MythicLib.inst().parseColors(MMOItems.plugin.getLanguage().getStatFormat("durability").replace("{max}", String.valueOf(maxDurability)));
|
||||
final String format = MythicLib.inst().parseColors(ItemStats.ITEM_DAMAGE.getGeneralStatFormat().replace("{max}", String.valueOf(maxDurability)));
|
||||
final String old = format.replace("{current}", String.valueOf(initialDurability));
|
||||
final String replaced = format.replace("{current}", String.valueOf(durability));
|
||||
return new LoreUpdate(item, old, replaced).updateLore();
|
||||
|
@ -11,6 +11,7 @@ import net.Indyuce.mmoitems.api.event.GenerateLoreEvent;
|
||||
import net.Indyuce.mmoitems.api.event.ItemBuildEvent;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
|
||||
import net.Indyuce.mmoitems.api.util.message.Message;
|
||||
import net.Indyuce.mmoitems.stat.data.MaterialData;
|
||||
import net.Indyuce.mmoitems.stat.data.StringListData;
|
||||
import net.Indyuce.mmoitems.stat.type.ItemStat;
|
||||
@ -203,10 +204,10 @@ public class ItemStackBuilder {
|
||||
|
||||
// Display gem stone lore hint thing
|
||||
if (builtMMOItem.getType() == Type.GEM_STONE)
|
||||
lore.insert("gem-stone-lore", ItemStat.translate("gem-stone-lore"));
|
||||
lore.insert("gem-stone-lore", Message.GEM_STONE_TAG.getUpdated());
|
||||
|
||||
// Display item type
|
||||
lore.insert("item-type", ItemStat.translate("item-type").replace("{type}",
|
||||
lore.insert("item-type", Message.ITEM_TYPE_TAG.getUpdated().replace("{type}",
|
||||
builtMMOItem.getStats().contains(ItemStats.DISPLAYED_TYPE) ? builtMMOItem.getData(ItemStats.DISPLAYED_TYPE)
|
||||
.toString() : builtMMOItem.getType().getName()));
|
||||
|
||||
|
@ -16,6 +16,10 @@ public enum Message {
|
||||
ITEM_ON_COOLDOWN("This item is on cooldown! Please wait #left# second#s#.", "item-cooldown"),
|
||||
NOT_ENOUGH_PERMS_COMMAND("You don't have enough permissions."),
|
||||
|
||||
// Item lore tags
|
||||
GEM_STONE_TAG("&8&l[&2&l*&8&l] &aDrag onto an item &7to apply!"),
|
||||
ITEM_TYPE_TAG("&c{type}"),
|
||||
|
||||
// Item restrictions
|
||||
NOT_ENOUGH_LEVELS("You don't have enough levels to use this item!", "cant-use-item"),
|
||||
SOULBOUND_RESTRICTION("This item is linked to another player, you can't use it!", "cant-use-item"),
|
||||
|
@ -35,7 +35,7 @@ import java.util.logging.Level;
|
||||
public class ConfigManager implements Reloadable {
|
||||
|
||||
// cached config files
|
||||
private ConfigFile loreFormat, stats, dynLore;
|
||||
private ConfigFile loreFormat, dynLore;
|
||||
|
||||
// Language
|
||||
private final Map<TriggerType, String> triggerTypeNames = new HashMap<>();
|
||||
@ -43,7 +43,6 @@ public class ConfigManager implements Reloadable {
|
||||
|
||||
// Cached config options
|
||||
public boolean replaceMushroomDrops, worldGenEnabled, upgradeRequirementsCheck, keepSoulboundOnDeath, rerollOnItemUpdate, opStatsEnabled, disableRemovedItems;
|
||||
public String abilitySplitter;
|
||||
public double soulboundBaseDamage, soulboundPerLvlDamage, levelSpread;
|
||||
public NumericStatFormula defaultItemCapacity;
|
||||
public ReforgeOptions revisionOptions, gemRevisionOptions, phatLootsOptions;
|
||||
@ -124,6 +123,11 @@ public class ConfigManager implements Reloadable {
|
||||
}
|
||||
messages.save();
|
||||
|
||||
// LEGACY CODE
|
||||
final ConfigurationSection statsConfig = new ConfigFile("stats").getConfig();
|
||||
if (statsConfig.contains("gem-stone-lore")) Message.GEM_STONE_TAG.setCurrent(statsConfig.getString("gem-stone-lore"));
|
||||
if (statsConfig.contains("item-type")) Message.ITEM_TYPE_TAG.setCurrent(statsConfig.getString("item-type"));
|
||||
|
||||
// Potion effects
|
||||
final LanguageFile potionEffects = new LanguageFile("potion-effects");
|
||||
for (PotionEffectType effect : PotionEffectType.values())
|
||||
@ -154,7 +158,7 @@ public class ConfigManager implements Reloadable {
|
||||
MMOItems.plugin.reloadConfig();
|
||||
|
||||
loreFormat = new ConfigFile("/language", "lore-format");
|
||||
stats = new ConfigFile("/language", "stats");
|
||||
|
||||
dynLore = new ConfigFile("/language", "dynamic-lore");
|
||||
|
||||
loadTranslations();
|
||||
@ -166,7 +170,6 @@ public class ConfigManager implements Reloadable {
|
||||
replaceMushroomDrops = MMOItems.plugin.getConfig().getBoolean("custom-blocks.replace-mushroom-drops");
|
||||
worldGenEnabled = MMOItems.plugin.getConfig().getBoolean("custom-blocks.enable-world-gen");
|
||||
|
||||
abilitySplitter = getStatFormat("ability-splitter");
|
||||
soulboundBaseDamage = MMOItems.plugin.getConfig().getDouble("soulbound.damage.base");
|
||||
soulboundPerLvlDamage = MMOItems.plugin.getConfig().getDouble("soulbound.damage.per-lvl");
|
||||
upgradeRequirementsCheck = MMOItems.plugin.getConfig().getBoolean("item-upgrade-requirements-check");
|
||||
@ -209,15 +212,20 @@ public class ConfigManager implements Reloadable {
|
||||
|
||||
/**
|
||||
* @return Can this block material be broken by tool mechanics
|
||||
* like 'Bouncing Crack'
|
||||
* like 'Bouncing Crack'
|
||||
*/
|
||||
public boolean isBlacklisted(Material material) {
|
||||
public boolean isBlacklisted(@NotNull Material material) {
|
||||
return MMOItems.plugin.getConfig().getStringList("block-blacklist").contains(material.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Will be removed in the future.
|
||||
*/
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public String getStatFormat(String path) {
|
||||
String found = stats.getConfig().getString(path);
|
||||
final ConfigurationSection config = new ConfigFile("/language", "stats").getConfig();
|
||||
final String found = config.getString(path);
|
||||
return found == null ? "<TranslationNotFound:" + path + ">" : found;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,6 @@ public class PluginUpdateManager {
|
||||
*/
|
||||
private final Map<Integer, PluginUpdate> updates = new HashMap<>();
|
||||
|
||||
|
||||
public PluginUpdateManager() {
|
||||
register(new PluginUpdate(1,
|
||||
new String[]{"Applies a fix for skull textures values in 4.7.1.", "Texture values data storage changed in 4.7.1 due to the UUID change."},
|
||||
|
@ -65,6 +65,17 @@ public class StatManager {
|
||||
|
||||
// Register custom stats
|
||||
loadCustom();
|
||||
|
||||
// Load stat translation objects
|
||||
final ConfigurationSection statOptions = new ConfigFile("/language", "stats").getConfig();
|
||||
for (ItemStat stat : getAll())
|
||||
try {
|
||||
@Nullable Object object = statOptions.get(stat.getPath());
|
||||
if (object == null) object = statOptions.get(stat.getLegacyTranslationPath());
|
||||
stat.loadConfiguration(statOptions, object != null ? object : "<TranslationNotFound:" + stat.getPath() + ">");
|
||||
} catch (RuntimeException exception) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load options for stat '" + stat.getId() + "': " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,9 +111,9 @@ public class StatManager {
|
||||
|
||||
/**
|
||||
* @return Collection of all numeric stats like atk damage, crit strike
|
||||
* chance, max mana... which can be applied on a gem stone. This is
|
||||
* used when applying gem stones to quickly access all the stats
|
||||
* which needs to be applied
|
||||
* chance, max mana... which can be applied on a gem stone. This is
|
||||
* used when applying gem stones to quickly access all the stats
|
||||
* which needs to be applied
|
||||
*/
|
||||
@NotNull
|
||||
public List<DoubleStat> getNumericStats() {
|
||||
@ -111,7 +122,7 @@ public class StatManager {
|
||||
|
||||
/**
|
||||
* @return Collection of all stats which constitute an item restriction:
|
||||
* required level, required class, soulbound..
|
||||
* required level, required class, soulbound..
|
||||
*/
|
||||
@NotNull
|
||||
public List<ItemRestriction> getItemRestrictionStats() {
|
||||
@ -120,7 +131,7 @@ public class StatManager {
|
||||
|
||||
/**
|
||||
* @return Collection of all stats implementing a consumable action like
|
||||
* deconstructing, identifying...
|
||||
* deconstructing, identifying...
|
||||
*/
|
||||
@NotNull
|
||||
public List<ConsumableItemInteraction> getConsumableActions() {
|
||||
@ -129,7 +140,7 @@ public class StatManager {
|
||||
|
||||
/**
|
||||
* @return Collection of all stats implementing self consumable like
|
||||
* restore health, mana, hunger...
|
||||
* restore health, mana, hunger...
|
||||
*/
|
||||
@NotNull
|
||||
public List<PlayerConsumable> getPlayerConsumables() {
|
||||
@ -151,7 +162,7 @@ public class StatManager {
|
||||
|
||||
/**
|
||||
* @deprecated Stat IDs are now stored in the stat instance directly.
|
||||
* Please use StatManager#register(ItemStat) instead
|
||||
* Please use StatManager#register(ItemStat) instead
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -33,189 +33,260 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
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" });
|
||||
}
|
||||
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"});
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomAbilityListData whenInitialized(Object object) {
|
||||
Validate.isTrue(object instanceof ConfigurationSection, "Must specify a valid config section");
|
||||
ConfigurationSection config = (ConfigurationSection) object;
|
||||
RandomAbilityListData list = new RandomAbilityListData();
|
||||
@Override
|
||||
public RandomAbilityListData whenInitialized(Object object) {
|
||||
Validate.isTrue(object instanceof ConfigurationSection, "Must specify a valid config section");
|
||||
ConfigurationSection config = (ConfigurationSection) object;
|
||||
RandomAbilityListData list = new RandomAbilityListData();
|
||||
|
||||
for (String key : config.getKeys(false))
|
||||
list.add(new RandomAbilityData(config.getConfigurationSection(key)));
|
||||
for (String key : config.getKeys(false))
|
||||
list.add(new RandomAbilityData(config.getConfigurationSection(key)));
|
||||
|
||||
return list;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull AbilityListData data) {
|
||||
private String generalFormat, modifierForEach, modifierSplitter, abilitySplitter;
|
||||
private boolean legacyFormat, useAbilitySplitter;
|
||||
private int modifiersPerLine;
|
||||
|
||||
//Modify Lore
|
||||
List<String> abilityLore = new ArrayList<>();
|
||||
boolean splitter = !MMOItems.plugin.getLanguage().abilitySplitter.equals("");
|
||||
@Deprecated
|
||||
@Override
|
||||
public void loadConfiguration(@NotNull ConfigurationSection legacyLanguageFile, @NotNull Object configObject) {
|
||||
|
||||
String modifierFormat = ItemStat.translate("ability-modifier"), abilityFormat = ItemStat.translate("ability-format");
|
||||
// MI <7 config
|
||||
if (configObject instanceof ConfigurationSection) {
|
||||
legacyFormat = false;
|
||||
final ConfigurationSection config = (ConfigurationSection) configObject;
|
||||
generalFormat = config.getString("general-format");
|
||||
modifierForEach = config.getString("modifier-foreach");
|
||||
modifierSplitter = config.getString("modifier-splitter");
|
||||
abilitySplitter = config.getString("ability-splitter.format");
|
||||
useAbilitySplitter = config.getBoolean("ability-splitter.enabled");
|
||||
modifiersPerLine = config.getInt("modifiers-per-line");
|
||||
|
||||
data.getAbilities().forEach(ability -> {
|
||||
abilityLore.add(abilityFormat.replace("{trigger}", MMOItems.plugin.getLanguage().getCastingModeName(ability.getTrigger())).replace("{ability}", ability.getAbility().getName()));
|
||||
} else {
|
||||
legacyFormat = true;
|
||||
generalFormat = legacyLanguageFile.getString("ability-format");
|
||||
modifierForEach = legacyLanguageFile.getString("ability-modifier");
|
||||
abilitySplitter = legacyLanguageFile.getString("ability-splitter");
|
||||
useAbilitySplitter = abilitySplitter != null && !abilitySplitter.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
for (String modifier : ability.getModifiers()) {
|
||||
item.getLore().registerPlaceholder("ability_" + ability.getAbility().getHandler().getId().toLowerCase() + "_" + modifier,
|
||||
MythicLib.plugin.getMMOConfig().decimals.format(ability.getParameter(modifier)));
|
||||
abilityLore.add(modifierFormat.replace("{modifier}", ability.getAbility().getParameterName(modifier)).replace("{value}",
|
||||
MythicLib.plugin.getMMOConfig().decimals.format(ability.getParameter(modifier))));
|
||||
}
|
||||
@Override
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull AbilityListData data) {
|
||||
|
||||
if (splitter)
|
||||
abilityLore.add(MMOItems.plugin.getLanguage().abilitySplitter);
|
||||
});
|
||||
// Modify Lore
|
||||
List<String> abilityLore = new ArrayList<>();
|
||||
|
||||
if (splitter && abilityLore.size() > 0)
|
||||
abilityLore.remove(abilityLore.size() - 1);
|
||||
// DEPRECATED CODE which supports old versions of the stats.yml config
|
||||
if (legacyFormat) {
|
||||
data.getAbilities().forEach(ability -> {
|
||||
abilityLore.add(generalFormat
|
||||
.replace("{trigger}", MMOItems.plugin.getLanguage().getCastingModeName(ability.getTrigger()))
|
||||
.replace("{ability}", ability.getAbility().getName()));
|
||||
|
||||
// Modify tags
|
||||
item.getLore().insert("abilities", abilityLore);
|
||||
item.addItemTag(getAppliedNBT(data));
|
||||
}
|
||||
for (String modifier : ability.getModifiers()) {
|
||||
item.getLore().registerPlaceholder("ability_" + ability.getAbility().getHandler().getId().toLowerCase() + "_" + modifier,
|
||||
MythicLib.plugin.getMMOConfig().decimals.format(ability.getParameter(modifier)));
|
||||
abilityLore.add(modifierForEach.replace("{modifier}", ability.getAbility().getParameterName(modifier)).replace("{value}",
|
||||
MythicLib.plugin.getMMOConfig().decimals.format(ability.getParameter(modifier))));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ArrayList<ItemTag> getAppliedNBT(@NotNull AbilityListData data) {
|
||||
if (useAbilitySplitter)
|
||||
abilityLore.add(abilitySplitter);
|
||||
});
|
||||
}
|
||||
|
||||
// Make Array
|
||||
ArrayList<ItemTag> ret = new ArrayList<>();
|
||||
// Up to date code
|
||||
else {
|
||||
data.getAbilities().forEach(ability -> {
|
||||
final StringBuilder builder = new StringBuilder(generalFormat
|
||||
.replace("{trigger}", MMOItems.plugin.getLanguage().getCastingModeName(ability.getTrigger()))
|
||||
.replace("{ability}", ability.getAbility().getName()));
|
||||
|
||||
// Convert to JSON
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
for (AbilityData ab : data.getAbilities()) { jsonArray.add(ab.toJson()); }
|
||||
boolean modifierAppened = false;
|
||||
int lineCounter = 0;
|
||||
for (String modifier : ability.getModifiers()) {
|
||||
final String formattedValue = MythicLib.plugin.getMMOConfig().decimals.format(ability.getParameter(modifier));
|
||||
item.getLore().registerPlaceholder("ability_" + ability.getAbility().getHandler().getId().toLowerCase() + "_" + modifier, formattedValue);
|
||||
if (modifierAppened) builder.append(modifierSplitter);
|
||||
builder.append(modifierForEach
|
||||
.replace("{modifier}", ability.getAbility().getParameterName(modifier))
|
||||
.replace("{value}", formattedValue));
|
||||
modifierAppened = true;
|
||||
lineCounter++;
|
||||
|
||||
// Put
|
||||
ret.add(new ItemTag(getNBTPath(), jsonArray.toString()));
|
||||
if (modifiersPerLine > 0 && lineCounter >= modifiersPerLine) {
|
||||
lineCounter = 0;
|
||||
modifierAppened = false;
|
||||
abilityLore.add(builder.toString());
|
||||
builder.setLength(0);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
if (modifierAppened) abilityLore.add(builder.toString());
|
||||
|
||||
@Override
|
||||
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
|
||||
new AbilityListEdition(inv.getPlayer(), inv.getEdited()).open(inv);
|
||||
}
|
||||
if (useAbilitySplitter)
|
||||
abilityLore.add(abilitySplitter);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
|
||||
String configKey = (String) info[0];
|
||||
String edited = (String) info[1];
|
||||
if (useAbilitySplitter && abilityLore.size() > 0)
|
||||
abilityLore.remove(abilityLore.size() - 1);
|
||||
|
||||
String format = message.toUpperCase().replace("-", "_").replace(" ", "_").replaceAll("[^A-Z0-9_]", "");
|
||||
// Modify tags
|
||||
item.getLore().insert("abilities", abilityLore);
|
||||
item.addItemTag(getAppliedNBT(data));
|
||||
}
|
||||
|
||||
if (edited.equals("ability")) {
|
||||
Validate.isTrue(MMOItems.plugin.getSkills().hasSkill(format),
|
||||
"format is not a valid ability! You may check the ability list using /mi list ability.");
|
||||
RegisteredSkill ability = MMOItems.plugin.getSkills().getSkill(format);
|
||||
@Override
|
||||
public String getLegacyTranslationPath() {
|
||||
return "ability-format";
|
||||
}
|
||||
|
||||
inv.getEditedSection().set("ability." + configKey, null);
|
||||
inv.getEditedSection().set("ability." + configKey + ".type", format);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(
|
||||
MMOItems.plugin.getPrefix() + "Successfully set the ability to " + ChatColor.GOLD + ability.getName() + ChatColor.GRAY + ".");
|
||||
return;
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
public ArrayList<ItemTag> getAppliedNBT(@NotNull AbilityListData data) {
|
||||
|
||||
if (edited.equals("mode")) {
|
||||
// Make Array
|
||||
ArrayList<ItemTag> ret = new ArrayList<>();
|
||||
|
||||
TriggerType castMode = TriggerType.valueOf(format);
|
||||
// Convert to JSON
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
for (AbilityData ab : data.getAbilities()) {
|
||||
jsonArray.add(ab.toJson());
|
||||
}
|
||||
|
||||
inv.getEditedSection().set("ability." + configKey + ".mode", castMode.name());
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully set the trigger to " + ChatColor.GOLD + castMode.getName()
|
||||
+ ChatColor.GRAY + ".");
|
||||
return;
|
||||
}
|
||||
// Put
|
||||
ret.add(new ItemTag(getNBTPath(), jsonArray.toString()));
|
||||
|
||||
new NumericStatFormula(message).fillConfigurationSection(inv.getEditedSection(), "ability." + configKey + "." + edited,
|
||||
FormulaSaveOption.NONE);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.GOLD + MMOUtils.caseOnWords(edited.replace("-", " ")) + ChatColor.GRAY
|
||||
+ " successfully added.");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenDisplayed(List<String> lore, Optional<RandomAbilityListData> statData) {
|
||||
lore.add(ChatColor.GRAY + "Current Abilities: " + ChatColor.GOLD
|
||||
+ (statData.isPresent() ? ((RandomAbilityListData) statData.get()).getAbilities().size() : 0));
|
||||
lore.add("");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to edit the item abilities.");
|
||||
}
|
||||
@Override
|
||||
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
|
||||
new AbilityListEdition(inv.getPlayer(), inv.getEdited()).open(inv);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AbilityListData getClearStatData() {
|
||||
return new AbilityListData();
|
||||
}
|
||||
@Override
|
||||
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
|
||||
String configKey = (String) info[0];
|
||||
String edited = (String) info[1];
|
||||
|
||||
@Override
|
||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||
String format = message.toUpperCase().replace("-", "_").replace(" ", "_").replaceAll("[^A-Z0-9_]", "");
|
||||
|
||||
// Get tags
|
||||
ArrayList<ItemTag> relevantTags = new ArrayList<>();
|
||||
if (edited.equals("ability")) {
|
||||
Validate.isTrue(MMOItems.plugin.getSkills().hasSkill(format),
|
||||
"format is not a valid ability! You may check the ability list using /mi list ability.");
|
||||
RegisteredSkill ability = MMOItems.plugin.getSkills().getSkill(format);
|
||||
|
||||
if (mmoitem.getNBT().hasTag(getNBTPath()))
|
||||
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
||||
inv.getEditedSection().set("ability." + configKey, null);
|
||||
inv.getEditedSection().set("ability." + configKey + ".type", format);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(
|
||||
MMOItems.plugin.getPrefix() + "Successfully set the ability to " + ChatColor.GOLD + ability.getName() + ChatColor.GRAY + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
AbilityListData data = (AbilityListData) getLoadedNBT(relevantTags);
|
||||
if (edited.equals("mode")) {
|
||||
|
||||
// Valid?
|
||||
if (data != null) {
|
||||
TriggerType castMode = TriggerType.valueOf(format);
|
||||
|
||||
// Set
|
||||
mmoitem.setData(this, data);
|
||||
}
|
||||
}
|
||||
inv.getEditedSection().set("ability." + configKey + ".mode", castMode.name());
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully set the trigger to " + ChatColor.GOLD + castMode.getName()
|
||||
+ ChatColor.GRAY + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AbilityListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
||||
new NumericStatFormula(message).fillConfigurationSection(inv.getEditedSection(), "ability." + configKey + "." + edited,
|
||||
FormulaSaveOption.NONE);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.GOLD + MMOUtils.caseOnWords(edited.replace("-", " ")) + ChatColor.GRAY
|
||||
+ " successfully added.");
|
||||
}
|
||||
|
||||
// Get Json Array thing
|
||||
ItemTag jsonCompact = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
||||
@Override
|
||||
public void whenDisplayed(List<String> lore, Optional<RandomAbilityListData> statData) {
|
||||
lore.add(ChatColor.GRAY + "Current Abilities: " + ChatColor.GOLD
|
||||
+ (statData.isPresent() ? statData.get().getAbilities().size() : 0));
|
||||
lore.add("");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to edit the item abilities.");
|
||||
}
|
||||
|
||||
// Found?
|
||||
if (jsonCompact != null) {
|
||||
@NotNull
|
||||
@Override
|
||||
public AbilityListData getClearStatData() {
|
||||
return new AbilityListData();
|
||||
}
|
||||
|
||||
// Attempt to parse
|
||||
try {
|
||||
@Override
|
||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||
|
||||
// New ablity list data
|
||||
AbilityListData list = new AbilityListData();
|
||||
JsonArray ar = new JsonParser().parse((String) jsonCompact.getValue()).getAsJsonArray();
|
||||
// Get tags
|
||||
ArrayList<ItemTag> relevantTags = new ArrayList<>();
|
||||
|
||||
// Convert every object into an ability
|
||||
for (JsonElement e : ar) {
|
||||
if (mmoitem.getNBT().hasTag(getNBTPath()))
|
||||
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
||||
|
||||
// For every object
|
||||
if (e.isJsonObject()) {
|
||||
AbilityListData data = getLoadedNBT(relevantTags);
|
||||
|
||||
// Get as object
|
||||
JsonObject obj = e.getAsJsonObject();
|
||||
// Valid?
|
||||
if (data != null) {
|
||||
|
||||
// Add to abilit list
|
||||
list.add(new AbilityData(obj));
|
||||
}
|
||||
}
|
||||
// Set
|
||||
mmoitem.setData(this, data);
|
||||
}
|
||||
}
|
||||
|
||||
// Well that mus thave worked aye?
|
||||
return list;
|
||||
@Nullable
|
||||
@Override
|
||||
public AbilityListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
||||
|
||||
} catch (JsonSyntaxException|IllegalStateException exception) {
|
||||
/*
|
||||
* OLD ITEM WHICH MUST BE UPDATED.
|
||||
*/
|
||||
}
|
||||
}
|
||||
// Get Json Array thing
|
||||
ItemTag jsonCompact = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
||||
|
||||
// Did not work out
|
||||
return null;
|
||||
}
|
||||
// Found?
|
||||
if (jsonCompact != null) {
|
||||
|
||||
// Attempt to parse
|
||||
try {
|
||||
|
||||
// New ablity list data
|
||||
AbilityListData list = new AbilityListData();
|
||||
JsonArray ar = new JsonParser().parse((String) jsonCompact.getValue()).getAsJsonArray();
|
||||
|
||||
// Convert every object into an ability
|
||||
for (JsonElement e : ar) {
|
||||
|
||||
// For every object
|
||||
if (e.isJsonObject()) {
|
||||
|
||||
// Get as object
|
||||
JsonObject obj = e.getAsJsonObject();
|
||||
|
||||
// Add to abilit list
|
||||
list.add(new AbilityData(obj));
|
||||
}
|
||||
}
|
||||
|
||||
// Well that mus thave worked aye?
|
||||
return list;
|
||||
|
||||
} catch (JsonSyntaxException | IllegalStateException exception) {
|
||||
/*
|
||||
* OLD ITEM WHICH MUST BE UPDATED.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// Did not work out
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -118,13 +118,13 @@ public class ArrowPotionEffects extends ItemStat<RandomPotionEffectListData, Pot
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull PotionEffectListData data) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
String permEffectFormat = ItemStat.translate("arrow-potion-effects");
|
||||
String permEffectFormat = getGeneralStatFormat();
|
||||
data.getEffects().forEach(effect -> {
|
||||
lore.add(permEffectFormat.replace("{effect}", MMOItems.plugin.getLanguage().getPotionEffectName(effect.getType())
|
||||
+ " " + MMOUtils.intToRoman(effect.getLevel()) + "(" + MythicLib.plugin.getMMOConfig().decimal.format(effect.getDuration()) + "s)"));
|
||||
});
|
||||
|
||||
item.getLore().insert("arrow-potion-effects", lore);
|
||||
item.getLore().insert(getPath(), lore);
|
||||
|
||||
// Add tags
|
||||
item.addItemTag(getAppliedNBT(data));
|
||||
|
@ -26,212 +26,216 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Commands extends ItemStat<CommandListData, CommandListData> {
|
||||
private static final int MAXIMUM_COMMANDS = 15;
|
||||
private static final int MAXIMUM_COMMANDS = 15;
|
||||
|
||||
public Commands() {
|
||||
super("COMMANDS", VersionMaterial.COMMAND_BLOCK_MINECART.toMaterial(), "Commands",
|
||||
new String[] { "The commands your item", "performs when right clicked." }, new String[] { "!armor", "!block", "!gem_stone", "all" });
|
||||
}
|
||||
public Commands() {
|
||||
super("COMMANDS", VersionMaterial.COMMAND_BLOCK_MINECART.toMaterial(), "Commands",
|
||||
new String[]{"The commands your item", "performs when right clicked."}, new String[]{"!armor", "!block", "!gem_stone", "all"});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandListData whenInitialized(Object object) {
|
||||
Validate.isTrue(object instanceof ConfigurationSection, "Must specify a config section");
|
||||
ConfigurationSection config = (ConfigurationSection) object;
|
||||
@Override
|
||||
public CommandListData whenInitialized(Object object) {
|
||||
Validate.isTrue(object instanceof ConfigurationSection, "Must specify a config section");
|
||||
ConfigurationSection config = (ConfigurationSection) object;
|
||||
|
||||
CommandListData list = new CommandListData();
|
||||
CommandListData list = new CommandListData();
|
||||
|
||||
for (String key : config.getKeys(false)) {
|
||||
ConfigurationSection section = config.getConfigurationSection(key);
|
||||
list.add(new CommandData(section.getString("format"), section.getDouble("delay"), section.getBoolean("console"),
|
||||
section.getBoolean("op")));
|
||||
}
|
||||
for (String key : config.getKeys(false)) {
|
||||
ConfigurationSection section = config.getConfigurationSection(key);
|
||||
list.add(new CommandData(section.getString("format"), section.getDouble("delay"), section.getBoolean("console"),
|
||||
section.getBoolean("op")));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
|
||||
new CommandListEdition(inv.getPlayer(), inv.getEdited()).open(inv);
|
||||
}
|
||||
@Override
|
||||
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
|
||||
new CommandListEdition(inv.getPlayer(), inv.getEdited()).open(inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
|
||||
if (inv.getEditedSection().contains("commands"))
|
||||
if (inv.getEditedSection().getConfigurationSection("commands").getKeys(false).size() >= MAXIMUM_COMMANDS) {
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Your item has reached the " + MAXIMUM_COMMANDS + " commands limit.");
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
|
||||
if (inv.getEditedSection().contains("commands"))
|
||||
if (inv.getEditedSection().getConfigurationSection("commands").getKeys(false).size() >= MAXIMUM_COMMANDS) {
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Your item has reached the " + MAXIMUM_COMMANDS + " commands limit.");
|
||||
return;
|
||||
}
|
||||
|
||||
double delay = 0;
|
||||
boolean console = false, op = false;
|
||||
double delay = 0;
|
||||
boolean console = false, op = false;
|
||||
|
||||
String[] split = message.split(" ");
|
||||
for (int j = 0; j < split.length && split[j].startsWith("-"); j++) {
|
||||
String arg = split[j];
|
||||
if (arg.startsWith("-d:")) {
|
||||
delay = MMOUtils.parseDouble(arg.substring(3));
|
||||
message = message.replaceFirst(arg + " ", "");
|
||||
} else if (arg.equalsIgnoreCase("-c")) {
|
||||
console = true;
|
||||
message = message.replaceFirst(arg + " ", "");
|
||||
} else if (arg.equalsIgnoreCase("-op")) {
|
||||
op = true;
|
||||
message = message.replaceFirst(arg + " ", "");
|
||||
}
|
||||
}
|
||||
String[] split = message.split(" ");
|
||||
for (int j = 0; j < split.length && split[j].startsWith("-"); j++) {
|
||||
String arg = split[j];
|
||||
if (arg.startsWith("-d:")) {
|
||||
delay = MMOUtils.parseDouble(arg.substring(3));
|
||||
message = message.replaceFirst(arg + " ", "");
|
||||
} else if (arg.equalsIgnoreCase("-c")) {
|
||||
console = true;
|
||||
message = message.replaceFirst(arg + " ", "");
|
||||
} else if (arg.equalsIgnoreCase("-op")) {
|
||||
op = true;
|
||||
message = message.replaceFirst(arg + " ", "");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* determine the command ID based on the command IDs which have been
|
||||
* registered before.
|
||||
*/
|
||||
ConfigurationSection commands = inv.getEditedSection().getConfigurationSection("commands");
|
||||
String path = "cmd" + (MAXIMUM_COMMANDS + 1);
|
||||
if (commands == null)
|
||||
path = "cmd0";
|
||||
else
|
||||
for (int j = 0; j < MAXIMUM_COMMANDS; j++)
|
||||
if (!commands.contains("cmd" + j)) {
|
||||
path = "cmd" + j;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* determine the command ID based on the command IDs which have been
|
||||
* registered before.
|
||||
*/
|
||||
ConfigurationSection commands = inv.getEditedSection().getConfigurationSection("commands");
|
||||
String path = "cmd" + (MAXIMUM_COMMANDS + 1);
|
||||
if (commands == null)
|
||||
path = "cmd0";
|
||||
else
|
||||
for (int j = 0; j < MAXIMUM_COMMANDS; j++)
|
||||
if (!commands.contains("cmd" + j)) {
|
||||
path = "cmd" + j;
|
||||
break;
|
||||
}
|
||||
|
||||
inv.getEditedSection().set("commands." + path + ".format", message);
|
||||
inv.getEditedSection().set("commands." + path + ".delay", delay);
|
||||
inv.getEditedSection().set("commands." + path + ".console", console ? console : null);
|
||||
inv.getEditedSection().set("commands." + path + ".op", op ? op : null);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Command successfully registered.");
|
||||
}
|
||||
inv.getEditedSection().set("commands." + path + ".format", message);
|
||||
inv.getEditedSection().set("commands." + path + ".delay", delay);
|
||||
inv.getEditedSection().set("commands." + path + ".console", console ? console : null);
|
||||
inv.getEditedSection().set("commands." + path + ".op", op ? op : null);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Command successfully registered.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenDisplayed(List<String> lore, Optional<CommandListData> statData) {
|
||||
lore.add(ChatColor.GRAY + "Current Commands: " + ChatColor.RED
|
||||
+ (statData.isPresent() ? ((CommandListData) statData.get()).getCommands().size() : "0"));
|
||||
lore.add("");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to edit item commands.");
|
||||
}
|
||||
@Override
|
||||
public void whenDisplayed(List<String> lore, Optional<CommandListData> statData) {
|
||||
lore.add(ChatColor.GRAY + "Current Commands: " + ChatColor.RED
|
||||
+ (statData.isPresent() ? ((CommandListData) statData.get()).getCommands().size() : "0"));
|
||||
lore.add("");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to edit item commands.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CommandListData getClearStatData() {
|
||||
return new CommandListData();
|
||||
}
|
||||
@Override
|
||||
public @NotNull CommandListData getClearStatData() {
|
||||
return new CommandListData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull CommandListData data) {
|
||||
@Override
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull CommandListData data) {
|
||||
|
||||
// Add persistent tags onto item
|
||||
item.addItemTag(getAppliedNBT(data));
|
||||
// Add persistent tags onto item
|
||||
item.addItemTag(getAppliedNBT(data));
|
||||
|
||||
// Addlore
|
||||
List<String> lore = new ArrayList<>();
|
||||
String commandFormat = ItemStat.translate("command");
|
||||
((CommandListData) data).getCommands().forEach(command -> {
|
||||
// Addlore
|
||||
List<String> lore = new ArrayList<>();
|
||||
String commandFormat = getGeneralStatFormat();
|
||||
data.getCommands().forEach(command -> lore.add(commandFormat
|
||||
.replace("{format}", "/" + command.getCommand())
|
||||
.replace("{cooldown}", String.valueOf(command.getDelay()))));
|
||||
item.getLore().insert("commands", lore);
|
||||
}
|
||||
|
||||
lore.add(commandFormat.replace("{format}", "/" + command.getCommand()).replace("{cooldown}", String.valueOf(command.getDelay())));
|
||||
});
|
||||
item.getLore().insert("commands", lore);
|
||||
}
|
||||
@Override
|
||||
public String getLegacyTranslationPath() {
|
||||
return "command";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ArrayList<ItemTag> getAppliedNBT(@NotNull CommandListData data) {
|
||||
@NotNull
|
||||
@Override
|
||||
public ArrayList<ItemTag> getAppliedNBT(@NotNull CommandListData data) {
|
||||
|
||||
// Will end up returning this
|
||||
ArrayList<ItemTag> ret = new ArrayList<>();
|
||||
// Will end up returning this
|
||||
ArrayList<ItemTag> ret = new ArrayList<>();
|
||||
|
||||
// But it contains only 1 tag: THIS
|
||||
JsonArray array = new JsonArray();
|
||||
// But it contains only 1 tag: THIS
|
||||
JsonArray array = new JsonArray();
|
||||
|
||||
// Add each command
|
||||
for (CommandData cd : data.getCommands()) {
|
||||
// Add each command
|
||||
for (CommandData cd : data.getCommands()) {
|
||||
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("Command", cd.getCommand());
|
||||
object.addProperty("Delay", cd.getDelay());
|
||||
object.addProperty("Console", cd.isConsoleCommand());
|
||||
object.addProperty("Op", cd.hasOpPerms());
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("Command", cd.getCommand());
|
||||
object.addProperty("Delay", cd.getDelay());
|
||||
object.addProperty("Console", cd.isConsoleCommand());
|
||||
object.addProperty("Op", cd.hasOpPerms());
|
||||
|
||||
// Include object
|
||||
array.add(object);
|
||||
}
|
||||
// Include object
|
||||
array.add(object);
|
||||
}
|
||||
|
||||
// Add that tag in there
|
||||
ret.add(new ItemTag(getNBTPath(), array.toString()));
|
||||
// Add that tag in there
|
||||
ret.add(new ItemTag(getNBTPath(), array.toString()));
|
||||
|
||||
// Thats it
|
||||
return ret;
|
||||
}
|
||||
// Thats it
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||
@Override
|
||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||
|
||||
// Find the relevant tag
|
||||
ArrayList<ItemTag> relevantTag = new ArrayList<>();
|
||||
// Find the relevant tag
|
||||
ArrayList<ItemTag> relevantTag = new ArrayList<>();
|
||||
|
||||
// Yes
|
||||
if (mmoitem.getNBT().hasTag(getNBTPath()))
|
||||
relevantTag.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
||||
// Yes
|
||||
if (mmoitem.getNBT().hasTag(getNBTPath()))
|
||||
relevantTag.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
||||
|
||||
// Attempt to bake data
|
||||
CommandListData data = (CommandListData) getLoadedNBT(relevantTag);
|
||||
// Attempt to bake data
|
||||
CommandListData data = (CommandListData) getLoadedNBT(relevantTag);
|
||||
|
||||
// Valid?
|
||||
if (data != null) {
|
||||
// Valid?
|
||||
if (data != null) {
|
||||
|
||||
// yup
|
||||
mmoitem.setData(this, data);
|
||||
}
|
||||
}
|
||||
// yup
|
||||
mmoitem.setData(this, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public CommandListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
||||
@Nullable
|
||||
@Override
|
||||
public CommandListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
||||
|
||||
// Find relevant tag
|
||||
ItemTag relevant = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
||||
// Find relevant tag
|
||||
ItemTag relevant = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
||||
|
||||
// Found it?
|
||||
if (relevant != null) {
|
||||
// Found it?
|
||||
if (relevant != null) {
|
||||
|
||||
// Attempt to parse it
|
||||
try {
|
||||
// Attempt to parse it
|
||||
try {
|
||||
|
||||
// New data <3
|
||||
CommandListData commands = new CommandListData();
|
||||
// New data <3
|
||||
CommandListData commands = new CommandListData();
|
||||
|
||||
// Parse array from it
|
||||
JsonArray ar = new JsonParser().parse((String) relevant.getValue()).getAsJsonArray();
|
||||
// Parse array from it
|
||||
JsonArray ar = new JsonParser().parse((String) relevant.getValue()).getAsJsonArray();
|
||||
|
||||
// Examine every element
|
||||
for (JsonElement e : ar) {
|
||||
// Examine every element
|
||||
for (JsonElement e : ar) {
|
||||
|
||||
// Valid?
|
||||
if (e.isJsonObject()) {
|
||||
// Valid?
|
||||
if (e.isJsonObject()) {
|
||||
|
||||
// Get Key
|
||||
JsonObject key = e.getAsJsonObject();
|
||||
// Get Key
|
||||
JsonObject key = e.getAsJsonObject();
|
||||
|
||||
// Interpret Command Data
|
||||
CommandData cd = new CommandData(
|
||||
key.get("Command").getAsString(),
|
||||
key.get("Delay").getAsDouble(),
|
||||
key.get("Console").getAsBoolean(),
|
||||
key.get("Op").getAsBoolean());
|
||||
// Interpret Command Data
|
||||
CommandData cd = new CommandData(
|
||||
key.get("Command").getAsString(),
|
||||
key.get("Delay").getAsDouble(),
|
||||
key.get("Console").getAsBoolean(),
|
||||
key.get("Op").getAsBoolean());
|
||||
|
||||
// Register
|
||||
commands.add(cd);
|
||||
}
|
||||
}
|
||||
return commands;
|
||||
// Register
|
||||
commands.add(cd);
|
||||
}
|
||||
}
|
||||
return commands;
|
||||
|
||||
// Needs updating
|
||||
} catch (JsonSyntaxException|IllegalStateException exception) {
|
||||
/*
|
||||
* OLD ITEM WHICH MUST BE UPDATED.
|
||||
*/
|
||||
}
|
||||
}
|
||||
// Needs updating
|
||||
} catch (JsonSyntaxException | IllegalStateException exception) {
|
||||
/*
|
||||
* OLD ITEM WHICH MUST BE UPDATED.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ public class Effects extends ItemStat<RandomPotionEffectListData, PotionEffectLi
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull PotionEffectListData data) {
|
||||
// Process Lore
|
||||
List<String> lore = new ArrayList<>();
|
||||
String effectFormat = ItemStat.translate("effect");
|
||||
String effectFormat = getGeneralStatFormat();
|
||||
data.getEffects().forEach(effect -> lore.add(effectFormat
|
||||
.replace("{effect}",
|
||||
MMOItems.plugin.getLanguage().getPotionEffectName(effect.getType())
|
||||
@ -121,11 +121,16 @@ public class Effects extends ItemStat<RandomPotionEffectListData, PotionEffectLi
|
||||
item.addItemTag(getAppliedNBT(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLegacyTranslationPath() {
|
||||
return "effect";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ArrayList<ItemTag> getAppliedNBT(@NotNull PotionEffectListData data) {
|
||||
|
||||
// Create aJson Array
|
||||
// Create a Json Array
|
||||
JsonArray array = new JsonArray();
|
||||
|
||||
// For every effect
|
||||
|
@ -29,9 +29,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
|
||||
public class Elements extends ItemStat<RandomElementListData, ElementListData> implements Previewable<RandomElementListData, ElementListData> {
|
||||
public Elements() {
|
||||
@ -77,7 +75,7 @@ public class Elements extends ItemStat<RandomElementListData, ElementListData> i
|
||||
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + MMOUtils.caseOnWords(elementPath.replace(".", " ")) + ChatColor.GRAY
|
||||
+ " successfully changed to " + ChatColor.GOLD + formula.toString() + ChatColor.GRAY + ".");
|
||||
+ " successfully changed to " + ChatColor.GOLD + formula + ChatColor.GRAY + ".");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -102,6 +100,32 @@ public class Elements extends ItemStat<RandomElementListData, ElementListData> i
|
||||
return new ElementListData();
|
||||
}
|
||||
|
||||
private Map<ElementStatType, String> statFormat = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void loadConfiguration(@NotNull ConfigurationSection legacyLanguageFile, @NotNull Object configObject) {
|
||||
|
||||
// LEGACY CODE
|
||||
if (configObject instanceof String) {
|
||||
for (ElementStatType statType : ElementStatType.values())
|
||||
statFormat.put(statType, legacyLanguageFile.getString("elemental-" + statType.lowerCaseName(), "<TranslationNotFound:" + statType.name().toLowerCase() + ">"));
|
||||
}
|
||||
|
||||
// Up-to-date code
|
||||
else {
|
||||
Validate.isTrue(configObject instanceof ConfigurationSection, "Must be a config section");
|
||||
final ConfigurationSection config = (ConfigurationSection) configObject;
|
||||
for (ElementStatType statType : ElementStatType.values())
|
||||
statFormat.put(statType, config.getString(statType.lowerCaseName(), "<TranslationNotFound:" + statType.lowerCaseName() + ">"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLegacyTranslationPath() {
|
||||
// Arbitrary
|
||||
return "elemental-damage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull ElementListData data) {
|
||||
|
||||
@ -109,7 +133,7 @@ public class Elements extends ItemStat<RandomElementListData, ElementListData> i
|
||||
|
||||
// Write Lore
|
||||
for (Pair<Element, ElementStatType> pair : data.getKeys()) {
|
||||
final String format = ItemStat.translate("elemental-" + pair.getValue().lowerCaseName())
|
||||
final String format = statFormat.get(pair.getValue())
|
||||
.replace("{color}", pair.getKey().getColor())
|
||||
.replace("{icon}", pair.getKey().getLoreIcon())
|
||||
.replace("{element}", pair.getKey().getName());
|
||||
@ -183,6 +207,8 @@ public class Elements extends ItemStat<RandomElementListData, ElementListData> i
|
||||
Validate.isTrue(currentData instanceof ElementListData, "Current Data is not ElementListData");
|
||||
Validate.isTrue(templateData instanceof RandomElementListData, "Template Data is not RandomElementListData");
|
||||
|
||||
List<String> elementLore = new ArrayList<>();
|
||||
|
||||
// Examine every element stat possible
|
||||
for (Element element : Element.values())
|
||||
for (ElementStatType statType : ElementStatType.values()) {
|
||||
@ -197,20 +223,20 @@ public class Elements extends ItemStat<RandomElementListData, ElementListData> i
|
||||
if (techMinimum != 0 || techMaximum != 0) {
|
||||
|
||||
// Get path
|
||||
String path = element.getId().toLowerCase() + "-" + statType.name().toLowerCase().replace("_", "-");
|
||||
|
||||
String builtRange;
|
||||
if (SilentNumbers.round(techMinimum, 2) == SilentNumbers.round(techMaximum, 2)) {
|
||||
builtRange = DoubleStat.formatPath(statType.getConcatenatedTagPath(element), ItemStat.translate(path), true, techMinimum);
|
||||
builtRange = DoubleStat.formatPath(statType.getConcatenatedTagPath(element), statFormat.get(statType), true, techMinimum);
|
||||
} else {
|
||||
builtRange = DoubleStat.formatPath(statType.getConcatenatedTagPath(element), ItemStat.translate(path), true, techMinimum, techMaximum);
|
||||
builtRange = DoubleStat.formatPath(statType.getConcatenatedTagPath(element), statFormat.get(statType), true, techMinimum, techMaximum);
|
||||
}
|
||||
|
||||
// Just display normally
|
||||
item.getLore().insert(path, builtRange);
|
||||
elementLore.add(builtRange);
|
||||
}
|
||||
}
|
||||
|
||||
if (!elementLore.isEmpty()) item.getLore().insert(getPath(), elementLore);
|
||||
|
||||
// Add tags
|
||||
item.addItemTag(getAppliedNBT(currentData));
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
@ -32,166 +33,192 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class GemSockets extends ItemStat<GemSocketsData, GemSocketsData> {
|
||||
public GemSockets() {
|
||||
super("GEM_SOCKETS", Material.EMERALD, "Gem Sockets", new String[] { "The amount of gem", "sockets your weapon has." },
|
||||
new String[] { "piercing", "slashing", "blunt", "catalyst", "range", "tool", "armor", "accessory", "!gem_stone" });
|
||||
}
|
||||
public GemSockets() {
|
||||
super("GEM_SOCKETS", Material.EMERALD, "Gem Sockets", new String[]{"The amount of gem", "sockets your weapon has."},
|
||||
new String[]{"piercing", "slashing", "blunt", "catalyst", "range", "tool", "armor", "accessory", "!gem_stone"});
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public GemSocketsData whenInitialized(Object object) {
|
||||
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
|
||||
return new GemSocketsData((List<String>) object);
|
||||
}
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public GemSocketsData whenInitialized(Object object) {
|
||||
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
|
||||
return new GemSocketsData((List<String>) object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull GemSocketsData sockets) {
|
||||
private String emptyGemSocketFormat, filledGemSocketFormat;
|
||||
|
||||
// Append NBT Tags
|
||||
item.addItemTag(getAppliedNBT(sockets));
|
||||
@Override
|
||||
public void loadConfiguration(@NotNull ConfigurationSection legacyLanguageFile, @NotNull Object configObject) {
|
||||
|
||||
// Edit Lore
|
||||
String empty = ItemStat.translate("empty-gem-socket"), filled = ItemStat.translate("filled-gem-socket");
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (GemstoneData gem : sockets.getGemstones()) {
|
||||
String gemName = gem.getName();
|
||||
// LEGACY CODE
|
||||
if (configObject instanceof String) {
|
||||
emptyGemSocketFormat = legacyLanguageFile.getString("empty-gem-socket");
|
||||
filledGemSocketFormat = legacyLanguageFile.getString("filled-gem-socket");
|
||||
}
|
||||
|
||||
// Upgrades?
|
||||
if (item.getMMOItem().hasUpgradeTemplate()) {
|
||||
// Up-to-date code
|
||||
else {
|
||||
Validate.isTrue(configObject instanceof ConfigurationSection, "Must be a config section");
|
||||
final ConfigurationSection config = (ConfigurationSection) configObject;
|
||||
emptyGemSocketFormat = config.getString("empty");
|
||||
filledGemSocketFormat = config.getString("filled");
|
||||
}
|
||||
}
|
||||
|
||||
int iLvl = item.getMMOItem().getUpgradeLevel();
|
||||
if (iLvl != 0) {
|
||||
@Override
|
||||
public String getLegacyTranslationPath() {
|
||||
return "empty-gem-socket";
|
||||
}
|
||||
|
||||
Integer gLvl = gem.getLevel();
|
||||
@Override
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull GemSocketsData sockets) {
|
||||
|
||||
if (gLvl != null) {
|
||||
// Append NBT Tags
|
||||
item.addItemTag(getAppliedNBT(sockets));
|
||||
|
||||
int dLevel = iLvl - gLvl;
|
||||
// Edit Lore
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (GemstoneData gem : sockets.getGemstones()) {
|
||||
String gemName = gem.getName();
|
||||
|
||||
gemName = DisplayName.appendUpgradeLevel(gemName, dLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Upgrades?
|
||||
if (item.getMMOItem().hasUpgradeTemplate()) {
|
||||
|
||||
lore.add(filled.replace("{name}", gemName));
|
||||
}
|
||||
sockets.getEmptySlots().forEach(slot -> lore.add(empty.replace("{name}", slot)));
|
||||
item.getLore().insert("gem-stones", lore);
|
||||
}
|
||||
int iLvl = item.getMMOItem().getUpgradeLevel();
|
||||
if (iLvl != 0) {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ArrayList<ItemTag> getAppliedNBT(@NotNull GemSocketsData sockets) {
|
||||
Integer gLvl = gem.getLevel();
|
||||
|
||||
// Well its just a Json tostring
|
||||
ArrayList<ItemTag> ret = new ArrayList<>();
|
||||
ret.add(new ItemTag(getNBTPath(), sockets.toJson().toString()));
|
||||
if (gLvl != null) {
|
||||
|
||||
// Thats it
|
||||
return ret;
|
||||
}
|
||||
int dLevel = iLvl - gLvl;
|
||||
|
||||
@Override
|
||||
@NotNull public String getNBTPath() {
|
||||
return "MMOITEMS_GEM_STONES";
|
||||
}
|
||||
gemName = DisplayName.appendUpgradeLevel(gemName, dLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lore.add(filledGemSocketFormat.replace("{name}", gemName));
|
||||
}
|
||||
sockets.getEmptySlots().forEach(slot -> lore.add(emptyGemSocketFormat.replace("{name}", slot)));
|
||||
item.getLore().insert("gem-stones", lore);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||
@NotNull
|
||||
@Override
|
||||
public ArrayList<ItemTag> getAppliedNBT(@NotNull GemSocketsData sockets) {
|
||||
|
||||
// Find relevant tags
|
||||
ArrayList<ItemTag> relevantTags = new ArrayList<>();
|
||||
if (mmoitem.getNBT().hasTag(getNBTPath()))
|
||||
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
||||
// Well its just a Json tostring
|
||||
ArrayList<ItemTag> ret = new ArrayList<>();
|
||||
ret.add(new ItemTag(getNBTPath(), sockets.toJson().toString()));
|
||||
|
||||
// Attempt to build
|
||||
StatData data = getLoadedNBT(relevantTags);
|
||||
// Thats it
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Valid?
|
||||
if (data != null) { mmoitem.setData(this, data); }
|
||||
}
|
||||
@Override
|
||||
@NotNull
|
||||
public String getNBTPath() {
|
||||
return "MMOITEMS_GEM_STONES";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public GemSocketsData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
||||
@Override
|
||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||
|
||||
// Find Tag
|
||||
ItemTag gTag = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
||||
// Find relevant tags
|
||||
ArrayList<ItemTag> relevantTags = new ArrayList<>();
|
||||
if (mmoitem.getNBT().hasTag(getNBTPath()))
|
||||
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
||||
|
||||
// Found?
|
||||
if (gTag != null) {
|
||||
// Attempt to build
|
||||
StatData data = getLoadedNBT(relevantTags);
|
||||
|
||||
try {
|
||||
// Interpret as Json Object
|
||||
JsonObject object = new JsonParser().parse((String) gTag.getValue()).getAsJsonObject();
|
||||
GemSocketsData sockets = new GemSocketsData(object.getAsJsonArray("EmptySlots"));
|
||||
// Valid?
|
||||
if (data != null) {
|
||||
mmoitem.setData(this, data);
|
||||
}
|
||||
}
|
||||
|
||||
JsonArray array = object.getAsJsonArray("Gemstones");
|
||||
array.forEach(element -> sockets.add(new GemstoneData(element.getAsJsonObject())));
|
||||
@Nullable
|
||||
@Override
|
||||
public GemSocketsData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
||||
|
||||
// Return built
|
||||
return sockets;
|
||||
// Find Tag
|
||||
ItemTag gTag = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
||||
|
||||
} catch (JsonSyntaxException|IllegalStateException exception) {
|
||||
/*
|
||||
* OLD ITEM WHICH MUST BE UPDATED.
|
||||
*/
|
||||
}
|
||||
}
|
||||
// Found?
|
||||
if (gTag != null) {
|
||||
|
||||
// Nope
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
// Interpret as Json Object
|
||||
JsonObject object = new JsonParser().parse((String) gTag.getValue()).getAsJsonObject();
|
||||
GemSocketsData sockets = new GemSocketsData(object.getAsJsonArray("EmptySlots"));
|
||||
|
||||
@Override
|
||||
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
|
||||
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
||||
new StatEdition(inv, ItemStats.GEM_SOCKETS).enable("Write in the chat the COLOR of the gem socket you want to add.");
|
||||
JsonArray array = object.getAsJsonArray("Gemstones");
|
||||
array.forEach(element -> sockets.add(new GemstoneData(element.getAsJsonObject())));
|
||||
|
||||
if (event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||
if (inv.getEditedSection().contains(getPath())) {
|
||||
List<String> lore = inv.getEditedSection().getStringList("" + getPath());
|
||||
if (lore.size() < 1)
|
||||
return;
|
||||
// Return built
|
||||
return sockets;
|
||||
|
||||
String last = lore.get(lore.size() - 1);
|
||||
lore.remove(last);
|
||||
inv.getEditedSection().set("" + getPath(), lore);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + last + ChatColor.GRAY + "'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (JsonSyntaxException | IllegalStateException exception) {
|
||||
/*
|
||||
* OLD ITEM WHICH MUST BE UPDATED.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
|
||||
List<String> lore = inv.getEditedSection().contains(getPath()) ? inv.getEditedSection().getStringList("" + getPath()) : new ArrayList<>();
|
||||
lore.add(message);
|
||||
inv.getEditedSection().set("" + getPath(), lore);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + message + " successfully added.");
|
||||
}
|
||||
// Nope
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenDisplayed(List<String> lore, Optional<GemSocketsData> statData) {
|
||||
@Override
|
||||
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
|
||||
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
||||
new StatEdition(inv, ItemStats.GEM_SOCKETS).enable("Write in the chat the COLOR of the gem socket you want to add.");
|
||||
|
||||
if (statData.isPresent()) {
|
||||
lore.add(ChatColor.GRAY + "Current Value:");
|
||||
GemSocketsData data = statData.get();
|
||||
data.getEmptySlots().forEach(socket -> lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + socket + " Gem Socket"));
|
||||
if (event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||
if (inv.getEditedSection().contains(getPath())) {
|
||||
List<String> lore = inv.getEditedSection().getStringList("" + getPath());
|
||||
if (lore.size() < 1)
|
||||
return;
|
||||
|
||||
} else
|
||||
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "No Sockets");
|
||||
String last = lore.get(lore.size() - 1);
|
||||
lore.remove(last);
|
||||
inv.getEditedSection().set("" + getPath(), lore);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + last + ChatColor.GRAY + "'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lore.add("");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a gem socket.");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the socket.");
|
||||
}
|
||||
@Override
|
||||
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
|
||||
List<String> lore = inv.getEditedSection().contains(getPath()) ? inv.getEditedSection().getStringList("" + getPath()) : new ArrayList<>();
|
||||
lore.add(message);
|
||||
inv.getEditedSection().set("" + getPath(), lore);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + message + " successfully added.");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public GemSocketsData getClearStatData() {
|
||||
return new GemSocketsData(new ArrayList<>());
|
||||
}
|
||||
@Override
|
||||
public void whenDisplayed(List<String> lore, Optional<GemSocketsData> statData) {
|
||||
|
||||
if (statData.isPresent()) {
|
||||
lore.add(ChatColor.GRAY + "Current Value:");
|
||||
GemSocketsData data = statData.get();
|
||||
data.getEmptySlots().forEach(socket -> lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + socket + " Gem Socket"));
|
||||
|
||||
} else
|
||||
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "No Sockets");
|
||||
|
||||
lore.add("");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a gem socket.");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the socket.");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public GemSocketsData getClearStatData() {
|
||||
return new GemSocketsData(new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
@ -61,4 +61,9 @@ public class ItemDamage extends DoubleStat implements GemStoneStat {
|
||||
@Nullable
|
||||
@Override
|
||||
public DoubleData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) { return null; }
|
||||
|
||||
@Override
|
||||
public String getLegacyTranslationPath() {
|
||||
return "durability";
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class ItemTierStat extends StringStat implements GemStoneStat {
|
||||
|
||||
ItemTier tier = MMOItems.plugin.getTiers().get(path);
|
||||
item.addItemTag(new ItemTag("MMOITEMS_TIER", path));
|
||||
item.getLore().insert("tier", MMOItems.plugin.getLanguage().getStatFormat(getPath()).replace("{value}", tier.getName()));
|
||||
item.getLore().insert(getPath(), getGeneralStatFormat().replace("{value}", tier.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,7 +35,7 @@ public class ItemTierStat extends StringStat implements GemStoneStat {
|
||||
String format = message.toUpperCase().replace(" ", "_").replace("-", "_");
|
||||
Validate.isTrue(MMOItems.plugin.getTiers().has(format), "Couldn't find the tier called '" + format + "'.");
|
||||
|
||||
inv.getEditedSection().set("tier", format);
|
||||
inv.getEditedSection().set(getPath(), format);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Tier successfully changed to " + format + ".");
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public class MaxConsume extends DoubleStat {
|
||||
|
||||
item.addItemTag(new ItemTag(getNBTPath(), left));
|
||||
|
||||
String format = MMOItems.plugin.getLanguage().getStatFormat("max-consume").replace("{value}", String.valueOf(left));
|
||||
item.getLore().insert("max-consume", format);
|
||||
String format = getGeneralStatFormat().replace("{value}", String.valueOf(left));
|
||||
item.getLore().insert(getPath(), format);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package net.Indyuce.mmoitems.stat;
|
||||
import io.lumine.mythic.lib.api.item.ItemTag;
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import net.Indyuce.mmoitems.ItemStats;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import net.Indyuce.mmoitems.api.player.RPGPlayer;
|
||||
@ -18,6 +17,7 @@ import net.Indyuce.mmoitems.stat.type.Upgradable;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@ -26,75 +26,81 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @author indyuce
|
||||
*/
|
||||
public class MaximumDurability extends DoubleStat implements ItemRestriction, GemStoneStat, Upgradable {
|
||||
public MaximumDurability() {
|
||||
super("MAX_DURABILITY", Material.SHEARS, "Maximum Durability", new String[]{"The amount of uses before your", "item becomes unusable/breaks."}, new String[]{"!block", "all"});
|
||||
}
|
||||
public MaximumDurability() {
|
||||
super("MAX_DURABILITY", Material.SHEARS, "Maximum Durability", new String[]{"The amount of uses before your", "item becomes unusable/breaks."}, new String[]{"!block", "all"});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull DoubleData currentData, @NotNull NumericStatFormula templateData) throws IllegalArgumentException {
|
||||
whenApplied(item, currentData);
|
||||
}
|
||||
@Override
|
||||
public void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull DoubleData currentData, @NotNull NumericStatFormula templateData) throws IllegalArgumentException {
|
||||
whenApplied(item, currentData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull DoubleData data) {
|
||||
@Override
|
||||
public void loadConfiguration(@NotNull ConfigurationSection legacyLanguageFile, @NotNull Object configObject) {
|
||||
generalStatFormat = legacyLanguageFile.getString("item-damage");
|
||||
if (generalStatFormat == null) generalStatFormat = legacyLanguageFile.getString("durability");
|
||||
}
|
||||
|
||||
int max = (int) data.getValue();
|
||||
int current = item.getMMOItem().hasData(ItemStats.CUSTOM_DURABILITY) ? (int) ((DoubleData) item.getMMOItem().getData(ItemStats.CUSTOM_DURABILITY)).getValue() : max;
|
||||
@Override
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull DoubleData data) {
|
||||
|
||||
item.addItemTag(new ItemTag(getNBTPath(), max));
|
||||
int max = (int) data.getValue();
|
||||
int current = item.getMMOItem().hasData(ItemStats.CUSTOM_DURABILITY) ? (int) ((DoubleData) item.getMMOItem().getData(ItemStats.CUSTOM_DURABILITY)).getValue() : max;
|
||||
|
||||
// Display durability in lore here.
|
||||
String format = MMOItems.plugin.getLanguage().getStatFormat("durability").replace("{max}", String.valueOf(max)).replace("{current}", String.valueOf(current));
|
||||
item.getLore().insert("durability", format);
|
||||
}
|
||||
item.addItemTag(new ItemTag(getNBTPath(), max));
|
||||
|
||||
@Override
|
||||
public void preprocess(@NotNull MMOItem item) {
|
||||
// Display durability in lore here.
|
||||
String format = getGeneralStatFormat().replace("{max}", String.valueOf(max)).replace("{current}", String.valueOf(current));
|
||||
item.getLore().insert("durability", format);
|
||||
}
|
||||
|
||||
// If this has no Max Upgrade Data
|
||||
if (!item.hasData(ItemStats.MAX_DURABILITY)) {
|
||||
@Override
|
||||
public void preprocess(@NotNull MMOItem item) {
|
||||
|
||||
// What durability will it have?
|
||||
int base = 400;
|
||||
// If this has no Max Upgrade Data
|
||||
if (!item.hasData(ItemStats.MAX_DURABILITY)) {
|
||||
|
||||
// I mean bruh
|
||||
if (item.hasData(ItemStats.MATERIAL)) {
|
||||
// What durability will it have?
|
||||
int base = 400;
|
||||
|
||||
// Use vanilla max durability
|
||||
MaterialData data = (MaterialData) item.getData(ItemStats.MATERIAL);
|
||||
// I mean bruh
|
||||
if (item.hasData(ItemStats.MATERIAL)) {
|
||||
|
||||
// Get mat
|
||||
Material mat = data.getMaterial();
|
||||
base = mat.getMaxDurability();
|
||||
}
|
||||
// Use vanilla max durability
|
||||
MaterialData data = (MaterialData) item.getData(ItemStats.MATERIAL);
|
||||
|
||||
// Yea no
|
||||
if (base < 8)
|
||||
base = 400;
|
||||
// Get mat
|
||||
Material mat = data.getMaterial();
|
||||
base = mat.getMaxDurability();
|
||||
}
|
||||
|
||||
// Set max dura
|
||||
item.setData(ItemStats.MAX_DURABILITY, new DoubleData(base));
|
||||
/*item.setData(ItemStats.CUSTOM_DURABILITY, new DoubleData(base));*/
|
||||
}
|
||||
}
|
||||
// Yea no
|
||||
if (base < 8)
|
||||
base = 400;
|
||||
|
||||
@Override
|
||||
public boolean canUse(RPGPlayer player, NBTItem item, boolean message) {
|
||||
// Set max dura
|
||||
item.setData(ItemStats.MAX_DURABILITY, new DoubleData(base));
|
||||
/*item.setData(ItemStats.CUSTOM_DURABILITY, new DoubleData(base));*/
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Items with no MMOITEMS_DURABILITY tag yet means that they still
|
||||
* have full durability
|
||||
*/
|
||||
if (!item.hasTag("MMOITEMS_DURABILITY"))
|
||||
return true;
|
||||
@Override
|
||||
public boolean canUse(RPGPlayer player, NBTItem item, boolean message) {
|
||||
|
||||
if (item.getDouble(ItemStats.CUSTOM_DURABILITY.getNBTPath()) <= 0) {
|
||||
if (message) {
|
||||
Message.ZERO_DURABILITY.format(ChatColor.RED).send(player.getPlayer());
|
||||
player.getPlayer().playSound(player.getPlayer().getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1.5f);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* Items with no MMOITEMS_DURABILITY tag yet means that they still
|
||||
* have full durability
|
||||
*/
|
||||
if (!item.hasTag("MMOITEMS_DURABILITY"))
|
||||
return true;
|
||||
|
||||
if (item.getDouble(ItemStats.CUSTOM_DURABILITY.getNBTPath()) <= 0) {
|
||||
if (message) {
|
||||
Message.ZERO_DURABILITY.format(ChatColor.RED).send(player.getPlayer());
|
||||
player.getPlayer().playSound(player.getPlayer().getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1.5f);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -43,170 +43,177 @@ import org.jetbrains.annotations.Nullable;
|
||||
* amplifier and duration are not numeric formulas but flat values.... TODO
|
||||
*/
|
||||
public class PermanentEffects extends ItemStat<RandomPotionEffectListData, PotionEffectListData> {
|
||||
public PermanentEffects() {
|
||||
super("PERM_EFFECTS", Material.POTION, "Permanent Effects", new String[] { "The potion effects your", "item grants to the holder." },
|
||||
new String[] { "!miscellaneous", "!block", "all" });
|
||||
}
|
||||
public PermanentEffects() {
|
||||
super("PERM_EFFECTS", Material.POTION, "Permanent Effects", new String[]{"The potion effects your", "item grants to the holder."},
|
||||
new String[]{"!miscellaneous", "!block", "all"});
|
||||
}
|
||||
|
||||
@Override
|
||||
public RandomPotionEffectListData whenInitialized(Object object) {
|
||||
Validate.isTrue(object instanceof ConfigurationSection, "Must specify a config section");
|
||||
ConfigurationSection config = (ConfigurationSection) object;
|
||||
@Override
|
||||
public RandomPotionEffectListData whenInitialized(Object object) {
|
||||
Validate.isTrue(object instanceof ConfigurationSection, "Must specify a config section");
|
||||
ConfigurationSection config = (ConfigurationSection) object;
|
||||
|
||||
RandomPotionEffectListData effects = new RandomPotionEffectListData();
|
||||
RandomPotionEffectListData effects = new RandomPotionEffectListData();
|
||||
|
||||
for (String effect : config.getKeys(false)) {
|
||||
PotionEffectType type = PotionEffectType.getByName(effect.toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||
Validate.notNull(type, "Could not find potion effect type named '" + effect + "'");
|
||||
effects.add(new RandomPotionEffectData(type, new NumericStatFormula(config.get(effect))));
|
||||
}
|
||||
for (String effect : config.getKeys(false)) {
|
||||
PotionEffectType type = PotionEffectType.getByName(effect.toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||
Validate.notNull(type, "Could not find potion effect type named '" + effect + "'");
|
||||
effects.add(new RandomPotionEffectData(type, new NumericStatFormula(config.get(effect))));
|
||||
}
|
||||
|
||||
return effects;
|
||||
}
|
||||
return effects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
|
||||
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
||||
new StatEdition(inv, ItemStats.PERM_EFFECTS).enable("Write in the chat the permanent potion effect you want to add.",
|
||||
ChatColor.AQUA + "Format: {Effect Name} {Amplifier Numeric Formula}");
|
||||
@Override
|
||||
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
|
||||
if (event.getAction() == InventoryAction.PICKUP_ALL)
|
||||
new StatEdition(inv, ItemStats.PERM_EFFECTS).enable("Write in the chat the permanent potion effect you want to add.",
|
||||
ChatColor.AQUA + "Format: {Effect Name} {Amplifier Numeric Formula}");
|
||||
|
||||
if (event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||
if (inv.getEditedSection().contains("perm-effects")) {
|
||||
Set<String> set = inv.getEditedSection().getConfigurationSection("perm-effects").getKeys(false);
|
||||
String last = new ArrayList<>(set).get(set.size() - 1);
|
||||
inv.getEditedSection().set("perm-effects." + last, null);
|
||||
if (set.size() <= 1)
|
||||
inv.getEditedSection().set("perm-effects", null);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed " + last.substring(0, 1).toUpperCase()
|
||||
+ last.substring(1).toLowerCase() + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event.getAction() == InventoryAction.PICKUP_HALF) {
|
||||
if (inv.getEditedSection().contains("perm-effects")) {
|
||||
Set<String> set = inv.getEditedSection().getConfigurationSection("perm-effects").getKeys(false);
|
||||
String last = new ArrayList<>(set).get(set.size() - 1);
|
||||
inv.getEditedSection().set("perm-effects." + last, null);
|
||||
if (set.size() <= 1)
|
||||
inv.getEditedSection().set("perm-effects", null);
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed " + last.substring(0, 1).toUpperCase()
|
||||
+ last.substring(1).toLowerCase() + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
|
||||
String[] split = message.split(" ");
|
||||
Validate.isTrue(split.length >= 2, "Use this format: {Effect Name} {Effect Amplifier Numeric Formula}. Example: 'speed 1 0.3' "
|
||||
+ "stands for Speed 1, plus 0.3 level per item level (rounded up to lower int)");
|
||||
@Override
|
||||
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
|
||||
String[] split = message.split(" ");
|
||||
Validate.isTrue(split.length >= 2, "Use this format: {Effect Name} {Effect Amplifier Numeric Formula}. Example: 'speed 1 0.3' "
|
||||
+ "stands for Speed 1, plus 0.3 level per item level (rounded up to lower int)");
|
||||
|
||||
PotionEffectType effect = PotionEffectType.getByName(split[0].replace("-", "_"));
|
||||
Validate.notNull(effect, split[0] + " is not a valid potion effect. All potion effects can be found here: "
|
||||
+ "https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionEffectType.html");
|
||||
PotionEffectType effect = PotionEffectType.getByName(split[0].replace("-", "_"));
|
||||
Validate.notNull(effect, split[0] + " is not a valid potion effect. All potion effects can be found here: "
|
||||
+ "https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionEffectType.html");
|
||||
|
||||
NumericStatFormula formula = new NumericStatFormula(message.substring(message.indexOf(" ") + 1));
|
||||
formula.fillConfigurationSection(inv.getEditedSection(), "perm-effects." + effect.getName());
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(
|
||||
MMOItems.plugin.getPrefix() + ChatColor.GOLD + effect.getName() + " " + formula + ChatColor.GRAY + " successfully added.");
|
||||
}
|
||||
NumericStatFormula formula = new NumericStatFormula(message.substring(message.indexOf(" ") + 1));
|
||||
formula.fillConfigurationSection(inv.getEditedSection(), "perm-effects." + effect.getName());
|
||||
inv.registerTemplateEdition();
|
||||
inv.getPlayer().sendMessage(
|
||||
MMOItems.plugin.getPrefix() + ChatColor.GOLD + effect.getName() + " " + formula + ChatColor.GRAY + " successfully added.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenDisplayed(List<String> lore, Optional<RandomPotionEffectListData> statData) {
|
||||
if (statData.isPresent()) {
|
||||
lore.add(ChatColor.GRAY + "Current Value:");
|
||||
RandomPotionEffectListData data = statData.get();
|
||||
for (RandomPotionEffectData effect : data.getEffects())
|
||||
lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + MMOUtils.caseOnWords(effect.getType().getName().replace("_", " ").toLowerCase())
|
||||
+ " " + effect.getAmplifier().toString());
|
||||
@Override
|
||||
public void whenDisplayed(List<String> lore, Optional<RandomPotionEffectListData> statData) {
|
||||
if (statData.isPresent()) {
|
||||
lore.add(ChatColor.GRAY + "Current Value:");
|
||||
RandomPotionEffectListData data = statData.get();
|
||||
for (RandomPotionEffectData effect : data.getEffects())
|
||||
lore.add(ChatColor.GRAY + "* " + ChatColor.GREEN + MMOUtils.caseOnWords(effect.getType().getName().replace("_", " ").toLowerCase())
|
||||
+ " " + effect.getAmplifier().toString());
|
||||
|
||||
} else
|
||||
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "None");
|
||||
} else
|
||||
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "None");
|
||||
|
||||
lore.add("");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add an effect.");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last effect.");
|
||||
}
|
||||
lore.add("");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add an effect.");
|
||||
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last effect.");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PotionEffectListData getClearStatData() {
|
||||
return new PotionEffectListData();
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
public PotionEffectListData getClearStatData() {
|
||||
return new PotionEffectListData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull PotionEffectListData data) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
@Override
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull PotionEffectListData data) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
String permEffectFormat = ItemStat.translate("perm-effect");
|
||||
((PotionEffectListData) data).getEffects().forEach(effect -> {
|
||||
lore.add(permEffectFormat.replace("{effect}", MMOItems.plugin.getLanguage().getPotionEffectName(effect.getType()) + " " + MMOUtils.intToRoman(effect.getLevel())));
|
||||
});
|
||||
String permEffectFormat = getGeneralStatFormat();
|
||||
data.getEffects().forEach(effect -> lore.add(permEffectFormat
|
||||
.replace("{effect}", MMOItems.plugin.getLanguage().getPotionEffectName(effect.getType())
|
||||
+ " " + MMOUtils.intToRoman(effect.getLevel()))));
|
||||
|
||||
item.getLore().insert("perm-effects", lore);
|
||||
item.getLore().insert("perm-effects", lore);
|
||||
|
||||
// Yes
|
||||
item.addItemTag(getAppliedNBT(data));
|
||||
}
|
||||
// Yes
|
||||
item.addItemTag(getAppliedNBT(data));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ArrayList<ItemTag> getAppliedNBT(@NotNull PotionEffectListData data) {
|
||||
@Override
|
||||
public String getLegacyTranslationPath() {
|
||||
return "perm-effect";
|
||||
}
|
||||
|
||||
// Them tags
|
||||
ArrayList<ItemTag> ret = new ArrayList<>();
|
||||
JsonObject object = new JsonObject();
|
||||
@NotNull
|
||||
@Override
|
||||
public ArrayList<ItemTag> getAppliedNBT(@NotNull PotionEffectListData data) {
|
||||
|
||||
// For every registered effect
|
||||
for (PotionEffectData effect : data.getEffects()) {
|
||||
// Them tags
|
||||
ArrayList<ItemTag> ret = new ArrayList<>();
|
||||
JsonObject object = new JsonObject();
|
||||
|
||||
// Add Properies
|
||||
object.addProperty(effect.getType().getName(), effect.getLevel());
|
||||
}
|
||||
// For every registered effect
|
||||
for (PotionEffectData effect : data.getEffects()) {
|
||||
|
||||
// Add onto the list
|
||||
ret.add(new ItemTag(getNBTPath(), object.toString()));
|
||||
// Add Properies
|
||||
object.addProperty(effect.getType().getName(), effect.getLevel());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
// Add onto the list
|
||||
ret.add(new ItemTag(getNBTPath(), object.toString()));
|
||||
|
||||
@Override
|
||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Find tags
|
||||
ArrayList<ItemTag> rTag = new ArrayList<>();
|
||||
if (mmoitem.getNBT().hasTag(getNBTPath()))
|
||||
rTag.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
||||
@Override
|
||||
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
|
||||
|
||||
// Build Data
|
||||
StatData data = getLoadedNBT(rTag);
|
||||
// Find tags
|
||||
ArrayList<ItemTag> rTag = new ArrayList<>();
|
||||
if (mmoitem.getNBT().hasTag(getNBTPath()))
|
||||
rTag.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.STRING));
|
||||
|
||||
// Add data, if valid
|
||||
if (data != null) { mmoitem.setData(this, data); }
|
||||
}
|
||||
// Build Data
|
||||
StatData data = getLoadedNBT(rTag);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PotionEffectListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
||||
// Add data, if valid
|
||||
if (data != null) {
|
||||
mmoitem.setData(this, data);
|
||||
}
|
||||
}
|
||||
|
||||
// Find tag
|
||||
ItemTag oTag = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
||||
@Nullable
|
||||
@Override
|
||||
public PotionEffectListData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
|
||||
|
||||
// Well
|
||||
if (oTag != null) {
|
||||
// Find tag
|
||||
ItemTag oTag = ItemTag.getTagAtPath(getNBTPath(), storedTags);
|
||||
|
||||
// Parse as Json
|
||||
try {
|
||||
// Well
|
||||
if (oTag != null) {
|
||||
|
||||
// A new effect
|
||||
PotionEffectListData effects = new PotionEffectListData();
|
||||
// Parse as Json
|
||||
try {
|
||||
|
||||
JsonElement element = new JsonParser().parse((String) oTag.getValue());
|
||||
// A new effect
|
||||
PotionEffectListData effects = new PotionEffectListData();
|
||||
|
||||
element.getAsJsonObject().entrySet().forEach(entry ->
|
||||
effects.add(new PotionEffectData(PotionEffectType.getByName(entry.getKey()), entry.getValue().getAsInt())));
|
||||
JsonElement element = new JsonParser().parse((String) oTag.getValue());
|
||||
|
||||
// Thats it
|
||||
return effects;
|
||||
element.getAsJsonObject().entrySet().forEach(entry ->
|
||||
effects.add(new PotionEffectData(PotionEffectType.getByName(entry.getKey()), entry.getValue().getAsInt())));
|
||||
|
||||
} catch (JsonSyntaxException |IllegalStateException exception) {
|
||||
/*
|
||||
* OLD ITEM WHICH MUST BE UPDATED.
|
||||
*/
|
||||
}
|
||||
}
|
||||
// Thats it
|
||||
return effects;
|
||||
|
||||
// Noep
|
||||
return null;
|
||||
}
|
||||
} catch (JsonSyntaxException | IllegalStateException exception) {
|
||||
/*
|
||||
* OLD ITEM WHICH MUST BE UPDATED.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// Noep
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class RequiredLevel extends DoubleStat implements ItemRestriction {
|
||||
|
||||
// Lore Management
|
||||
int lvl = (int) data.getValue();
|
||||
item.getLore().insert("required-level", formatNumericStat(lvl, "{value}", String.valueOf(lvl)));
|
||||
item.getLore().insert(getPath(), formatNumericStat(lvl, "{value}", String.valueOf(lvl)));
|
||||
|
||||
// Insert NBT
|
||||
item.addItemTag(getAppliedNBT(data));
|
||||
@ -51,8 +51,8 @@ public class RequiredLevel extends DoubleStat implements ItemRestriction {
|
||||
public void whenPreviewed(@NotNull ItemStackBuilder item, @NotNull DoubleData currentData, @NotNull NumericStatFormula templateData) throws IllegalArgumentException {
|
||||
|
||||
// Get Value
|
||||
double techMinimum = ((NumericStatFormula) templateData).calculate(0, -2.5);
|
||||
double techMaximum = ((NumericStatFormula) templateData).calculate(0, 2.5);
|
||||
double techMinimum = templateData.calculate(0, -2.5);
|
||||
double techMaximum = templateData.calculate(0, 2.5);
|
||||
|
||||
// Cancel if it its NEGATIVE and this doesn't support negative stats.
|
||||
if (techMaximum < 0 && !handleNegativeStats()) {
|
||||
@ -61,11 +61,11 @@ public class RequiredLevel extends DoubleStat implements ItemRestriction {
|
||||
if (techMinimum < 0 && !handleNegativeStats()) {
|
||||
techMinimum = 0;
|
||||
}
|
||||
if (techMinimum < ((NumericStatFormula) templateData).getBase() - ((NumericStatFormula) templateData).getMaxSpread()) {
|
||||
techMinimum = ((NumericStatFormula) templateData).getBase() - ((NumericStatFormula) templateData).getMaxSpread();
|
||||
if (techMinimum < templateData.getBase() - templateData.getMaxSpread()) {
|
||||
techMinimum = templateData.getBase() - templateData.getMaxSpread();
|
||||
}
|
||||
if (techMaximum > ((NumericStatFormula) templateData).getBase() + ((NumericStatFormula) templateData).getMaxSpread()) {
|
||||
techMaximum = ((NumericStatFormula) templateData).getBase() + ((NumericStatFormula) templateData).getMaxSpread();
|
||||
if (techMaximum > templateData.getBase() + templateData.getMaxSpread()) {
|
||||
techMaximum = templateData.getBase() + templateData.getMaxSpread();
|
||||
}
|
||||
|
||||
// Add NBT Path
|
||||
@ -82,7 +82,7 @@ public class RequiredLevel extends DoubleStat implements ItemRestriction {
|
||||
}
|
||||
|
||||
// Just display normally
|
||||
item.getLore().insert("required-level", formatNumericStat(techMinimum, "{value}", builtRange));
|
||||
item.getLore().insert(getPath(), formatNumericStat(techMinimum, "{value}", builtRange));
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ public class RequiredLevel extends DoubleStat implements ItemRestriction {
|
||||
|
||||
// Make and bake
|
||||
ArrayList<ItemTag> ret = new ArrayList<>();
|
||||
ret.add(new ItemTag(getNBTPath(), ((DoubleData) data).getValue()));
|
||||
ret.add(new ItemTag(getNBTPath(), data.getValue()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class UpgradeStat extends ItemStat<UpgradeData, UpgradeData> implements C
|
||||
// Show in lore
|
||||
if (data.getMaxUpgrades() > 0)
|
||||
item.getLore().insert(getPath(),
|
||||
MMOItems.plugin.getLanguage().getStatFormat(getPath()).replace("{value}", String.valueOf(data.getMaxUpgrades())));
|
||||
getGeneralStatFormat().replace("{value}", String.valueOf(data.getMaxUpgrades())));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@ -52,7 +52,7 @@ public class BooleanStat extends ItemStat<RandomBooleanData, BooleanData> {
|
||||
item.addItemTag(getAppliedNBT(data));
|
||||
|
||||
// Show in lore
|
||||
item.getLore().insert(getPath(), MMOItems.plugin.getLanguage().getStatFormat(getPath()));
|
||||
item.getLore().insert(getPath(), getGeneralStatFormat());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import net.Indyuce.mmoitems.gui.edition.EditionInventory;
|
||||
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
|
||||
import net.Indyuce.mmoitems.stat.data.type.StatData;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -148,6 +149,26 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
|
||||
*/
|
||||
public abstract void whenDisplayed(List<String> lore, Optional<R> statData);
|
||||
|
||||
protected String generalStatFormat;
|
||||
|
||||
@Deprecated
|
||||
public void loadConfiguration(@NotNull ConfigurationSection legacyLanguageFile, @NotNull Object configObject) {
|
||||
loadConfiguration(configObject);
|
||||
}
|
||||
|
||||
public void loadConfiguration(@NotNull Object configObject) {
|
||||
generalStatFormat = configObject.toString();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getLegacyTranslationPath() {
|
||||
return getPath();
|
||||
}
|
||||
|
||||
public String getGeneralStatFormat() {
|
||||
return generalStatFormat;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -166,7 +187,7 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
|
||||
/**
|
||||
* @return The stat ID
|
||||
* @deprecated Use getId() instead. Type is no longer an util since they can
|
||||
* now be registered from external plugins
|
||||
* now be registered from external plugins
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
@ -184,8 +205,8 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
|
||||
|
||||
/**
|
||||
* @return The NBT path used by the stat to save data in an item's NBTTags.
|
||||
* The format is 'MMOITEMS_' followed by the stat name in capital
|
||||
* letters only using _
|
||||
* The format is 'MMOITEMS_' followed by the stat name in capital
|
||||
* letters only using _
|
||||
*/
|
||||
@NotNull
|
||||
public String getNBTPath() {
|
||||
@ -228,10 +249,9 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
|
||||
}
|
||||
|
||||
public String formatNumericStat(double value, String... replace) {
|
||||
String format = MMOItems.plugin.getLanguage().getStatFormat(getPath()).replace("<plus>", value > 0 ? "+" : "");
|
||||
for (int j = 0; j < replace.length; j += 2) {
|
||||
String format = getGeneralStatFormat().replace("<plus>", value > 0 ? "+" : "");
|
||||
for (int j = 0; j < replace.length; j += 2)
|
||||
format = format.replace(replace[j], replace[j + 1]);
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
@ -248,9 +268,9 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
|
||||
return Objects.hash(id);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String translate(String path) {
|
||||
String str = MMOItems.plugin.getLanguage().getStatFormat(path);
|
||||
return str == null ? "<TranslationNotFound:" + path + ">" : str;
|
||||
return MMOItems.plugin.getLanguage().getStatFormat(path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,8 +39,8 @@ public abstract class RequiredLevelStat extends DoubleStat implements ItemRestri
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull DoubleData data) {
|
||||
|
||||
// Lore Management
|
||||
int lvl = (int) ((DoubleData) data).getValue();
|
||||
String format = MMOItems.plugin.getLanguage().getStatFormat(getPath()).replace("{value}", String.valueOf(lvl));
|
||||
int lvl = (int) data.getValue();
|
||||
String format = getGeneralStatFormat().replace("{value}", String.valueOf(lvl));
|
||||
item.getLore().insert(getPath(), format);
|
||||
|
||||
// Insert NBT
|
||||
|
@ -42,92 +42,16 @@ public class StringListStat extends ItemStat<StringListData, StringListData> {
|
||||
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringListData data) {
|
||||
|
||||
// Empty stuff
|
||||
if (!(data instanceof StringListData)) { return; }
|
||||
if (data.getList().size() == 0) { return; }
|
||||
if (!(data instanceof StringListData)) return;
|
||||
if (data.getList().size() == 0) return;
|
||||
|
||||
// Chop
|
||||
final String joined = String.join(", ", data.getList());
|
||||
final String format = MMOItems.plugin.getLanguage().getStatFormat(getPath());
|
||||
final String format = getGeneralStatFormat();
|
||||
final String finalStr = format.replace("{value}", joined);
|
||||
|
||||
/*
|
||||
// Identify colour
|
||||
StringBuilder col = new StringBuilder(""); int pnd = format.indexOf('#');
|
||||
if (pnd > 0) {
|
||||
|
||||
// Everything before thay pound
|
||||
String input = format.substring(0, pnd);
|
||||
int length = input.length();
|
||||
|
||||
for(int index = length - 1; index > -1; --index) {
|
||||
|
||||
// Observe char
|
||||
char section = input.charAt(index);
|
||||
|
||||
boolean isSection = (section == '\u00a7' || section == '&');
|
||||
boolean isAngle = (section == '<');
|
||||
|
||||
// Is there at least one char, as for it to be a color code
|
||||
if (isSection && index < (length - 1)) {
|
||||
|
||||
// Observe next character
|
||||
char c = input.charAt(index + 1);
|
||||
ChatColor color = ChatColor.getByChar(c);
|
||||
|
||||
// Was it a color code?
|
||||
if (color != null) {
|
||||
|
||||
// That's our color
|
||||
col.insert(0, color.toString());
|
||||
|
||||
// If its a reset or a color character, that's the end
|
||||
if (color.isColor() || color == ChatColor.RESET) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If there is at least 10 chars, as for it to complete HEX######>
|
||||
} else if(isAngle && index < (length - 10)) {
|
||||
|
||||
// Observe tenth characters
|
||||
char aC = input.charAt(index + 10);
|
||||
|
||||
// Closing bracket
|
||||
if (aC == '>') {
|
||||
|
||||
// Observe hex
|
||||
char lH = input.charAt(index + 1);
|
||||
char lE = input.charAt(index + 2);
|
||||
char lX = input.charAt(index + 3);
|
||||
if (lH == 'H' && lE == 'E' && lX == 'X') {
|
||||
|
||||
// Get hex
|
||||
char c1 = input.charAt(index + 4);
|
||||
char c2 = input.charAt(index + 5);
|
||||
char c3 = input.charAt(index + 6);
|
||||
char c4 = input.charAt(index + 7);
|
||||
char c5 = input.charAt(index + 8);
|
||||
char c6 = input.charAt(index + 9);
|
||||
|
||||
col.insert(0, '>')
|
||||
.insert(0, c6)
|
||||
.insert(0, c5)
|
||||
.insert(0, c4)
|
||||
.insert(0, c3)
|
||||
.insert(0, c2)
|
||||
.insert(0, c1)
|
||||
.insert(0, "<HEX");
|
||||
|
||||
// Um yes that qualifies as a color code
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
// Display in lore
|
||||
// item.getLore().insert(getPath(), SilentNumbers.chop(finalStr, 50, col.toString()));
|
||||
// item.getLore().insert(getPath(), SilentNumbers.chop(finalStr, 50, col.toString()));
|
||||
item.getLore().insert(getPath(), finalStr);
|
||||
item.addItemTag(getAppliedNBT(data));
|
||||
}
|
||||
@ -140,7 +64,7 @@ public class StringListStat extends ItemStat<StringListData, StringListData> {
|
||||
JsonArray array = new JsonArray();
|
||||
|
||||
// For every list entry
|
||||
for (String str : ((StringListData) data).getList()) {
|
||||
for (String str : data.getList()) {
|
||||
|
||||
// Add to the array as-is
|
||||
array.add(str);
|
||||
@ -196,7 +120,9 @@ public class StringListStat extends ItemStat<StringListData, StringListData> {
|
||||
StatData data = getLoadedNBT(relevantTags);
|
||||
|
||||
// Valid?
|
||||
if (data != null) { mmoitem.setData(this, data); }
|
||||
if (data != null) {
|
||||
mmoitem.setData(this, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -216,7 +142,7 @@ public class StringListStat extends ItemStat<StringListData, StringListData> {
|
||||
// Create String List Data
|
||||
return new StringListData(array);
|
||||
|
||||
} catch (JsonSyntaxException |IllegalStateException exception) {
|
||||
} catch (JsonSyntaxException | IllegalStateException exception) {
|
||||
/*
|
||||
* OLD ITEM WHICH MUST BE UPDATED.
|
||||
*/
|
||||
|
@ -30,10 +30,14 @@ physical-damage: '&3 &7■ Physical Damage: &f<plus>{value}%'
|
||||
projectile-damage: '&3 &7■ Projectile Damage: &f<plus>{value}%'
|
||||
faction-damage-undead: '&3 &7■ Undead Faction Damage: &f<plus>{value}%'
|
||||
|
||||
# Abilities
|
||||
ability-format: '&a>&8| &7{trigger} &8|&e|&8| &7&l{ability}'
|
||||
ability-modifier: ' &3>&8|&7 {modifier}&8: &f{value}'
|
||||
ability-splitter: '&8'
|
||||
# Abilities (changed in MI 6.9.5)
|
||||
ability:
|
||||
general-format: "&f䀐 &7{trigger} &8|&e|&8| &7&l{ability}\n"
|
||||
modifier-foreach: "&7{modifier}&8: &f{value}"
|
||||
modifier-splitter: " &8&l|&7 "
|
||||
ability-splitter:
|
||||
enabled: true
|
||||
format: ''
|
||||
|
||||
# Armor Stats
|
||||
block-power: '&3 &7■ Block Power: &f<plus>{value}%'
|
||||
@ -78,8 +82,8 @@ additional-experience-smithing: '&7■ Additional Smithing Experience: &f<plus>{
|
||||
additional-experience-woodcutting: '&7■ Additional Woodcutting Experience: &f<plus>{value}%'
|
||||
|
||||
# Extra Options
|
||||
perm-effect: '&3 &7■ Permanent &f{effect}'
|
||||
command: '&3 &7■ Command: &f{format} &3 &7(&f{cooldown}&3 &7s)'
|
||||
perm-effects: '&3 &7■ Permanent &f{effect}'
|
||||
commands: '&3 &7■ Command: &f{format} &3 &7(&f{cooldown}&3 &7s)'
|
||||
item-cooldown: '&3 &7■ &f{value}&3 &7s Cooldown'
|
||||
arrow-potion-effects: '&3 &7■ Arrow Effect: &f{effect}'
|
||||
|
||||
@ -89,7 +93,7 @@ restore-food: '&3 &7■ Restores &f{value} &7Food'
|
||||
restore-saturation: '&3 &7■ Restores &f{value} &7Saturation'
|
||||
restore-mana: '&3 &7■ Restores &f{value} &7Mana'
|
||||
restore-stamina: '&3 &7■ Restores &f{value} &7Stamina'
|
||||
effect: '&3 &7■ Grants &f{effect} &7for &f{duration} &7s'
|
||||
effects: '&3 &7■ Grants &f{effect} &7for &f{duration} &7s'
|
||||
repair: '&3 &7■ Repair: &f{value}'
|
||||
repair-percent: '&3 &7■ Repair: &f{value}%'
|
||||
can-identify: '&3 &7■ Can identify items.'
|
||||
@ -99,10 +103,9 @@ success-rate: '&3 &7■ Success Rate: &a&l{value}%'
|
||||
max-consume: '&3 &7■ &f{value} &7Uses Left'
|
||||
|
||||
# Gem Stones
|
||||
empty-gem-socket: '&a◆ Empty {name} Gem Socket'
|
||||
filled-gem-socket: '&a◆ {name}'
|
||||
when-applied: '&aWhen Applied:'
|
||||
gem-stone-lore: '&8&l[&2&l*&8&l] &aDrag onto an item &7to apply!'
|
||||
gem-sockets:
|
||||
empty-gem-socket: '&a◆ Empty {name} Gem Socket'
|
||||
filled-gem-socket: '&a◆ {name}'
|
||||
|
||||
# Soulbound
|
||||
soulbinding-chance: '&3 &7■ Has a &a{value}% &7chance to bind your item.'
|
||||
@ -113,10 +116,9 @@ soulbound-level: '&3 &7■ Level &e{value} &7Soulbound'
|
||||
autosmelt: '&3 &7■ &fAutosmelt'
|
||||
bouncing-crack: '&3 &7■ &fBouncing Crack'
|
||||
pickaxe-power: '&3 &7■ &fPickaxe Power: &a{value}'
|
||||
durability: '&7Durability: {current} / {max}'
|
||||
item-damage: '&7Durability: {current} / {max}'
|
||||
|
||||
# General
|
||||
item-type: '&c{type}'
|
||||
tier: '&3 &7Tier: {value}'
|
||||
required-class: '&3 &7{value} Item'
|
||||
required-level: '&eRequires Lvl {value}'
|
||||
@ -140,12 +142,13 @@ profession-smelting: '&eSmelting Level: &c{value}'
|
||||
profession-smithing: '&eSmithing Level: &c{value}'
|
||||
profession-woodcutting: '&eWoodcutting Level: &c{value}'
|
||||
|
||||
# Elemental Stat Format
|
||||
elemental-damage: '{color}{icon}&7 {value} {element} Damage'
|
||||
elemental-damage-percent: '{color}{icon}&7 +{value}% {element} Damage'
|
||||
elemental-defense: '{color}{icon}&7 {value} {element} Defense'
|
||||
elemental-defense-percent: '{color}{icon}&7 +{value}% {element} Defense'
|
||||
elemental-weakness: '{color}{icon}&7 {value}% {element} Weakness'
|
||||
# Elemental Stat Formats
|
||||
element:
|
||||
damage: '{color}{icon}&7 {value} {element} Damage'
|
||||
damage-percent: '{color}{icon}&7 +{value}% {element} Damage'
|
||||
defense: '{color}{icon}&7 {value} {element} Defense'
|
||||
defense-percent: '{color}{icon}&7 +{value}% {element} Defense'
|
||||
weakness: '{color}{icon}&7 {value}% {element} Weakness'
|
||||
|
||||
# Custom stats
|
||||
custom-myluck: '&3 &7■ Luck: &f<plus>{value}'
|
Loading…
Reference in New Issue
Block a user