Skip to content

Commit

Permalink
Merge pull request #14 from DeveloperDeborah/main
Browse files Browse the repository at this point in the history
add ability to edit inventories that the target player doesn't currently have open
  • Loading branch information
mortenn authored Jan 22, 2024
2 parents 8f58711 + 2760155 commit 28ca545
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
11 changes: 0 additions & 11 deletions .idea/libraries/joda_time_2_1_sources.xml

This file was deleted.

2 changes: 1 addition & 1 deletion META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Manifest-Version: 1.0
Class-Path: runsafe/framework.jar runsafe/joda-time-2.1.jar
Class-Path: runsafe/framework.jar

1 change: 0 additions & 1 deletion RunsafeInventories.iml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="framework" level="project" />
<orderEntry type="library" name="joda-time-2.1-sources" level="project" />
<orderEntry type="library" name="spigot" level="project" />
<orderEntry type="library" name="RunsafeWorldGuardBridge" level="project" />
</component>
Expand Down
2 changes: 1 addition & 1 deletion ant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Class-Path" value="runsafe/framework.jar runsafe/joda-time-2.1.jar"/>
<attribute name="Class-Path" value="runsafe/framework.jar"/>
</manifest>
<fileset dir="${build.dir}" includes="plugin.yml"/>
<fileset dir="${src.dir}" includes="defaults.yml"/>
Expand Down
20 changes: 19 additions & 1 deletion src/no/runsafe/runsafeinventories/InventoryViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)
{
Expand All @@ -54,5 +71,6 @@ public void OnConfigurationChanged(IConfiguration configuration)

private final IServer server;
private final InventoryRepository repository;
private static final HashMap<IPlayer, PlayerInventory> inventoryEditors = new HashMap<>();
private String defaultUniverse;
}
8 changes: 7 additions & 1 deletion src/no/runsafe/runsafeinventories/PlayerInventory.java
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -39,6 +40,11 @@ public String getInventoryString()
return this.inventoryString;
}

public void setInventory(RunsafeInventory inventory)
{
inventoryString = inventory.serialize();
}

public int getLevel()
{
return this.level;
Expand All @@ -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;
Expand Down

0 comments on commit 28ca545

Please sign in to comment.