From 6af54584873fbef0876b6906d7194d7d6a60ec9c Mon Sep 17 00:00:00 2001 From: DevDeborah Date: Sun, 21 Jan 2024 18:17:55 -0500 Subject: [PATCH 1/2] remove joda time --- .idea/libraries/joda_time_2_1_sources.xml | 11 ----------- META-INF/MANIFEST.MF | 2 +- RunsafeInventories.iml | 1 - ant.xml | 2 +- 4 files changed, 2 insertions(+), 14 deletions(-) delete mode 100644 .idea/libraries/joda_time_2_1_sources.xml diff --git a/.idea/libraries/joda_time_2_1_sources.xml b/.idea/libraries/joda_time_2_1_sources.xml deleted file mode 100644 index 9bfb868..0000000 --- a/.idea/libraries/joda_time_2_1_sources.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF index 440056f..be474d7 100644 --- a/META-INF/MANIFEST.MF +++ b/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ Manifest-Version: 1.0 -Class-Path: runsafe/framework.jar runsafe/joda-time-2.1.jar +Class-Path: runsafe/framework.jar diff --git a/RunsafeInventories.iml b/RunsafeInventories.iml index 776874c..ac156ff 100644 --- a/RunsafeInventories.iml +++ b/RunsafeInventories.iml @@ -8,7 +8,6 @@ - diff --git a/ant.xml b/ant.xml index 58a04e8..7110dcd 100644 --- a/ant.xml +++ b/ant.xml @@ -34,7 +34,7 @@ - + From 2760155a301e51e6842e8ea4198eef1cbe0a5c10 Mon Sep 17 00:00:00 2001 From: DevDeborah Date: Sun, 21 Jan 2024 19:49:42 -0500 Subject: [PATCH 2/2] add ability to edit inventories that the target player isn't currently using. --- .../runsafeinventories/InventoryViewer.java | 20 ++++++++++++++++++- .../runsafeinventories/PlayerInventory.java | 8 +++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/no/runsafe/runsafeinventories/InventoryViewer.java b/src/no/runsafe/runsafeinventories/InventoryViewer.java index 2fbaea6..2d20d9c 100644 --- a/src/no/runsafe/runsafeinventories/InventoryViewer.java +++ b/src/no/runsafe/runsafeinventories/InventoryViewer.java @@ -2,12 +2,16 @@ import no.runsafe.framework.api.IConfiguration; import no.runsafe.framework.api.IServer; +import no.runsafe.framework.api.event.inventory.IInventoryClosed; import no.runsafe.framework.api.event.plugin.IConfigurationChanged; import no.runsafe.framework.api.player.IPlayer; +import no.runsafe.framework.minecraft.event.inventory.RunsafeInventoryCloseEvent; import no.runsafe.framework.minecraft.inventory.RunsafeInventory; import no.runsafe.runsafeinventories.repositories.InventoryRepository; -public class InventoryViewer implements IConfigurationChanged +import java.util.HashMap; + +public class InventoryViewer implements IConfigurationChanged, IInventoryClosed { public InventoryViewer(IServer server, InventoryRepository repository) { @@ -37,6 +41,7 @@ public boolean viewUniverseInventory(IPlayer viewer, IPlayer owner, String unive RunsafeInventory inventory = server.createInventory(null, 45, String.format("%s's Inventory", owner.getName())); inventory.unserialize(inventoryData.getInventoryString()); viewer.openInventory(inventory); + inventoryEditors.put(viewer, inventoryData); return true; } @@ -46,6 +51,18 @@ public boolean hasDefaultUniverse() return (this.defaultUniverse != null); } + @Override + public void OnInventoryClosed(RunsafeInventoryCloseEvent event) + { + if (inventoryEditors.isEmpty() || !inventoryEditors.containsKey(event.getPlayer())) + return; + + PlayerInventory inventory = inventoryEditors.get(event.getPlayer()); + inventory.setInventory(event.getInventory()); + repository.saveInventory(inventory); + inventoryEditors.remove(event.getPlayer()); + } + @Override public void OnConfigurationChanged(IConfiguration configuration) { @@ -54,5 +71,6 @@ public void OnConfigurationChanged(IConfiguration configuration) private final IServer server; private final InventoryRepository repository; + private static final HashMap inventoryEditors = new HashMap<>(); private String defaultUniverse; } diff --git a/src/no/runsafe/runsafeinventories/PlayerInventory.java b/src/no/runsafe/runsafeinventories/PlayerInventory.java index 7a8778f..75313fb 100644 --- a/src/no/runsafe/runsafeinventories/PlayerInventory.java +++ b/src/no/runsafe/runsafeinventories/PlayerInventory.java @@ -1,6 +1,7 @@ package no.runsafe.runsafeinventories; import no.runsafe.framework.api.player.IPlayer; +import no.runsafe.framework.minecraft.inventory.RunsafeInventory; public class PlayerInventory { @@ -39,6 +40,11 @@ public String getInventoryString() return this.inventoryString; } + public void setInventory(RunsafeInventory inventory) + { + inventoryString = inventory.serialize(); + } + public int getLevel() { return this.level; @@ -56,7 +62,7 @@ public int getFoodLevel() private final String inventoryName; private final IPlayer owner; - private final String inventoryString; + private String inventoryString; private final int level; private final float experience; private final int foodLevel;