Support for armor trims

This commit is contained in:
Jules 2023-06-18 18:40:59 +02:00
parent 31725146b5
commit 9bb85a2977
12 changed files with 286 additions and 140 deletions

View File

@ -122,7 +122,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18-R0.1-SNAPSHOT</version>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-clean-plugin -->

View File

@ -183,6 +183,8 @@ public class ItemStats {
SKULL_TEXTURE = new SkullTextureStat(),
DYE_COLOR = new DyeColor(),
HIDE_DYE = new HideDye(),
TRIM_MATERIAL = new TrimMaterialStat(),
TRIM_PATTERN = new TrimPatternStat(),
POTION_EFFECTS = new PotionEffects(),
POTION_COLOR = new PotionColor(),
SHIELD_PATTERN = new ShieldPatternStat(),

View File

@ -163,19 +163,16 @@ public class GemStone extends UseItem {
* Get the item's level, important for the GemScalingStat
*/
Integer levelIdentified = null;
String scaling = GemUpgradeScaling.defaultValue;
if (gemMMOItem.hasData(ItemStats.GEM_UPGRADE_SCALING)) {
scaling = gemMMOItem.getData(ItemStats.GEM_UPGRADE_SCALING).toString();
}
final String scaling = gemMMOItem.hasData(ItemStats.GEM_UPGRADE_SCALING) ? gemMMOItem.getData(ItemStats.GEM_UPGRADE_SCALING).toString() : GemUpgradeScaling.defaultValue;
//UPGRD//MMOItems.log("Scaling Identified: \u00a73" + scaling);
switch (scaling) {
case GemUpgradeScaling.HISTORIC:
case "HISTORIC":
levelIdentified = 0;
break;
case GemUpgradeScaling.SUBSEQUENT:
case "SUBSEQUENT":
levelIdentified = targetMMO.getUpgradeLevel();
break;
case GemUpgradeScaling.NEVER:
case "NEVER":
default:
break;
}

View File

@ -93,10 +93,12 @@ public class ItemStackBuilder {
* of a specific material (like the Shield Pattern stat which checks if
* the item is a shield)
*/
@NotNull
public ItemStack getItemStack() {
return item;
}
@NotNull
public ItemMeta getMeta() {
return meta;
}

View File

@ -170,7 +170,7 @@ public class ConfigManager implements Reloadable {
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");
GemUpgradeScaling.defaultValue = MMOItems.plugin.getConfig().getString("gem-upgrade-default", GemUpgradeScaling.SUBSEQUENT);
GemUpgradeScaling.defaultValue = MMOItems.plugin.getConfig().getString("gem-upgrade-default", GemUpgradeScaling.SUBSEQUENT.getId());
keepSoulboundOnDeath = MMOItems.plugin.getConfig().getBoolean("soulbound.keep-on-death");
rerollOnItemUpdate = MMOItems.plugin.getConfig().getBoolean("item-revision.reroll-when-updated");
levelSpread = MMOItems.plugin.getConfig().getDouble("item-level-spread");

View File

@ -9,6 +9,7 @@ import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.stat.type.ItemRestriction;
import net.Indyuce.mmoitems.util.StatChoice;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@ -21,112 +22,123 @@ import java.util.ArrayList;
* @author Gunging
*/
public class Amphibian extends ChooseStat implements ItemRestriction, GemStoneStat {
public static final String
NORMAL = "UNRESTRICTED",
DRY = "DRY",
WET = "WET",
DAMP = "DAMP",
LAVA = "LAVA",
MOLTEN = "MOLTEN",
LIQUID = "LIQUID",
SUBMERGED = "SUBMERGED";
public static final StatChoice
NORMAL = new StatChoice("NORMAL", "No liquids dependency"),
DRY = new StatChoice("DRY", "The item does not work if the player is touching a liquid block."),
WET = new StatChoice("WET", "The only works if the player is touching water (rain does not count)."),
DAMP = new StatChoice("DAMP", "The only works if the player is completely submerged in water."),
LAVA = new StatChoice("LAVA", "The only works if the player is touching lava."),
MOLTEN = new StatChoice("MOLTEN", "The only works if the player is completely submerged in lava."),
LIQUID = new StatChoice("LIQUID", "The only works if the player is touching any liquid."),
SUBMERGED = new StatChoice("SUBMERGED", "The only works if the player is completely submerged in any liquid.");
public Amphibian() {
super("AMPHIBIAN", Material.WATER_BUCKET, "Amphibian", new String[]{"May this item only be used in specific", "environments regarding liquids?"}, new String[]{"!block", "all"});
addChoices(NORMAL, DRY, WET, DAMP, LAVA, MOLTEN, LIQUID, SUBMERGED);
// Put definitions
setHint(NORMAL, "No liquids dependency");
setHint(DRY, "The item does not work if the player is touching a liquid block.");
setHint(WET, "The only works if the player is touching water (rain does not count).");
setHint(DAMP, "The only works if the player is completely submerged in water.");
setHint(LAVA, "The only works if the player is touching lava.");
setHint(MOLTEN, "The only works if the player is completely submerged in lava.");
setHint(LIQUID, "The only works if the player is touching any liquid.");
setHint(SUBMERGED, "The only works if the player is completely submerged in any liquid.");
}
@NotNull
@Override public StringData getClearStatData() { return new StringData(NORMAL); }
@Override
public StringData getClearStatData() {
return new StringData(NORMAL.getId());
}
@Override
public boolean canUse(RPGPlayer player, NBTItem item, boolean message) {
// bruh
if (!item.hasTag(getNBTPath())) { return true; }
if (!item.hasTag(getNBTPath())) {
return true;
}
// Find the relevant tags
ArrayList<ItemTag> relevantTags = new ArrayList<>();
if (item.hasTag(getNBTPath())) { relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), item, SupportedNBTTagValues.STRING)); }
if (item.hasTag(getNBTPath())) {
relevantTags.add(ItemTag.getTagAtPath(getNBTPath(), item, SupportedNBTTagValues.STRING));
}
// Generate data
StringData data = (StringData) getLoadedNBT(relevantTags);
String data = getLoadedNBT(relevantTags).toString();
// Well...
if (data != null) {
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a77 Checking Amphibian: \u00a7f" + item.getType() + " \u00a7b" + data.toString());
// Switch
switch (data.toString()) {
case NORMAL:
switch (data) {
case "NORMAL":
default:
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a>\u00a77 Normal \u00a7aSucceed");
return true;
case DRY:
case "DRY":
for (Block b : blocksTouchedByPlayer(player.getPlayer())) {
//BKK//MMOItems. Log(" \u00a77>\u00a77>\u00a73>\u00a77 Examining \u00a7f" + b.getType().toString());
if (b.isLiquid()) {
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a> \u00a7cFail");
return false; } }
return false;
}
}
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a> \u00a7aSucceed");
return true;
case WET:
case "WET":
for (Block b : blocksTouchedByPlayer(player.getPlayer())) {
//BKK//MMOItems. Log(" \u00a77>\u00a77>\u00a73>\u00a77 Examining \u00a7f" + b.getType().toString());
if (b.getType().equals(Material.WATER)) {
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a> \u00a7aSucceed");
return true; } }
return true;
}
}
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a> \u00a7cFail");
return false;
case DAMP:
case "DAMP":
for (Block b : blocksTouchedByPlayer(player.getPlayer())) {
//BKK//MMOItems. Log(" \u00a77>\u00a77>\u00a73>\u00a77 Examining \u00a7f" + b.getType().toString());
if (!b.getType().equals(Material.WATER)) {
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a> \u00a7cFail");
return false; } }
return false;
}
}
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a> \u00a7aSucceed");
return true;
case LAVA:
case "LAVA":
for (Block b : blocksTouchedByPlayer(player.getPlayer())) {
//BKK//MMOItems. Log(" \u00a77>\u00a77>\u00a73>\u00a77 Examining \u00a7f" + b.getType().toString());
if (b.getType().equals(Material.LAVA)) {
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a> \u00a7aSucceed");
return true; } }
return true;
}
}
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a> \u00a7cFail");
return false;
case MOLTEN:
case "MOLTEN":
for (Block b : blocksTouchedByPlayer(player.getPlayer())) {
//BKK//MMOItems. Log(" \u00a77>\u00a77>\u00a73>\u00a77 Examining \u00a7f" + b.getType().toString());
if (!b.getType().equals(Material.LAVA)) {
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a> \u00a7cFail");
return false; } }
return false;
}
}
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a> \u00a7aSucceed");
return true;
case LIQUID:
case "LIQUID":
for (Block b : blocksTouchedByPlayer(player.getPlayer())) {
//BKK//MMOItems. Log(" \u00a77>\u00a77>\u00a73>\u00a77 Examining \u00a7f" + b.getType().toString());
if (b.isLiquid()) {
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a> \u00a7aSucceed");
return true; } }
return true;
}
}
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a> \u00a7cFail");
return false;
case SUBMERGED:
case "SUBMERGED":
for (Block b : blocksTouchedByPlayer(player.getPlayer())) {
//BKK//MMOItems. Log(" \u00a77>\u00a77>\u00a73>\u00a77 Examining \u00a7f" + b.getType().toString());
if (!b.isLiquid()) {
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a> \u00a7cFail");
return false; } }
return false;
}
}
//BKK//MMOItems. Log(" \u00a7a>\u00a73>\u00a7a> \u00a7aSucceed");
return true;
}
@ -135,7 +147,9 @@ public class Amphibian extends ChooseStat implements ItemRestriction, GemStoneSt
}
@Override
public boolean isDynamic() { return true; }
public boolean isDynamic() {
return true;
}
// Yes
ArrayList<Block> blocksTouchedByPlayer(@NotNull Player p) {
@ -152,9 +166,9 @@ public class Amphibian extends ChooseStat implements ItemRestriction, GemStoneSt
for (double dz = box.getMinZ(); dz <= box.getMaxZ(); dz += Math.min(1, Math.max(box.getWidthZ() - (dz - box.getMinZ()), 0.001))) {
// Exclusion
int dxI =SilentNumbers.floor(dx);
int dyI =SilentNumbers.floor(dy);
int dzI =SilentNumbers.floor(dz);
int dxI = SilentNumbers.floor(dx);
int dyI = SilentNumbers.floor(dy);
int dzI = SilentNumbers.floor(dz);
//BKK//MMOItems. Log(" \u00a77at \u00a76" + dxI + " " + dyI + " " + dzI + "\u00a78 (" + dx + " " + dy + " " + dz + ")");

View File

@ -5,6 +5,7 @@ import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.util.StatChoice;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
@ -13,24 +14,24 @@ import java.util.HashMap;
* Defines how gem stats will scale when the item they are put on upgrades.
*/
public class GemUpgradeScaling extends ChooseStat implements GemStoneStat {
public static final String NEVER = "NEVER", HISTORIC = "HISTORIC", SUBSEQUENT = "SUBSEQUENT";
public static final StatChoice
NEVER = new StatChoice("NEVER", "Gem stats are never scaled by upgrading the item."),
HISTORIC = new StatChoice("HISTORIC", "Gem stats instantly upgrade to the current item level, and subsequently thereafter."),
SUBSEQUENT = new StatChoice("SUBSEQUENT", "Gem stats scale by upgrading the item, but only after putting the gem in.");
/**
* Can't be final as it is a plugin configuration option
*/
public static String defaultValue = SUBSEQUENT;
public static String defaultValue = SUBSEQUENT.getId();
public GemUpgradeScaling() {
super("GEM_UPGRADE_SCALING", VersionMaterial.LIME_DYE.toMaterial(), "Gem Upgrade Scaling", new String[] { "Gem stones add their stats to items, but you may also", "upgrade your items via crafting stations or consumables.", "", "\u00a76Should this gem stone stats be affected by upgrading?" }, new String[] { "gem_stone" });
// Set the acceptable values
addChoices(SUBSEQUENT, NEVER, HISTORIC);
// Put definitions
setHint(SUBSEQUENT, "Gem stats scale by upgrading the item, but only after putting the gem in.");
setHint(NEVER, "Gem stats are never scaled by upgrading the item.");
setHint(HISTORIC, "Gem stats instantly upgrade to the current item level, and subsequently thereafter.");
}
@NotNull @Override public StringData getClearStatData() { return new StringData(defaultValue); }
@NotNull
@Override
public StringData getClearStatData() { return new StringData(defaultValue); }
}

View File

@ -0,0 +1,54 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.MythicLib;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.util.StatChoice;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.inventory.meta.ArmorMeta;
import org.bukkit.inventory.meta.trim.ArmorTrim;
import org.bukkit.inventory.meta.trim.TrimMaterial;
import org.bukkit.inventory.meta.trim.TrimPattern;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
/**
* @author Jules
*/
public class TrimMaterialStat extends ChooseStat implements GemStoneStat {
public TrimMaterialStat() {
super("TRIM_MATERIAL", Material.LEATHER_CHESTPLATE, "Trim Material", new String[]{"Material to trim your armor with."}, new String[]{"armor"});
if (MythicLib.plugin.getVersion().isBelowOrEqual(1, 19)) disable();
for (TrimMaterial mat : Registry.TRIM_MATERIAL)
addChoices(new StatChoice(mat.getKey().getKey()));
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
if (!(item.getMeta() instanceof ArmorMeta)) return;
@Nullable TrimMaterial material = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft(data.toString().toLowerCase()));
if (material == null) return;
final ArmorMeta meta = (ArmorMeta) item.getMeta();
final ArmorTrim currentTrim = meta.hasTrim() ? meta.getTrim() : new ArmorTrim(TrimMaterial.AMETHYST, TrimPattern.COAST);
meta.setTrim(new ArmorTrim(material, currentTrim.getPattern()));
}
@Override
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
if (!(mmoitem.getNBT().getItem().getItemMeta() instanceof ArmorMeta)) return;
final ArmorMeta meta = (ArmorMeta) mmoitem.getNBT().getItem().getItemMeta();
if (!meta.hasTrim()) return;
mmoitem.setData(this, new StringData(meta.getTrim().getMaterial().getKey().getKey()));
}
}

View File

@ -0,0 +1,52 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.MythicLib;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import net.Indyuce.mmoitems.util.StatChoice;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.inventory.meta.ArmorMeta;
import org.bukkit.inventory.meta.trim.ArmorTrim;
import org.bukkit.inventory.meta.trim.TrimMaterial;
import org.bukkit.inventory.meta.trim.TrimPattern;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author Jules
*/
public class TrimPatternStat extends ChooseStat implements GemStoneStat {
public TrimPatternStat() {
super("TRIM_PATTERN", Material.LEATHER_CHESTPLATE, "Trim Pattern", new String[]{"Pattern of trimmed armor."}, new String[]{"armor"});
if (MythicLib.plugin.getVersion().isBelowOrEqual(1, 19)) disable();
for (TrimPattern mat : Registry.TRIM_PATTERN)
addChoices(new StatChoice(mat.getKey().getKey()));
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
if (!(item.getMeta() instanceof ArmorMeta)) return;
@Nullable TrimPattern pattern = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft(data.toString().toLowerCase()));
if (pattern == null) return;
final ArmorMeta meta = (ArmorMeta) item.getMeta();
final ArmorTrim currentTrim = meta.hasTrim() ? meta.getTrim() : new ArmorTrim(TrimMaterial.AMETHYST, TrimPattern.COAST);
meta.setTrim(new ArmorTrim(currentTrim.getMaterial(), pattern));
}
@Override
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
if (!(mmoitem.getNBT().getItem().getItemMeta() instanceof ArmorMeta)) return;
final ArmorMeta meta = (ArmorMeta) mmoitem.getNBT().getItem().getItemMeta();
if (!meta.hasTrim()) return;
mmoitem.setData(this, new StringData(meta.getTrim().getPattern().getKey().getKey()));
}
}

View File

@ -8,43 +8,47 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class StringData implements StatData, RandomStatData<StringData>, Mergeable<StringData> {
@Nullable private String value;
@Nullable
private String value;
public StringData(@Nullable String str) {
this.value = str;
}
public StringData(@Nullable String str) {
this.value = str;
}
@Nullable public String getString() { return value; }
@Nullable
public String getString() {
return value;
}
public void setString(@Nullable String str) {
this.value = str;
}
public void setString(@Nullable String str) {
this.value = str;
}
@Override
public String toString() {
return String.valueOf(value);
}
@Override
public String toString() {
return String.valueOf(value);
}
@Override
public StringData randomize(MMOItemBuilder builder) {
return this;
}
@Override
public StringData randomize(MMOItemBuilder builder) {
return this;
}
@Override
public boolean isEmpty() {
return value == null || value.isEmpty();
}
@Override
public boolean isEmpty() {
return value == null || value.isEmpty();
}
@Override
public void merge(@Nullable StringData data) {
@Override
public void merge(@Nullable StringData data) {
// Overwrite
value = data.getString();
}
// Overwrite
value = data.getString();
}
@NotNull
@Override
public StringData cloneData() {
return new StringData(value);
}
@NotNull
@Override
public StringData cloneData() {
return new StringData(value);
}
}

View File

@ -6,12 +6,14 @@ import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.util.StatChoice;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@ -30,28 +32,27 @@ public abstract class ChooseStat extends StringStat {
* Contains the list of different options the player may choose from.
* <b>Make sure its is always initialized and with at least 1 element</b>
*/
private final ArrayList<String> choices = new ArrayList<>();
/**
* Definitions of what each choosing type does, for display in lore.
*/
private final HashMap<String, String> hints = new HashMap<>();
private final List<StatChoice> choices = new ArrayList<>();
public ChooseStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) {
super(id, mat, name, lore, types, materials);
}
public void addChoices(String... choices) {
public void addChoices(StatChoice... choices) {
this.choices.addAll(Arrays.asList(choices));
}
public void setHint(String choice, String desc) {
hints.put(choice, desc);
@Nullable
public StatChoice getChoice(String id) {
for (StatChoice choice : choices)
if (choice.getId().equals(id))
return choice;
return null;
}
@Override
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
Validate.isTrue(choices.size() > 0, "\u00a77Invalid Chooseable Item Stat " + ChatColor.GOLD + getId() + "\u00a77' - \u00a7cNo options to choose from.");
Validate.isTrue(choices.size() > 0, "Invalid choice-based stat '" + getId() + ": no options to choose from.");
// If removing, reset to default
if (event.getAction() == InventoryAction.PICKUP_HALF) {
@ -66,25 +67,19 @@ public abstract class ChooseStat extends StringStat {
} else {
// Get current
String current = inv.getEditedSection().getString(getPath());
StatChoice current = getChoice(inv.getEditedSection().getString(getPath()));
// Included?
int currentIndex = 0;
if (current != null && choices.contains(current)) {
currentIndex = choices.indexOf(current);
}
int currentIndex = current != null ? Math.max(0, choices.indexOf(current)) : 0;
// Increase and Cap
currentIndex++;
if (currentIndex >= choices.size()) {
currentIndex = 0;
}
if (++currentIndex >= choices.size()) currentIndex = 0;
// Get
current = choices.get(currentIndex);
// Edits into persistent files
inv.getEditedSection().set(getPath(), current);
inv.getEditedSection().set(getPath(), current.getId());
inv.registerTemplateEdition();
// Sends a message
@ -94,44 +89,24 @@ public abstract class ChooseStat extends StringStat {
@Override
public void whenDisplayed(List<String> lore, Optional<StringData> statData) {
Validate.isTrue(choices.size() > 0, "\u00a77Invalid Chooseable Item Stat " + ChatColor.GOLD + getId() + "\u00a77' - \u00a7cNo options to choose from.");
Validate.isTrue(choices.size() > 0, "Invalid choice-based stat '" + getId() + ": no options to choose from.");
// To display current choosing, gets the very first element
String def = choices.get(0);
StatChoice def = statData.isPresent() ? getChoice(statData.get().toString()) : choices.get(0);
lore.add(ChatColor.GRAY + "Current Value: " + (statData.isPresent() ? ChatColor.GREEN : ChatColor.RED) + def);
// Does this item have any specified value for this?
if (statData.isPresent()) {
// Put in current
def = statData.get().toString();
// Display the value of the current stat data
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.GREEN + def);
} else {
// Mention that it currently has no value
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + def);
}
// Get Definition
if (hints.containsKey(def))
for (String definition : SilentNumbers.chop(hints.get(def), 50, "")) {
lore.add(ChatColor.GRAY + " " + definition);
}
// Display Definition
for (String definition : SilentNumbers.chop(def.getHint(), 50, ""))
lore.add(ChatColor.GRAY + " " + definition);
lore.add("");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to return to default value.");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Left click to cycle through the available options:");
for (String str : choices) {
for (StatChoice existing : choices) {
// Is it the one?
String pick = ChatColor.GOLD.toString();
if (str.equals(def)) {
pick = ChatColor.RED.toString() + ChatColor.BOLD.toString();
}
lore.add(pick + " " + AltChar.smallListDash + " \u00a77" + str);
String pick = existing.equals(def) ? ChatColor.RED.toString() + ChatColor.BOLD : ChatColor.GOLD.toString();
lore.add(pick + " " + AltChar.smallListDash + " " + ChatColor.GRAY + existing.getId());
}
}
}
}

View File

@ -0,0 +1,45 @@
package net.Indyuce.mmoitems.util;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
public class StatChoice {
private final String id, hint;
public StatChoice(String id) {
this(id, "- No Hint Available - ");
}
public StatChoice(String id, @Nullable String hint) {
this.id = id;
this.hint = hint;
}
public String getId() {
return id;
}
@Nullable
public String getHint() {
return hint;
}
@Override
public String toString() {
return getId();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StatChoice choice = (StatChoice) o;
return id.equals(choice.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
}