From 7b22ffe01bf850d4e8efed514998000b1707dcd9 Mon Sep 17 00:00:00 2001 From: Peaches_MLG Date: Sat, 4 May 2024 20:00:00 +0100 Subject: [PATCH] Version Increment --- build.gradle.kts | 2 +- .../iridium/mocknbtapi/FakeNBTApiFactory.java | 2 +- .../com/iridium/mocknbtapi/FakeNBTItem.java | 20 +++++++++++++++++++ .../java/com/iridium/mocknbtapi/NBTItem.java | 4 ++++ .../com/iridium/mocknbtapi/RealNBTItem.java | 9 +++++++-- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index fc7267d..1fa2d4a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "com.iridium" -version = "1.0.0" +version = "1.0.1" description = "MockNBTApi" repositories { diff --git a/src/main/java/com/iridium/mocknbtapi/FakeNBTApiFactory.java b/src/main/java/com/iridium/mocknbtapi/FakeNBTApiFactory.java index a9b1b7f..e718354 100644 --- a/src/main/java/com/iridium/mocknbtapi/FakeNBTApiFactory.java +++ b/src/main/java/com/iridium/mocknbtapi/FakeNBTApiFactory.java @@ -5,6 +5,6 @@ public class FakeNBTApiFactory implements NBTApiFactory{ @Override public NBTItem getNBTItem(ItemStack itemStack) { - return new FakeNBTItem(); + return FakeNBTItem.getFakeNBTItem(itemStack); } } diff --git a/src/main/java/com/iridium/mocknbtapi/FakeNBTItem.java b/src/main/java/com/iridium/mocknbtapi/FakeNBTItem.java index 5986323..b4c4348 100644 --- a/src/main/java/com/iridium/mocknbtapi/FakeNBTItem.java +++ b/src/main/java/com/iridium/mocknbtapi/FakeNBTItem.java @@ -1,9 +1,24 @@ package com.iridium.mocknbtapi; +import org.bukkit.inventory.ItemStack; + import java.util.HashMap; public class FakeNBTItem implements NBTItem { + private final ItemStack itemStack; private final HashMap nbtData = new HashMap<>(); + private final static HashMap fakeNBTItemHashMap = new HashMap<>(); + + public FakeNBTItem(ItemStack itemStack){ + this.itemStack = itemStack; + } + + public static FakeNBTItem getFakeNBTItem(ItemStack itemStack){ + if(!fakeNBTItemHashMap.containsKey(itemStack)){ + fakeNBTItemHashMap.put(itemStack, new FakeNBTItem(itemStack)); + } + return fakeNBTItemHashMap.get(itemStack); + } @Override public void setString(String key, String value) { @@ -44,4 +59,9 @@ public double getDouble(String key) { public boolean getBoolean(String key) { return (boolean) nbtData.get(key); } + + @Override + public ItemStack getItem() { + return itemStack; + } } diff --git a/src/main/java/com/iridium/mocknbtapi/NBTItem.java b/src/main/java/com/iridium/mocknbtapi/NBTItem.java index 4638f66..2471ebd 100644 --- a/src/main/java/com/iridium/mocknbtapi/NBTItem.java +++ b/src/main/java/com/iridium/mocknbtapi/NBTItem.java @@ -1,5 +1,7 @@ package com.iridium.mocknbtapi; +import org.bukkit.inventory.ItemStack; + public interface NBTItem { void setString(String key, String value); @@ -16,4 +18,6 @@ public interface NBTItem { double getDouble(String key); boolean getBoolean(String key); + + ItemStack getItem(); } diff --git a/src/main/java/com/iridium/mocknbtapi/RealNBTItem.java b/src/main/java/com/iridium/mocknbtapi/RealNBTItem.java index 4317d5a..e756b59 100644 --- a/src/main/java/com/iridium/mocknbtapi/RealNBTItem.java +++ b/src/main/java/com/iridium/mocknbtapi/RealNBTItem.java @@ -2,11 +2,11 @@ import org.bukkit.inventory.ItemStack; -public class RealNBTItem implements NBTItem{ +public class RealNBTItem implements NBTItem { private de.tr7zw.changeme.nbtapi.NBTItem nbtItem; - public RealNBTItem(ItemStack itemStack){ + public RealNBTItem(ItemStack itemStack) { nbtItem = new de.tr7zw.changeme.nbtapi.NBTItem(itemStack); } @@ -49,4 +49,9 @@ public double getDouble(String key) { public boolean getBoolean(String key) { return nbtItem.getBoolean(key); } + + @Override + public ItemStack getItem() { + return nbtItem.getItem(); + } }