diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..eb7cc580
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,32 @@
+# Compiled binaries
+/target/
+*.class
+/bin/
+
+# Package files
+*.jar
+*.war
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# Redundant Gradle files
+/.gradle/
+/build/
+
+# IntelliJ IDEA project files
+/.idea/
+*.iml
+
+# Eclipse project files
+/.settings/
+.classpath
+.project
+
+# Redundant Maven files
+dependency-reduced-pom.xml
+
+# Temporary and log files
+**/temp.**
+*.log
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index fb3e3189..2b62a2a4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
org.shanerx
tradeshop
- 2.2.2-STABLE
+ 2.2.4-STABLE
jar
TradeShop
https://tradeshop.github.io/
diff --git a/src/main/java/org/shanerx/tradeshop/commands/CommandTabCompleter.java b/src/main/java/org/shanerx/tradeshop/commands/CommandTabCompleter.java
index 951cd8bb..43edf2dd 100644
--- a/src/main/java/org/shanerx/tradeshop/commands/CommandTabCompleter.java
+++ b/src/main/java/org/shanerx/tradeshop/commands/CommandTabCompleter.java
@@ -42,8 +42,8 @@
public class CommandTabCompleter extends Utils {
- private TradeShop plugin;
- private CommandPass command;
+ private final TradeShop plugin;
+ private final CommandPass command;
private Player pSender;
public CommandTabCompleter(TradeShop instance, CommandPass command) {
@@ -71,7 +71,7 @@ public List help() {
public List addSet() {
if (command.argsSize() == 2) {
- return Arrays.asList("1", "2", "4", "8", "16", "32", "64", "96", "128");
+ return Arrays.asList("1", "2", "4", "8", "16", "32", "64", "80", "96", "128");
} else if (command.argsSize() == 3) {
return partialGameMats(command.getArgAt(2));
}
diff --git a/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java b/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java
index 6d3132fb..b1cb02fc 100644
--- a/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java
+++ b/src/main/java/org/shanerx/tradeshop/listeners/ShopProtectionListener.java
@@ -58,43 +58,48 @@
public class ShopProtectionListener extends Utils implements Listener {
- private TradeShop plugin;
+ private final TradeShop plugin;
- public ShopProtectionListener(TradeShop instance) {
- plugin = instance;
- }
+ public ShopProtectionListener(TradeShop instance) {
+ plugin = instance;
+ }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
- public void onInventoryMoveItem(InventoryMoveItemEvent event) {
+ public void onInventoryMoveItem(InventoryMoveItemEvent event) {
- if (event.isCancelled())
- return;
+ try {
+ if (event.isCancelled()) {
+ return;
+ }
- if (event instanceof HopperShopAccessEvent)
- return;
+ if (event instanceof HopperShopAccessEvent) {
+ return;
+ }
- if (!(event.getInitiator().getType().equals(InventoryType.HOPPER) &&
- plugin.getListManager().isInventory(event.getSource().getLocation().getBlock()))) {
- return;
- }
+ if (!(event.getInitiator().getType().equals(InventoryType.HOPPER) &&
+ plugin.getListManager().isInventory(event.getSource().getLocation().getBlock()))) {
+ return;
+ }
- Block invBlock = event.getSource().getLocation().getBlock();
-
- Nameable fromContainer = (Nameable) invBlock.getState();
-
- if (ShopChest.isShopChest(invBlock)) {
- Shop shop = new ShopChest(invBlock.getLocation()).getShop();
- debugger.log("ShopProtectionListener: Shop Location as SL > " + shop.getInventoryLocationAsSL().serialize(), DebugLevels.PROTECTION);
- boolean isForbidden = !Setting.findSetting(shop.getShopType().name() + "SHOP_HOPPER_EXPORT").getBoolean();
- debugger.log("ShopProtectionListener: isForbidden > " + isForbidden, DebugLevels.PROTECTION);
- debugger.log("ShopProtectionListener: checked hopper setting > " + shop.getShopType().name() + "SHOP_HOPPER_EXPORT", DebugLevels.PROTECTION);
- HopperShopAccessEvent hopperEvent = new HopperShopAccessEvent(shop, event.getSource(), event.getDestination(), event.getItem(), isForbidden);
- Bukkit.getPluginManager().callEvent(hopperEvent);
- debugger.log("ShopProtectionListener: HopperEvent thrown! ", DebugLevels.PROTECTION);
- event.setCancelled(hopperEvent.isForbidden());
- debugger.log("ShopProtectionListener: HopperEvent isCancelled: " + hopperEvent.isForbidden(), DebugLevels.PROTECTION);
- debugger.log("ShopProtectionListener: HopperEvent isCancelled: " + isForbidden, DebugLevels.PROTECTION);
- }
+ Block invBlock = event.getSource().getLocation().getBlock();
+
+ Nameable fromContainer = (Nameable) invBlock.getState();
+
+ if (ShopChest.isShopChest(invBlock)) {
+ Shop shop = new ShopChest(invBlock.getLocation()).getShop();
+ debugger.log("ShopProtectionListener: Shop Location as SL > " + shop.getInventoryLocationAsSL().serialize(), DebugLevels.PROTECTION);
+ boolean isForbidden = !Setting.findSetting(shop.getShopType().name() + "SHOP_HOPPER_EXPORT").getBoolean();
+ debugger.log("ShopProtectionListener: isForbidden > " + isForbidden, DebugLevels.PROTECTION);
+ debugger.log("ShopProtectionListener: checked hopper setting > " + shop.getShopType().name() + "SHOP_HOPPER_EXPORT", DebugLevels.PROTECTION);
+ HopperShopAccessEvent hopperEvent = new HopperShopAccessEvent(shop, event.getSource(), event.getDestination(), event.getItem(), isForbidden);
+ Bukkit.getPluginManager().callEvent(hopperEvent);
+ debugger.log("ShopProtectionListener: HopperEvent thrown! ", DebugLevels.PROTECTION);
+ event.setCancelled(hopperEvent.isForbidden());
+ debugger.log("ShopProtectionListener: HopperEvent isCancelled: " + hopperEvent.isForbidden(), DebugLevels.PROTECTION);
+ debugger.log("ShopProtectionListener: HopperEvent isForbidden: " + isForbidden, DebugLevels.PROTECTION);
+ }
+ } catch (NullPointerException ignored) {
+ } // Fix for random NPE triggering from this event that shows no stack trace
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@@ -217,7 +222,7 @@ public void onChestOpen(PlayerInteractEvent e) {
Block block = e.getClickedBlock();
- if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK && plugin.getListManager().isInventory(block))) {
+ if (e.getAction() != Action.RIGHT_CLICK_BLOCK || !plugin.getListManager().isInventory(block)) {
return;
}
diff --git a/src/main/java/org/shanerx/tradeshop/listeners/ShopRestockListener.java b/src/main/java/org/shanerx/tradeshop/listeners/ShopRestockListener.java
index 371c2f09..07abb6b1 100644
--- a/src/main/java/org/shanerx/tradeshop/listeners/ShopRestockListener.java
+++ b/src/main/java/org/shanerx/tradeshop/listeners/ShopRestockListener.java
@@ -36,7 +36,7 @@
public class ShopRestockListener extends Utils implements Listener {
- private TradeShop plugin;
+ private final TradeShop plugin;
public ShopRestockListener(TradeShop instance) {
plugin = instance;
@@ -49,8 +49,10 @@ public ShopRestockListener(TradeShop instance) {
public void onInventoryClose(InventoryCloseEvent event) {
if (ShopChest.isShopChest(event.getInventory())) {
Shop shop = new ShopChest(event.getInventory().getLocation()).getShop();
- shop.updateSign();
- shop.saveShop();
+ if (shop != null) {
+ shop.updateSign();
+ shop.saveShop();
+ }
}
}
}
diff --git a/src/main/java/org/shanerx/tradeshop/listeners/ShopTradeListener.java b/src/main/java/org/shanerx/tradeshop/listeners/ShopTradeListener.java
index d8bd501b..b96b4941 100644
--- a/src/main/java/org/shanerx/tradeshop/listeners/ShopTradeListener.java
+++ b/src/main/java/org/shanerx/tradeshop/listeners/ShopTradeListener.java
@@ -179,7 +179,7 @@ public void onBlockInteract(PlayerInteractEvent e) {
private boolean tradeAllItems(Shop shop, int multiplier, Action action, Player buyer) {
ArrayList costItems = new ArrayList<>(), productItems = new ArrayList<>();
- Inventory shopInventory = shop.getChestAsSC().getInventory();
+ Inventory shopInventory = shop.hasStorage() ? shop.getChestAsSC().getInventory() : null;
Inventory playerInventory = buyer.getInventory();
if (shop.getShopType() == ShopType.ITRADE && action.equals(Action.RIGHT_CLICK_BLOCK)) { //ITrade trade
diff --git a/src/main/java/org/shanerx/tradeshop/objects/Shop.java b/src/main/java/org/shanerx/tradeshop/objects/Shop.java
index 0f021912..fd067ed5 100644
--- a/src/main/java/org/shanerx/tradeshop/objects/Shop.java
+++ b/src/main/java/org/shanerx/tradeshop/objects/Shop.java
@@ -52,12 +52,14 @@ public class Shop implements Serializable {
private ShopUser owner;
private List managers, members;
private ShopType shopType;
- private ShopLocation shopLoc, chestLoc;
- private List product, cost;
+ private final ShopLocation shopLoc;
+ private final List product;
+ private final List cost;
+ private ShopLocation chestLoc;
private transient SignChangeEvent signChangeEvent;
private transient Inventory storageInv;
private transient Utils utils;
- private ShopStatus status = ShopStatus.INCOMPLETE;
+ private ShopStatus status = ShopStatus.INCOMPLETE;
/**
* Creates a Shop object
@@ -639,7 +641,8 @@ public void updateSign() {
String[] signLines = updateSignLines();
for (int i = 0; i < 4; i++) {
- s.setLine(i, signLines[i]);
+ if (signLines[i] != null && s != null)
+ s.setLine(i, signLines[i]);
}
s.update();
@@ -676,16 +679,16 @@ private String[] updateSignLines() {
if (product.isEmpty()) {
signLines[1] = "";
} else if (product.size() == 1) {
- StringBuilder sb = new StringBuilder();
+ StringBuilder sb = new StringBuilder();
- ShopItemStack item = product.get(0);
+ ShopItemStack item = product.get(0);
- sb.append(item.getItemStack().getAmount());
- sb.append(" ");
+ sb.append(item.getItemStack().getAmount());
+ sb.append(" ");
- sb.append(item.getItemName());
+ sb.append(item.getItemName());
- signLines[1] = sb.toString().substring(0, Math.min(sb.length(), 15));
+ signLines[1] = sb.substring(0, Math.min(sb.length(), 15));
} else {
signLines[1] = Setting.MULTIPLE_ITEMS_ON_SIGN.getString();
@@ -694,16 +697,16 @@ private String[] updateSignLines() {
if (cost.isEmpty()) {
signLines[2] = "";
} else if (cost.size() == 1) {
- StringBuilder sb = new StringBuilder();
+ StringBuilder sb = new StringBuilder();
- ShopItemStack item = cost.get(0);
+ ShopItemStack item = cost.get(0);
- sb.append(item.getItemStack().getAmount());
- sb.append(" ");
+ sb.append(item.getItemStack().getAmount());
+ sb.append(" ");
- sb.append(item.getItemName());
+ sb.append(item.getItemName());
- signLines[2] = sb.toString().substring(0, Math.min(sb.length(), 15));
+ signLines[2] = sb.substring(0, Math.min(sb.length(), 15));
} else {
signLines[2] = Setting.MULTIPLE_ITEMS_ON_SIGN.getString();
}
diff --git a/src/main/java/org/shanerx/tradeshop/objects/ShopChest.java b/src/main/java/org/shanerx/tradeshop/objects/ShopChest.java
index 22cc04f2..cdf6f8c8 100644
--- a/src/main/java/org/shanerx/tradeshop/objects/ShopChest.java
+++ b/src/main/java/org/shanerx/tradeshop/objects/ShopChest.java
@@ -28,29 +28,30 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Nameable;
-import org.bukkit.block.Block;
-import org.bukkit.block.BlockState;
-import org.bukkit.block.Container;
-import org.bukkit.block.DoubleChest;
+import org.bukkit.block.*;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.shanerx.tradeshop.TradeShop;
+import org.shanerx.tradeshop.enumys.DebugLevels;
import org.shanerx.tradeshop.utils.Utils;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
public class ShopChest extends Utils {
- private transient static TradeShop plugin = (TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop");
+ private final transient static TradeShop plugin = (TradeShop) Bukkit.getPluginManager().getPlugin("TradeShop");
private ShopLocation shopSign;
- private Location loc;
+ private final Location loc;
private Block chest;
private UUID owner;
- private String sectionSeparator = "\\$ \\^", titleSeparator = ":";
+ private final String sectionSeparator = "\\$ \\^";
+ private final String titleSeparator = ";;";
public ShopChest(Location chestLoc) {
this.loc = chestLoc;
@@ -67,14 +68,25 @@ public ShopChest(Block chest, UUID owner, Location sign) {
}
public static boolean isShopChest(Block checking) {
+ plugin.getDebugger().log("isShopChest checking Block at " + new ShopLocation(checking.getLocation()).serialize() + "", DebugLevels.PROTECTION);
try {
if (isDoubleChest(checking)) {
DoubleChest dbl = getDoubleChest(checking);
- return ((Container) dbl.getLeftSide().getInventory().getLocation().getBlock()).getPersistentDataContainer().has(plugin.getSignKey(), PersistentDataType.STRING) ||
- ((Container) dbl.getRightSide().getInventory().getLocation().getBlock()).getPersistentDataContainer().has(plugin.getSignKey(), PersistentDataType.STRING);
+ boolean leftHas = ((Container) dbl.getLeftSide()).getPersistentDataContainer().has(plugin.getSignKey(), PersistentDataType.STRING),
+ rightHas = ((Container) dbl.getRightSide()).getPersistentDataContainer().has(plugin.getSignKey(), PersistentDataType.STRING);
+
+ plugin.getDebugger().log("Block is DoubleChest", DebugLevels.PROTECTION);
+ plugin.getDebugger().log("Left side PerData: " + (leftHas ? ((Container) dbl.getLeftSide()).getPersistentDataContainer().get(plugin.getSignKey(), PersistentDataType.STRING) : "null"), DebugLevels.PROTECTION);
+ plugin.getDebugger().log("Right side PerData: " + (rightHas ? ((Container) dbl.getRightSide()).getPersistentDataContainer().get(plugin.getSignKey(), PersistentDataType.STRING) : "null"), DebugLevels.PROTECTION);
+
+ return leftHas || rightHas;
}
- return ((Container) checking.getState()).getPersistentDataContainer().has(plugin.getSignKey(), PersistentDataType.STRING);
+ boolean conHas = ((Container) checking.getState()).getPersistentDataContainer().has(plugin.getSignKey(), PersistentDataType.STRING);
+ plugin.getDebugger().log("Block is SINGLE inventory", DebugLevels.PROTECTION);
+ plugin.getDebugger().log("Storage Block PerData: " + (conHas ? ((Container) checking.getState()).getPersistentDataContainer().get(plugin.getSignKey(), PersistentDataType.STRING) : "null"), DebugLevels.PROTECTION);
+ return conHas;
} catch (NullPointerException | ClassCastException ex) {
+ plugin.getDebugger().log("NPE thrown during isShopChest by: \n" + ex.getCause(), DebugLevels.PROTECTION);
}
return false;
}
@@ -116,7 +128,7 @@ public static void resetOldName(Block checking) {
public static DoubleChest getDoubleChest(Block chest) {
try {
- return (DoubleChest) chest.getState();
+ return (DoubleChest) ((Chest) chest.getState()).getInventory().getHolder();
} catch (ClassCastException | NullPointerException ex) {
return null;
}
@@ -127,13 +139,20 @@ public static boolean isDoubleChest(Block chest) {
}
private void getBlock() {
- if (loc.getBlock() != null && plugin.getListManager().isInventory(loc.getBlock())) {
+ if (plugin.getListManager().isInventory(loc.getBlock())) {
Block block = loc.getBlock();
- if (isDoubleChest(block)) {
- chest = getDoubleChest(block).getInventory().getLocation().getBlock();
- } else {
- chest = block;
- }
+
+ try {
+ if (isDoubleChest(block)) {
+ DoubleChest dbl = getDoubleChest(block);
+ Container left = ((Container) dbl.getLeftSide()),
+ right = ((Container) dbl.getRightSide());
+ chest = left.getPersistentDataContainer().has(plugin.getSignKey(), PersistentDataType.STRING) ? left.getBlock() : right.getBlock();
+ } else
+ chest = block;
+ } catch (NullPointerException npe) {
+ chest = block;
+ }
}
}
@@ -156,9 +175,16 @@ public boolean hasStock(List product) {
public void loadFromName() {
if (isShopChest(chest)) {
- String[] name = ((Container) chest.getState()).getPersistentDataContainer().get(plugin.getSignKey(), PersistentDataType.STRING).split(sectionSeparator);
- shopSign = ShopLocation.deserialize(name[1].split(titleSeparator)[1]);
- owner = UUID.fromString(name[2].split(titleSeparator)[1]);
+ String[] name = ((Container) chest.getState()).getPersistentDataContainer().get(plugin.getSignKey(), PersistentDataType.STRING)
+ .replaceAll("Sign:", "Sign" + titleSeparator).replaceAll("Owner:", "Owner" + titleSeparator)
+ .split(sectionSeparator);
+ Map chestData = new HashMap<>();
+ for (String s : name) {
+ chestData.put(s.split(titleSeparator)[0], s.replace(s.split(titleSeparator)[0] + titleSeparator, ""));
+ }
+ chestData.forEach((k, v) -> plugin.getDebugger().log(k + " = " + v, DebugLevels.PROTECTION));
+ shopSign = ShopLocation.deserialize(chestData.get("Sign"));
+ owner = UUID.fromString(chestData.get("Owner"));
}
}
@@ -179,47 +205,33 @@ public boolean isEmpty() {
public String getName() {
StringBuilder sb = new StringBuilder();
- sb.append("$ ^Sign:");
+ sb.append("$ ^Sign");
+ sb.append(titleSeparator);
sb.append(shopSign.serialize());
- sb.append("$ ^Owner:");
+ sb.append("$ ^Owner");
+ sb.append(titleSeparator);
sb.append(owner.toString());
return sb.toString();
}
- public void resetName() {
- if (isShopChest(chest)) {
- Container container = (Container) chest.getState();
- container.getPersistentDataContainer().remove(plugin.getStorageKey());
- container.update();
-
-/*
- if (isDoubleChest(chest)) {
- Container container2 = (Container)getOtherHalfOfDoubleChest(chest).getState();
- container2.getPersistentDataContainer().remove(plugin.getStorageKey());
- container2.update();
- }
-*/
-
- }
+ public void setName(Block toSet) {
+ Container container = (Container) chest.getState();
+ container.getPersistentDataContainer().set(plugin.getSignKey(), PersistentDataType.STRING, getName());
+ container.update();
}
public void setName() {
setName(chest);
}
- public void setName(Block toSet) {
- Container container = (Container) chest.getState();
- container.getPersistentDataContainer().set(plugin.getSignKey(), PersistentDataType.STRING, getName());
- container.update();
-
-/*
- if (isDoubleChest(chest)) {
- Container container2 = (Container)getOtherHalfOfDoubleChest(chest).getState();
- container2.getPersistentDataContainer().set(plugin.getSignKey(), PersistentDataType.STRING, getName());
- container2.update();
+ public void resetName() {
+ if (isShopChest(chest)) {
+ Container container = (Container) chest.getState();
+ container.getPersistentDataContainer().remove(plugin.getStorageKey());
+ container.getPersistentDataContainer().remove(plugin.getSignKey());
+ container.update();
}
-*/
}
public void setEventName(BlockPlaceEvent event) {
diff --git a/src/main/java/org/shanerx/tradeshop/objects/ShopChunk.java b/src/main/java/org/shanerx/tradeshop/objects/ShopChunk.java
index e4095fbd..ff20946e 100644
--- a/src/main/java/org/shanerx/tradeshop/objects/ShopChunk.java
+++ b/src/main/java/org/shanerx/tradeshop/objects/ShopChunk.java
@@ -33,10 +33,11 @@
public class ShopChunk implements Serializable {
- final private String div = "_";
- private World world;
- private int x, z;
- private Chunk chunk;
+ final private String div = ";;";
+ private final World world;
+ private final int x;
+ private final int z;
+ private final Chunk chunk;
public ShopChunk(World w, int x, int z) {
this.world = w;
@@ -54,9 +55,11 @@ public ShopChunk(Chunk c) {
public static Chunk deserialize(String loc) {
if (loc.startsWith("c")) {
- String[] locA = loc.split("_");//Keep same as div
- World world = Bukkit.getWorld(locA[1].replace("-", "_"));
- int x = Integer.parseInt(locA[2]), z = Integer.parseInt(locA[3]);
+ String[] locA = loc.contains(";;") ? loc.split(";;") : loc.split("_"); //Keep same as div
+ World world = Bukkit.getWorld(locA[1]);
+ if (world == null)
+ world = Bukkit.getWorld(locA[1].replace("-", "_"));
+ int x = Integer.parseInt(locA[2]), z = Integer.parseInt(locA[4]);
return world.getChunkAt(x, z);
}
@@ -65,7 +68,7 @@ public static Chunk deserialize(String loc) {
}
public String serialize() {
- return "c" + div + world.getName().replace("_", "-") + div + x + div + z;
+ return "c" + div + world.getName() + div + x + div + z;
}
public World getWorld() {
diff --git a/src/main/java/org/shanerx/tradeshop/objects/ShopItemStack.java b/src/main/java/org/shanerx/tradeshop/objects/ShopItemStack.java
index c5d6a904..5341fedb 100644
--- a/src/main/java/org/shanerx/tradeshop/objects/ShopItemStack.java
+++ b/src/main/java/org/shanerx/tradeshop/objects/ShopItemStack.java
@@ -33,6 +33,7 @@
import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;
import org.shanerx.tradeshop.enumys.DebugLevels;
+import org.shanerx.tradeshop.utils.Utils;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
import java.io.ByteArrayInputStream;
@@ -178,7 +179,7 @@ public void setCompareBookPages(boolean compareBookPages) {
}
public boolean isSimilar(ItemStack toCompare) {
- debugger = new Debug();
+ debugger = new Utils().debugger;
// Return False if either item is null
if (itemStack == null || toCompare == null) {
diff --git a/src/main/java/org/shanerx/tradeshop/objects/ShopLocation.java b/src/main/java/org/shanerx/tradeshop/objects/ShopLocation.java
index bfcb74b3..c501dd2e 100644
--- a/src/main/java/org/shanerx/tradeshop/objects/ShopLocation.java
+++ b/src/main/java/org/shanerx/tradeshop/objects/ShopLocation.java
@@ -33,7 +33,7 @@
public class ShopLocation implements Serializable {
- final private String div = "_";
+ final private String div = "::";
private transient World world;
private String worldName;
private double x, y, z;
@@ -56,8 +56,10 @@ public ShopLocation(Location loc) {
public static ShopLocation deserialize(String loc) {
if (loc.startsWith("l")) {
- String[] locA = loc.split("_"); //Keep same as div
- World world = Bukkit.getWorld(locA[1].replace("-", "_"));
+ String[] locA = loc.contains("::") ? loc.split("::") : loc.split("_"); //Keep same as div
+ World world = Bukkit.getWorld(locA[1]);
+ if (world == null)
+ world = Bukkit.getWorld(locA[1].replace("-", "_"));
double x = Double.parseDouble(locA[2]), y = Double.parseDouble(locA[3]), z = Double.parseDouble(locA[4]);
return new ShopLocation(world, x, y, z);
@@ -67,7 +69,7 @@ public static ShopLocation deserialize(String loc) {
}
public String serialize() {
- return "l" + div + world.getName().replace("_", "-") + div + x + div + y + div + z;
+ return "l" + div + world.getName() + div + x + div + y + div + z;
}
public World getWorld() {
diff --git a/src/main/java/org/shanerx/tradeshop/utils/JsonConfiguration.java b/src/main/java/org/shanerx/tradeshop/utils/JsonConfiguration.java
index 8663f37e..afefe2b8 100644
--- a/src/main/java/org/shanerx/tradeshop/utils/JsonConfiguration.java
+++ b/src/main/java/org/shanerx/tradeshop/utils/JsonConfiguration.java
@@ -26,6 +26,7 @@
package org.shanerx.tradeshop.utils;
import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import org.bukkit.Chunk;
@@ -39,13 +40,13 @@
import java.util.*;
public class JsonConfiguration extends Utils implements Serializable {
- private String pluginFolder;
- private String path;
+ private final String pluginFolder;
+ private final String path;
private File file;
- private File filePath;
+ private final File filePath;
private JsonObject jsonObj;
- private int configType;
- private Gson gson;
+ private final int configType;
+ private final Gson gson;
public JsonConfiguration(Chunk c) {
gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create();
@@ -57,14 +58,28 @@ public JsonConfiguration(Chunk c) {
this.filePath = new File(path);
this.filePath.mkdirs();
if (!this.file.exists()) {
+ // If could not find file try with old separators
+ if (new File(path + File.separator + chunk.serialize().replace(";;", "_") + ".json").exists())
+ this.file = new File(path + File.separator + chunk.serialize().replace(";;", "_") + ".json");
+
try {
- this.file.createNewFile();
+ new File(path + File.separator + chunk.serialize() + ".json").createNewFile();
} catch (Exception exception) {
throw new RuntimeException(exception);
}
}
loadContents();
+ if (!file.getName().contains(chunk.serialize())) {
+ this.file = new File(path + File.separator + chunk.serialize() + ".json");
+ saveContents(gson.toJson(jsonObj));
+
+ try {
+ new File(path + File.separator + chunk.serialize().replace(";;", "_") + ".json").delete();
+ } catch (SecurityException | NullPointerException ignored) {
+
+ }
+ }
}
public JsonConfiguration(UUID uuid) {
@@ -94,6 +109,16 @@ private void loadContents() {
} catch (IllegalStateException e) {
jsonObj = new JsonObject();
}
+
+ if (configType == 0) {
+ for (Map.Entry entry : Sets.newHashSet(jsonObj.entrySet())) {
+ if (entry.getKey().contains("l_")) {
+ jsonObj.add(ShopLocation.deserialize(entry.getKey()).serialize(), entry.getValue());
+ jsonObj.remove(entry.getKey());
+ }
+ }
+ }
+
}
private void saveContents(String str) {
diff --git a/src/main/java/org/shanerx/tradeshop/utils/Utils.java b/src/main/java/org/shanerx/tradeshop/utils/Utils.java
index c385b3ec..d12f5506 100644
--- a/src/main/java/org/shanerx/tradeshop/utils/Utils.java
+++ b/src/main/java/org/shanerx/tradeshop/utils/Utils.java
@@ -485,16 +485,18 @@ public ArrayList getItems(Inventory inventory, List it
totalCount += item.getItemStack().getAmount() * multiplier;
if (item.getItemStack().getType().name().endsWith("SHULKER_BOX")) {
for (ItemStack itm : clone.getStorageContents()) {
- if (!itm.getType().name().endsWith("SHULKER_BOX"))
- break;
-
- if (compareShulkers(itm, item.getItemStack())) {
- clone.removeItem(itm);
- ret.add(itm);
- currentCount++;
- break;
- }
- }
+ if (itm != null && itm.getType().name().endsWith("SHULKER_BOX")) {
+ StringBuilder contents = new StringBuilder();
+ Arrays.stream(clone.getContents()).forEach(a -> contents.append(a != null ? a.getType().toString() : "Empty").append("|"));
+
+ debugger.log("ShopTradeListener > clone Contents: " + contents.toString(), DebugLevels.TRADE);
+ if (compareShulkers(itm, item.getItemStack())) {
+ clone.removeItem(itm);
+ ret.add(itm);
+ currentCount++;
+ }
+ }
+ }
} else {
int count = item.getItemStack().getAmount() * multiplier, traded;