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>
<scope>provided</scope>
</dependency>
<!-- ProtocolLib -->
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.7.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<!-- mcMMO -->
<dependency>
<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.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<StringInputParser> stringInputParsers = new ArrayList<>();
private final List<EnchantPlugin<? extends Enchantment>> 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<StringInputParser> getStringInputParsers() {
return stringInputParsers;
}
//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);
// 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;

View File

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

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

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.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<EquippedItem> items = data.getInventory().getEquipped();
ArrayList<EditableEquippedItem> 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<EquippedItem> equipped = data.getInventory().getEquipped();
for (Iterator<EquippedItem> 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
*

View File

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

View File

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

View File

@ -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<EquippedItem> getInventory(Player player) {
List<EquippedItem> list = new ArrayList<>();
@Override
public List<EquippedItem> getInventory(Player player) {
final List<EquippedItem> 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();
}
}

View File

@ -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<PlayerInventory> filter) {

View File

@ -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<EquippedItem> getInventory(Player player) {
List<EquippedItem> list = new ArrayList<>();
@Override
public List<EquippedItem> getInventory(Player player) {
List<EquippedItem> 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());
}
}
}

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.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) {

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.api.item.NBTItem;

View File

@ -30,5 +30,4 @@ public class PluginUtils {
callback.accept(null);
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]
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: