Skip to content

Commit

Permalink
Fix player check with database
Browse files Browse the repository at this point in the history
Fixes #40
  • Loading branch information
Coppertine authored Sep 5, 2021
1 parent 9d95db5 commit 1439ff4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/main/java/com/alpsbte/plotsystem/core/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1439ff4

Please sign in to comment.