Check if coords already exist if player try's to save new
This commit is contained in:
@@ -10,10 +10,13 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
import static net.kyori.adventure.text.Component.text;
|
import static net.kyori.adventure.text.Component.text;
|
||||||
import static net.kyori.adventure.text.format.NamedTextColor.*;
|
import static net.kyori.adventure.text.format.NamedTextColor.*;
|
||||||
@@ -53,7 +56,19 @@ public class CoordSave extends JavaPlugin {
|
|||||||
public void doSaveSubcommand(Player player, String coordname) throws SQLException {
|
public void doSaveSubcommand(Player player, String coordname) throws SQLException {
|
||||||
Location location = player.getLocation();
|
Location location = player.getLocation();
|
||||||
String playerUUID = player.getUniqueId().toString();
|
String playerUUID = player.getUniqueId().toString();
|
||||||
|
String checkQuery = "SELECT * FROM coords WHERE uuid = ? and coordname = ?";
|
||||||
|
PreparedStatement checkPstmt = connection.prepareStatement(checkQuery);
|
||||||
|
checkPstmt.setString(1, playerUUID);
|
||||||
|
checkPstmt.setString(2, coordname);
|
||||||
|
ResultSet checkResult = checkPstmt.executeQuery();
|
||||||
|
|
||||||
|
if (Objects.equals(checkResult.getString("coordname"), coordname)) {
|
||||||
|
TextComponent alreadyExistMessage = text()
|
||||||
|
.content("A entry with the name ")
|
||||||
|
.append(text(coordname)).color(TextColor.color(RED))
|
||||||
|
.append(text("already exists.")).build();
|
||||||
|
player.sendMessage(alreadyExistMessage);
|
||||||
|
} else {
|
||||||
// Preparing the query string
|
// Preparing the query string
|
||||||
String query = "INSERT INTO coords (uuid, coordname, X, Y, Z) VALUES(?, ?, ?, ?, ?)";
|
String query = "INSERT INTO coords (uuid, coordname, X, Y, Z) VALUES(?, ?, ?, ?, ?)";
|
||||||
PreparedStatement pstmt = connection.prepareStatement(query);
|
PreparedStatement pstmt = connection.prepareStatement(query);
|
||||||
@@ -75,6 +90,7 @@ public class CoordSave extends JavaPlugin {
|
|||||||
// Sending the message component to player
|
// Sending the message component to player
|
||||||
player.sendMessage(conformationMessage);
|
player.sendMessage(conformationMessage);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void doShowSubcommand(Player player, String subarg) throws SQLException {
|
public void doShowSubcommand(Player player, String subarg) throws SQLException {
|
||||||
// Prepare SQL query
|
// Prepare SQL query
|
||||||
|
|||||||
Reference in New Issue
Block a user