From 1439ff4875ecdee3c1a146f9b535b7dcbac5af17 Mon Sep 17 00:00:00 2001 From: Coppertine <37494321+Coppertine@users.noreply.github.com> Date: Sun, 5 Sep 2021 21:56:10 +1000 Subject: [PATCH] Fix player check with database Fixes #40 --- .../plotsystem/core/EventListener.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/alpsbte/plotsystem/core/EventListener.java b/src/main/java/com/alpsbte/plotsystem/core/EventListener.java index f9db9fc4..09f88dcb 100644 --- a/src/main/java/com/alpsbte/plotsystem/core/EventListener.java +++ b/src/main/java/com/alpsbte/plotsystem/core/EventListener.java @@ -84,15 +84,19 @@ public void onPlayerJoinEvent(PlayerJoinEvent event) { } } - if(!event.getPlayer().hasPlayedBefore()) { - try { - DatabaseConnection.createStatement("INSERT INTO plotsystem_builders (uuid, name) VALUES (?, ?)") - .setValue(event.getPlayer().getUniqueId().toString()) - .setValue(event.getPlayer().getName()) - .executeUpdate(); - } catch (SQLException ex) { - Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex); + // Check if player even exists in database. + try { + if(!DatabaseConnection.createStatement("SELECT * FROM plotsystem_builders WHERE uuid = ?") + .setValue(event.getPlayer().getUniqueId()).executeQuery().first()) { + + DatabaseConnection.createStatement("INSERT INTO plotsystem_builders (uuid, name) VALUES (?, ?)") + .setValue(event.getPlayer().getUniqueId().toString()) + .setValue(event.getPlayer().getName()) + .executeUpdate(); + } + } catch (SQLException ex) { + Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex); } // Inform player about update