From 7b748b47d298419d2e73307dc5c8d9e320459281 Mon Sep 17 00:00:00 2001 From: Brian Ronald Date: Tue, 11 Sep 2018 20:25:31 +0100 Subject: [PATCH] Better insertion for new players --- src/main/java/net/simplycrafted/StickyLocks/Database.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/simplycrafted/StickyLocks/Database.java b/src/main/java/net/simplycrafted/StickyLocks/Database.java index 931c1c6..9b4e73a 100644 --- a/src/main/java/net/simplycrafted/StickyLocks/Database.java +++ b/src/main/java/net/simplycrafted/StickyLocks/Database.java @@ -294,7 +294,7 @@ public void addPlayer(Player player) { try { // The sub-select is used to preserve the notification setting. If // nothing is returned, the default is used. - psql = db_conn.prepareStatement("REPLACE INTO player (uuid,name,notify,automatic) SELECT ?,?,notify,automatic FROM player WHERE uuid=?))"); + psql = db_conn.prepareStatement("INSERT INTO player (uuid,name) SELECT ?,? WHERE NOT EXISTS (SELECT 1 FROM player WHERE uuid=?)"); psql.setString(1, player.getUniqueId().toString()); psql.setString(2, player.getName()); psql.setString(3, player.getUniqueId().toString()); @@ -312,7 +312,7 @@ public void addPlayer(OfflinePlayer offlinePlayer) { try { // The sub-select is used to preserve the notification setting. If // nothing is returned, the default is used. - psql = db_conn.prepareStatement("REPLACE INTO player (uuid,name,notify,automatic) SELECT ?,?,notify,automatic FROM player WHERE uuid=?))"); + psql = db_conn.prepareStatement("INSERT INTO player (uuid,name) SELECT ?,? WHERE NOT EXISTS (SELECT 1 FROM player WHERE uuid=?)"); psql.setString(1, offlinePlayer.getUniqueId().toString()); psql.setString(2, offlinePlayer.getName()); psql.setString(3, offlinePlayer.getUniqueId().toString());