Coordinates saving validation
This commit is contained in:
@@ -54,8 +54,10 @@ 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 = ?";
|
String checkQuery = "SELECT * FROM coords WHERE uuid = ? and coordname = ?";
|
||||||
PreparedStatement checkPstmt = connection.prepareStatement(checkQuery);
|
PreparedStatement checkPstmt = connection.prepareStatement(checkQuery);
|
||||||
checkPstmt.setString(1, playerUUID);
|
checkPstmt.setString(1, playerUUID);
|
||||||
@@ -81,6 +83,13 @@ public class CoordSave extends JavaPlugin {
|
|||||||
// Executing the query
|
// Executing the query
|
||||||
pstmt.executeUpdate();
|
pstmt.executeUpdate();
|
||||||
|
|
||||||
|
String validateQuery = "SELECT * FROM coords WHERE uuid = ? and coordname = ?";
|
||||||
|
PreparedStatement validatePstmt = connection.prepareStatement(validateQuery);
|
||||||
|
checkPstmt.setString(1, playerUUID);
|
||||||
|
checkPstmt.setString(2, coordname);
|
||||||
|
ResultSet validateResult = validatePstmt.executeQuery();
|
||||||
|
|
||||||
|
if (Objects.equals(validateResult.getString("coordname"), coordname)) {
|
||||||
// Building the message component
|
// Building the message component
|
||||||
final TextComponent conformationMessage = text()
|
final TextComponent conformationMessage = text()
|
||||||
.content("The coordinates for ")
|
.content("The coordinates for ")
|
||||||
@@ -89,6 +98,17 @@ public class CoordSave extends JavaPlugin {
|
|||||||
|
|
||||||
// Sending the message component to player
|
// Sending the message component to player
|
||||||
player.sendMessage(conformationMessage);
|
player.sendMessage(conformationMessage);
|
||||||
|
} else {
|
||||||
|
// Building the message component
|
||||||
|
final TextComponent errorSavingMessage = text()
|
||||||
|
.content("Error saving the ").color(TextColor.color(RED))
|
||||||
|
.append(text(coordname).color(TextColor.color(RED)))
|
||||||
|
.append(text(" coordinates!")).color(TextColor.color(RED)).build();
|
||||||
|
|
||||||
|
// Sending the message component to player
|
||||||
|
player.sendMessage(errorSavingMessage);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user