diff --git a/src/main/java/party/cybsec/oyeshops/database/ShopRepository.java b/src/main/java/party/cybsec/oyeshops/database/ShopRepository.java index 29ab6ec..bd2bbff 100644 --- a/src/main/java/party/cybsec/oyeshops/database/ShopRepository.java +++ b/src/main/java/party/cybsec/oyeshops/database/ShopRepository.java @@ -178,6 +178,21 @@ public class ShopRepository { } } + /** + * delete shop by location (world, x, y, z) + */ + public void deleteShopByLocation(Location loc) throws SQLException { + String sql = "delete from shops where world_uuid = ? and sign_x = ? and sign_y = ? and sign_z = ?"; + + try (PreparedStatement stmt = dbManager.getConnection().prepareStatement(sql)) { + stmt.setString(1, loc.getWorld().getUID().toString()); + stmt.setInt(2, loc.getBlockX()); + stmt.setInt(3, loc.getBlockY()); + stmt.setInt(4, loc.getBlockZ()); + stmt.executeUpdate(); + } + } + /** * get all shops owned by player */ diff --git a/src/main/java/party/cybsec/oyeshops/gui/SetupDialog.java b/src/main/java/party/cybsec/oyeshops/gui/SetupDialog.java index ac2203d..ddb1504 100644 --- a/src/main/java/party/cybsec/oyeshops/gui/SetupDialog.java +++ b/src/main/java/party/cybsec/oyeshops/gui/SetupDialog.java @@ -30,7 +30,7 @@ public class SetupDialog { .inputs(List.of( // product (selling) DialogInput.text("product_item", - Component.text("what are you selling? (e.g. diamond)", + Component.text("what are you selling? (e.g. oak log)", NamedTextColor.YELLOW)) .build(), DialogInput.text("product_qty", @@ -41,7 +41,7 @@ public class SetupDialog { // price (buying) DialogInput.text("price_item", - Component.text("what do you want? (e.g. gold ingot)", + Component.text("what do you want? (e.g. diamond)", NamedTextColor.GREEN)) .build(), DialogInput.text("price_qty", diff --git a/src/main/java/party/cybsec/oyeshops/listener/ShopActivationListener.java b/src/main/java/party/cybsec/oyeshops/listener/ShopActivationListener.java index c8795e0..f2c55c8 100644 --- a/src/main/java/party/cybsec/oyeshops/listener/ShopActivationListener.java +++ b/src/main/java/party/cybsec/oyeshops/listener/ShopActivationListener.java @@ -198,6 +198,9 @@ public class ShopActivationListener implements Listener { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> { try { + // cleanup potential existing shop to avoid unique constraint error + plugin.getShopRepository().deleteShopByLocation(signLocation); + int shopId = plugin.getShopRepository().createShop(shop); plugin.getServer().getScheduler().runTask(plugin, () -> { // re-verify sign on main thread