!Hopefully fixed an item requirement issue

Small code cleanup
This commit is contained in:
Indyuce 2021-06-13 14:21:00 +02:00
parent 4442f1221d
commit 97f4f59889
24 changed files with 364 additions and 394 deletions

View File

@ -1,8 +1,5 @@
package net.Indyuce.mmoitems;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory;
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackMessage;
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider;
@ -237,14 +234,13 @@ public class MMOItems extends LuminePlugin {
* Registers Player Inventories. Each of these add locations of items to search for
* when doing inventory updates.
*/
registerPlayerInventory(new DefaultPlayerInventory());
getInventory().register(new DefaultPlayerInventory());
if (Bukkit.getPluginManager().getPlugin("RPGInventory") != null) {
registerPlayerInventory(new RPGInventoryHook());
getInventory().register(new RPGInventoryHook());
getLogger().log(Level.INFO, "Hooked onto RPGInventory");
}
if (MMOItems.plugin.getConfig().getBoolean("iterate-whole-inventory")) {
registerPlayerInventory(new OrnamentPlayerInventory());
}
if (MMOItems.plugin.getConfig().getBoolean("iterate-whole-inventory"))
getInventory().register(new OrnamentPlayerInventory());
if (Bukkit.getPluginManager().getPlugin("AdvancedEnchantments") != null) {
Bukkit.getPluginManager().registerEvents(new AdvancedEnchantmentsHook(), this);
@ -406,19 +402,6 @@ public class MMOItems extends LuminePlugin {
return inventory;
}
/**
* The PlayerInventory interface lets MMOItems knows what items to look for
* in player inventories whe doing inventory updates. By default, it only
* checks held items + armor slots. However other plugins like MMOInv do
* implement custom slots and therefore must register a custom
* PlayerInventory instance that tells of additional items to look for.
*/
public void registerPlayerInventory(PlayerInventory value) {
// Registers in the Inventory Handler
getInventory().register(value);
}
/**
* The PlayerInventory interface lets MMOItems knows what items to look for
* in player inventories whe doing inventory updates. By default, it only
@ -431,7 +414,7 @@ public class MMOItems extends LuminePlugin {
* @param value The player inventory subclass
* @deprecated Rather than setting this to the only inventory MMOItems will
* search equipment within, you must add your inventory to the
* handler with <code>getInventory().Register()</code>. This method
* handler with <code>getInventory().register()</code>. This method
* will clear all other PlayerInventories for now, as to keep
* backwards compatibility.
*/
@ -560,9 +543,9 @@ public class MMOItems extends LuminePlugin {
// Mention it
print(null, "Using $s{0}$b as RPGPlayer provider", "RPG Provider", preferredRPG.getName());
return;
} else {
} else
print(null, "Preferred RPGPlayer provider $r{0}$b is not installed!", "RPG Provider", preferred); }
print(null, "Preferred RPGPlayer provider $r{0}$b is not installed!", "RPG Provider", preferred);
} catch (IllegalArgumentException ignored) {
@ -596,16 +579,19 @@ public class MMOItems extends LuminePlugin {
/**
* @return Generates an item given an item template. The item level will
* scale according to the player RPG level if the template has the
* 'level-item' option. The item will pick a random tier if the
* template has the 'tiered' option
* scale according to the player RPG level if the template has the
* 'level-item' option. The item will pick a random tier if the
* template has the 'tiered' option
*/
@Nullable public MMOItem getMMOItem(@Nullable Type type, @Nullable String id, @NotNull PlayerData player) {
if (type == null || id == null) { return null; }
@Nullable
public MMOItem getMMOItem(@NotNull Type type, @NotNull String id, @NotNull PlayerData player) {
Validate.notNull(type, "Type cannot be null");
Validate.notNull(id, "ID cannot be null");
// Valid template?
MMOItemTemplate found = getTemplates().getTemplate(type, id);
if (found == null) { return null; }
if (found == null)
return null;
// Build if found
return found.newBuilder(player.getRPG()).build();
@ -613,50 +599,59 @@ public class MMOItems extends LuminePlugin {
/**
* @return Generates an item given an item template. The item level will
* scale according to the player RPG level if the template has the
* 'level-item' option. The item will pick a random tier if the
* template has the 'tiered' option
* scale according to the player RPG level if the template has the
* 'level-item' option. The item will pick a random tier if the
* template has the 'tiered' option
*/
@Nullable public ItemStack getItem(@Nullable Type type, @Nullable String id, @NotNull PlayerData player) {
if (type == null || id == null) { return null; }
@Nullable
public ItemStack getItem(@NotNull Type type, @NotNull String id, @NotNull PlayerData player) {
Validate.notNull(type, "Type cannot be null");
Validate.notNull(id, "ID cannot be null");
// Valid MMOItem?
MMOItem m = getMMOItem(type, id, player);
if (m == null) { return null; }
if (m == null)
return null;
// Build if found
return m.newBuilder().build();
}
/**
* @param itemLevel The desired item level
* @param itemTier The desired item tier, can be null
* @return Generates an item given an item template with a
* specific item level and item tier
* @param itemLevel The desired item level
* @param itemTier The desired item tier, can be null
* @return Generates an item given an item template with a
* specific item level and item tier
*/
@Nullable public MMOItem getMMOItem(@Nullable Type type, @Nullable String id, int itemLevel, @Nullable ItemTier itemTier) {
if (type == null || id == null) { return null; }
@Nullable
public MMOItem getMMOItem(@NotNull Type type, @NotNull String id, int itemLevel, @Nullable ItemTier itemTier) {
Validate.notNull(type, "Type cannot be null");
Validate.notNull(id, "ID cannot be null");
// Valid template?
MMOItemTemplate found = getTemplates().getTemplate(type, id);
if (found == null) { return null; }
if (found == null)
return null;
// Build if found
return found.newBuilder(itemLevel, itemTier).build();
}
/**
* @param itemLevel The desired item level
* @param itemTier The desired item tier, can be null
* @return Generates an item given an item template with a
* specific item level and item tier
* @param itemLevel The desired item level
* @param itemTier The desired item tier, can be null
* @return Generates an item given an item template with a
* specific item level and item tier
*/
@Nullable public ItemStack getItem(@Nullable Type type, @Nullable String id, int itemLevel, @Nullable ItemTier itemTier) {
if (type == null || id == null) { return null; }
@Nullable
public ItemStack getItem(@NotNull Type type, @NotNull String id, int itemLevel, @Nullable ItemTier itemTier) {
Validate.notNull(type, "Type cannot be null");
Validate.notNull(id, "ID cannot be null");
// Valid MMOItem?
MMOItem m = getMMOItem(type, id, itemLevel, itemTier);
if (m == null) { return null; }
if (m == null)
return null;
// Build if found
return m.newBuilder().build();
@ -664,17 +659,19 @@ public class MMOItems extends LuminePlugin {
/**
* @return Generates an item given an item template. The item level will be
* 0 and the item will have no item tier unless one is specified in
* the base item data.
* <p></p>
* Will return <code>null</code> if such MMOItem does not exist.
* 0 and the item will have no item tier unless one is specified in
* the base item data.
* <p></p>
* Will return <code>null</code> if such MMOItem does not exist.
*/
@Nullable public MMOItem getMMOItem(@Nullable Type type, @Nullable String id) {
if (type == null || id == null) { return null; }
@Nullable
public MMOItem getMMOItem(@NotNull Type type, @NotNull String id) {
Validate.notNull(type, "Type cannot be null");
Validate.notNull(id, "ID cannot be null");
// Valid template?
MMOItemTemplate found = getTemplates().getTemplate(type, id);
if (found == null) { return null; }
if (found == null) return null;
// Build if found
return found.newBuilder(0, null).build();
@ -682,70 +679,43 @@ public class MMOItems extends LuminePlugin {
/**
* @return Generates an item given an item template. The item level will be
* 0 and the item will have no item tier unless one is specified in
* the base item data.
* <p></p>
* Will return <code>null</code> if such MMOItem does not exist.
* 0 and the item will have no item tier unless one is specified in
* the base item data.
* <p></p>
* Will return <code>null</code> if such MMOItem does not exist.
*/
@Nullable public ItemStack getItem(@Nullable String type, @Nullable String id) {
if (type == null || id == null) { return null; }
return getItem(getType(type), id);
@Nullable
public ItemStack getItem(@Nullable String type, @Nullable String id) {
if (type == null || id == null) {
return null;
}
return getItem(getTypes().get(type), id);
}
/**
* @return Generates an item given an item template. The item level will be
* 0 and the item will have no item tier unless one is specified in
* the base item data.
* <p></p>
* Will return <code>null</code> if such MMOItem does not exist.
* 0 and the item will have no item tier unless one is specified in
* the base item data.
* <p></p>
* Will return <code>null</code> if such MMOItem does not exist.
*/
@Nullable public ItemStack getItem(@Nullable Type type, @Nullable String id) {
if (type == null || id == null) { return null; }
@Nullable
public ItemStack getItem(@Nullable Type type, @Nullable String id) {
if (type == null || id == null) {
return null;
}
// Valid MMOItem?
MMOItem m = getMMOItem(type, id);
if (m == null) { return null; }
if (m == null) {
return null;
}
// Build if found
return m.newBuilder().build();
}
/**
* @param nbtItem The NBTItem you are testing
* @return The MMOItem Type of this item, if it is a MMOItem
*/
@Nullable public Type getType(@Nullable NBTItem nbtItem) {
if (nbtItem == null || !nbtItem.hasType()) { return null; }
// Try that one instead
return getType(nbtItem.getType());
}
/**
* @param nbtItem The NBTItem you are testing
* @return The MMOItem ID of this item, if it is a MMOItem
*/
@Nullable public String getID(@Nullable NBTItem nbtItem) {
if (nbtItem == null || !nbtItem.hasType()) { return null; }
ItemTag type = ItemTag.getTagAtPath("MMOITEMS_ITEM_ID", nbtItem, SupportedNBTTagValues.STRING);
if (type == null) { return null; }
return (String) type.getValue();
}
/**
* Shorthand to get the specified type.
*
* @param type What do you think its called
*
* @return A type if such exists.
*/
@Nullable public Type getType(@Nullable String type) {
if (type == null) { return null; }
return getTypes().get(type);
}
/**
* Logs something into the console with a cool [MMOItems] prefix :)
* <p></p>
@ -782,31 +752,4 @@ public class MMOItems extends LuminePlugin {
* @author Gunging
*/
@NotNull public static ConsoleCommandSender getConsole() { return plugin.getServer().getConsoleSender(); }
/**
* @param item The item stack you are testing.
* @param type MMOItem Type you are expecting {@link Type#getId()}
* @param id MMOItem ID you are expecting
*
* @return If the given item is the desired MMOItem
*/
public static boolean isMMOItem(@Nullable ItemStack item, @NotNull String type, @NotNull String id) {
if (item == null) { return false; }
// Make it into an NBT Item
NBTItem asNBT = NBTItem.get(item);
// ID Matches?
String itemID = MMOItems.plugin.getID(asNBT);
// Not a MMOItem
if (itemID == null) { return false; }
// ID matches?
if (!itemID.equals(id)) { return false; }
// If the type matches too, we are set.
return asNBT.getType().equals(type);
}
//endregion
}

View File

@ -2,18 +2,18 @@ package net.Indyuce.mmoitems;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.Indyuce.mmoitems.api.player.PlayerData;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.player.PlayerData;
import org.apache.commons.codec.binary.Base64;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.*;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -23,13 +23,14 @@ import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.*;
@SuppressWarnings("unused")
public class MMOUtils {
/**
* @return The skull texture URL from a given player head
*/
public static String getSkullTextureURL(ItemStack item) {
try {
ItemMeta meta = item.getItemMeta();
@ -44,7 +45,67 @@ public class MMOUtils {
}
/**
* Returns either the normalized vector, or null vector if input is null
* @param item The item stack you are testing.
* @param type MMOItem Type you are expecting {@link Type#getId()}
* @param id MMOItem ID you are expecting
* @return If the given item is the desired MMOItem
*/
public static boolean isMMOItem(@Nullable ItemStack item, @NotNull String type, @NotNull String id) {
if (item == null) {
return false;
}
// Make it into an NBT Item
NBTItem asNBT = NBTItem.get(item);
// ID Matches?
String itemID = getID(asNBT);
// Not a MMOItem
if (itemID == null)
return false;
// ID matches?
if (!itemID.equals(id))
return false;
// If the type matches too, we are set.
return asNBT.getType().equals(type);
}
/**
* @param nbtItem The NBTItem you are testing
* @return The MMOItem Type of this item, if it is a MMOItem
*/
@Nullable
public static Type getType(@Nullable NBTItem nbtItem) {
if (nbtItem == null || !nbtItem.hasType()) {
return null;
}
// Try that one instead
return MMOItems.plugin.getTypes().get(nbtItem.getType());
}
/**
* @param nbtItem The NBTItem you are testing
* @return The MMOItem ID of this item, if it is a MMOItem
*/
@Nullable
public static String getID(@Nullable NBTItem nbtItem) {
if (nbtItem == null || !nbtItem.hasType()) {
return null;
}
ItemTag type = ItemTag.getTagAtPath("MMOITEMS_ITEM_ID", nbtItem, SupportedNBTTagValues.STRING);
if (type == null) {
return null;
}
return (String) type.getValue();
}
/**
* * Returns either the normalized vector, or null vector if input is null
* vector which cannot be normalized.
*
* @param vector Vector which can be of length 0
@ -70,6 +131,24 @@ public class MMOUtils {
}
}
/**
* Returns an UUID from thay string, or null if it is not in UUID format.
*/
@Nullable
public static UUID UUIDFromString(@org.jetbrains.annotations.Nullable String anything) {
if (anything == null) { return null; }
// Correct Format?
if (anything.matches("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}")) {
// Return thay
return UUID.fromString(anything);
}
// No
return null;
}
public static String getProgressBar(double ratio, int n, String barChar) {
StringBuilder bar = new StringBuilder();
for (int k = 0; k < n; k++)

View File

@ -123,7 +123,7 @@ public class MMOItemUIFilter implements UIFilter {
data = data.replace(" ", "_").replace("-", "_").toUpperCase();
// Type exists?
Type t = MMOItems.plugin.getType(argument);
Type t = MMOItems.plugin.getTypes().get(argument);
// Nope
if (t == null) {
@ -267,7 +267,7 @@ public class MMOItemUIFilter implements UIFilter {
if (dataments.endsWith("}")) { dataments = dataments.substring(0, dataments.length()-1); } }
data = data.replace(" ", "_").replace("-", "_").toUpperCase();
MMOItem m = MMOItems.plugin.getMMOItem(MMOItems.plugin.getType(argument), data);
MMOItem m = MMOItems.plugin.getMMOItem(MMOItems.plugin.getTypes().get(argument), data);
// Find upgrade?
if (!dataments.isEmpty()) {

View File

@ -30,7 +30,7 @@ public class Consumable extends UseItem {
}
@Override
public boolean applyItemCosts() {
public boolean checkItemRequirements() {
return MMOItems.plugin.getFlags().isFlagAllowed(player, CustomFlag.MI_CONSUMABLES) && playerData.getRPG().canUse(getNBTItem(), true);
}

View File

@ -22,7 +22,7 @@ public class Tool extends UseItem {
}
@Override
public boolean applyItemCosts() {
public boolean checkItemRequirements() {
return MMOItems.plugin.getFlags().isFlagAllowed(player, CustomFlag.MI_TOOLS) && playerData.getRPG().canUse(getNBTItem(), true);
}

View File

@ -67,7 +67,7 @@ public class UseItem {
*
* @return If the item can be used
*/
public boolean applyItemCosts() {
public boolean checkItemRequirements() {
return playerData.getRPG().canUse(mmoitem.getNBT(), true);
}

View File

@ -1,13 +1,6 @@
package net.Indyuce.mmoitems.api.interaction.weapon;
import javax.annotation.Nullable;
import net.Indyuce.mmoitems.comp.flags.FlagPlugin;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
@ -17,10 +10,14 @@ import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.PlayerData.CooldownType;
import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats;
import net.Indyuce.mmoitems.api.util.message.Message;
import net.Indyuce.mmoitems.comp.flags.FlagPlugin;
import net.Indyuce.mmoitems.comp.flags.FlagPlugin.CustomFlag;
import io.lumine.mythic.lib.api.item.NBTItem;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.logging.Level;
import javax.annotation.Nullable;
public class Weapon extends UseItem {
public Weapon(Player player, NBTItem item) {
@ -32,21 +29,25 @@ public class Weapon extends UseItem {
}
@Override
public boolean applyItemCosts() {
public boolean checkItemRequirements() {
if (MMOUtils.twoHandedCase(getPlayer())) {
Message.HANDS_TOO_CHARGED.format(ChatColor.RED).send(getPlayer(), "two-handed");
return false;
}
// Check for class, level...
boolean asCanUse = playerData.getRPG().canUse(getNBTItem(), true);
boolean asFlagAllowed = true; FlagPlugin fg = MMOItems.plugin.getFlags(); if (fg != null) { asFlagAllowed = fg.isFlagAllowed(getPlayer(), CustomFlag.MI_WEAPONS); }
else { MMOItems.print(Level.WARNING, "$fFlag plugin not found", null); }
return asCanUse || asFlagAllowed;
// Check for flags
FlagPlugin flagPlugin = MMOItems.plugin.getFlags();
boolean asFlagAllowed = flagPlugin == null || flagPlugin.isFlagAllowed(getPlayer(), CustomFlag.MI_WEAPONS);
return asCanUse && asFlagAllowed;
}
/**
* Applies mana and stamina weapon costs
*
* Only applies mana and stamina weapon costs
*
* @return If the attack was cast successfully
*/
public boolean applyWeaponCosts() {
@ -55,11 +56,11 @@ public class Weapon extends UseItem {
/**
* Applies cooldown, mana and stamina weapon costs
*
* @param attackSpeed The weapon attack speed
* @param cooldown The weapon cooldown type. When set to null, no
* cooldown will be applied. This is made to handle
* @return If the attack was cast successfully
*
* @param attackSpeed The weapon attack speed
* @param cooldown The weapon cooldown type. When set to null, no
* cooldown will be applied. This is made to handle
* @return If requirements were met ie the attack was cast successfully
*/
public boolean applyWeaponCosts(double attackSpeed, @Nullable CooldownType cooldown) {
if (cooldown != null && getPlayerData().isOnCooldown(cooldown))

View File

@ -27,7 +27,7 @@ public class Crossbow extends UntargetedWeapon {
if (getPlayer().getGameMode() != GameMode.CREATIVE && !getPlayer().getInventory().containsAtLeast(new ItemStack(Material.ARROW), 1))
return;
if (!ItemUse.eitherHandSuccess(getPlayer(), getNBTItem(), slot))
if (!ItemUse.checkDualWield(getPlayer(), getNBTItem(), slot))
return;
PlayerStats stats = getPlayerData().getStats();
if (!applyWeaponCosts(1 / getValue(stats.getStat(ItemStats.ATTACK_SPEED), MMOItems.plugin.getConfig().getDouble("default.attack-speed")),

View File

@ -1,6 +1,5 @@
package net.Indyuce.mmoitems.api.interaction.weapon.untargeted;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import io.lumine.mythic.lib.MythicLib;
import net.Indyuce.mmoitems.ItemStats;
@ -36,7 +35,7 @@ public class Lute extends UntargetedWeapon {
@Override
public void untargetedAttack(EquipmentSlot slot) {
if (!ItemUse.eitherHandSuccess(getPlayer(), getNBTItem(), slot))
if (!ItemUse.checkDualWield(getPlayer(), getNBTItem(), slot))
return;
CachedStats stats = getPlayerData().getStats().newTemporary();
double attackSpeed = 1 / getValue(stats.getStat(ItemStats.ATTACK_SPEED), MMOItems.plugin.getConfig().getDouble("default.attack-speed"));

View File

@ -26,7 +26,7 @@ public class Musket extends UntargetedWeapon {
@Override
public void untargetedAttack(EquipmentSlot slot) {
if (!ItemUse.eitherHandSuccess(getPlayer(), getNBTItem(), slot))
if (!ItemUse.checkDualWield(getPlayer(), getNBTItem(), slot))
return;
CachedStats stats = getPlayerData().getStats().newTemporary();

View File

@ -2,6 +2,7 @@ package net.Indyuce.mmoitems.api.item.mmoitem;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.UpgradeTemplate;
import net.Indyuce.mmoitems.api.item.ItemReference;
@ -9,7 +10,6 @@ import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
import net.Indyuce.mmoitems.stat.Enchants;
import net.Indyuce.mmoitems.stat.data.GemSocketsData;
import net.Indyuce.mmoitems.stat.data.GemstoneData;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.data.UpgradeData;
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
import net.Indyuce.mmoitems.stat.data.type.StatData;
@ -45,8 +45,7 @@ public class MMOItem implements ItemReference {
@Override public String getId() { return id; }
//region Item Stats - Where the Magic Happens
/*
/**
* Where data about all the item stats is stored. When the item is
* generated, this map is read and all the stats are applied. The order in
* which stats are added is not very important anymore
@ -54,7 +53,7 @@ public class MMOItem implements ItemReference {
@NotNull private final Map<ItemStat, StatData> stats = new HashMap<>();
/**
* Will merge that data into this item's:
* Will merge that data into this item:
* <p></p>
* If the item does not have this stat yet, it will be set with <code>MMOItem.setData()</code>
* <p>If this data is not <code>Mergeable</code>, it will also be set</p>
@ -208,9 +207,7 @@ public class MMOItem implements ItemReference {
public void setStatHistory(@NotNull ItemStat stat, @NotNull StatHistory hist) {
mergeableStatHistory.put(stat.getNBTPath(), hist);
}
//endregion
//region Upgrading API
/**
* Upgrades this MMOItem one level.
* <p></p>
@ -227,37 +224,14 @@ public class MMOItem implements ItemReference {
* required to call
*/
public boolean hasUpgradeTemplate() {
// Does it have Upgrade Stat?
if (hasData(ItemStats.UPGRADE)) {
// Get that data
UpgradeData data = (UpgradeData) getData(ItemStats.UPGRADE);
// A template its all that's required
return data.getTemplate() != null;
}
// Nope
return false;
return hasData(ItemStats.UPGRADE) && ((UpgradeData) getData(ItemStats.UPGRADE)).getTemplate() != null;
}
/**
* @return The upgrade level, or 0 if there is none.
*/
public int getUpgradeLevel() {
// Does it have Upgrade Data?
if (hasData(ItemStats.UPGRADE)) {
//UPGR//MMOItems.log(" \u00a7b?\u00a7c?\u00a7e? \u00a77Found Upgrade Data: \u00a7b" + ((UpgradeData) getData(ItemStats.UPGRADE)).getLevel());
// Return the registered level.
return ((UpgradeData) getData(ItemStats.UPGRADE)).getLevel();
}
//UPGR//MMOItems.log(" \u00a7b?\u00a7c?\u00a7e? \u00a77No Upgrade Data: \u00a7b0");
// Nope? Well its level 0 I guess.
return 0;
return hasData(ItemStats.UPGRADE) ? ((UpgradeData) getData(ItemStats.UPGRADE)).getLevel() : 0;
}
/**
@ -284,7 +258,7 @@ public class MMOItem implements ItemReference {
*/
@SuppressWarnings("ConstantConditions")
@NotNull public UpgradeTemplate getUpgradeTemplate() {
Validate.isTrue(hasUpgradeTemplate(), "This item has no Upgrade Information, do not call this method without checking first!");
Validate.isTrue(hasUpgradeTemplate(), "Item without upgrade information");
// All Right
UpgradeData data = (UpgradeData) getData(ItemStats.UPGRADE);
@ -344,7 +318,7 @@ public class MMOItem implements ItemReference {
//XTC//MMOItems.log("\u00a7a *\u00a77 Found gem stone -\u00a7a " + gem.getMMOItemType() + " " + gem.getMMOItemID());
// Can we generate?
MMOItem restored = MMOItems.plugin.getMMOItem(MMOItems.plugin.getType(gem.getMMOItemType()), gem.getMMOItemID());
MMOItem restored = MMOItems.plugin.getMMOItem(MMOItems.plugin.getTypes().get(gem.getMMOItemType()), gem.getMMOItemID());
// Valid? neat-o
if (restored != null) {
@ -404,7 +378,7 @@ public class MMOItem implements ItemReference {
//XTC//MMOItems.log("\u00a7a *\u00a77 Extracting gem stone -\u00a7a " + gem.getMMOItemType() + " " + gem.getMMOItemID());
// Can we generate?
MMOItem restored = MMOItems.plugin.getMMOItem(MMOItems.plugin.getType(gem.getMMOItemType()), gem.getMMOItemID());
MMOItem restored = MMOItems.plugin.getMMOItem(MMOItems.plugin.getTypes().get(gem.getMMOItemType()), gem.getMMOItemID());
// Valid? neat-o
if (restored != null) {

View File

@ -88,10 +88,13 @@ public abstract class RPGPlayer {
*/
public boolean canUse(NBTItem item, boolean message) { return canUse(item, message, false); }
/**g
* If this item can be used by this player
* @param message Should the player be notified that they cant use the item?
* <p>Use for active checks (the player actually clicking)</p>
/**
* Calculates passive and dynamic item requirements. This does NOT apply item costs
* like Mana or Stamina costs and does not check for required stamina or mana either.
* Mana, stamina and cooldowns are handled in Weapon.applyWeaponCosts()
*
* @param message Should the player be notified that they cant use the item?
* <p>Use for active checks (the player actually clicking)</p>
* @param allowDynamic If a Stat Restriction is dynamic, it will be ignored
* if it fails (returning true even if it is not met).
* @see ItemRestriction#isDynamic()
@ -106,18 +109,22 @@ public abstract class RPGPlayer {
}
//REQ//MMOItems. Log("Checking REQS");
for (ItemRestriction condition : MMOItems.plugin.getStats().getItemRestrictionStats()) {
//REQ//MMOItems. Log(" \u00a7a> \u00a77" + ((ItemStat) condition).getNBTPath());
if (!condition.isDynamic() || !allowDynamic) {
//REQ//MMOItems. Log(" \u00a78> \u00a77Nondynamic / Dynamic Unallowed");
if (!condition.canUse(this, item, message)) {
//REQ//MMOItems. Log(" \u00a7c> Cant use");
return false; } } }
for (ItemRestriction condition : MMOItems.plugin.getStats().getItemRestrictionStats())
if (!condition.isDynamic() || !allowDynamic)
if (!condition.canUse(this, item, message))
return false;
//REQ//MMOItems. Log(" \u00a7a> Success use");
return true;
}
/**
* This does not apply ability costs like Mana or Stamina costs. This does not
* apply ability cooldown either but it does check if the ability is still on cooldown
*
* @param data Ability being cast
* @return If the player can cast the ability
*/
public boolean canCast(AbilityData data) {
if (playerData.hasCooldownInfo(data.getAbility())) {

View File

@ -7,6 +7,7 @@ import com.codisimus.plugins.phatloots.events.PlayerLootEvent;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.api.util.MMOItemReforger;
@ -52,7 +53,7 @@ public class PhatLootsHook implements Listener {
continue; }
// The MMOItem does not exist anymore (must have been deleted after being added
if (MMOItems.plugin.getTemplates().getTemplate(MMOItems.plugin.getType(loot), MMOItems.plugin.getID(loot)) == null) { continue; }
if (MMOItems.plugin.getTemplates().getTemplate(MMOUtils.getType(loot), MMOUtils.getID(loot)) == null) { continue; }
// All right update the bitch
MMOItemReforger mod = new MMOItemReforger(loot);

View File

@ -51,7 +51,7 @@ public class RealDualWieldHook implements Listener {
return;
}
if (!weapon.applyItemCosts()) {
if (!weapon.checkItemRequirements()) {
event.setCancelled(true);
return;
}
@ -70,7 +70,7 @@ public class RealDualWieldHook implements Listener {
return;
}
if (!weapon.applyItemCosts()) {
if (!weapon.checkItemRequirements()) {
event.setCancelled(true);
return;
}

View File

@ -73,7 +73,7 @@ public class ItemUse implements Listener {
/*
* (BUG FIX) cancel the event to prevent things like shield blocking
*/
if (!useItem.applyItemCosts()) {
if (!useItem.checkItemRequirements()) {
event.setCancelled(true);
return;
}
@ -141,7 +141,7 @@ public class ItemUse implements Listener {
return;
}
if (!weapon.applyItemCosts()) {
if (!weapon.checkItemRequirements()) {
event.setCancelled(true);
return;
}
@ -172,7 +172,7 @@ public class ItemUse implements Listener {
return;
Tool tool = new Tool(player, item);
if (!tool.applyItemCosts()) {
if (!tool.checkItemRequirements()) {
event.setCancelled(true);
return;
}
@ -196,7 +196,7 @@ public class ItemUse implements Listener {
return;
UseItem weapon = UseItem.getItem(player, item, item.getType());
if (!weapon.applyItemCosts())
if (!weapon.checkItemRequirements())
return;
// special staff attack
@ -220,7 +220,7 @@ public class ItemUse implements Listener {
return;
UseItem useItem = UseItem.getItem(player, item, item.getType());
if (!useItem.applyItemCosts())
if (!useItem.checkItemRequirements())
return;
if (useItem instanceof ItemSkin) {
@ -277,7 +277,7 @@ public class ItemUse implements Listener {
PlayerData playerData = PlayerData.get((Player) event.getEntity());
if (type != null) {
Weapon weapon = new Weapon(playerData, item);
if (!weapon.applyItemCosts() || !weapon.applyWeaponCosts()) {
if (!weapon.checkItemRequirements() || !weapon.applyWeaponCosts()) {
event.setCancelled(true);
return;
}
@ -285,7 +285,7 @@ public class ItemUse implements Listener {
ItemStack itemInMainHand = playerData.getPlayer().getInventory().getItemInMainHand();
EquipmentSlot bowSlot = (itemInMainHand.isSimilar(event.getBow())) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND;
if (!eitherHandSuccess((Player) event.getEntity(), item, bowSlot)) {
if (!checkDualWield((Player) event.getEntity(), item, bowSlot)) {
event.setCancelled(true);
return;
}
@ -298,6 +298,36 @@ public class ItemUse implements Listener {
event.getForce());
}
@EventHandler
public void g(PlayerItemConsumeEvent event) {
NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getItem());
if (!item.hasType())
return;
Player player = event.getPlayer();
UseItem useItem = UseItem.getItem(player, item, item.getType());
if (!useItem.checkItemRequirements()) {
event.setCancelled(true);
return;
}
if (useItem instanceof Consumable) {
if (!useItem.getPlayerData().canUseItem(useItem.getMMOItem().getId())) {
Message.ITEM_ON_COOLDOWN.format(ChatColor.RED).send(player);
return;
}
if (!((Consumable) useItem).useWithoutItem()) {
event.setCancelled(true);
return;
}
useItem.getPlayerData().applyItemCooldown(useItem.getMMOItem().getId(), useItem.getNBTItem().getStat("ITEM_COOLDOWN"));
useItem.executeCommands();
}
}
/**
* It is undesirable to fire bows whose arrows have the stats of the Mainhand weapon.
* <p></p>
@ -305,7 +335,7 @@ public class ItemUse implements Listener {
* check when you really suspect it is an EITHER_HAND weapon. Otherwise the check already
* happened when its stats where added in the first place.
*/
public static boolean eitherHandSuccess(@NotNull Player p, @NotNull NBTItem item, @NotNull EquipmentSlot held) {
public static boolean checkDualWield(@NotNull Player player, @NotNull NBTItem item, @NotNull EquipmentSlot held) {
/*
* Make sure it is a plugin item to begin with
@ -319,7 +349,7 @@ public class ItemUse implements Listener {
Type.EquipmentSlot mainheld_type = null;
// Get Mainhand Item
ItemStack mainheld = p.getInventory().getItemInMainHand();
ItemStack mainheld = player.getInventory().getItemInMainHand();
// Existed?
if (mainheld.getType().isItem()) {
@ -370,34 +400,4 @@ public class ItemUse implements Listener {
// Does it match?
return eitem.matches(itemType, mainheld_type);
}
@EventHandler
public void g(PlayerItemConsumeEvent event) {
NBTItem item = MythicLib.plugin.getVersion().getWrapper().getNBTItem(event.getItem());
if (!item.hasType())
return;
Player player = event.getPlayer();
UseItem useItem = UseItem.getItem(player, item, item.getType());
if (!useItem.applyItemCosts()) {
event.setCancelled(true);
return;
}
if (useItem instanceof Consumable) {
if (!useItem.getPlayerData().canUseItem(useItem.getMMOItem().getId())) {
Message.ITEM_ON_COOLDOWN.format(ChatColor.RED).send(player);
return;
}
if (!((Consumable) useItem).useWithoutItem()) {
event.setCancelled(true);
return;
}
useItem.getPlayerData().applyItemCooldown(useItem.getMMOItem().getId(), useItem.getNBTItem().getStat("ITEM_COOLDOWN"));
useItem.executeCommands();
}
}
}

View File

@ -15,7 +15,6 @@ import net.Indyuce.mmoitems.api.interaction.util.InteractItem;
import net.Indyuce.mmoitems.api.interaction.weapon.Weapon;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -160,7 +159,7 @@ public class PlayerListener implements Listener {
if (type != null) {
Weapon weapon = new Weapon(playerData, nbtItem);
if (!weapon.applyItemCosts() || !weapon.applyWeaponCosts()) {
if (!weapon.checkItemRequirements() || !weapon.applyWeaponCosts()) {
event.setCancelled(true);
return;
}

View File

@ -12,9 +12,9 @@ import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
* register methods are now in the TemplateManager.
*
* @author cympe
*
*/
public class ItemManager {
/**
* @param type The item type
* @param id The item id

View File

@ -4,9 +4,6 @@ import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
@ -20,46 +17,35 @@ import org.bukkit.util.BoundingBox;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
/**
* @author Gunging
*/
public class Amphibian extends ChooseStat implements ItemRestriction, GemStoneStat {
public static final String
NORMAL = "UNRESTRICTED",
DRY = "DRY",
WET = "WET",
DAMP = "DAMP",
LAVA = "LAVA",
MOLTEN = "MOLTEN",
LIQUID = "LIQUID",
SUBMERGED = "SUBMERGED";
NORMAL = "UNRESTRICTED",
DRY = "DRY",
WET = "WET",
DAMP = "DAMP",
LAVA = "LAVA",
MOLTEN = "MOLTEN",
LIQUID = "LIQUID",
SUBMERGED = "SUBMERGED";
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", Material.WATER_BUCKET, "Amphibian", new String[]{"May this item only be used in specific", "environments regarding liquids?"}, new String[]{"!block", "all"});
// Create the list
ArrayList<String> amphibianStuff = new ArrayList<>();
Collections.addAll(amphibianStuff, NORMAL, DRY, WET, DAMP, LAVA, MOLTEN, LIQUID, SUBMERGED);
// Set the acceptable values
InitializeChooseableList(amphibianStuff);
addChoices(NORMAL, DRY, WET, DAMP, LAVA, MOLTEN, LIQUID, SUBMERGED);
// Put definitions
HashMap<String, String> definitions = new HashMap<>();
definitions.put(NORMAL, "No liquids dependency");
definitions.put(DRY, "The item does not work if the player is touching a liquid block.");
definitions.put(WET, "The only works if the player is touching water (rain does not count).");
definitions.put(DAMP, "The only works if the player is completely submerged in water.");
definitions.put(LAVA, "The only works if the player is touching lava.");
definitions.put(MOLTEN, "The only works if the player is completely submerged in lava.");
definitions.put(LIQUID, "The only works if the player is touching any liquid.");
definitions.put(SUBMERGED, "The only works if the player is completely submerged in any liquid.");
// Update
HintChooseableDefs(definitions);
setHint(NORMAL, "No liquids dependency");
setHint(DRY, "The item does not work if the player is touching a liquid block.");
setHint(WET, "The only works if the player is touching water (rain does not count).");
setHint(DAMP, "The only works if the player is completely submerged in water.");
setHint(LAVA, "The only works if the player is touching lava.");
setHint(MOLTEN, "The only works if the player is completely submerged in lava.");
setHint(LIQUID, "The only works if the player is touching any liquid.");
setHint(SUBMERGED, "The only works if the player is completely submerged in any liquid.");
}
@NotNull

View File

@ -1,15 +1,12 @@
package net.Indyuce.mmoitems.stat;
import io.lumine.mythic.lib.version.VersionMaterial;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import net.Indyuce.mmoitems.stat.type.ChooseStat;
import net.Indyuce.mmoitems.stat.type.GemStoneStat;
import io.lumine.mythic.lib.version.VersionMaterial;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
/**
@ -17,26 +14,22 @@ import java.util.HashMap;
*/
public class GemUpgradeScaling extends ChooseStat implements GemStoneStat {
public static final String NEVER = "NEVER", HISTORIC = "HISTORIC", SUBSEQUENT = "SUBSEQUENT";
/**
* Can't be final as it is a plugin configuration option
*/
public static String defaultValue = SUBSEQUENT;
public GemUpgradeScaling() {
super("GEM_UPGRADE_SCALING", VersionMaterial.LIME_DYE.toMaterial(), "Gem Upgrade Scaling", new String[] { "Gem stones add their stats to items, but you may also", "upgrade your items via crafting stations or consumables.", "", "\u00a76Should this gem stone stats be affected by upgrading?" }, new String[] { "gem_stone" });
// Create the list
ArrayList<String> applicationScalingTypes = new ArrayList<>();
Collections.addAll(applicationScalingTypes, SUBSEQUENT, NEVER, HISTORIC);
// Set the acceptable values
InitializeChooseableList(applicationScalingTypes);
addChoices(SUBSEQUENT, NEVER, HISTORIC);
// Put definitions
HashMap<String, String> definitions = new HashMap<>();
definitions.put(SUBSEQUENT, "Gem stats scale by upgrading the item, but only after putting the gem in.");
definitions.put(NEVER, "Gem stats are never scaled by upgrading the item.");
definitions.put(HISTORIC, "Gem stats instantly upgrade to the current item level, and subsequently thereafter.");
// Update
HintChooseableDefs(definitions);
setHint(SUBSEQUENT, "Gem stats scale by upgrading the item, but only after putting the gem in.");
setHint(NEVER, "Gem stats are never scaled by upgrading the item.");
setHint(HISTORIC, "Gem stats instantly upgrade to the current item level, and subsequently thereafter.");
}
@NotNull @Override public StatData getClearStatData() { return new StringData(defaultValue); }

View File

@ -96,7 +96,7 @@ public class GemstoneData {
// Its of this gen of gemstones...
String hUUID = uuid.getAsString();
UUID hisUUID = UUIDFromString(hUUID);
UUID hisUUID = MMOUtils.UUIDFromString(hUUID);
if (hisUUID != null) { historicUUID = hisUUID; }
else { historicUUID = UUID.randomUUID(); }
@ -281,27 +281,6 @@ public class GemstoneData {
object.add("Effects", effects);
*/
// This has been commented a long time. I dont know why or waht I'll just not touch it.
// if (particle != null)
// object.add("Particles", particle.toJson());
return object;
}
/**
* Returns an UUID from thay string, or null if it is not in UUID format.
*/
@Nullable public static UUID UUIDFromString(@Nullable String anything) {
if (anything == null) { return null; }
// Correct Format?
if (anything.matches("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}")) {
// Return thay
return UUID.fromString(anything);
}
// No
return null;
}
}

View File

@ -1,16 +1,10 @@
package net.Indyuce.mmoitems.stat.type;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.api.util.ui.SilentNumbers;
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.data.StringData;
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.ChatColor;
import org.bukkit.Material;
@ -18,10 +12,7 @@ import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.*;
/**
* Choose Stats present a list of options from which the user may choose one.
@ -31,13 +22,33 @@ import java.util.Optional;
* Stats cycle through a list instead.
*/
public abstract class ChooseStat extends StringStat {
/**
* Contains the list of different options the player may choose from.
* <b>Make sure its is always initialized and with at least 1 element</b>
*/
private final ArrayList<String> choices = new ArrayList<>();
/**
* Definitions of what each choosing type does, for display in lore.
*/
private final HashMap<String, String> hints = new HashMap<>();
public ChooseStat(String id, Material mat, String name, String[] lore, String[] types, Material... materials) {
super(id, mat, name, lore, types, materials);
}
public void addChoices(String... choices) {
this.choices.addAll(Arrays.asList(choices));
}
public void setHint(String choice, String desc) {
hints.put(choice, desc);
}
@Override
public void whenClicked(@NotNull EditionInventory inv, @NotNull InventoryClickEvent event) {
Validate.isTrue(chooseableList.size() > 0, "\u00a77Invalid Chooseable Item Stat " + ChatColor.GOLD + getId() + "\u00a77' - \u00a7cNo options to choose from.");
Validate.isTrue(choices.size() > 0, "\u00a77Invalid Chooseable Item Stat " + ChatColor.GOLD + getId() + "\u00a77' - \u00a7cNo options to choose from.");
// If removing, reset to default
if (event.getAction() == InventoryAction.PICKUP_HALF) {
@ -56,30 +67,34 @@ public abstract class ChooseStat extends StringStat {
// Included?
int currentIndex = 0;
if (current != null && chooseableList.contains(current)) { currentIndex = chooseableList.indexOf(current);}
if (current != null && choices.contains(current)) {
currentIndex = choices.indexOf(current);
}
// Increase and Cap
currentIndex++;
if (currentIndex >= chooseableList.size()) { currentIndex = 0; }
if (currentIndex >= choices.size()) {
currentIndex = 0;
}
// Get
current = chooseableList.get(currentIndex);
current = choices.get(currentIndex);
// Edits into persistent files
inv.getEditedSection().set(getPath(), current);
inv.registerTemplateEdition();
// Sends a message
inv.getPlayer().sendMessage( MMOItems.plugin.getPrefix() + getName() + " successfully changed to " + current + ChatColor.GRAY + ".");
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + getName() + " successfully changed to " + current + ChatColor.GRAY + ".");
}
}
@Override
public void whenDisplayed(List<String> lore, Optional<RandomStatData> statData) {
Validate.isTrue(chooseableList.size() > 0, "\u00a77Invalid Chooseable Item Stat " + ChatColor.GOLD + getId() + "\u00a77' - \u00a7cNo options to choose from.");
Validate.isTrue(choices.size() > 0, "\u00a77Invalid Chooseable Item Stat " + ChatColor.GOLD + getId() + "\u00a77' - \u00a7cNo options to choose from.");
// To display current choosing, gets the very first element
String def = chooseableList.get(0);
String def = choices.get(0);
// Does this item have any specified value for this?
if (statData.isPresent()) {
@ -97,31 +112,23 @@ public abstract class ChooseStat extends StringStat {
}
// Get Definition
if (chooseableDefs.containsKey(def)) { for (String definition : SilentNumbers.chop(chooseableDefs.get(def), 50, "")) { lore.add(ChatColor.GRAY + " " + definition); } }
if (hints.containsKey(def))
for (String definition : SilentNumbers.chop(hints.get(def), 50, "")) {
lore.add(ChatColor.GRAY + " " + definition);
}
lore.add("");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to return to default value.");
lore.add(ChatColor.YELLOW + AltChar.listDash + " Left click to cycle through the available options:");
for (String str : chooseableList) {
for (String str : choices) {
// Is it the one?
String pick = ChatColor.GOLD.toString();
if (str.equals(def)) { pick = ChatColor.RED.toString() + ChatColor.BOLD.toString();}
if (str.equals(def)) {
pick = ChatColor.RED.toString() + ChatColor.BOLD.toString();
}
lore.add(pick + " " + AltChar.smallListDash + " \u00a77" + str);
}
}
/**
* 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>
*/
@NotNull ArrayList<String> chooseableList;
public void InitializeChooseableList(@NotNull ArrayList<String> list) { chooseableList = list; }
/**
* Definitions of what each choosing type does, for display in lore.
*/
@NotNull HashMap<String, String> chooseableDefs = new HashMap<>();
public void HintChooseableDefs(@NotNull HashMap<String, String> list) { chooseableDefs = list; }
}

View File

@ -24,7 +24,7 @@ public interface ItemRestriction {
* internally needs some similar check)
* @return False if the item cannot be used
*/
boolean canUse(RPGPlayer player, NBTItem item, boolean message);
boolean canUse(RPGPlayer/**/ player, NBTItem item, boolean message);
/**
* Usually, item restrictions are checked <i>when equipping</i>

View File

@ -1,15 +1,6 @@
package net.Indyuce.mmoitems.stat.type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import io.lumine.mythic.lib.api.item.ItemTag;
import org.bukkit.Material;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.build.ItemStackBuilder;
@ -17,11 +8,19 @@ import net.Indyuce.mmoitems.api.item.mmoitem.ReadMMOItem;
import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.data.random.RandomStatData;
import net.Indyuce.mmoitems.stat.data.type.StatData;
import org.bukkit.Material;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
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;
public abstract class ItemStat {
@NotNull private final String id, name;
@NotNull private final String id, name, configPath, nbtPath;
@NotNull private final Material material;
private final String[] lore;
@ -56,6 +55,9 @@ public abstract class ItemStat {
this.compatibleTypes = types == null ? new ArrayList<>() : Arrays.asList(types);
this.name = name;
this.compatibleMaterials = Arrays.asList(materials);
this.configPath = id.toLowerCase().replace("_", "-");
this.nbtPath = "MMOITEMS_" +id;
}
/**
@ -164,23 +166,22 @@ public abstract class ItemStat {
return id;
}
String path_Built = null;
@NotNull public String getPath() {
if (path_Built != null) { return path_Built; }
path_Built = id.toLowerCase().replace("_", "-");
return path_Built;
/**
* @return Path being used to reference this item stat in MMOItems config files. It's the stat path users are familiar with
*/
@NotNull
public String getPath() {
return configPath;
}
String nbtPath_Built = null;
/**
* @return The NBT path used by the stat to save data in an item's NBTTags.
* The format is 'MMOITEMS_' followed by the stat name in capital
* letters only using _
* The format is 'MMOITEMS_' followed by the stat name in capital
* letters only using _
*/
@NotNull public String getNBTPath() {
if (nbtPath_Built != null) { return nbtPath_Built; }
nbtPath_Built = "MMOITEMS_" + id;
return nbtPath_Built;
@NotNull
public String getNBTPath() {
return nbtPath;
}
public Material getDisplayMaterial() {

View File

@ -6,6 +6,7 @@ import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory;
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.util.message.FFPMMOItems;
import net.Indyuce.mmoitems.stat.data.*;
@ -34,7 +35,7 @@ public class StatHistory {
* Which stat is this the history of?
*/
@NotNull
ItemStat itemStat;
private final ItemStat itemStat;
/**
* Which stat is this the history of?
@ -781,7 +782,7 @@ public class StatHistory {
String gemUUID = entry.getKey();
// Attempt to parse gemuuid
UUID actualUUID = GemstoneData.UUIDFromString(gemUUID);
UUID actualUUID = MMOUtils.UUIDFromString(gemUUID);
// Get Stat compressed tag
JsonElement compressedTags = entry.getValue();
@ -856,7 +857,7 @@ public class StatHistory {
String modUUID = entry.getKey();
// Attempt to parse gemuuid
UUID actualUUID = GemstoneData.UUIDFromString(modUUID);
UUID actualUUID = MMOUtils.UUIDFromString(modUUID);
// Get Stat compressed tag
JsonElement compressedTags = entry.getValue();