Removed most outdated non-component-friendly constructors

This commit is contained in:
Jules 2025-01-06 04:05:10 +01:00
parent 00f703fc12
commit 06ced6dc69
56 changed files with 819 additions and 752 deletions

View File

@ -49,19 +49,20 @@ public class ItemStats {
PROJECTILE_PARTICLES = new ProjectileParticles(),
// Disable Interaction Stats
DISABLE_INTERACTION = new DisableStat("INTERACTION", VMaterial.GRASS_BLOCK.get(), "Disable Interaction", new String[]{"!block", "all"}, "Disable any unwanted interaction:", "block placement, item use..."),
DISABLE_CRAFTING = new DisableStat("CRAFTING", Material.CRAFTING_TABLE, "Disable Crafting", "Players can't use this item while crafting."), DISABLE_SMELTING = new DisableStat("SMELTING", Material.FURNACE, "Disable Smelting", "Players can't use this item in furnaces."),
DISABLE_SMITHING = new DisableStat("SMITHING", Material.DAMAGED_ANVIL, "Disable Smithing", "Players can't smith this item in smithing tables."),
DISABLE_ENCHANTING = new DisableStat("ENCHANTING", Material.ENCHANTING_TABLE, "Disable Enchanting", new String[]{"!block", "all"}, "Players can't enchant this item."),
DISABLE_REPAIRING = new DisableStat("REPAIRING", Material.ANVIL, "Disable Repairing", new String[]{"!block", "all"}, "Players can't use this item in anvils."),
DISABLE_ARROW_SHOOTING = new DisableStat("ARROW_SHOOTING", Material.ARROW, "Disable Arrow Shooting", new Material[]{Material.ARROW}, "Players can't shoot this", "item using a bow."),
DISABLE_DROP = new DisableStat("DROPING", Material.LAVA_BUCKET, "Disable Item Dropping", new String[0], "Disables the dropping of this item!"),
DISABLE_ARROW_CONSUMPTION = new DisableStat("ARROW_CONSUMPTION", Material.ARROW, "Disable Arrow Consumption", new String[]{"crossbow"}, "Disable arrow requirement and consumption."),
DISABLE_INTERACTION = new DisableStat("INTERACTION", VMaterial.GRASS_BLOCK.get(), "Disable Interaction", "Disable any unwanted interaction: block placement, item use...", new String[]{"!block", "all"}),
DISABLE_CRAFTING = new DisableStat("CRAFTING", Material.CRAFTING_TABLE, "Disable Crafting", "Players can't use this item while crafting.", null),
DISABLE_SMELTING = new DisableStat("SMELTING", Material.FURNACE, "Disable Smelting", "Players can't use this item in furnaces.", null),
DISABLE_SMITHING = new DisableStat("SMITHING", Material.DAMAGED_ANVIL, "Disable Smithing", "Players can't smith this item in smithing tables.", null),
DISABLE_ENCHANTING = new DisableStat("ENCHANTING", Material.ENCHANTING_TABLE, "Disable Enchanting", "Players can't enchant this item.", new String[]{"!block", "all"}),
DISABLE_REPAIRING = new DisableStat("REPAIRING", Material.ANVIL, "Disable Repairing", "Players can't use this item in anvils.", new String[]{"!block", "all"}),
DISABLE_ARROW_SHOOTING = new DisableStat("ARROW_SHOOTING", Material.ARROW, "Disable Arrow Shooting", "Players can't shoot this item using a bow.", null).setCompatibleMaterials(Material.ARROW),
DISABLE_DROP = new DisableStat("DROPING", Material.LAVA_BUCKET, "Disable Item Dropping", "Disables the dropping of this item!", null),
DISABLE_ARROW_CONSUMPTION = new DisableStat("ARROW_CONSUMPTION", Material.ARROW, "Disable Arrow Consumption", "Disable arrow requirement and consumption.", new String[]{"crossbow"}),
// Special item interactions/skills
LEFT_CLICK_SCRIPT = new ActionLeftClick(),
RIGHT_CLICK_SCRIPT = new ActionRightClick(),
DISABLE_ATTACK_PASSIVE = new DisableStat("ATTACK_PASSIVE", Material.BARRIER, "Disable On-Hit Effect", new String[]{"weapon"}, "Disables on-hit effects granted by the item type."),
DISABLE_ATTACK_PASSIVE = new DisableStat("ATTACK_PASSIVE", Material.BARRIER, "Disable On-Hit Effect", "Disables on-hit effects granted by the item type.", new String[]{"weapon"}),
// RPG Stats
REQUIRED_LEVEL = new RequiredLevel(),
@ -118,7 +119,7 @@ public class ItemStats {
MAX_MANA = new DoubleStat("MAX_MANA", Material.LAPIS_LAZULI, "Max Mana", new String[]{"Adds mana to your max mana bar."}).setCategory(StatCategories.MISC_STATS),
KNOCKBACK_RESISTANCE = new KnockbackResistance(),
MOVEMENT_SPEED = new MovementSpeed(),
TWO_HANDED = new BooleanStat("TWO_HANDED", Material.IRON_INGOT, "Two Handed", new String[]{"If set to true, a player will be", "significantly slower if holding two", "items, one being Two Handed."}, new String[]{"handheld"}).setCategory(StatCategories.MISC),
TWO_HANDED = new BooleanStat("TWO_HANDED", Material.IRON_INGOT, "Two Handed", "If set to true, players will be significantly slower (emcumbered) when holding two items, one being Two Handed.", new String[]{"handheld"}).setCategory(StatCategories.MISC),
REQUIRED_BIOMES = new RequiredBiomes(),
DROP_ON_DEATH = new DisableDeathDrop(),
HIDE_DURABILITY_BAR = new HideDurabilityBar(),
@ -177,8 +178,8 @@ public class ItemStats {
//CRAFT_AMOUNT = new DoubleStat("CRAFTED_AMOUNT", Material.WOODEN_AXE, "Crafted Amount", new String[]{"The stack count for", "this item when crafted."}, new String[0]),
// Unique Stats
AUTOSMELT = new BooleanStat("AUTOSMELT", Material.COAL, "Autosmelt", new String[]{"If set to true, your tool will", "automaticaly smelt mined ores."}, new String[]{"tool"}).setCategory(StatCategories.TOOLS),
BOUNCING_CRACK = new BooleanStat("BOUNCING_CRACK", Material.COBBLESTONE_WALL, "Bouncing Crack", new String[]{"If set to true, your tool will", "also break nearby blocks."}, new String[]{"tool"}).setCategory(StatCategories.TOOLS),
AUTOSMELT = new BooleanStat("AUTOSMELT", Material.COAL, "Autosmelt", "When toggled on, your tool will automatically smelt mined ores.", new String[]{"tool"}).setCategory(StatCategories.TOOLS),
BOUNCING_CRACK = new BooleanStat("BOUNCING_CRACK", Material.COBBLESTONE_WALL, "Bouncing Crack", "When toggled on, your tool will also break nearby blocks.", new String[]{"tool"}).setCategory(StatCategories.TOOLS),
PICKAXE_POWER = new PickaxePower(),
CUSTOM_SOUNDS = new CustomSounds(),
ELEMENTS = new Elements(),
@ -187,7 +188,7 @@ public class ItemStats {
LUTE_ATTACK_SOUND = new LuteAttackSoundStat(),
LUTE_ATTACK_EFFECT = new LuteAttackEffectStat(),
NOTE_WEIGHT = new DoubleStat("NOTE_WEIGHT", Material.MUSIC_DISC_MALL, "Note Weight", new String[]{"Defines how the projectile cast", "by your lute tilts downwards."}, new String[]{"lute"}).setCategory(StatCategories.RANGED_WEAPONS),
REMOVE_ON_CRAFT = new BooleanStat("REMOVE_ON_CRAFT", Material.GLASS_BOTTLE, "Remove on Craft", new String[]{"If the item should be completely", "removed when used in a recipe,", "or if it should become an", "empty bottle or bucket."}, new String[0], Material.POTION, Material.SPLASH_POTION, Material.LINGERING_POTION, Material.MILK_BUCKET, Material.LAVA_BUCKET, Material.WATER_BUCKET).setCategory(StatCategories.MISC),
REMOVE_ON_CRAFT = new BooleanStat("REMOVE_ON_CRAFT", Material.GLASS_BOTTLE, "Remove on Craft", "If the item should be completely removed when used in a recipe, or if it should become an empty bottle or bucket.", null).setCompatibleMaterials(Material.POTION, Material.SPLASH_POTION, Material.LINGERING_POTION, Material.MILK_BUCKET, Material.LAVA_BUCKET, Material.WATER_BUCKET).setCategory(StatCategories.MISC),
COMPATIBLE_TYPES = new CompatibleTypes(),
COMPATIBLE_IDS = new CompatibleIds(),
COMPATIBLE_MATERIALS = new CompatibleMaterials(),
@ -197,25 +198,24 @@ public class ItemStats {
REPAIR = new RepairPower(),
REPAIR_PERCENT = new RepairPowerPercent(),
REPAIR_TYPE = new RepairReference(),
INEDIBLE = new BooleanStat("INEDIBLE", Material.POISONOUS_POTATO, "Inedible", new String[]{"Players won't be able to right-click this consumable.", "", "No effects of it will take place."}, new String[]{"consumable"}).setCategory(StatCategories.CONSUMABLES),
DISABLE_RIGHT_CLICK_CONSUME = new DisableStat("RIGHT_CLICK_CONSUME", Material.BAKED_POTATO, "Infinite Consume", new String[]{"consumable"}, "Players will be able to right-click this consumable", "and benefit from its effects, but it won't be consumed.").setCategory(StatCategories.CONSUMABLES),
INEDIBLE = new BooleanStat("INEDIBLE", Material.POISONOUS_POTATO, "Inedible", "Makes it impossible to right-click consume this consumable.", new String[]{"consumable"}).setCategory(StatCategories.CONSUMABLES),
DISABLE_RIGHT_CLICK_CONSUME = new DisableStat("RIGHT_CLICK_CONSUME", Material.BAKED_POTATO, "Infinite Consume", "Players will be able to right-click this consumable and benefit from its effects, but it won't be consumed.", new String[]{"consumable"}).setCategory(StatCategories.CONSUMABLES),
KNOCKBACK = new DoubleStat("KNOCKBACK", Material.IRON_HORSE_ARMOR, "Knockback", new String[]{"Using this musket will knock", "the user back if positive."}, new String[]{"musket", "gem_stone"}).setCategory(StatCategories.RANGED_WEAPONS),
RECOIL = new DoubleStat("RECOIL", Material.IRON_HORSE_ARMOR, "Recoil", new String[]{"Corresponds to the shooting innacuracy."}, new String[]{"musket", "gem_stone"}).setCategory(StatCategories.RANGED_WEAPONS),
HANDWORN = new BooleanStat("HANDWORN", Material.STRING, "Handworn", new String[]{"This item can be held along with a", "two-handed weapon in the other hand."}, new String[]{"catalyst", "off_catalyst", "main_catalyst"}).setCategory(StatCategories.MISC),
HANDWORN = new BooleanStat("HANDWORN", Material.STRING, "Handworn", "This item can be held along with a two-handed weapon in the other hand, bypassing the encumbered debuff.", new String[]{"catalyst", "off_catalyst", "main_catalyst"}).setCategory(StatCategories.MISC),
AMPHIBIAN = new Amphibian(),
// Abilities & Upgrading
ABILITIES = new Abilities(),
UPGRADE = new UpgradeStat(),
DOWNGRADE_ON_BREAK = new BooleanStat("BREAK_DOWNGRADE", Material.DAMAGED_ANVIL, "Downgrade when Broken", new String[]{"If this item's durability reaches 0,", "it will be fully repaired but also", "downgraded by one level.", "", "&cIt will only break if it cannot be", "&cdowngraded further", "", "Requires to define an &6Upgrade Template", "Required to define &6Custom Durability"}, new String[]{"equipment"}).setCategory(StatCategories.UPGRADING),
DOWNGRADE_ON_DEATH = new BooleanStat("DEATH_DOWNGRADE", Material.DAMAGED_ANVIL, "Downgrade on Death", new String[]{"If the wearer of this item dies, it may", "downgrade (based on &6Death Downgrade", "&6Chance &7stat)", "", "Required to define an &6Upgrade Template", "Requires keep-inventory gamerule. "}, new String[]{"equipment"}).setCategory(StatCategories.UPGRADING),
DOWNGRADE_ON_BREAK = new BooleanStat("BREAK_DOWNGRADE", Material.DAMAGED_ANVIL, "Downgrade when Broken", "If this item's durability reaches 0, it will be fully repaired but also downgraded by one level. &cIt will only break if it cannot be downgraded further.\n&7Requires to define an &6Upgrade Template.\n&7Required to define &6Custom Durability", new String[]{"equipment"}).setCategory(StatCategories.UPGRADING),
DOWNGRADE_ON_DEATH = new BooleanStat("DEATH_DOWNGRADE", Material.DAMAGED_ANVIL, "Downgrade on Death", "If the wearer of this item dies, it may downgrade (based on &6Death Downgrade Chance &7stat).\nRequired to define an &6Upgrade Template.\nRequires keep-inventory gamerule. ", new String[]{"equipment"}).setCategory(StatCategories.UPGRADING),
DOWNGRADE_ON_DEATH_CHANCE = new DoubleStat("DEATH_DOWNGRADE_CHANCE", Material.SKELETON_SKULL, "Death Downgrade Chance", "Probability that an item with &cDowngrade on Death &7will be downgraded when the player dies.\n\n Exceeding 100% will for sure downgrade one item, and roll again to downgrade another (with the excess probability). The same item won't be downgraded twice.", new String[]{"equipment"}, false).setCategory(StatCategories.UPGRADING),
// Unique Item Stats
DYE_COLOR = new DyeColor(),
HIDE_DYE = new HideDye(),
TRIM_MATERIAL = new TrimMaterialStat(),
TRIM_PATTERN = new TrimPatternStat(),
ARMOR_TRIM = new ArmorTrimStat(),
HIDE_ARMOR_TRIM = new HideTrim(),
POTION_EFFECTS = new PotionEffects(),
POTION_COLOR = new PotionColor(),

View File

@ -5,7 +5,6 @@ import org.bukkit.Material;
public class DisableAdvancedEnchantments extends DisableStat {
public DisableAdvancedEnchantments() {
super("ADVANCED_ENCHANTS", Material.ENCHANTED_BOOK, "Disable Advanced Enchants", new String[0], "When toggled on, prevents players", "from applying AE onto this item.");
super("ADVANCED_ENCHANTS", Material.ENCHANTED_BOOK, "Disable Advanced Enchants", "When toggled on, prevents players from applying AE onto this item.", null);
}
}

View File

@ -1,35 +1,22 @@
package net.Indyuce.mmoitems.comp.mmoinventory.stat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.StringStat;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
@HasCategory(cat = "misc")
public class AccessorySet extends StringStat implements GemStoneStat {
public AccessorySet() {
super("ACCESSORY_SET", Material.OAK_SIGN, "Accessory Set (MMOInventory)", new String[] { "Used with MMOInventory's unique", "restriction to only allow one", "accessory to be equipped per set." }, new String[] { "!block", "all" });
super("ACCESSORY_SET", Material.OAK_SIGN, "Accessory Set (MMOInventory)", "MMOInventory features slots (marked with slot restriction 'unique') which allow the player to only equip one accessory per set. Sets are defined as items with the same accessory set ID. This option can be used to edit the accessory set ID. Leave it empty to ignore.", new String[]{"!block", "all"});
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
item.addItemTag(new ItemTag(getNBTPath(), data.toString()));
}
@Deprecated
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
message = message.toLowerCase();
inv.getEditedSection().set(getPath(), message);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(
MMOItems.plugin.getPrefix() + getName() + " successfully changed to " + MythicLib.plugin.parseColors(message) + ChatColor.GRAY + ".");
}
}

View File

@ -16,94 +16,94 @@ import org.bukkit.event.Listener;
public class McMMOHook implements RPGHandler, Listener {
public static final StatCategory STAT_CATEGORY = new StatCategory("MCMMO", "mcMMO", "mcMMO");
public static final StatCategory STAT_CATEGORY = new StatCategory("MCMMO", "mcMMO", "mcMMO");
/**
* McMMO is a special plugin, it can be used along with other RPG plugins
* like MMOCore. That stat must be registered even if McMMO is not the main
* RPG core plugin, therefore the register() method is on the onEnable() and
* not in the constructor of that class
*/
public static final ItemStat disableMcMMORepair = new DisableStat("MCMMO_REPAIR", Material.IRON_BLOCK, "Disable McMMO Repair",
"Players can't repair this with McMMO.").setCategory(STAT_CATEGORY);
/**
* McMMO is a special plugin, it can be used along with other RPG plugins
* like MMOCore. That stat must be registered even if McMMO is not the main
* RPG core plugin, therefore the register() method is on the onEnable() and
* not in the constructor of that class
*/
public static final ItemStat disableMcMMORepair = new DisableStat("MCMMO_REPAIR", Material.IRON_BLOCK, "Disable McMMO Repair",
"Players can't repair this with McMMO.", null).setCategory(STAT_CATEGORY);
public McMMOHook() {
MMOItems.plugin.getStats().registerCategory(STAT_CATEGORY);
}
public McMMOHook() {
MMOItems.plugin.getStats().registerCategory(STAT_CATEGORY);
}
@EventHandler(ignoreCancelled = true)
public void a(McMMOPlayerLevelUpEvent event) {
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
}
@EventHandler(ignoreCancelled = true)
public void a(McMMOPlayerLevelUpEvent event) {
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
}
@EventHandler(ignoreCancelled = true)
public void b(McMMOPlayerLevelDownEvent event) {
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
}
@EventHandler(ignoreCancelled = true)
public void b(McMMOPlayerLevelDownEvent event) {
PlayerData.get(event.getPlayer()).getInventory().scheduleUpdate();
}
@Override
public RPGPlayer getInfo(PlayerData data) {
return new McMMOPlayer(data);
}
@Override
public RPGPlayer getInfo(PlayerData data) {
return new McMMOPlayer(data);
}
@Override
public void refreshStats(PlayerData data) {
}
@Override
public void refreshStats(PlayerData data) {
}
public static class McMMOPlayer extends RPGPlayer {
public McMMOPlayer(PlayerData playerData) {
super(playerData);
}
public static class McMMOPlayer extends RPGPlayer {
public McMMOPlayer(PlayerData playerData) {
super(playerData);
}
@Override
public int getLevel() {
//RPG*/MMOItems. Log("Getting level of \u00a7c" + getPlayer().getName());
@Override
public int getLevel() {
//RPG*/MMOItems. Log("Getting level of \u00a7c" + getPlayer().getName());
// No errors, right?
try {
// No errors, right?
try {
// Get through Experience API I suppose
int r = ExperienceAPI.getPowerLevel(getPlayer());
// Get through Experience API I suppose
int r = ExperienceAPI.getPowerLevel(getPlayer());
// Log rq
//RPG*/MMOItems. Log("\u00a76 + \u00a77Found level as \u00a7c" + r);
// Log rq
//RPG*/MMOItems. Log("\u00a76 + \u00a77Found level as \u00a7c" + r);
// thats it
return r;
// thats it
return r;
// A problem may have occured
} catch (McMMOPlayerNotFoundException exception) {
// A problem may have occured
} catch (McMMOPlayerNotFoundException exception) {
// Log rq
//RPG*/MMOItems. Log("\u00a76 - \u00a77No data found. Using \u00a7c0");
// Log rq
//RPG*/MMOItems. Log("\u00a76 - \u00a77No data found. Using \u00a7c0");
// Thats it
return 0;
}
}
// Thats it
return 0;
}
}
@Override
public String getClassName() {
return "";
}
@Override
public String getClassName() {
return "";
}
@Override
public double getMana() {
return getPlayer().getFoodLevel();
}
@Override
public double getMana() {
return getPlayer().getFoodLevel();
}
@Override
public double getStamina() {
return 0;
}
@Override
public double getStamina() {
return 0;
}
@Override
public void setMana(double value) {
getPlayer().setFoodLevel((int) value);
}
@Override
public void setMana(double value) {
getPlayer().setFoodLevel((int) value);
}
@Override
public void setStamina(double value) {
}
}
@Override
public void setStamina(double value) {
}
}
}

View File

@ -266,6 +266,10 @@ public class StatManager {
if (stat.getCategory() == null)
MMOItems.plugin.getLogger().log(Level.WARNING, "Registered stat " + stat.getName() + " with no category");
if (stat.getComponentType() == null)
MMOItems.plugin.getLogger().log(Level.WARNING, "Registered stat " + stat.getName() + " with no component type");
/*
* Cache stat for every type which may have this stat. Really important
* otherwise the stat will NOT be used anywhere in the plugin. This

View File

@ -1,14 +1,13 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.component.type.builtin.StringComponentType;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.StringStat;
import org.bukkit.Material;
@ -19,19 +18,21 @@ import java.util.ArrayList;
@HasCategory(cat = "abilities")
public class ActionLeftClick extends StringStat {
public ActionLeftClick() {
super("ON_LEFT_CLICK", Material.COMMAND_BLOCK_MINECART, "Left Click Action", new String[]{"ID of skill ran when left clicking. When used,", "The item will naturally apply item costs like", "mana, stamina, cooldown. This option overrides the", "script provided by the item type."}, new String[]{"weapon"});
super("ON_LEFT_CLICK", new String[]{"weapon"});
// Staff spirit set as alias
setAliases(LEGACY_ID);
setComponentType(StringComponentType.skillHandler()
.setIcon(Material.COMMAND_BLOCK_MINECART)
.setName("Left Click Action")
.trimLore("ID of skill ran when left clicking. When used, The item will naturally apply item costs like mana, stamina, cooldown. This option overrides the script/skill provided by the item type.")
.build());
}
@Deprecated
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
final String format = UtilityMethods.enumName(message);
MythicLib.plugin.getSkills().getHandlerOrThrow(format);
inv.getEditedSection().set(getPath(), format);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + getName() + " successfully changed to '" + format + "'");
throw new RuntimeException("not called");
}
@Override

View File

@ -1,12 +1,10 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.item.ItemTag;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.component.type.builtin.StringComponentType;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.StringStat;
import org.bukkit.Material;
@ -15,16 +13,13 @@ import org.jetbrains.annotations.NotNull;
@HasCategory(cat = "abilities")
public class ActionRightClick extends StringStat {
public ActionRightClick() {
super("ON_RIGHT_CLICK", Material.COMMAND_BLOCK_MINECART, "Right Click Action", new String[]{"ID of skill ran when right clicking. When used,", "The item will naturally apply item costs like", "mana, stamina, cooldown. This option overrides the", "script provided by the item type."}, new String[]{"weapon"});
}
super("ON_RIGHT_CLICK", new String[]{"weapon"});
@Deprecated
public void whenInput(@NotNull EditionInventory inv, @NotNull String message, Object... info) {
final String format = UtilityMethods.enumName(message);
MythicLib.plugin.getSkills().getHandlerOrThrow(format);
inv.getEditedSection().set(getPath(), format);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + getName() + " successfully changed to '" + format + "'");
setComponentType(StringComponentType.skillHandler()
.setIcon(Material.COMMAND_BLOCK_MINECART)
.setName("Right Click Action")
.trimLore("ID of skill ran when right clicking. When used, The item will naturally apply item costs like mana, stamina, cooldown. This option overrides the script/skill provided by the item type.")
.build());
}
@Override

View File

@ -6,11 +6,12 @@ import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.behaviour.ItemRestriction;
import net.Indyuce.mmoitems.util.StatChoice;
import net.Indyuce.mmoitems.stat.component.type.builtin.StringComponentType;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.StringStat;
import net.Indyuce.mmoitems.util.HintedString;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@ -23,21 +24,25 @@ import java.util.ArrayList;
* @author Gunging
*/
@HasCategory(cat = "requirement")
public class Amphibian extends ChooseStat implements ItemRestriction, GemStoneStat {
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 class Amphibian extends StringStat implements ItemRestriction, GemStoneStat {
public static final HintedString
NORMAL = new HintedString("NORMAL", "No liquids dependency"),
DRY = new HintedString("DRY", "The item does not work if the player is touching a liquid block."),
WET = new HintedString("WET", "The only works if the player is touching water (rain does not count)."),
DAMP = new HintedString("DAMP", "The only works if the player is completely submerged in water."),
LAVA = new HintedString("LAVA", "The only works if the player is touching lava."),
MOLTEN = new HintedString("MOLTEN", "The only works if the player is completely submerged in lava."),
LIQUID = new HintedString("LIQUID", "The only works if the player is touching any liquid."),
SUBMERGED = new HintedString("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"});
super("AMPHIBIAN", new String[]{"!block", "all"});
addChoices(NORMAL, DRY, WET, DAMP, LAVA, MOLTEN, LIQUID, SUBMERGED);
setComponentType(StringComponentType.withChoices(NORMAL, DRY, WET, DAMP, LAVA, MOLTEN, LIQUID, SUBMERGED)
.setIcon(Material.WATER_BUCKET)
.setName("Amphibian Mode")
.trimLore("May this item only be used in specific environments regarding liquids?")
.build());
}
@NotNull

View File

@ -0,0 +1,120 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.annotation.VersionDependant;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.component.type.ComponentType;
import net.Indyuce.mmoitems.stat.component.type.builtin.ObjectComponentType;
import net.Indyuce.mmoitems.stat.component.type.builtin.StringComponentType;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.StringStat;
import net.Indyuce.mmoitems.util.HintedString;
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.stream.Collectors;
/**
* @author Jules
*/
@HasCategory(cat = "item")
@VersionDependant(version = {1, 20})
public class ArmorTrimStat extends StringStat implements GemStoneStat {
public ArmorTrimStat() {
super("ARMOR_TRIM", new String[]{"armor", "skin"});
setAliases("TRIM");
if (!isEnabled()) return;
// VERSION DEPENDENT CODE AHEAD!!
ComponentType<?, ?> trimMaterialSubtype = StringComponentType
.withChoices(Registry.TRIM_MATERIAL.stream().map(mat -> new HintedString(mat.getKey().toString())).collect(Collectors.toList()))
.adaptor(ArmorTrimStat::fixNamespacedKey)
.setIcon(Material.LEATHER_CHESTPLATE)
.setName("Trim Material")
.trimLore("Material to trim your armor with.")
.build();
ComponentType<?, ?> trimPatternSubtype = StringComponentType
.withChoices(Registry.TRIM_PATTERN.stream().map(pattern -> new HintedString(pattern.getKey().toString())).collect(Collectors.toList()))
.adaptor(ArmorTrimStat::fixNamespacedKey)
.setIcon(Material.LEATHER_CHESTPLATE)
.setName("Trim Pattern")
.trimLore("Material to trim your armor with.")
.build();
setComponentType(ObjectComponentType.object()
.addField("material", trimMaterialSubtype)
.addField("pattern", trimPatternSubtype)
.setIcon(Material.LEATHER_CHESTPLATE)
.setName("Armor Trim")
.trimLore("Options for armor trim.")
.build());
// TODO legacy config adapter from 'trim-material' and 'trim-pattern' instead.
}
public static String fixNamespacedKey(String str) {
return NamespacedKey.fromString(str.toLowerCase().replace("-", "_")).toString();
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
if (!(item.getMeta() instanceof ArmorMeta)) return;
@Nullable TrimMaterial material = Registry.TRIM_MATERIAL.get(NamespacedKey.fromString(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().toString()));
}
/*
@Nullable
@Override
public HintedString getChoice(String id) {
return super.getChoice(fixNamespacedKey(id).toString());
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
if (!(item.getMeta() instanceof ArmorMeta)) return;
@Nullable TrimPattern pattern = Registry.TRIM_PATTERN.get(fixNamespacedKey(data.toString()));
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().toString()));
}
*/
}

View File

@ -99,9 +99,7 @@ public class CanBreak extends ItemStat<StringListData, StringListData> {
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringListData data) {
List<Material> mats = data.getList().stream().map(Material::valueOf).collect(Collectors.toList());
item.addFutureAction(nbt -> {
nbt.setCanMine(mats);
});
item.addFutureAction(nbt -> nbt.setCanMine(mats));
item.addItemTag(getAppliedNBT(data));
}

View File

@ -1,8 +1,17 @@
package net.Indyuce.mmoitems.stat;
import java.util.List;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ItemTier;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.event.item.DeconstructItemEvent;
import net.Indyuce.mmoitems.api.interaction.Consumable;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -10,50 +19,40 @@ import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.util.MMOUtils;
import net.Indyuce.mmoitems.api.ItemTier;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.event.item.DeconstructItemEvent;
import net.Indyuce.mmoitems.api.interaction.Consumable;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import io.lumine.mythic.lib.api.item.NBTItem;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@HasCategory(cat = "consumables")
public class CanDeconstruct extends BooleanStat implements ConsumableItemInteraction {
public CanDeconstruct() {
super("CAN_DECONSTRUCT", Material.PAPER, "Can Deconstruct?",
new String[] { "Players can deconstruct their item", "using this consumable, creating", "another random item." },
new String[] { "consumable" });
}
public CanDeconstruct() {
super("CAN_DECONSTRUCT", Material.PAPER, "Can Deconstruct?",
"Players can deconstruct their item using this consumable, dropping another random item following deconstruction drop tables.",
new String[]{"consumable"});
}
@Override
public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, Type targetType) {
String itemTierTag = target.getString("MMOITEMS_TIER");
if (itemTierTag.equals("") || !consumable.getNBTItem().getBoolean("MMOITEMS_CAN_DECONSTRUCT"))
return false;
@Override
public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, Type targetType) {
String itemTierTag = target.getString("MMOITEMS_TIER");
if (itemTierTag.equals("") || !consumable.getNBTItem().getBoolean("MMOITEMS_CAN_DECONSTRUCT"))
return false;
ItemTier tier = MMOItems.plugin.getTiers().get(itemTierTag);
List<ItemStack> loot = tier.getDeconstructedLoot(playerData);
if (loot.isEmpty())
return false;
ItemTier tier = MMOItems.plugin.getTiers().get(itemTierTag);
List<ItemStack> loot = tier.getDeconstructedLoot(playerData);
if (loot.isEmpty())
return false;
DeconstructItemEvent called = new DeconstructItemEvent(playerData, consumable.getMMOItem(), target, loot);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
return false;
DeconstructItemEvent called = new DeconstructItemEvent(playerData, consumable.getMMOItem(), target, loot);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
return false;
Player player = playerData.getPlayer();
Message.SUCCESSFULLY_DECONSTRUCTED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(event.getCurrentItem())).send(player);
event.getCurrentItem().setAmount(event.getCurrentItem().getAmount() - 1);
for (ItemStack drop : player.getInventory().addItem(loot.toArray(new ItemStack[0])).values())
player.getWorld().dropItem(player.getLocation(), drop);
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
return true;
}
Player player = playerData.getPlayer();
Message.SUCCESSFULLY_DECONSTRUCTED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(event.getCurrentItem())).send(player);
event.getCurrentItem().setAmount(event.getCurrentItem().getAmount() - 1);
for (ItemStack drop : player.getInventory().addItem(loot.toArray(new ItemStack[0])).values())
player.getWorld().dropItem(player.getLocation(), drop);
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
return true;
}
}

View File

@ -15,10 +15,10 @@ import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.data.ParticleData;
import net.Indyuce.mmoitems.stat.data.SkullTextureData;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
@ -37,7 +37,8 @@ import java.util.logging.Level;
public class CanDeskin extends BooleanStat implements ConsumableItemInteraction {
public CanDeskin() {
super("CAN_DESKIN", Material.LEATHER, "Can Deskin?",
new String[]{"Players can deskin their item", "and get their skin back", "from the item."}, new String[]{"consumable"});
"When toggled on, players can deskin items by drag & dropping this item, while getting their skin back.",
new String[]{"consumable"});
}
@Override
@ -82,7 +83,8 @@ public class CanDeskin extends BooleanStat implements ConsumableItemInteraction
if (targetItemMeta instanceof ArmorMeta && originalItemMeta instanceof ArmorMeta) {
((ArmorMeta) targetItemMeta).setTrim(((ArmorMeta) originalItemMeta).getTrim());
if (originalItemMeta.hasItemFlag(ItemFlag.HIDE_ARMOR_TRIM)) targetItemMeta.addItemFlags(ItemFlag.HIDE_ARMOR_TRIM);
if (originalItemMeta.hasItemFlag(ItemFlag.HIDE_ARMOR_TRIM))
targetItemMeta.addItemFlags(ItemFlag.HIDE_ARMOR_TRIM);
else targetItemMeta.removeItemFlags(ItemFlag.HIDE_ARMOR_TRIM);
}

View File

@ -1,54 +1,54 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import net.Indyuce.mmoitems.util.MMOUtils;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.event.item.IdentifyItemEvent;
import net.Indyuce.mmoitems.api.interaction.Consumable;
import net.Indyuce.mmoitems.api.item.util.identify.IdentifiedItem;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull;
@HasCategory(cat = "consumables")
public class CanIdentify extends BooleanStat implements ConsumableItemInteraction {
public CanIdentify() {
super("CAN_IDENTIFY", Material.PAPER, "Can Identify?",
new String[] { "Players can identify & make their", "item usable using this consumable." }, new String[] { "consumable" });
}
public CanIdentify() {
super("CAN_IDENTIFY", Material.PAPER, "Can Identify?",
"When toggled on, players may drag & drop this item onto an unidentified item in order to identify it. Identifying an item reveals its exact identity and makes it usable.",
new String[]{"consumable"});
}
@Override
public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, Type targetType) {
if (targetType != null)
return false;
@Override
public boolean handleConsumableEffect(@NotNull InventoryClickEvent event, @NotNull PlayerData playerData, @NotNull Consumable consumable, @NotNull NBTItem target, Type targetType) {
if (targetType != null)
return false;
if (!consumable.getNBTItem().getBoolean("MMOITEMS_CAN_IDENTIFY") || !target.hasTag("MMOITEMS_UNIDENTIFIED_ITEM"))
return false;
if (!consumable.getNBTItem().getBoolean("MMOITEMS_CAN_IDENTIFY") || !target.hasTag("MMOITEMS_UNIDENTIFIED_ITEM"))
return false;
Player player = playerData.getPlayer();
if (target.getItem().getAmount() > 1) {
Message.CANNOT_IDENTIFY_STACKED_ITEMS.format(ChatColor.RED).send(player);
return false;
}
Player player = playerData.getPlayer();
if (target.getItem().getAmount() > 1) {
Message.CANNOT_IDENTIFY_STACKED_ITEMS.format(ChatColor.RED).send(player);
return false;
}
IdentifyItemEvent called = new IdentifyItemEvent(playerData, consumable.getMMOItem(), target);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
return false;
IdentifyItemEvent called = new IdentifyItemEvent(playerData, consumable.getMMOItem(), target);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
return false;
event.setCurrentItem(new IdentifiedItem(target).identify());
Message.SUCCESSFULLY_IDENTIFIED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
return true;
}
event.setCurrentItem(new IdentifiedItem(target).identify());
Message.SUCCESSFULLY_IDENTIFIED.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(target.getItem())).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
return true;
}
}

View File

@ -2,8 +2,6 @@ package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.util.MMOUtils;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.interaction.Consumable;
import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem;
@ -11,10 +9,12 @@ import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.stat.data.GemSocketsData;
import net.Indyuce.mmoitems.stat.data.GemstoneData;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import net.Indyuce.mmoitems.stat.behaviour.ConsumableItemInteraction;
import net.Indyuce.mmoitems.util.MMOUtils;
import net.Indyuce.mmoitems.util.Pair;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -34,8 +34,8 @@ import java.util.List;
public class CanUnsocket extends BooleanStat implements ConsumableItemInteraction {
public CanUnsocket() {
super("CAN_UNSOCKET", Material.PAPER, "Can Unsocket?",
new String[] { "This item, when used on another item, if", "that other item has Gem Stones", "may be used to remove those Gems." },
new String[] { "consumable" });
"When toggled on, players can drag & drop this item onto another item to take off a random gem stone from the item.",
new String[]{"consumable"});
}
@Override
@ -44,15 +44,21 @@ public class CanUnsocket extends BooleanStat implements ConsumableItemInteractio
/*
* Cancel if the target is just not an MMOItem
*/
if (targetType == null) { return false; }
if (targetType == null) {
return false;
}
/*
* No Gemstones? No service
*/
MMOItem mmo = new VolatileMMOItem(target);
if (!mmo.hasData(ItemStats.GEM_SOCKETS)) { return false; }
if (!mmo.hasData(ItemStats.GEM_SOCKETS)) {
return false;
}
GemSocketsData mmoGems = (GemSocketsData) mmo.getData(ItemStats.GEM_SOCKETS);
if (mmoGems == null || mmoGems.getGemstones().size() == 0) { return false; }
if (mmoGems == null || mmoGems.getGemstones().size() == 0) {
return false;
}
Player player = playerData.getPlayer();
/*
@ -64,7 +70,8 @@ public class CanUnsocket extends BooleanStat implements ConsumableItemInteractio
final List<Pair<GemstoneData, MMOItem>> mmoGemStones = mmo.extractGemstones();
if (mmoGemStones.isEmpty()) {
Message.RANDOM_UNSOCKET_GEM_TOO_OLD.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(event.getCurrentItem())).send(player);
return false; }
return false;
}
return true;
}

View File

@ -1,83 +1,61 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.gson.JsonArray;
import io.lumine.mythic.lib.gson.JsonParser;
import io.lumine.mythic.lib.gson.JsonSyntaxException;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.input.LegacyItemInputHandler;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.component.type.builtin.ArrayComponentType;
import net.Indyuce.mmoitems.stat.component.type.builtin.StringComponentType;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
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.ArrayList;
import java.util.List;
import java.util.Optional;
@HasCategory(cat = "skins")
public class CompatibleIds extends ItemStat<StringListData, StringListData> {
public CompatibleIds() {
super("COMPATIBLE_IDS", Material.COMMAND_BLOCK, "Compatible IDs",
new String[]{"The item ids this skin is", "compatible with."}, new String[]{"skin"});
StringComponentType itemIdComponentType = StringComponentType.init()
.adaptor(UtilityMethods::enumName) // Transform to uppercase
// Don't provide a list of possible values, it's much too long
.build();
setComponentType(ArrayComponentType.arrayOf(itemIdComponentType)
.setIcon(Material.COMMAND_BLOCK)
.setName("Compatible Items")
.trimLore("Provide here the IDs of items this skin should be compatible with. If empty, it is compatible with any item.")
.build());
// TODO lore tooltips
}
@Override
@SuppressWarnings("unchecked")
public StringListData whenInitialized(Object object) {
Validate.isTrue(object instanceof List<?>, "Must specify a string list");
return new StringListData((List<String>) object);
throw new RuntimeException("not called");
}
@Deprecated
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
if (event.getAction() == InventoryAction.PICKUP_ALL)
new LegacyItemInputHandler(inv, this).enable("Write in the chat the item id you want to add.");
if (event.getAction() != InventoryAction.PICKUP_HALF || !inv.getEditedSection().contains(getPath()))
return;
List<String> lore = inv.getEditedSection().getStringList(getPath());
if (lore.isEmpty()) return;
String last = lore.removeLast();
inv.getEditedSection().set(getPath(), lore);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed '" + last + "'.");
throw new RuntimeException("not called");
}
@Deprecated
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.toUpperCase());
inv.getEditedSection().set(getPath(), lore);
inv.registerTemplateEdition();
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "ID '" + message.toUpperCase() + "' successfully added.");
}
public void whenDisplayed(List<String> lore, Optional<StringListData> statData) {
if (statData.isPresent()) {
lore.add(ChatColor.GRAY + "Current Value:");
statData.get().getList().forEach(str -> lore.add(ChatColor.GRAY + "* " + str));
} else
lore.add(ChatColor.GRAY + "Current Value: " + ChatColor.RED + "Compatible with any item.");
lore.add("");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Click to add a new id.");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove the last id.");
throw new RuntimeException("not called");
}
@NotNull

View File

@ -9,10 +9,8 @@ import org.bukkit.Material;
@HasCategory(cat = "template_option")
public class CraftingPermission extends StringStat implements TemplateOption, GemStoneStat {
public CraftingPermission() {
super("CRAFT_PERMISSION",
Material.OAK_SIGN,
"Crafting Recipe Permission",
new String[]{"The permission needed to craft this item.", "Changing this value requires &o/mi reload recipes&7."},
super("CRAFT_PERMISSION", Material.OAK_SIGN, "Crafting Recipe Permission",
"The permission needed to craft this item. Changing this value requires &o/mi reload recipes&7.",
null);
}
}

View File

@ -8,6 +8,7 @@ import org.bukkit.Material;
public class DisableDeathDrop extends BooleanStat {
public DisableDeathDrop() {
super("DISABLE_DEATH_DROP", Material.BONE, "Disable Drop On Death",
new String[] { "Enable this to prevent this item", "from dropping on the wielder's death." }, new String[0]);
"Enable this option to prevent this item from dropping from a player inventory while dying.",
new String[0]);
}
}

View File

@ -9,8 +9,8 @@ import net.Indyuce.mmoitems.api.ItemTier;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.NameData;
import net.Indyuce.mmoitems.stat.type.StatHistory;
import net.Indyuce.mmoitems.stat.type.StringStat;
@ -26,11 +26,9 @@ import java.util.ArrayList;
public class DisplayName extends StringStat implements GemStoneStat {
public DisplayName() {
super("NAME",
Material.NAME_TAG,
"Display Name",
new String[]{"The item display name."},
new String[0]);
super("NAME", Material.NAME_TAG, "Display Name",
"The item display name.",
null);
}
@Override

View File

@ -8,10 +8,8 @@ import org.bukkit.Material;
@HasCategory(cat = "tooltip")
public class DisplayedType extends StringStat implements GemStoneStat {
public DisplayedType() {
super("DISPLAYED_TYPE",
Material.OAK_SIGN,
"Displayed Type",
new String[]{"This option will only affect the", "type displayed on the item lore."},
super("DISPLAYED_TYPE", Material.OAK_SIGN, "Displayed Type",
"This option will only affect the type displayed on the item lore.",
null);
}
}

View File

@ -31,14 +31,10 @@ public class DyeColor extends ItemStat<ColorData, ColorData> {
.build());
}
@Override
public ColorData whenInitialized(Object object) {
Validate.isTrue(object instanceof String, "Must specify a string");
return new ColorData((String) object);
throw new RuntimeException("not called");
}
@NotNull
@Override
public ColorData getClearStatData() {
return new ColorData(0, 0, 0);
}

View File

@ -3,20 +3,22 @@ package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.api.item.ItemTag;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.StringStat;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
@HasCategory(cat = "gem_stones")
public class GemColor extends StringStat implements GemStoneStat {
public GemColor() {
super("GEM_COLOR", Material.LIGHT_BLUE_DYE, "Gem Color", new String[] { "Defines the color of the socket in", "which the gem can be applied." }, new String[] { "gem_stone" });
}
public GemColor() {
super("GEM_COLOR", Material.LIGHT_BLUE_DYE, "Gem Color",
"Defines the color of the socket in which the gem can be applied.",
new String[]{"gem_stone"});
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
item.addItemTag(new ItemTag(getNBTPath(), data.toString()));
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
item.addItemTag(new ItemTag(getNBTPath(), data.toString()));
}
}

View File

@ -1,10 +1,11 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.util.StatChoice;
import net.Indyuce.mmoitems.stat.component.type.builtin.StringComponentType;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.StringStat;
import net.Indyuce.mmoitems.util.HintedString;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
@ -12,11 +13,11 @@ import org.jetbrains.annotations.NotNull;
* Defines how gem stats will scale when the item they are put on upgrades.
*/
@HasCategory(cat = "gem_stones")
public class GemUpgradeScaling extends ChooseStat implements GemStoneStat {
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.");
public class GemUpgradeScaling extends StringStat implements GemStoneStat {
public static final HintedString
NEVER = new HintedString("NEVER", "Gem stats are never scaled by upgrading the item."),
HISTORIC = new HintedString("HISTORIC", "Gem stats instantly upgrade to the current item level, and subsequently thereafter."),
SUBSEQUENT = new HintedString("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
@ -24,13 +25,18 @@ public class GemUpgradeScaling extends ChooseStat implements GemStoneStat {
public static String defaultValue = SUBSEQUENT.getId();
public GemUpgradeScaling() {
super("GEM_UPGRADE_SCALING", Material.LIME_DYE, "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" });
super("GEM_UPGRADE_SCALING", new String[]{"gem_stone"});
// Set the acceptable values
addChoices(SUBSEQUENT, NEVER, HISTORIC);
setComponentType(StringComponentType.withChoices(SUBSEQUENT, NEVER, HISTORIC)
.setIcon(Material.LIME_DYE)
.setName("Gem Upgrade Scaling")
.trimLore("Gem stones add their stats to items, but you may also upgrade your items via crafting stations or consumables.\n\u00a76Should this gem stone stats be affected by upgrading?")
.build());
}
@NotNull
@Override
public StringData getClearStatData() { return new StringData(defaultValue); }
public StringData getClearStatData() {
return new StringData(defaultValue);
}
}

View File

@ -8,6 +8,7 @@ import org.bukkit.Material;
public class HideDurabilityBar extends BooleanStat {
public HideDurabilityBar() {
super("DURABILITY_BAR", Material.DAMAGED_ANVIL, "Hide Durability Bar",
new String[]{"Enable this to have the green bar", "hidden when using &ncustom&7 durability.", "Does not work when using vanilla durability."}, new String[]{"!block", "all"});
"Enable this to have the green bar hidden when using &ncustom&7 durability. Does not work when using vanilla durability.",
new String[]{"!block", "all"});
}
}

View File

@ -5,9 +5,9 @@ import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.annotation.VersionDependant;
import net.Indyuce.mmoitems.stat.data.BooleanData;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import net.Indyuce.mmoitems.stat.annotation.VersionDependant;
import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag;
import org.jetbrains.annotations.NotNull;
@ -22,37 +22,43 @@ import java.util.ArrayList;
@VersionDependant(version = {1, 16, 3})
@HasCategory(cat = "tooltip")
public class HideDye extends BooleanStat {
public HideDye() {
super("HIDE_DYE", Material.CYAN_DYE, "Hide Dyed", new String[] { "Enable to hide the 'Dyed' tag from the item." }, new String[0],
Material.LEATHER_HELMET, Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, Material.LEATHER_BOOTS, Material.LEATHER_HORSE_ARMOR);
}
public HideDye() {
super("HIDE_DYE", Material.CYAN_DYE, "Hide Dyed",
"Enable to hide the 'Dyed' tag from the item.", null);
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull BooleanData data) {
if (data.isEnabled())
item.getMeta().addItemFlags(ItemFlag.HIDE_DYE);
}
setCompatibleMaterials(Material.LEATHER_HELMET, Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, Material.LEATHER_BOOTS, Material.LEATHER_HORSE_ARMOR);
}
/**
* This stat is saved not as a custom tag, but as the vanilla HideFlag itself.
* Alas this is an empty array
*/
@NotNull
@Override
public ArrayList<ItemTag> getAppliedNBT(@NotNull BooleanData data) { return new ArrayList<>(); }
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull BooleanData data) {
if (data.isEnabled())
item.getMeta().addItemFlags(ItemFlag.HIDE_DYE);
}
@Override
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
if (mmoitem.getNBT().getItem().getItemMeta().hasItemFlag(ItemFlag.HIDE_DYE))
mmoitem.setData(ItemStats.HIDE_DYE, new BooleanData(true));
}
/**
* This stat is saved not as a custom tag, but as the vanilla HideFlag itself.
* Alas this is an empty array
*/
@NotNull
@Override
public ArrayList<ItemTag> getAppliedNBT(@NotNull BooleanData data) {
return new ArrayList<>();
}
@Override
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
if (mmoitem.getNBT().getItem().getItemMeta().hasItemFlag(ItemFlag.HIDE_DYE))
mmoitem.setData(ItemStats.HIDE_DYE, new BooleanData(true));
}
/**
* This stat is saved not as a custom tag, but as the vanilla HideFlag itself.
* Alas this method returns null.
*/
@Nullable
@Override
public BooleanData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) { return null; }
/**
* This stat is saved not as a custom tag, but as the vanilla HideFlag itself.
* Alas this method returns null.
*/
@Nullable
@Override
public BooleanData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
return null;
}
}

View File

@ -6,7 +6,6 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.BooleanData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag;
@ -21,34 +20,41 @@ import java.util.ArrayList;
@Deprecated
@HasCategory(cat = "tooltip")
public class HideEnchants extends BooleanStat {
public HideEnchants() {
super("HIDE_ENCHANTS", Material.BOOK, "Hide Enchantments", new String[] { "Enable to completely hide your item", "enchants. You can still see the glowing effect." }, new String[0]);
}
public HideEnchants() {
super("HIDE_ENCHANTS", Material.BOOK, "Hide Enchantments",
"Enable to completely hide your item enchants. A notable limitation to this vanilla item tag is that the glowing effect remains visible.",
null);
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull BooleanData data) {
if (data.isEnabled())
item.getMeta().addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull BooleanData data) {
if (data.isEnabled())
item.getMeta().addItemFlags(ItemFlag.HIDE_ENCHANTS);
}
@Override
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
if (mmoitem.getNBT().getItem().getItemMeta().hasItemFlag(ItemFlag.HIDE_ENCHANTS))
mmoitem.setData(ItemStats.HIDE_ENCHANTS, new BooleanData(true));
}
@Override
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
if (mmoitem.getNBT().getItem().getItemMeta().hasItemFlag(ItemFlag.HIDE_ENCHANTS))
mmoitem.setData(ItemStats.HIDE_ENCHANTS, new BooleanData(true));
}
/**
* This stat is saved not as a custom tag, but as the vanilla HideFlag itself.
* Alas this is an empty array
*/
@NotNull
@Override
public ArrayList<ItemTag> getAppliedNBT(@NotNull BooleanData data) { return new ArrayList<>(); }
/**
* This stat is saved not as a custom tag, but as the vanilla HideFlag itself.
* Alas this method returns null.
*/
@Nullable
@Override
public BooleanData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) { return null; }
/**
* This stat is saved not as a custom tag, but as the vanilla HideFlag itself.
* Alas this is an empty array
*/
@NotNull
@Override
public ArrayList<ItemTag> getAppliedNBT(@NotNull BooleanData data) {
return new ArrayList<>();
}
/**
* This stat is saved not as a custom tag, but as the vanilla HideFlag itself.
* Alas this method returns null.
*/
@Nullable
@Override
public BooleanData getLoadedNBT(@NotNull ArrayList<ItemTag> storedTags) {
return null;
}
}

View File

@ -24,7 +24,11 @@ import java.util.Arrays;
@Deprecated
public class HidePotionEffects extends BooleanStat {
public HidePotionEffects() {
super("HIDE_POTION_EFFECTS", Material.POTION, "Hide Additional Tooltips", new String[]{"Hides potion effects & additional", "vanilla tooltips from the item lore."}, new String[0], Material.POTION, Material.SPLASH_POTION, Material.LINGERING_POTION, Material.TIPPED_ARROW);
super("HIDE_POTION_EFFECTS", Material.POTION, "Hide Additional Tooltips",
"Hides potion effects & additional vanilla tooltips from the item lore.",
null);
setCompatibleMaterials(Material.POTION, Material.SPLASH_POTION, Material.LINGERING_POTION, Material.TIPPED_ARROW);
}
@BackwardsCompatibility(version = "1.20.5")

View File

@ -5,9 +5,9 @@ import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.annotation.VersionDependant;
import net.Indyuce.mmoitems.stat.data.BooleanData;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import net.Indyuce.mmoitems.stat.annotation.VersionDependant;
import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag;
import org.jetbrains.annotations.NotNull;
@ -23,7 +23,9 @@ import java.util.ArrayList;
@HasCategory(cat = "tooltip")
public class HideTrim extends BooleanStat {
public HideTrim() {
super("HIDE_ARMOR_TRIM", Material.LEATHER_CHESTPLATE, "Hide Armor Trim", new String[]{"Hides armor trim from item lore."}, new String[]{"armor", "skin"});
super("HIDE_ARMOR_TRIM", Material.LEATHER_CHESTPLATE, "Hide Armor Trim",
"Hides armor trim from item lore.",
new String[]{"armor", "skin"});
}
@Override

View File

@ -6,8 +6,8 @@ import net.Indyuce.mmoitems.api.ItemSet;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.StringStat;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
@ -22,8 +22,9 @@ import java.util.ArrayList;
public class ItemSetStat extends StringStat implements GemStoneStat {
public ItemSetStat() {
super("SET", Material.LEATHER_CHESTPLATE, "Item Set",
new String[]{"Item sets can give to the player extra", "bonuses that depend on how many items", "from the same set your wear."},
"Item sets can give to the player extra bonuses that depend on how many items from the same set your wear.",
new String[]{"!gem_stone", "!consumable", "!material", "!block", "!miscellaneous", "all"});
;
}
@Deprecated

View File

@ -1,18 +1,14 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import org.bukkit.Material;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.stat.data.BooleanData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import io.lumine.mythic.lib.api.item.ItemTag;
import org.jetbrains.annotations.NotNull;
import org.bukkit.Material;
@HasCategory(cat = "durability")
public class LostWhenBroken extends BooleanStat {
public LostWhenBroken() {
super("WILL_BREAK", Material.SHEARS, "Lost when Broken?", new String[] { "If set to true, the item will be lost", "once it reaches 0 durability." }, new String[] { "!block", "all" });
}
public LostWhenBroken() {
super("WILL_BREAK", Material.SHEARS, "Lost when Broken?",
"If set to true, the item will be lost once it reaches 0 durability.",
new String[]{"!block", "all"});
}
}

View File

@ -1,62 +0,0 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.util.StatChoice;
import net.Indyuce.mmoitems.stat.annotation.VersionDependant;
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
*/
@HasCategory(cat = "item")
@VersionDependant(version = {1, 20})
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", "skin"});
// Version dependency
if (!isEnabled()) return;
for (TrimMaterial mat : Registry.TRIM_MATERIAL)
addChoices(new StatChoice(mat.getKey().toString()));
}
@Nullable
@Override
public StatChoice getChoice(String id) {
return super.getChoice(TrimPatternStat.fixNamespacedKey(id).toString());
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
if (!(item.getMeta() instanceof ArmorMeta)) return;
@Nullable TrimMaterial material = Registry.TRIM_MATERIAL.get(TrimPatternStat.fixNamespacedKey(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().toString()));
}
}

View File

@ -1,67 +0,0 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.behaviour.GemStoneStat;
import net.Indyuce.mmoitems.util.StatChoice;
import net.Indyuce.mmoitems.stat.annotation.VersionDependant;
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
*/
@HasCategory(cat = "item")
@VersionDependant(version = {1, 20})
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", "skin"});
// Version dependency
if (!isEnabled()) return;
for (TrimPattern mat : Registry.TRIM_PATTERN)
addChoices(new StatChoice(mat.getKey().toString()));
}
public static NamespacedKey fixNamespacedKey(String str) {
if (!str.contains(":")) return NamespacedKey.minecraft(str);
return NamespacedKey.fromString(str);
}
@Nullable
@Override
public StatChoice getChoice(String id) {
return super.getChoice(fixNamespacedKey(id).toString());
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull StringData data) {
if (!(item.getMeta() instanceof ArmorMeta)) return;
@Nullable TrimPattern pattern = Registry.TRIM_PATTERN.get(fixNamespacedKey(data.toString()));
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().toString()));
}
}

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
@ -7,7 +8,6 @@ import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.BooleanData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import io.lumine.mythic.lib.api.item.ItemTag;
import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag;
import org.jetbrains.annotations.NotNull;
@ -18,7 +18,9 @@ import java.util.ArrayList;
@HasCategory(cat = "durability")
public class Unbreakable extends BooleanStat {
public Unbreakable() {
super("UNBREAKABLE", Material.ANVIL, "Unbreakable", new String[]{"Infinite durability if set to true."}, new String[0]);
super("UNBREAKABLE", Material.ANVIL, "Unbreakable",
"Infinite durability if set to true.",
null);
}
@Override

View File

@ -1,29 +1,28 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.api.item.ItemTag;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.BooleanData;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import org.bukkit.Material;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.stat.data.BooleanData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import io.lumine.mythic.lib.api.item.ItemTag;
import org.jetbrains.annotations.NotNull;
@HasCategory(cat = "item")
public class Unstackable extends BooleanStat {
public Unstackable() {
super("UNSTACKABLE", Material.CHEST_MINECART, "Unstackable",
new String[] { "This will make the item unable", "to be stacked with itself." }, new String[0]);
}
public Unstackable() {
super("UNSTACKABLE", Material.CHEST_MINECART, "Unstackable",
"This will make the item unable to be stacked with itself. On MC 1.20.5+ it is recommended to set the item max stack size to 1 instead, which utilizes a stable vanilla item tag.",
null);
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull BooleanData data) {
if (data.isEnabled()) {
item.addItemTag(new ItemTag(getNBTPath(), true));
item.addItemTag(new ItemTag(getNBTPath() + "_UUID", UUID.randomUUID().toString()));
}
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull BooleanData data) {
if (data.isEnabled()) {
item.addItemTag(new ItemTag(getNBTPath(), true));
item.addItemTag(new ItemTag(getNBTPath() + "_UUID", UUID.randomUUID().toString()));
}
}
}

View File

@ -1,28 +1,26 @@
package net.Indyuce.mmoitems.stat;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import org.bukkit.Material;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.stat.data.BooleanData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import io.lumine.mythic.lib.api.item.ItemTag;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.stat.annotation.HasCategory;
import net.Indyuce.mmoitems.stat.data.BooleanData;
import net.Indyuce.mmoitems.stat.type.BooleanStat;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
@HasCategory(cat = "consumables")
public class VanillaEatingAnimation extends BooleanStat {
public VanillaEatingAnimation() {
super("VANILLA_EATING",
Material.COOKED_BEEF,
"Vanilla Eating Animation",
new String[]{"When enabled, players have to wait", "for the vanilla eating animation", "in order to eat the consumable.", "", "Only works on items that", "can normally be eaten."},
new String[]{"consumable"});
}
public VanillaEatingAnimation() {
super("VANILLA_EATING",
Material.COOKED_BEEF,
"Vanilla Eating Animation",
"When enabled, players have to wait for the vanilla eating animation in order to eat the consumable. This only works on items that are actually edible in vanilla Minecraft.",
new String[]{"consumable"});
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull BooleanData data) {
if (data.isEnabled())
item.addItemTag(new ItemTag("MMOITEMS_VANILLA_EATING", true));
}
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull BooleanData data) {
if (data.isEnabled())
item.addItemTag(new ItemTag("MMOITEMS_VANILLA_EATING", true));
}
}

View File

@ -6,9 +6,8 @@ import org.bukkit.Material;
/**
* Vanilla behaviour:
* When a player tries to break a block but doesn't
* have enough pickaxe power, the block is broken but
* does NOT drop anything.
* When a player tries to break a block but doesn't have enough pickaxe power, the
* block is broken but does NOT drop anything.
* <p>
* This option:
* When toggled on, the block simply won't break/drop
@ -16,6 +15,8 @@ import org.bukkit.Material;
@HasCategory(cat = "blocks")
public class RequirePowerToBreak extends BooleanStat {
public RequirePowerToBreak() {
super("REQUIRE_POWER_TO_BREAK", Material.BEDROCK, "Require Power to Break", new String[]{"When enabled, the block will NOT break", "if the player doesn't have enough pickaxe", "power, unlike vanilla block behaviour."}, new String[]{"block"});
super("REQUIRE_POWER_TO_BREAK", Material.BEDROCK, "Require Power to Break",
"When enabled, the block will NOT break if the player doesn't have enough pickaxe power, unlike vanilla block behaviour.",
new String[]{"block"});
}
}

View File

@ -1,34 +1,28 @@
package net.Indyuce.mmoitems.stat.component.builtin;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.gson.JsonElement;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.skill.RegisteredSkill;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import net.Indyuce.mmoitems.stat.component.model.Model;
import net.Indyuce.mmoitems.stat.component.type.ComponentType;
import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.BiConsumer;
public class AbilityComponent extends ObjectComponent implements Model<AbilityComponent> {
private WrapperComponent<RegisteredSkill> skill;
public class AbilityComponent extends ObjectComponent {
private SimpleComponent<RegisteredSkill> skill;
public AbilityComponent(RegisteredSkill value) {
super(value);
public AbilityComponent(RegisteredSkill skill) {
// super(value);
}
/*
@NotNull
public static Type.Builder type() {
return new Type().new Builder();
}
*/
@Override
public void set(@NotNull String key, @NotNull StatComponent component) {
@ -49,7 +43,7 @@ public class AbilityComponent extends ObjectComponent implements Model<AbilityCo
@NotNull
@Override
public Collection<String> getComponentKeys() {
return List.of();
return List.of("ability");
}
@Override
@ -57,18 +51,19 @@ public class AbilityComponent extends ObjectComponent implements Model<AbilityCo
return this;
}
/*
public static class Type extends ComponentType<AbilityComponent, AbilityComponent> {
@NotNull
@Override
public List<String> editionUiFormat(AbilityComponent data) {
return Collections.singletonList(data.getValue().getName());
/*
List<String> format = new ArrayList<>(1 + data.getComponentKeys().size());
format.add("Ability: " + data.getAbility().getName());
data.forEachModifier((key, comp) -> format.add(key + ": " + comp.getValue()));
return format;
*/
}
@Nullable
@ -100,4 +95,5 @@ public class AbilityComponent extends ObjectComponent implements Model<AbilityCo
}
}
}
*/
}

View File

@ -8,7 +8,7 @@ import java.util.Collection;
import java.util.List;
import java.util.function.BiConsumer;
public class CommandComponent extends ObjectComponent{
public class CommandComponent extends ObjectComponent {
@Override
public void set(@NotNull String key, @NotNull StatComponent component) {

View File

@ -11,7 +11,7 @@ import java.util.function.BiConsumer;
@Deprecated
public class EnchantComponent extends ObjectComponent {
private WrapperComponent<Enchantment> enchant;
private SimpleComponent<Enchantment> enchant;
private DoubleComponent level;
@Override
@ -20,7 +20,7 @@ public class EnchantComponent extends ObjectComponent {
case "level":
level = (DoubleComponent) component;
case "enchant":
enchant = (WrapperComponent<Enchantment>) component;
enchant = (SimpleComponent<Enchantment>) component;
}
}

View File

@ -1,11 +1,12 @@
package net.Indyuce.mmoitems.stat.component.builtin;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.gson.JsonElement;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.stat.component.StatComponent;
import net.Indyuce.mmoitems.stat.component.model.Model;
import net.Indyuce.mmoitems.stat.component.type.ComponentType;
import net.Indyuce.mmoitems.util.MMOUtils;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -44,22 +45,22 @@ public class MaterialComponent extends StatComponent implements Model<MaterialCo
return Collections.singletonList(data.getMaterial().name());
}
private static final String INVALID_MATERIAL_MESSAGE = "Could not find material with ID '%s'";
@Nullable
@Override
public Object fromInput(@NotNull String playerInput) {
String format = UtilityMethods.enumName(playerInput);
try {
// Just make sure it exists
Material.valueOf(format);
} catch (Exception exception) {
throw new RuntimeException(String.format("Could not find material called '%s'", format));
}
return format;
return MMOUtils.friendlyValueOf(Material::valueOf, playerInput, INVALID_MATERIAL_MESSAGE).name();
}
@Override
public MaterialComponent fromJson(@NotNull JsonElement json) {
return fromConfig(json.getAsString());
}
@Override
public MaterialComponent fromConfig(@NotNull Object object) {
return new MaterialComponent(Material.valueOf(UtilityMethods.enumName(object.toString())));
return new MaterialComponent(MMOUtils.friendlyValueOf(Material::valueOf, object.toString(), INVALID_MATERIAL_MESSAGE));
}
@NotNull

View File

@ -3,10 +3,10 @@ package net.Indyuce.mmoitems.stat.component.builtin;
import net.Indyuce.mmoitems.stat.component.StatComponent;
// TODO implement mergeable?
public class WrapperComponent<T> extends StatComponent {
public class SimpleComponent<T> extends StatComponent {
private T value;
public WrapperComponent(T value) {
public SimpleComponent(T value) {
this.value = value;
}

View File

@ -1,6 +1,8 @@
package net.Indyuce.mmoitems.stat.component.builtin;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.gson.JsonElement;
import io.lumine.mythic.lib.gson.JsonObject;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.stat.component.model.Model;
import net.Indyuce.mmoitems.stat.component.type.ComponentType;
@ -11,7 +13,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
public class SkullTextureComponent extends WrapperComponent<Object> implements Model<SkullTextureComponent> {
public class SkullTextureComponent extends SimpleComponent<Object> implements Model<SkullTextureComponent> {
public SkullTextureComponent(Object profile) {
super(profile);
}
@ -41,6 +43,17 @@ public class SkullTextureComponent extends WrapperComponent<Object> implements M
return new SkullTextureComponent(profile);
}
@Override
public SkullTextureComponent fromJson(@NotNull JsonElement json) {
JsonObject obj = json.getAsJsonObject();
String value = obj.get("Value").getAsString();
UUID uuid = UUID.fromString(obj.get("UUID").getAsString());
Object profile = MythicLib.plugin.getVersion().getWrapper().newProfile(uuid, value);
return new SkullTextureComponent(profile);
}
@Nullable
@Override
public Object fromInput(@NotNull String playerInput) {

View File

@ -0,0 +1,22 @@
package net.Indyuce.mmoitems.stat.component.model.builtin.composite;
import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder;
import net.Indyuce.mmoitems.stat.component.builtin.AbilityComponent;
import net.Indyuce.mmoitems.stat.component.model.Model;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class AbilityModel implements Model<AbilityComponent> {
@Override
public AbilityComponent randomizeComponent(MMOItemBuilder builder) {
return null;
}
@Nullable
@Override
public Model<?> getModel(@NotNull String key) {
return Model.super.getModel(key);
}
}

View File

@ -1,5 +0,0 @@
package net.Indyuce.mmoitems.stat.component.model.builtin.composite;
public class EnchantComponentType {
// TODO
}

View File

@ -89,7 +89,7 @@ public class ArrayComponentType<C extends StatComponent>
}
public class Builder extends ComponentType<ArrayModel<C>, ArrayComponent<C>>.Builder {
public Builder() {
Builder() {
//setActionLoreTags("Left click to edit this material.", "Right click to remove this option.");
}

View File

@ -54,7 +54,7 @@ public class BooleanComponentType extends ComponentType<BooleanModel, BooleanCom
}
public class Builder extends ComponentType<BooleanModel, BooleanComponent>.Builder {
public Builder() {
Builder() {
setActionLoreTags("Left click to switch this value.", "Right click to choose a probability to have this option.");
setTerminal(true);
}

View File

@ -155,7 +155,7 @@ public class DoubleComponentType extends ComponentType<DoubleModel, DoubleCompon
}
public class Builder extends ComponentType<DoubleModel, DoubleComponent>.Builder {
public Builder() {
Builder() {
setActionLoreTags("Left click to edit this number.", "Right click to remove this option.");
setTerminal(true);
}

View File

@ -158,7 +158,7 @@ public class ObjectComponentType extends ComponentType<ObjectModel, ObjectCompon
}
public class Builder extends ComponentType<ObjectModel, ObjectComponent>.Builder {
public Builder() {
Builder() {
//setActionLoreTags("Left click to edit this material.", "Right click to remove this option.");
}

View File

@ -1,24 +1,53 @@
package net.Indyuce.mmoitems.stat.component.type.builtin;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.gson.JsonElement;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ItemSet;
import net.Indyuce.mmoitems.stat.component.builtin.StringComponent;
import net.Indyuce.mmoitems.stat.component.type.ComponentType;
import net.Indyuce.mmoitems.util.HintedString;
import org.apache.commons.lang.Validate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
public class StringComponentType extends ComponentType<StringComponent, StringComponent> {
private int maximumDisplayLength = -1;
/**
* This makes sure any input string (from user, config or item) is properly formatted.
* This throws an exception otherwise.
*/
@Nullable
private Integer maximumDisplayLength;
private Function<String, String> adaptor;
/**
* Only for user end interaction. This returns a collection of possible values the string
* component can take at this instant in time. For instance, if this component corresponds
* to an item set ID, it should return the list of IDs of existing MMOItems item sets.
*/
@Nullable
private Supplier<List<HintedString>> fetchCandidates;
/**
* Is this a string component with a fixed set of choices?
*/
private boolean choice;
@NotNull
@Override
public List<String> editionUiFormat(StringComponent data) {
String str;
if (maximumDisplayLength != null)
if (maximumDisplayLength > 0)
str = data.getValue().length() > maximumDisplayLength ? data.getValue().substring(0, maximumDisplayLength) : data.getValue();
else str = data.getValue();
return Collections.singletonList(str);
@ -26,17 +55,21 @@ public class StringComponentType extends ComponentType<StringComponent, StringCo
@Override
public StringComponent fromConfig(@NotNull Object object) {
return new StringComponent(object.toString());
return fromInput(object.toString());
}
@Override
public StringComponent fromInput(@NotNull String playerInput) {
return new StringComponent(playerInput);
return new StringComponent(adapt(playerInput));
}
@Override
public StringComponent fromJson(@NotNull JsonElement json) {
return new StringComponent(json.getAsString());
return fromInput(json.getAsString());
}
private String adapt(@NotNull String input) {
return adaptor == null ? input : adaptor.apply(input);
}
@NotNull
@ -44,11 +77,70 @@ public class StringComponentType extends ComponentType<StringComponent, StringCo
return new StringComponentType().new Builder();
}
@NotNull
public static StringComponentType.Builder skillHandler() {
return new StringComponentType().new Builder().adaptor(input -> {
input = UtilityMethods.enumName(input);
MythicLib.plugin.getSkills().getHandlerOrThrow(input); // Validate
return input;
})
// Add an option to provide a list of possible skill handlers?
// List might be very very long
;
}
@NotNull
public static StringComponentType.Builder itemSet() {
return new StringComponentType().new Builder().adaptor(input -> {
input = UtilityMethods.enumName(input);
if (MMOItems.plugin.getSets().get(input) == null)
throw new IllegalArgumentException("Could not find item set with ID '%s'");
return input;
}).valueIndicator(() -> {
List<HintedString> values = new ArrayList<>();
for (ItemSet set : MMOItems.plugin.getSets().getAll())
values.add(new HintedString(set.getId(), set.getName()));
return values;
});
}
public static StringComponentType.Builder withChoices(@NotNull HintedString... candidates) {
return withChoices(Arrays.asList(candidates));
}
public static StringComponentType.Builder withChoices(@NotNull List<HintedString> candidates) {
return new StringComponentType().new Builder().adaptor(input -> {
// Upper case always? Might be made an option later
input = UtilityMethods.enumName(input);
for (HintedString candidate : candidates)
if (candidate.getId().equals(input)) return input;
// Candidate not found
throw new IllegalArgumentException(String.format("Choice '%' not found", input));
}).valueIndicator(() -> candidates).enableChoices();
}
public class Builder extends ComponentType<StringComponent, StringComponent>.Builder {
public Builder() {
Builder() {
setActionLoreTags("Left click to edit this string.", "Right click to remove this option.");
}
public Builder adaptor(@Nullable Function<String, String> adaptor) {
StringComponentType.this.adaptor = adaptor;
return this;
}
public Builder valueIndicator(@Nullable Supplier<List<HintedString>> fetchCandidates) {
StringComponentType.this.fetchCandidates = fetchCandidates;
return this;
}
public Builder enableChoices() {
Validate.notNull(StringComponentType.this.fetchCandidates, "fetchCandidates cannot be null");
Validate.notNull(StringComponentType.this.adaptor, "adaptor cannot be null");
StringComponentType.this.choice = true;
return this;
}
public Builder maxUiDisplayLength(int length) {
maximumDisplayLength = length;
return this;
@ -59,4 +151,65 @@ public class StringComponentType extends ComponentType<StringComponent, StringCo
return (StringComponentType) super.build();
}
}
/*
@Deprecated
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
Validate.isTrue(!choices.isEmpty(), "Invalid choice-based stat '" + getId() + ": no options to choose from.");
// If removing, reset to default
if (event.getAction() == InventoryAction.PICKUP_HALF) {
// Edits into persistent files
inv.getEditedSection().set(getPath(), null);
inv.registerTemplateEdition();
// Mention that it was removed
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed " + getName() + ".");
} else {
// Get current
String found = inv.getEditedSection().getString(getPath());
int currentIndex = found == null ? -1 : choices.indexOf(getChoice(found));
// Increase and Cap
if (++currentIndex >= choices.size()) currentIndex = 0;
// Edits into persistent files
HintedString current = choices.get(currentIndex);
inv.getEditedSection().set(getPath(), current.getId());
inv.registerTemplateEdition();
// Sends a message
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + getName() + " successfully changed to " + current + ChatColor.GRAY + ".");
}
}
@Deprecated
public void whenDisplayed(List<String> lore, Optional<StringData> statData) {
Validate.isTrue(!choices.isEmpty(), "Invalid choice-based stat '" + getId() + ": no options to choose from.");
// To display current choosing, gets the very first element
@Nullable HintedString found = statData.isPresent() ? getChoice(statData.get().toString()) : null;
lore.add(ChatColor.GRAY + "Current Value: " + (found != null ? ChatColor.GREEN + found.getId() : ChatColor.RED + "None"));
// Display Definition
if (found != null && found.getHint() != null)
for (String definition : MMOUtils.trimString(LORE_LINE_WIDTH, found.getHint()))
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 (HintedString existing : choices) {
// Is it the one?
String pick = existing.equals(found) ? ChatColor.RED.toString() + ChatColor.BOLD : ChatColor.GOLD.toString();
lore.add(pick + " " + AltChar.smallListDash + " " + ChatColor.GRAY + existing.getId());
}
}
*/
}

View File

@ -5,10 +5,10 @@ import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.api.util.AltChar;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.input.LegacyItemInputHandler;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.input.LegacyItemInputHandler;
import net.Indyuce.mmoitems.stat.component.type.builtin.BooleanComponentType;
import net.Indyuce.mmoitems.stat.data.BooleanData;
import net.Indyuce.mmoitems.stat.data.random.RandomBooleanData;
@ -26,13 +26,8 @@ import java.util.List;
import java.util.Optional;
public class BooleanStat extends ItemStat<RandomBooleanData, BooleanData> {
@Deprecated
public BooleanStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) {
this(id, mat, name, MMOUtils.append(lore), types, materials);
}
public BooleanStat(String id, Material mat, String name, String lore, String[] types, Material... materials) {
super(id, types, materials);
public BooleanStat(String id, Material mat, String name, String lore, String[] types) {
super(id, types);
setComponentType(BooleanComponentType.toggle()
//.setKey(id)

View File

@ -1,110 +0,0 @@
package net.Indyuce.mmoitems.stat.type;
import io.lumine.mythic.lib.api.util.AltChar;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.util.MMOUtils;
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.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
/**
* Choose Stats present a list of options from which the user may choose one.
* <p></p>
* You could consider them a more advanced DisableStat, while DisableStat only
* allows to choose <b>true</b> or <b>false</b>, alternating when clicked, Choose
* Stats cycle through a list instead.
*
* @author Gunging
*/
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 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(StatChoice... choices) {
this.choices.addAll(Arrays.asList(choices));
}
@Nullable
public StatChoice getChoice(String id) {
for (StatChoice choice : choices)
if (choice.getId().equals(id))
return choice;
return null;
}
@Deprecated
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
Validate.isTrue(!choices.isEmpty(), "Invalid choice-based stat '" + getId() + ": no options to choose from.");
// If removing, reset to default
if (event.getAction() == InventoryAction.PICKUP_HALF) {
// Edits into persistent files
inv.getEditedSection().set(getPath(), null);
inv.registerTemplateEdition();
// Mention that it was removed
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Successfully removed " + getName() + ".");
} else {
// Get current
String found = inv.getEditedSection().getString(getPath());
int currentIndex = found == null ? -1 : choices.indexOf(getChoice(found));
// Increase and Cap
if (++currentIndex >= choices.size()) currentIndex = 0;
// Edits into persistent files
StatChoice current = choices.get(currentIndex);
inv.getEditedSection().set(getPath(), current.getId());
inv.registerTemplateEdition();
// Sends a message
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + getName() + " successfully changed to " + current + ChatColor.GRAY + ".");
}
}
@Deprecated
public void whenDisplayed(List<String> lore, Optional<StringData> statData) {
Validate.isTrue(!choices.isEmpty(), "Invalid choice-based stat '" + getId() + ": no options to choose from.");
// To display current choosing, gets the very first element
@Nullable StatChoice found = statData.isPresent() ? getChoice(statData.get().toString()) : null;
lore.add(ChatColor.GRAY + "Current Value: " + (found != null ? ChatColor.GREEN + found.getId() : ChatColor.RED + "None"));
// Display Definition
if (found != null && found.getHint() != null) for (String definition : MMOUtils.trimString(LORE_LINE_WIDTH, found.getHint()))
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 (StatChoice existing : choices) {
// Is it the one?
String pick = existing.equals(found) ? ChatColor.RED.toString() + ChatColor.BOLD : ChatColor.GOLD.toString();
lore.add(pick + " " + AltChar.smallListDash + " " + ChatColor.GRAY + existing.getId());
}
}
}

View File

@ -10,21 +10,9 @@ import io.lumine.mythic.lib.api.item.ItemTag;
import org.jetbrains.annotations.NotNull;
public class DisableStat extends BooleanStat {
public DisableStat(String id, Material material, String name, String... lore) {
public DisableStat(String id, Material material, String name, String lore, String[] types) {
super("DISABLE_" + id, material, name, lore, null);
setCategory(StatCategories.TOGGLES);
}
public DisableStat(String id, Material material, String name, Material[] materials, String... lore) {
super("DISABLE_" + id, material, name, lore, null, materials);
setCategory(StatCategories.TOGGLES);
}
public DisableStat(String id, Material material, String name, String[] types, String... lore) {
super("DISABLE_" + id, material, name, lore, types);
setCategory(StatCategories.TOGGLES);
}
}

View File

@ -7,21 +7,21 @@ import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.annotation.VersionDependant;
import net.Indyuce.mmoitems.stat.category.StatCategory;
import net.Indyuce.mmoitems.stat.component.type.ComponentType;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import org.apache.commons.lang.Validate;
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;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData> {
@ -116,15 +116,22 @@ public abstract class ItemStat<R extends RandomStatData<S>, S extends StatData>
public void setComponentType(ComponentType<?, ?> componentType) {
this.componentType = componentType;
// Validate.isTrue(componentType.getKey().equals(getId()), "Stat ID and component key do not match");
// Validate.isTrue(componentType.getKey().equals(getId()), "Stat ID and component key do not match");
}
public ComponentType<?, ?> getComponentType() {
return componentType;
}
public void setCompatibleMaterials(@Nullable List<Material> compatibleMaterials) {
@NotNull
public ItemStat<R, S> setCompatibleMaterials(@NotNull Material... compatibleMaterials) {
return setCompatibleMaterials(Arrays.asList(compatibleMaterials));
}
@NotNull
public ItemStat<R, S> setCompatibleMaterials(@Nullable List<Material> compatibleMaterials) {
this.compatibleMaterials = compatibleMaterials;
return this;
}
/**

View File

@ -12,7 +12,10 @@ import org.jetbrains.annotations.NotNull;
* stat displays the RNG result it got when crafted)
*
* @author Gunging
*
* // TODO generalize this via double components.
*/
@Deprecated
public interface Previewable<R extends RandomStatData<S>, S extends StatData> {
/**

View File

@ -14,12 +14,14 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
public class StringStat extends ItemStat<StringData, StringData> {
public StringStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) {
this(id, mat, name, MMOUtils.append(lore), types, materials);
@Deprecated
public StringStat(String id, Material mat, String name, String[] lore, String[] types) {
this(id, mat, name, MMOUtils.append(lore), types);
}
public StringStat(String id, Material mat, String name, String lore, String[] types, Material... materials) {
super(id, types, materials);
public StringStat(String id, Material mat, String name, String lore, String[] types) {
super(id, types);
setComponentType(StringComponentType.init()
//.setKey(id)
@ -29,6 +31,10 @@ public class StringStat extends ItemStat<StringData, StringData> {
.build());
}
public StringStat(String id, String[] types) {
super(id, types);
}
@Override
public StringData whenInitialized(Object object) {
return new StringData(object.toString());

View File

@ -4,14 +4,17 @@ import org.jetbrains.annotations.Nullable;
import java.util.Objects;
public class StatChoice {
/**
* Basically a fancy pair of strings
*/
public class HintedString {
private final String id, hint;
public StatChoice(String id) {
public HintedString(String id) {
this(id, null);
}
public StatChoice(String id, @Nullable String hint) {
public HintedString(String id, @Nullable String hint) {
this.id = id;
this.hint = hint;
}
@ -34,7 +37,7 @@ public class StatChoice {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StatChoice choice = (StatChoice) o;
HintedString choice = (HintedString) o;
return id.equals(choice.id);
}

View File

@ -29,6 +29,7 @@ import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.function.Function;
@SuppressWarnings("unused")
public class MMOUtils {
@ -86,6 +87,19 @@ public class MMOUtils {
return builder.toString();
}
/**
* Catch exception with a more friendly error message
*/
@NotNull
public static <T> T friendlyValueOf(Function<String, T> valueOfFunction, String input, String messageFormat) {
input = UtilityMethods.enumName(input);
try {
return valueOfFunction.apply(input);
} catch (Exception exception) {
throw new RuntimeException(String.format(messageFormat, input));
}
}
@NotNull
public static ItemStack readIcon(@NotNull String stringInput) {
Validate.notNull(stringInput, "Input must not be null");