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 {
|
||||
|
||||
Location location = player.getLocation();
|
||||
String playerUUID = player.getUniqueId().toString();
|
||||
|
||||
String checkQuery = "SELECT * FROM coords WHERE uuid = ? and coordname = ?";
|
||||
PreparedStatement checkPstmt = connection.prepareStatement(checkQuery);
|
||||
checkPstmt.setString(1, playerUUID);
|
||||
@@ -81,14 +83,32 @@ public class CoordSave extends JavaPlugin {
|
||||
// Executing the query
|
||||
pstmt.executeUpdate();
|
||||
|
||||
// Building the message component
|
||||
final TextComponent conformationMessage = text()
|
||||
.content("The coordinates for ")
|
||||
.append(text(coordname).color(TextColor.color(BLUE)))
|
||||
.append(text(" where saved!")).build();
|
||||
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();
|
||||
|
||||
// Sending the message component to player
|
||||
player.sendMessage(conformationMessage);
|
||||
if (Objects.equals(validateResult.getString("coordname"), coordname)) {
|
||||
// Building the message component
|
||||
final TextComponent conformationMessage = text()
|
||||
.content("The coordinates for ")
|
||||
.append(text(coordname).color(TextColor.color(BLUE)))
|
||||
.append(text(" where saved!")).build();
|
||||
|
||||
// Sending the message component to player
|
||||
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