From 640fc62119b4e2df3e6d19535512e71abe038afd Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sat, 17 Dec 2022 16:46:16 +0100 Subject: [PATCH] Fixed an issue with ornaments; improved comp with MMOInv --- MMOItems-API/pom.xml | 8 ++ .../java/net/Indyuce/mmoitems/MMOItems.java | 30 +------ .../java/net/Indyuce/mmoitems/api/Type.java | 4 +- .../mmoitems/api/edition/StatEdition.java | 12 +-- .../inventory/EditableEquippedItem.java | 26 ------ .../api/player/inventory/EquippedItem.java | 12 ++- .../mmoitems/api/util/DeathDowngrading.java | 80 +++++-------------- .../mmoitems/comp/WorldEditSupport.java | 2 +- .../inventory/DefaultPlayerInventory.java | 13 ++- .../inventory/OrnamentPlayerInventory.java | 64 ++++++++------- .../inventory/PlayerInventoryHandler.java | 4 + .../comp/inventory/RPGInventoryHook.java | 50 ++++++------ ...ltInventory.java => SlotEquippedItem.java} | 27 ++++--- .../comp/parse/StringInputParser.java | 18 ----- .../DefaultPlaceholderParser.java | 12 --- .../placeholders/PlaceholderAPIParser.java | 18 ----- .../parse/placeholders/PlaceholderParser.java | 8 -- .../placeholders/MMOItemsPlaceholders.java | 2 +- .../Indyuce/mmoitems/util/PluginUtils.java | 1 - MMOItems-Dist/src/main/resources/config.yml | 4 + 20 files changed, 142 insertions(+), 253 deletions(-) delete mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EditableEquippedItem.java rename MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/{EIDefaultInventory.java => SlotEquippedItem.java} (71%) delete mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/StringInputParser.java delete mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/DefaultPlaceholderParser.java delete mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/PlaceholderAPIParser.java delete mode 100644 MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/PlaceholderParser.java rename MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/{parse => }/placeholders/MMOItemsPlaceholders.java (98%) diff --git a/MMOItems-API/pom.xml b/MMOItems-API/pom.xml index 832742d4..6b4eaab5 100644 --- a/MMOItems-API/pom.xml +++ b/MMOItems-API/pom.xml @@ -223,6 +223,14 @@ 1.9.22 provided + + + com.comphenix.protocol + ProtocolLib + 4.7.0 + provided + true + com.gmail.nossr50 diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java index 8fee4c1a..28ad3405 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/MMOItems.java @@ -29,10 +29,6 @@ import net.Indyuce.mmoitems.comp.mmocore.MMOCoreMMOLoader; import net.Indyuce.mmoitems.comp.mmoinventory.MMOInventorySupport; import net.Indyuce.mmoitems.comp.mythicmobs.LootsplosionListener; import net.Indyuce.mmoitems.comp.mythicmobs.MythicMobsCompatibility; -import net.Indyuce.mmoitems.comp.parse.StringInputParser; -import net.Indyuce.mmoitems.comp.parse.placeholders.DefaultPlaceholderParser; -import net.Indyuce.mmoitems.comp.parse.placeholders.PlaceholderAPIParser; -import net.Indyuce.mmoitems.comp.parse.placeholders.PlaceholderParser; import net.Indyuce.mmoitems.comp.rpg.DefaultHook; import net.Indyuce.mmoitems.comp.rpg.HeroesHook; import net.Indyuce.mmoitems.comp.rpg.McMMOHook; @@ -77,8 +73,6 @@ public class MMOItems extends JavaPlugin { private final TypeManager typeManager = new TypeManager(); private final ItemManager itemManager = new ItemManager(); private final PlayerInventoryHandler inventory = new PlayerInventoryHandler(); - @Deprecated - private final List stringInputParsers = new ArrayList<>(); private final List> enchantPlugins = new ArrayList<>(); private final StatManager statManager = new StatManager(); @@ -90,8 +84,6 @@ public class MMOItems extends JavaPlugin { private TierManager tierManager; private SetManager setManager; - @Deprecated - private PlaceholderParser placeholderParser = new DefaultPlaceholderParser(); private VaultSupport vaultSupport; private RPGHandler rpgPlugin; @@ -215,17 +207,16 @@ public class MMOItems extends JavaPlugin { PluginUtils.isDependencyPresent("mcMMO", unused -> Bukkit.getPluginManager().registerEvents(new McMMONonRPGHook(), this)); /* - * Registers Player Inventories. Each of these add locations of items to search for - * when doing inventory updates. + * Registers Player Inventories. Each of these add locations + * of items to search for when doing inventory updates. */ getInventory().register(new DefaultPlayerInventory()); PluginUtils.hookDependencyIfPresent("RPGInventory", unused -> getInventory().register(new RPGInventoryHook())); - PluginUtils.hookDependencyIfPresent("CrazyEnchantments", unused -> getStats().register(new CrazyEnchantsStat())); - PluginUtils.hookDependencyIfPresent("AdvancedEnchantments", unused -> Bukkit.getPluginManager().registerEvents(new AdvancedEnchantmentsHook(), this)); - PluginUtils.hookDependencyIfPresent("PlaceholderAPI", unused -> placeholderParser = new PlaceholderAPIParser()); if (MMOItems.plugin.getConfig().getBoolean("iterate-whole-inventory")) getInventory().register(new OrnamentPlayerInventory()); + PluginUtils.hookDependencyIfPresent("CrazyEnchantments", unused -> getStats().register(new CrazyEnchantsStat())); + PluginUtils.hookDependencyIfPresent("AdvancedEnchantments", unused -> Bukkit.getPluginManager().registerEvents(new AdvancedEnchantmentsHook(), this)); if (Bukkit.getPluginManager().getPlugin("BossShopPro") != null) { getLogger().log(Level.INFO, "Hooked onto BossShopPro"); @@ -476,11 +467,6 @@ public class MMOItems extends JavaPlugin { return upgradeManager; } - @Deprecated - public PlaceholderParser getPlaceholderParser() { - return placeholderParser; - } - public TemplateManager getTemplates() { return templateManager; } @@ -513,14 +499,6 @@ public class MMOItems extends JavaPlugin { return vaultSupport; } - /** - * @deprecated Not used - */ - @Deprecated - public List getStringInputParsers() { - return stringInputParsers; - } - //region Easy-Access API /** diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java index 1eb1aa05..36375eb0 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/Type.java @@ -46,7 +46,7 @@ public class Type { public static final Type MAIN_CATALYST = new Type(TypeSet.CATALYST, "MAIN_CATALYST", false, ModifierSource.MAINHAND_ITEM); // Any - public static final Type ORNAMENT = new Type(TypeSet.EXTRA, "ORNAMENT", false, ModifierSource.OTHER); + public static final Type ORNAMENT = new Type(TypeSet.EXTRA, "ORNAMENT", false, ModifierSource.VOID); // Extra public static final Type ARMOR = new Type(TypeSet.EXTRA, "ARMOR", false, ModifierSource.ARMOR); @@ -55,7 +55,7 @@ public class Type { public static final Type MISCELLANEOUS = new Type(TypeSet.EXTRA, "MISCELLANEOUS", false, ModifierSource.MAINHAND_ITEM); public static final Type GEM_STONE = new Type(TypeSet.EXTRA, "GEM_STONE", false, ModifierSource.VOID); public static final Type SKIN = new Type(TypeSet.EXTRA, "SKIN", false, ModifierSource.VOID); - public static final Type ACCESSORY = new Type(TypeSet.EXTRA, "ACCESSORY", false, ModifierSource.OTHER); + public static final Type ACCESSORY = new Type(TypeSet.EXTRA, "ACCESSORY", false, ModifierSource.ACCESSORY); public static final Type BLOCK = new Type(TypeSet.EXTRA, "BLOCK", false, ModifierSource.VOID); private final String id; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/edition/StatEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/edition/StatEdition.java index 7424bb1e..ce8bf0cf 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/edition/StatEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/edition/StatEdition.java @@ -5,7 +5,6 @@ import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.edition.input.AnvilGUI; import net.Indyuce.mmoitems.api.edition.input.ChatEdition; -import net.Indyuce.mmoitems.comp.parse.StringInputParser; import net.Indyuce.mmoitems.gui.PluginInventory; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.stat.type.ItemStat; @@ -51,7 +50,7 @@ public class StatEdition implements Edition { inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Type 'cancel' to abort editing."); /* - * anvil text input feature. enables players to use an anvil to input + * Anvil text input feature. enables players to use an anvil to input * text if they are having conflicts with their chat management plugins. */ if (MMOItems.plugin.getConfig().getBoolean("anvil-text-input") && MythicLib.plugin.getVersion().isBelowOrEqual(1, 13)) { @@ -59,20 +58,15 @@ public class StatEdition implements Edition { return; } - /* - * default chat edition feature - */ + // Default chat edition feature new ChatEdition(this); inv.getPlayer().sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "Item Edition", "See chat.", 10, 40, 10); } @Override public boolean processInput(String input) { - // apply string input parsers - for (StringInputParser parser : MMOItems.plugin.getStringInputParsers()) - input = parser.parseInput(inv.getPlayer(), input); - // if cancel, open back inventory + // If cancel, open back inventory if (input.equals("cancel")) { inv.open(); return true; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EditableEquippedItem.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EditableEquippedItem.java deleted file mode 100644 index 5f9cd064..00000000 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EditableEquippedItem.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.Indyuce.mmoitems.api.player.inventory; - -import io.lumine.mythic.lib.api.item.NBTItem; -import io.lumine.mythic.lib.api.player.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.Nullable; - -public abstract class EditableEquippedItem extends EquippedItem { - public EditableEquippedItem(ItemStack item, EquipmentSlot slot) { - super(item, slot); - } - - public EditableEquippedItem(NBTItem item, EquipmentSlot slot) { - super(item, slot); - } - - /** - * Allows editing the item, wherever it is that it is - * currently equipped, due to stats like - * {@link net.Indyuce.mmoitems.ItemStats#DOWNGRADE_ON_DEATH} - * that target equipped items. - * - * @param item Item to replace in the current slot - */ - public abstract void setItem(@Nullable ItemStack item); -} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EquippedItem.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EquippedItem.java index e578a598..4e5f6a8d 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EquippedItem.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/player/inventory/EquippedItem.java @@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.api.player.inventory; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.player.EquipmentSlot; import io.lumine.mythic.lib.player.modifier.ModifierSource; +import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; @@ -12,7 +13,7 @@ import org.bukkit.inventory.ItemStack; import javax.annotation.Nullable; import java.util.Objects; -public class EquippedItem { +public abstract class EquippedItem { private final NBTItem item; private final EquipmentSlot slot; @@ -76,4 +77,13 @@ public class EquippedItem { final ModifierSource modSource = type.getModifierSource(); return EquipmentSlot.OFF_HAND.isCompatible(modSource, slot) || EquipmentSlot.MAIN_HAND.isCompatible(modSource, slot); } + + /** + * Allows editing the item, wherever it is that it is + * currently equipped, due to stats like {@link ItemStats#DOWNGRADE_ON_DEATH} + * that target equipped items. + * + * @param item Item to replace in the current slot + */ + public abstract void setItem(@Nullable ItemStack item); } \ No newline at end of file diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/DeathDowngrading.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/DeathDowngrading.java index 63029d2f..d7b56663 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/DeathDowngrading.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/util/DeathDowngrading.java @@ -8,7 +8,6 @@ import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem; 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.player.inventory.EditableEquippedItem; import net.Indyuce.mmoitems.api.player.inventory.EquippedItem; import net.Indyuce.mmoitems.api.player.inventory.InventoryUpdateHandler; import net.Indyuce.mmoitems.api.util.message.Message; @@ -22,10 +21,12 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Random; public class DeathDowngrading { + private static final Random RANDOM = new Random(); /** * This will go through the following steps: @@ -33,7 +34,6 @@ public class DeathDowngrading { * #1 Evaluate the list of equipped items {@link InventoryUpdateHandler#getEquipped()} to * find those that can be death-downgraded. * - * * #2 Roll for death downgrade chances, downgrading the items * * @param player Player whose inventory is to be death-downgraded. @@ -41,7 +41,7 @@ public class DeathDowngrading { public static void playerDeathDowngrade(@NotNull Player player) { // Get Player - PlayerData data = PlayerData.get(player); + final PlayerData data = PlayerData.get(player); // Get total downgrade chance, anything less than zero is invalid double deathChance = data.getStats().getStat(ItemStats.DOWNGRADE_ON_DEATH_CHANCE); @@ -50,27 +50,18 @@ public class DeathDowngrading { // Make sure the equipped items list is up to date and retrieve it data.updateInventory(); - List items = data.getInventory().getEquipped(); - ArrayList equipped = new ArrayList<>(); - - // Equipped Player Items yeah... - for (EquippedItem playerItem : items) { - - // Cannot downgrade? skip - if (!canDeathDowngrade(playerItem)) { continue; } - - // Okay explore stat - equipped.add((EditableEquippedItem) playerItem); - //DET//MMOItems.log("\u00a78DETH \u00a7cDG\u00a77 Yes. \u00a7aAccepted"); + final List equipped = data.getInventory().getEquipped(); + for (Iterator ite = equipped.iterator(); ite.hasNext(); ) { + EquippedItem next = ite.next(); + if (next == null || !canDeathDowngrade(next.getCached())) + ite.remove(); } // Nothing to perform operations? Snooze if (equipped.size() == 0) { //DET//MMOItems.log("\u00a78DETH \u00a7cDG\u00a77 No items to downgrade. "); - return; } - - // Create random - Random random = new Random(); + return; + } // Degrade those items! while (deathChance >= 100 && equipped.size() > 0) { @@ -78,13 +69,9 @@ public class DeathDowngrading { // Decrease deathChance -= 100; - // Downgrade random item - int deathChosen = random.nextInt(equipped.size()); - - /* - * The item was chosen, we must downgrade it by one level. - */ - EditableEquippedItem equip = equipped.get(deathChosen); + // The item was randomly chosen, we must downgrade it by one level. + int deathChosen = RANDOM.nextInt(equipped.size()); + EquippedItem equip = equipped.get(deathChosen); // Downgrade and remove from list equip.setItem(downgrade(new LiveMMOItem(equip.getNBT()), player)); @@ -94,15 +81,11 @@ public class DeathDowngrading { } // If there is chance, and there is size, and there is chance success - if (deathChance > 0 && equipped.size() > 0 && random.nextInt(100) < deathChance) { + if (deathChance > 0 && equipped.size() > 0 && RANDOM.nextInt(100) < deathChance) { // Downgrade random item - int d = random.nextInt(equipped.size()); - - /* - * The item was chosen, we must downgrade it by one level. - */ - EditableEquippedItem equip = equipped.get(d); + int d = RANDOM.nextInt(equipped.size()); + EquippedItem equip = equipped.get(d); // Downgrade and remove from list equip.setItem(downgrade(new LiveMMOItem(equip.getNBT()), player)); @@ -147,9 +130,6 @@ public class DeathDowngrading { } } - // Create random - Random random = new Random(); - // Degrade those items! while (deathChance >= 100 && downgrade.size() > 0) { @@ -157,7 +137,7 @@ public class DeathDowngrading { deathChance -= 100; // Downgrade random item - int deathChosen = random.nextInt(downgrade.size()); + int deathChosen = RANDOM.nextInt(downgrade.size()); /* * The item was chosen, we must downgrade it by one level. @@ -172,10 +152,10 @@ public class DeathDowngrading { } // If there is chance, and there is size, and there is chance success - if (deathChance > 0 && downgrade.size() > 0 && random.nextInt(100) < deathChance) { + if (deathChance > 0 && downgrade.size() > 0 && RANDOM.nextInt(100) < deathChance) { // Downgrade random item - int deathChosen = random.nextInt(downgrade.size()); + int deathChosen = RANDOM.nextInt(downgrade.size()); /* * The item was chosen, we must downgrade it by one level. @@ -263,28 +243,6 @@ public class DeathDowngrading { return data.getStats().getStat(ItemStats.DOWNGRADE_ON_DEATH_CHANCE); } - /** - * @param playerItem Equipped Item you want to know if it can be death downgraded - * - * @return If this is an instance of {@link EditableEquippedItem} and meets {@link #canDeathDowngrade(MMOItem)} - */ - @Contract("null->false") - public static boolean canDeathDowngrade(@Nullable EquippedItem playerItem) { - - // Null - if (playerItem == null) { return false; } - //DET//playerItem.getItem().hasData(ItemStats.NAME); - //DET//MMOItems.log("\u00a78DETH \u00a7cDG\u00a77 Item:\u00a7b " + playerItem.getItem().getData(ItemStats.NAME)); - - // Cannot perform operations of items that are uneditable - if (!(playerItem instanceof EditableEquippedItem)) { - //DET//MMOItems.log("\u00a78DETH \u00a7cDG\u00a77 Not equippable. \u00a7cCancel"); - return false; } - - // Delegate to MMOItem Method - return canDeathDowngrade(playerItem.getCached()); - } - /** * @param playerItem Item you want to know if it can be death downgraded * diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/WorldEditSupport.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/WorldEditSupport.java index 39ffef21..2ef9572e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/WorldEditSupport.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/WorldEditSupport.java @@ -17,7 +17,7 @@ public class WorldEditSupport { WorldEdit.getInstance().getBlockFactory().register(new WECustomBlockInputParser()); } - public static class WECustomBlockInputParser extends InputParser { + public class WECustomBlockInputParser extends InputParser { public WECustomBlockInputParser() { super(WorldEdit.getInstance()); } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/DefaultPlayerInventory.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/DefaultPlayerInventory.java index a1739383..5ff9767a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/DefaultPlayerInventory.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/DefaultPlayerInventory.java @@ -3,7 +3,6 @@ package net.Indyuce.mmoitems.comp.inventory; import io.lumine.mythic.lib.api.player.EquipmentSlot; import net.Indyuce.mmoitems.api.player.inventory.EquippedItem; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -24,16 +23,16 @@ public class DefaultPlayerInventory implements PlayerInventory { if (player.getEquipment() == null) { return list; } // Mainhand - list.add(new EIDefaultInventory(player, -7, player.getEquipment().getItemInMainHand(), EquipmentSlot.MAIN_HAND)); + list.add(new SlotEquippedItem(player, -7, player.getEquipment().getItemInMainHand(), EquipmentSlot.MAIN_HAND)); // Offhand - list.add(new EIDefaultInventory(player, -106, player.getEquipment().getItemInOffHand(), EquipmentSlot.OFF_HAND)); + list.add(new SlotEquippedItem(player, -106, player.getEquipment().getItemInOffHand(), EquipmentSlot.OFF_HAND)); // Armor - list.add(new EIDefaultInventory(player, 103, player.getEquipment().getHelmet(), EquipmentSlot.ARMOR)); - list.add(new EIDefaultInventory(player, 102, player.getEquipment().getChestplate(), EquipmentSlot.ARMOR)); - list.add(new EIDefaultInventory(player, 101, player.getEquipment().getLeggings(), EquipmentSlot.ARMOR)); - list.add(new EIDefaultInventory(player, 100, player.getEquipment().getBoots(), EquipmentSlot.ARMOR)); + list.add(new SlotEquippedItem(player, 103, player.getEquipment().getHelmet(), EquipmentSlot.ARMOR)); + list.add(new SlotEquippedItem(player, 102, player.getEquipment().getChestplate(), EquipmentSlot.ARMOR)); + list.add(new SlotEquippedItem(player, 101, player.getEquipment().getLeggings(), EquipmentSlot.ARMOR)); + list.add(new SlotEquippedItem(player, 100, player.getEquipment().getBoots(), EquipmentSlot.ARMOR)); return list; } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/OrnamentPlayerInventory.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/OrnamentPlayerInventory.java index e2513b2e..3b2cd484 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/OrnamentPlayerInventory.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/OrnamentPlayerInventory.java @@ -3,18 +3,19 @@ package net.Indyuce.mmoitems.comp.inventory; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.player.EquipmentSlot; -import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.inventory.EquippedItem; -import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -25,37 +26,40 @@ import java.util.List; * Ornaments - Found in any inventory slot. */ public class OrnamentPlayerInventory implements PlayerInventory, Listener { - public OrnamentPlayerInventory() { - Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin); - } - @Override - public List getInventory(Player player) { - List list = new ArrayList<>(); + @Override + public List getInventory(Player player) { + final List list = new ArrayList<>(); - // Ornaments - for (ItemStack item : player.getInventory().getContents()) { - NBTItem nbtItem; - if (item != null && (nbtItem = MythicLib.plugin.getVersion().getWrapper().getNBTItem(item)).hasType() && Type.get(nbtItem.getType()).getSupertype().equals(Type.ORNAMENT)) - list.add(new EquippedItem(nbtItem, EquipmentSlot.OTHER)); - } + // Find ornaments + final ItemStack[] matrix = player.getInventory().getContents(); + for (int i = 0; i < matrix.length; i++) { + final ItemStack curr = matrix[i]; + if (curr == null || curr.getType() == Material.AIR) + continue; - return list; - } + final NBTItem nbtItem = MythicLib.plugin.getVersion().getWrapper().getNBTItem(curr); + final @Nullable Type itemType = Type.get(nbtItem.getType()); + if (itemType != null && itemType.getSupertype().equals(Type.ORNAMENT)) + list.add(new SlotEquippedItem(player, i, nbtItem, EquipmentSlot.OTHER)); + } - @EventHandler(ignoreCancelled = true) - public void a(EntityPickupItemEvent event) { - if (event.getEntityType() == EntityType.PLAYER) { - NBTItem nbt = NBTItem.get(event.getItem().getItemStack()); - if (nbt.hasType() && Type.get(nbt.getType()).getSupertype().equals(Type.ORNAMENT)) - PlayerData.get((Player) event.getEntity()).updateInventory(); - } - } + return list; + } - @EventHandler(ignoreCancelled = true) - public void b(PlayerDropItemEvent event) { - NBTItem nbt = NBTItem.get(event.getItemDrop().getItemStack()); - if (nbt.hasType() && Type.get(nbt.getType()).getSupertype().equals(Type.ORNAMENT)) - PlayerData.get(event.getPlayer()).updateInventory(); - } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void updateOnItemPickup(EntityPickupItemEvent event) { + if (event.getEntityType() == EntityType.PLAYER) { + final NBTItem nbt = NBTItem.get(event.getItem().getItemStack()); + if (nbt.hasType() && Type.get(nbt.getType()).getSupertype().equals(Type.ORNAMENT)) + PlayerData.get((Player) event.getEntity()).getInventory().scheduleUpdate(); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void updateOnItemDrop(PlayerDropItemEvent event) { + final NBTItem nbt = NBTItem.get(event.getItemDrop().getItemStack()); + if (nbt.hasType() && Type.get(nbt.getType()).getSupertype().equals(Type.ORNAMENT)) + PlayerData.get(event.getPlayer()).updateInventory(); + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/PlayerInventoryHandler.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/PlayerInventoryHandler.java index f1a8568b..f151298a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/PlayerInventoryHandler.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/PlayerInventoryHandler.java @@ -1,6 +1,8 @@ package net.Indyuce.mmoitems.comp.inventory; +import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.player.inventory.EquippedItem; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; @@ -38,6 +40,8 @@ public class PlayerInventoryHandler { */ public void register(@NotNull PlayerInventory pInventory) { registeredInventories.add(pInventory); + if (pInventory instanceof Listener) + Bukkit.getPluginManager().registerEvents((Listener) pInventory, MMOItems.plugin); } public void unregisterIf(Predicate filter) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/RPGInventoryHook.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/RPGInventoryHook.java index 5cebc073..4daadada 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/RPGInventoryHook.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/RPGInventoryHook.java @@ -1,15 +1,14 @@ package net.Indyuce.mmoitems.comp.inventory; import io.lumine.mythic.lib.api.player.EquipmentSlot; -import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.inventory.EquippedItem; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Nullable; import ru.endlesscode.rpginventory.api.InventoryAPI; import java.util.ArrayList; @@ -22,29 +21,34 @@ import java.util.List; */ public class RPGInventoryHook implements PlayerInventory, Listener { - /* - * RPGInventory is outdated. MI still supports it but it shall NEVER be - * considered a priority to keep MI compatible OR performance efficient with - * RPGInventory - */ - public RPGInventoryHook() { - Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin); - } + @Override + public List getInventory(Player player) { + List list = new ArrayList<>(); - @Override - public List getInventory(Player player) { - List list = new ArrayList<>(); + for (ItemStack passive : InventoryAPI.getPassiveItems(player)) + if (passive != null) + list.add(new LegacyEquippedItem(passive)); - for (ItemStack passive : InventoryAPI.getPassiveItems(player)) - if (passive != null) - list.add(new EquippedItem(passive, EquipmentSlot.ACCESSORY)); + return list; + } - return list; - } + @EventHandler + public void a(InventoryCloseEvent event) { + if (InventoryAPI.isRPGInventory(event.getInventory())) + PlayerData.get((Player) event.getPlayer()).updateInventory(); + } - @EventHandler - public void a(InventoryCloseEvent event) { - if (InventoryAPI.isRPGInventory(event.getInventory())) - PlayerData.get((Player) event.getPlayer()).updateInventory(); - } + public class LegacyEquippedItem extends EquippedItem { + public LegacyEquippedItem(ItemStack item) { + super(item, EquipmentSlot.ACCESSORY); + } + + @Override + public void setItem(@Nullable ItemStack item) { + final ItemStack ref = getNBT().getItem(); + ref.setType(item.getType()); + ref.setAmount(item.getAmount()); + ref.setItemMeta(ref.getItemMeta()); + } + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/EIDefaultInventory.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/SlotEquippedItem.java similarity index 71% rename from MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/EIDefaultInventory.java rename to MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/SlotEquippedItem.java index fee45cd5..0ccdafcf 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/EIDefaultInventory.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/SlotEquippedItem.java @@ -2,31 +2,40 @@ package net.Indyuce.mmoitems.comp.inventory; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.player.EquipmentSlot; -import net.Indyuce.mmoitems.api.player.inventory.EditableEquippedItem; +import net.Indyuce.mmoitems.api.player.inventory.EquippedItem; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class EIDefaultInventory extends EditableEquippedItem { - @NotNull public Player getPlayer() { return player; } - @NotNull Player player; +public class SlotEquippedItem extends EquippedItem { + private final Player player; + private final int slotNumber; - public int getSlotNumber() { return slotNumber; } - int slotNumber; - - public EIDefaultInventory(@NotNull Player player, int slotNumber, ItemStack item, EquipmentSlot slot) { + public SlotEquippedItem(@NotNull Player player, int slotNumber, ItemStack item, EquipmentSlot slot) { super(item, slot); + this.player = player; this.slotNumber = slotNumber; } - public EIDefaultInventory(@NotNull Player player, int slotNumber, NBTItem item, EquipmentSlot slot) { + public SlotEquippedItem(@NotNull Player player, int slotNumber, NBTItem item, EquipmentSlot slot) { super(item, slot); + this.player = player; this.slotNumber = slotNumber; } + @NotNull + public Player getPlayer() { + return player; + } + + @NotNull + public int getSlotNumber() { + return slotNumber; + } + @Override public void setItem(@Nullable ItemStack item) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/StringInputParser.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/StringInputParser.java deleted file mode 100644 index b60999d8..00000000 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/StringInputParser.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.Indyuce.mmoitems.comp.parse; - -import org.bukkit.entity.Player; - -/** - * @deprecated Not used - */ -@Deprecated -public interface StringInputParser { - - /* - * this interface is used to apply changes to string inputs when editing - * stats, for instance Iridescent applies weird ass color codes to strings - * and therefore all strings must be updated before being processed by stat - * edition methods - */ - String parseInput(Player player, String input); -} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/DefaultPlaceholderParser.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/DefaultPlaceholderParser.java deleted file mode 100644 index e0c193f9..00000000 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/DefaultPlaceholderParser.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.Indyuce.mmoitems.comp.parse.placeholders; - -import org.bukkit.OfflinePlayer; - -@Deprecated -public class DefaultPlaceholderParser implements PlaceholderParser { - - @Override - public String parse(OfflinePlayer player, String string) { - return string.replace("%player%", player.getName()); - } -} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/PlaceholderAPIParser.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/PlaceholderAPIParser.java deleted file mode 100644 index 03dc8580..00000000 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/PlaceholderAPIParser.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.Indyuce.mmoitems.comp.parse.placeholders; - -import org.bukkit.OfflinePlayer; - -import me.clip.placeholderapi.PlaceholderAPI; -import io.lumine.mythic.lib.MythicLib; - -@Deprecated -public class PlaceholderAPIParser implements PlaceholderParser { - public PlaceholderAPIParser() { - new MMOItemsPlaceholders().register(); - } - - @Override - public String parse(OfflinePlayer player, String string) { - return MythicLib.plugin.parseColors(PlaceholderAPI.setPlaceholders(player, string)); - } -} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/PlaceholderParser.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/PlaceholderParser.java deleted file mode 100644 index f08edfe6..00000000 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/PlaceholderParser.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.Indyuce.mmoitems.comp.parse.placeholders; - -import org.bukkit.OfflinePlayer; - -@Deprecated -public interface PlaceholderParser { - String parse(OfflinePlayer player, String string); -} diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/MMOItemsPlaceholders.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java similarity index 98% rename from MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/MMOItemsPlaceholders.java rename to MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java index 7284290a..1ae9dde4 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/parse/placeholders/MMOItemsPlaceholders.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/placeholders/MMOItemsPlaceholders.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmoitems.comp.parse.placeholders; +package net.Indyuce.mmoitems.comp.placeholders; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.item.NBTItem; diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/PluginUtils.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/PluginUtils.java index af2403d5..aba490e9 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/PluginUtils.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/util/PluginUtils.java @@ -30,5 +30,4 @@ public class PluginUtils { callback.accept(null); MMOItems.plugin.getLogger().log(Level.INFO, "Hooked onto %s".formatted(name)); } - } diff --git a/MMOItems-Dist/src/main/resources/config.yml b/MMOItems-Dist/src/main/resources/config.yml index f38f1bd2..42d62487 100644 --- a/MMOItems-Dist/src/main/resources/config.yml +++ b/MMOItems-Dist/src/main/resources/config.yml @@ -28,6 +28,10 @@ inventory-update-delay: 10 # interval [playerLevel - spread, playerLevel + spread] item-level-spread: 2 +# There is currently a client-side Minecraft issue +# where left clicking a +fix-left-click-interact: false + # When an item is generated with no tier, # this is the capacity formula it will use. default-item-capacity: