Fixed an issue with ornaments; improved comp with MMOInv

This commit is contained in:
Indyuce 2022-12-17 16:46:16 +01:00
parent 0e8e358abb
commit 640fc62119
20 changed files with 142 additions and 253 deletions

View File

@ -223,6 +223,14 @@
<version>1.9.22</version> <version>1.9.22</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- ProtocolLib -->
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.7.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<!-- mcMMO --> <!-- mcMMO -->
<dependency> <dependency>
<groupId>com.gmail.nossr50</groupId> <groupId>com.gmail.nossr50</groupId>

View File

@ -29,10 +29,6 @@ import net.Indyuce.mmoitems.comp.mmocore.MMOCoreMMOLoader;
import net.Indyuce.mmoitems.comp.mmoinventory.MMOInventorySupport; import net.Indyuce.mmoitems.comp.mmoinventory.MMOInventorySupport;
import net.Indyuce.mmoitems.comp.mythicmobs.LootsplosionListener; import net.Indyuce.mmoitems.comp.mythicmobs.LootsplosionListener;
import net.Indyuce.mmoitems.comp.mythicmobs.MythicMobsCompatibility; 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.DefaultHook;
import net.Indyuce.mmoitems.comp.rpg.HeroesHook; import net.Indyuce.mmoitems.comp.rpg.HeroesHook;
import net.Indyuce.mmoitems.comp.rpg.McMMOHook; import net.Indyuce.mmoitems.comp.rpg.McMMOHook;
@ -77,8 +73,6 @@ public class MMOItems extends JavaPlugin {
private final TypeManager typeManager = new TypeManager(); private final TypeManager typeManager = new TypeManager();
private final ItemManager itemManager = new ItemManager(); private final ItemManager itemManager = new ItemManager();
private final PlayerInventoryHandler inventory = new PlayerInventoryHandler(); private final PlayerInventoryHandler inventory = new PlayerInventoryHandler();
@Deprecated
private final List<StringInputParser> stringInputParsers = new ArrayList<>();
private final List<EnchantPlugin<? extends Enchantment>> enchantPlugins = new ArrayList<>(); private final List<EnchantPlugin<? extends Enchantment>> enchantPlugins = new ArrayList<>();
private final StatManager statManager = new StatManager(); private final StatManager statManager = new StatManager();
@ -90,8 +84,6 @@ public class MMOItems extends JavaPlugin {
private TierManager tierManager; private TierManager tierManager;
private SetManager setManager; private SetManager setManager;
@Deprecated
private PlaceholderParser placeholderParser = new DefaultPlaceholderParser();
private VaultSupport vaultSupport; private VaultSupport vaultSupport;
private RPGHandler rpgPlugin; private RPGHandler rpgPlugin;
@ -215,17 +207,16 @@ public class MMOItems extends JavaPlugin {
PluginUtils.isDependencyPresent("mcMMO", unused -> Bukkit.getPluginManager().registerEvents(new McMMONonRPGHook(), this)); PluginUtils.isDependencyPresent("mcMMO", unused -> Bukkit.getPluginManager().registerEvents(new McMMONonRPGHook(), this));
/* /*
* Registers Player Inventories. Each of these add locations of items to search for * Registers Player Inventories. Each of these add locations
* when doing inventory updates. * of items to search for when doing inventory updates.
*/ */
getInventory().register(new DefaultPlayerInventory()); getInventory().register(new DefaultPlayerInventory());
PluginUtils.hookDependencyIfPresent("RPGInventory", unused -> getInventory().register(new RPGInventoryHook())); 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")) if (MMOItems.plugin.getConfig().getBoolean("iterate-whole-inventory"))
getInventory().register(new OrnamentPlayerInventory()); 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) { if (Bukkit.getPluginManager().getPlugin("BossShopPro") != null) {
getLogger().log(Level.INFO, "Hooked onto BossShopPro"); getLogger().log(Level.INFO, "Hooked onto BossShopPro");
@ -476,11 +467,6 @@ public class MMOItems extends JavaPlugin {
return upgradeManager; return upgradeManager;
} }
@Deprecated
public PlaceholderParser getPlaceholderParser() {
return placeholderParser;
}
public TemplateManager getTemplates() { public TemplateManager getTemplates() {
return templateManager; return templateManager;
} }
@ -513,14 +499,6 @@ public class MMOItems extends JavaPlugin {
return vaultSupport; return vaultSupport;
} }
/**
* @deprecated Not used
*/
@Deprecated
public List<StringInputParser> getStringInputParsers() {
return stringInputParsers;
}
//region Easy-Access API //region Easy-Access API
/** /**

View File

@ -46,7 +46,7 @@ public class Type {
public static final Type MAIN_CATALYST = new Type(TypeSet.CATALYST, "MAIN_CATALYST", false, ModifierSource.MAINHAND_ITEM); public static final Type MAIN_CATALYST = new Type(TypeSet.CATALYST, "MAIN_CATALYST", false, ModifierSource.MAINHAND_ITEM);
// Any // 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 // Extra
public static final Type ARMOR = new Type(TypeSet.EXTRA, "ARMOR", false, ModifierSource.ARMOR); 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 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 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 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); public static final Type BLOCK = new Type(TypeSet.EXTRA, "BLOCK", false, ModifierSource.VOID);
private final String id; private final String id;

View File

@ -5,7 +5,6 @@ import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.edition.input.AnvilGUI; import net.Indyuce.mmoitems.api.edition.input.AnvilGUI;
import net.Indyuce.mmoitems.api.edition.input.ChatEdition; 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.PluginInventory;
import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.gui.edition.EditionInventory;
import net.Indyuce.mmoitems.stat.type.ItemStat; 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."); 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. * 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)) { if (MMOItems.plugin.getConfig().getBoolean("anvil-text-input") && MythicLib.plugin.getVersion().isBelowOrEqual(1, 13)) {
@ -59,20 +58,15 @@ public class StatEdition implements Edition {
return; return;
} }
/* // Default chat edition feature
* default chat edition feature
*/
new ChatEdition(this); new ChatEdition(this);
inv.getPlayer().sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "Item Edition", "See chat.", 10, 40, 10); inv.getPlayer().sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "Item Edition", "See chat.", 10, 40, 10);
} }
@Override @Override
public boolean processInput(String input) { 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")) { if (input.equals("cancel")) {
inv.open(); inv.open();
return true; return true;

View File

@ -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);
}

View File

@ -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.item.NBTItem;
import io.lumine.mythic.lib.api.player.EquipmentSlot; import io.lumine.mythic.lib.api.player.EquipmentSlot;
import io.lumine.mythic.lib.player.modifier.ModifierSource; import io.lumine.mythic.lib.player.modifier.ModifierSource;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
@ -12,7 +13,7 @@ import org.bukkit.inventory.ItemStack;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Objects; import java.util.Objects;
public class EquippedItem { public abstract class EquippedItem {
private final NBTItem item; private final NBTItem item;
private final EquipmentSlot slot; private final EquipmentSlot slot;
@ -76,4 +77,13 @@ public class EquippedItem {
final ModifierSource modSource = type.getModifierSource(); final ModifierSource modSource = type.getModifierSource();
return EquipmentSlot.OFF_HAND.isCompatible(modSource, slot) || EquipmentSlot.MAIN_HAND.isCompatible(modSource, slot); 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);
} }

View File

@ -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.MMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.player.PlayerData; 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.EquippedItem;
import net.Indyuce.mmoitems.api.player.inventory.InventoryUpdateHandler; import net.Indyuce.mmoitems.api.player.inventory.InventoryUpdateHandler;
import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.api.util.message.Message;
@ -22,10 +21,12 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
public class DeathDowngrading { public class DeathDowngrading {
private static final Random RANDOM = new Random();
/** /**
* This will go through the following steps: * 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 * #1 Evaluate the list of equipped items {@link InventoryUpdateHandler#getEquipped()} to
* find those that can be death-downgraded. * find those that can be death-downgraded.
* *
*
* #2 Roll for death downgrade chances, downgrading the items * #2 Roll for death downgrade chances, downgrading the items
* *
* @param player Player whose inventory is to be death-downgraded. * @param player Player whose inventory is to be death-downgraded.
@ -41,7 +41,7 @@ public class DeathDowngrading {
public static void playerDeathDowngrade(@NotNull Player player) { public static void playerDeathDowngrade(@NotNull Player player) {
// Get Player // Get Player
PlayerData data = PlayerData.get(player); final PlayerData data = PlayerData.get(player);
// Get total downgrade chance, anything less than zero is invalid // Get total downgrade chance, anything less than zero is invalid
double deathChance = data.getStats().getStat(ItemStats.DOWNGRADE_ON_DEATH_CHANCE); 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 // Make sure the equipped items list is up to date and retrieve it
data.updateInventory(); data.updateInventory();
List<EquippedItem> items = data.getInventory().getEquipped(); final List<EquippedItem> equipped = data.getInventory().getEquipped();
ArrayList<EditableEquippedItem> equipped = new ArrayList<>(); for (Iterator<EquippedItem> ite = equipped.iterator(); ite.hasNext(); ) {
EquippedItem next = ite.next();
// Equipped Player Items yeah... if (next == null || !canDeathDowngrade(next.getCached()))
for (EquippedItem playerItem : items) { ite.remove();
// Cannot downgrade? skip
if (!canDeathDowngrade(playerItem)) { continue; }
// Okay explore stat
equipped.add((EditableEquippedItem) playerItem);
//DET//MMOItems.log("\u00a78DETH \u00a7cDG\u00a77 Yes. \u00a7aAccepted");
} }
// Nothing to perform operations? Snooze // Nothing to perform operations? Snooze
if (equipped.size() == 0) { if (equipped.size() == 0) {
//DET//MMOItems.log("\u00a78DETH \u00a7cDG\u00a77 No items to downgrade. "); //DET//MMOItems.log("\u00a78DETH \u00a7cDG\u00a77 No items to downgrade. ");
return; } return;
}
// Create random
Random random = new Random();
// Degrade those items! // Degrade those items!
while (deathChance >= 100 && equipped.size() > 0) { while (deathChance >= 100 && equipped.size() > 0) {
@ -78,13 +69,9 @@ public class DeathDowngrading {
// Decrease // Decrease
deathChance -= 100; deathChance -= 100;
// Downgrade random item // The item was randomly chosen, we must downgrade it by one level.
int deathChosen = random.nextInt(equipped.size()); int deathChosen = RANDOM.nextInt(equipped.size());
EquippedItem equip = equipped.get(deathChosen);
/*
* The item was chosen, we must downgrade it by one level.
*/
EditableEquippedItem equip = equipped.get(deathChosen);
// Downgrade and remove from list // Downgrade and remove from list
equip.setItem(downgrade(new LiveMMOItem(equip.getNBT()), player)); 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 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 // Downgrade random item
int d = random.nextInt(equipped.size()); int d = RANDOM.nextInt(equipped.size());
EquippedItem equip = equipped.get(d);
/*
* The item was chosen, we must downgrade it by one level.
*/
EditableEquippedItem equip = equipped.get(d);
// Downgrade and remove from list // Downgrade and remove from list
equip.setItem(downgrade(new LiveMMOItem(equip.getNBT()), player)); equip.setItem(downgrade(new LiveMMOItem(equip.getNBT()), player));
@ -147,9 +130,6 @@ public class DeathDowngrading {
} }
} }
// Create random
Random random = new Random();
// Degrade those items! // Degrade those items!
while (deathChance >= 100 && downgrade.size() > 0) { while (deathChance >= 100 && downgrade.size() > 0) {
@ -157,7 +137,7 @@ public class DeathDowngrading {
deathChance -= 100; deathChance -= 100;
// Downgrade random item // 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. * 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 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 // 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. * 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); 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 * @param playerItem Item you want to know if it can be death downgraded
* *

View File

@ -17,7 +17,7 @@ public class WorldEditSupport {
WorldEdit.getInstance().getBlockFactory().register(new WECustomBlockInputParser()); WorldEdit.getInstance().getBlockFactory().register(new WECustomBlockInputParser());
} }
public static class WECustomBlockInputParser extends InputParser<BaseBlock> { public class WECustomBlockInputParser extends InputParser<BaseBlock> {
public WECustomBlockInputParser() { public WECustomBlockInputParser() {
super(WorldEdit.getInstance()); super(WorldEdit.getInstance());
} }

View File

@ -3,7 +3,6 @@ package net.Indyuce.mmoitems.comp.inventory;
import io.lumine.mythic.lib.api.player.EquipmentSlot; import io.lumine.mythic.lib.api.player.EquipmentSlot;
import net.Indyuce.mmoitems.api.player.inventory.EquippedItem; import net.Indyuce.mmoitems.api.player.inventory.EquippedItem;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
@ -24,16 +23,16 @@ public class DefaultPlayerInventory implements PlayerInventory {
if (player.getEquipment() == null) { return list; } if (player.getEquipment() == null) { return list; }
// Mainhand // 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 // 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 // Armor
list.add(new EIDefaultInventory(player, 103, player.getEquipment().getHelmet(), EquipmentSlot.ARMOR)); list.add(new SlotEquippedItem(player, 103, player.getEquipment().getHelmet(), EquipmentSlot.ARMOR));
list.add(new EIDefaultInventory(player, 102, player.getEquipment().getChestplate(), EquipmentSlot.ARMOR)); list.add(new SlotEquippedItem(player, 102, player.getEquipment().getChestplate(), EquipmentSlot.ARMOR));
list.add(new EIDefaultInventory(player, 101, player.getEquipment().getLeggings(), EquipmentSlot.ARMOR)); list.add(new SlotEquippedItem(player, 101, player.getEquipment().getLeggings(), EquipmentSlot.ARMOR));
list.add(new EIDefaultInventory(player, 100, player.getEquipment().getBoots(), EquipmentSlot.ARMOR)); list.add(new SlotEquippedItem(player, 100, player.getEquipment().getBoots(), EquipmentSlot.ARMOR));
return list; return list;
} }

View File

@ -3,18 +3,19 @@ package net.Indyuce.mmoitems.comp.inventory;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.player.EquipmentSlot; import io.lumine.mythic.lib.api.player.EquipmentSlot;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.inventory.EquippedItem; 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.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -25,36 +26,39 @@ import java.util.List;
* Ornaments - Found in any inventory slot. * Ornaments - Found in any inventory slot.
*/ */
public class OrnamentPlayerInventory implements PlayerInventory, Listener { public class OrnamentPlayerInventory implements PlayerInventory, Listener {
public OrnamentPlayerInventory() {
Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin);
}
@Override @Override
public List<EquippedItem> getInventory(Player player) { public List<EquippedItem> getInventory(Player player) {
List<EquippedItem> list = new ArrayList<>(); final List<EquippedItem> list = new ArrayList<>();
// Ornaments // Find ornaments
for (ItemStack item : player.getInventory().getContents()) { final ItemStack[] matrix = player.getInventory().getContents();
NBTItem nbtItem; for (int i = 0; i < matrix.length; i++) {
if (item != null && (nbtItem = MythicLib.plugin.getVersion().getWrapper().getNBTItem(item)).hasType() && Type.get(nbtItem.getType()).getSupertype().equals(Type.ORNAMENT)) final ItemStack curr = matrix[i];
list.add(new EquippedItem(nbtItem, EquipmentSlot.OTHER)); if (curr == null || curr.getType() == Material.AIR)
continue;
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));
} }
return list; return list;
} }
@EventHandler(ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void a(EntityPickupItemEvent event) { public void updateOnItemPickup(EntityPickupItemEvent event) {
if (event.getEntityType() == EntityType.PLAYER) { if (event.getEntityType() == EntityType.PLAYER) {
NBTItem nbt = NBTItem.get(event.getItem().getItemStack()); final NBTItem nbt = NBTItem.get(event.getItem().getItemStack());
if (nbt.hasType() && Type.get(nbt.getType()).getSupertype().equals(Type.ORNAMENT)) if (nbt.hasType() && Type.get(nbt.getType()).getSupertype().equals(Type.ORNAMENT))
PlayerData.get((Player) event.getEntity()).updateInventory(); PlayerData.get((Player) event.getEntity()).getInventory().scheduleUpdate();
} }
} }
@EventHandler(ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void b(PlayerDropItemEvent event) { public void updateOnItemDrop(PlayerDropItemEvent event) {
NBTItem nbt = NBTItem.get(event.getItemDrop().getItemStack()); final NBTItem nbt = NBTItem.get(event.getItemDrop().getItemStack());
if (nbt.hasType() && Type.get(nbt.getType()).getSupertype().equals(Type.ORNAMENT)) if (nbt.hasType() && Type.get(nbt.getType()).getSupertype().equals(Type.ORNAMENT))
PlayerData.get(event.getPlayer()).updateInventory(); PlayerData.get(event.getPlayer()).updateInventory();
} }

View File

@ -1,6 +1,8 @@
package net.Indyuce.mmoitems.comp.inventory; package net.Indyuce.mmoitems.comp.inventory;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.player.inventory.EquippedItem; import net.Indyuce.mmoitems.api.player.inventory.EquippedItem;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -38,6 +40,8 @@ public class PlayerInventoryHandler {
*/ */
public void register(@NotNull PlayerInventory pInventory) { public void register(@NotNull PlayerInventory pInventory) {
registeredInventories.add(pInventory); registeredInventories.add(pInventory);
if (pInventory instanceof Listener)
Bukkit.getPluginManager().registerEvents((Listener) pInventory, MMOItems.plugin);
} }
public void unregisterIf(Predicate<PlayerInventory> filter) { public void unregisterIf(Predicate<PlayerInventory> filter) {

View File

@ -1,15 +1,14 @@
package net.Indyuce.mmoitems.comp.inventory; package net.Indyuce.mmoitems.comp.inventory;
import io.lumine.mythic.lib.api.player.EquipmentSlot; 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.PlayerData;
import net.Indyuce.mmoitems.api.player.inventory.EquippedItem; import net.Indyuce.mmoitems.api.player.inventory.EquippedItem;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import ru.endlesscode.rpginventory.api.InventoryAPI; import ru.endlesscode.rpginventory.api.InventoryAPI;
import java.util.ArrayList; import java.util.ArrayList;
@ -22,22 +21,13 @@ import java.util.List;
*/ */
public class RPGInventoryHook implements PlayerInventory, Listener { 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 @Override
public List<EquippedItem> getInventory(Player player) { public List<EquippedItem> getInventory(Player player) {
List<EquippedItem> list = new ArrayList<>(); List<EquippedItem> list = new ArrayList<>();
for (ItemStack passive : InventoryAPI.getPassiveItems(player)) for (ItemStack passive : InventoryAPI.getPassiveItems(player))
if (passive != null) if (passive != null)
list.add(new EquippedItem(passive, EquipmentSlot.ACCESSORY)); list.add(new LegacyEquippedItem(passive));
return list; return list;
} }
@ -47,4 +37,18 @@ public class RPGInventoryHook implements PlayerInventory, Listener {
if (InventoryAPI.isRPGInventory(event.getInventory())) if (InventoryAPI.isRPGInventory(event.getInventory()))
PlayerData.get((Player) event.getPlayer()).updateInventory(); 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());
}
}
} }

View File

@ -2,31 +2,40 @@ package net.Indyuce.mmoitems.comp.inventory;
import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.player.EquipmentSlot; 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.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class EIDefaultInventory extends EditableEquippedItem { public class SlotEquippedItem extends EquippedItem {
@NotNull public Player getPlayer() { return player; } private final Player player;
@NotNull Player player; private final int slotNumber;
public int getSlotNumber() { return slotNumber; } public SlotEquippedItem(@NotNull Player player, int slotNumber, ItemStack item, EquipmentSlot slot) {
int slotNumber;
public EIDefaultInventory(@NotNull Player player, int slotNumber, ItemStack item, EquipmentSlot slot) {
super(item, slot); super(item, slot);
this.player = player; this.player = player;
this.slotNumber = slotNumber; 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); super(item, slot);
this.player = player; this.player = player;
this.slotNumber = slotNumber; this.slotNumber = slotNumber;
} }
@NotNull
public Player getPlayer() {
return player;
}
@NotNull
public int getSlotNumber() {
return slotNumber;
}
@Override @Override
public void setItem(@Nullable ItemStack item) { public void setItem(@Nullable ItemStack item) {

View File

@ -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);
}

View File

@ -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());
}
}

View File

@ -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));
}
}

View File

@ -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);
}

View File

@ -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.MythicLib;
import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.item.NBTItem;

View File

@ -30,5 +30,4 @@ public class PluginUtils {
callback.accept(null); callback.accept(null);
MMOItems.plugin.getLogger().log(Level.INFO, "Hooked onto %s".formatted(name)); MMOItems.plugin.getLogger().log(Level.INFO, "Hooked onto %s".formatted(name));
} }
} }

View File

@ -28,6 +28,10 @@ inventory-update-delay: 10
# interval [playerLevel - spread, playerLevel + spread] # interval [playerLevel - spread, playerLevel + spread]
item-level-spread: 2 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, # When an item is generated with no tier,
# this is the capacity formula it will use. # this is the capacity formula it will use.
default-item-capacity: default-item-capacity: