From 0db2980fdabba933a5f0e1fd931b5f230921edb4 Mon Sep 17 00:00:00 2001 From: Roch Blonndiaux Date: Thu, 2 Feb 2023 10:58:50 +0100 Subject: [PATCH] Reload inventories on stats reload --- .../command/mmoitems/ReloadCommandTreeNode.java | 14 ++++++++++++++ .../comp/inventory/model/PlayerMMOInventory.java | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/ReloadCommandTreeNode.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/ReloadCommandTreeNode.java index 7a31dcc0..bd5aa6b2 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/ReloadCommandTreeNode.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/command/mmoitems/ReloadCommandTreeNode.java @@ -3,8 +3,11 @@ package net.Indyuce.mmoitems.command.mmoitems; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.command.api.CommandTreeNode; import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.util.MMOItemReforger; import net.Indyuce.mmoitems.api.util.NumericStatFormula; +import net.Indyuce.mmoitems.comp.inventory.PlayerInventoryHandler; +import net.Indyuce.mmoitems.comp.inventory.model.PlayerMMOInventory; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -50,6 +53,8 @@ public class ReloadCommandTreeNode extends CommandTreeNode { MythicLib.plugin.getSkills().initialize(true); MMOItems.plugin.getSkills().initialize(true); sender.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reloaded " + MMOItems.plugin.getSkills().getAll().size() + " skills."); + + reloadPlayerInventories(); } public void reloadMain(CommandSender sender) { @@ -100,4 +105,13 @@ public class ReloadCommandTreeNode extends CommandTreeNode { sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getCrafting().countRecipes() + ChatColor.GRAY + " Recipes"); } + + public void reloadPlayerInventories() { + PlayerData.getLoaded() + .stream() + .map(PlayerData::getInventory) + .map(PlayerMMOInventory::getHandler) + .peek(PlayerInventoryHandler::reset) + .forEach(PlayerInventoryHandler::start); + } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/model/PlayerMMOInventory.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/model/PlayerMMOInventory.java index 3552f79b..0e3b0a16 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/model/PlayerMMOInventory.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/inventory/model/PlayerMMOInventory.java @@ -68,4 +68,8 @@ public class PlayerMMOInventory { public List equipped() { return Collections.unmodifiableList(content); } + + public PlayerInventoryHandler getHandler() { + return handler; + } }