Compare commits
7 Commits
master
...
More-valid
| Author | SHA1 | Date | |
|---|---|---|---|
| a0acee4950 | |||
| 2016add473 | |||
| da16d37574 | |||
| a63a2d2999 | |||
| 9441cff71d | |||
| 434918a178 | |||
| 8b481340b1 |
@@ -1,9 +1,10 @@
|
||||
plugins {
|
||||
id("java")
|
||||
id("io.papermc.paperweight.userdev") version "1.5.10" // Check for new versions at https://plugins.gradle.org/plugin/io.papermc.paperweight.userdev
|
||||
}
|
||||
|
||||
group = "dev.protron"
|
||||
version = "0.0.4"
|
||||
version = "0.0.5"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -14,6 +15,7 @@ dependencies {
|
||||
testImplementation(platform("org.junit:junit-bom:5.9.1"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
|
||||
paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT")
|
||||
implementation("org.xerial:sqlite-jdbc:3.42.0.0")
|
||||
}
|
||||
|
||||
|
||||
166
src/main/java/dev/protron/coordsave/Commands.java
Normal file
166
src/main/java/dev/protron/coordsave/Commands.java
Normal file
@@ -0,0 +1,166 @@
|
||||
package dev.protron.coordsave;
|
||||
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.*;
|
||||
import static net.kyori.adventure.text.format.TextColor.color;
|
||||
|
||||
public class Commands {
|
||||
public static void doSaveSubcommand(Player player, String coordname, Connection connection) 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);
|
||||
checkPstmt.setString(2, coordname);
|
||||
ResultSet checkResult = checkPstmt.executeQuery();
|
||||
|
||||
if (checkResult.getString("coordname") != null) {
|
||||
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
|
||||
String query = "INSERT INTO coords (uuid, coordname, X, Y, Z) VALUES(?, ?, ?, ?, ?)";
|
||||
PreparedStatement pstmt = connection.prepareStatement(query);
|
||||
pstmt.setString(1, playerUUID);
|
||||
pstmt.setString(2, coordname);
|
||||
pstmt.setFloat(3, location.getBlockX());
|
||||
pstmt.setFloat(4, location.getBlockY());
|
||||
pstmt.setFloat(5, location.getBlockZ());
|
||||
|
||||
// Executing the query
|
||||
pstmt.executeUpdate();
|
||||
|
||||
String validateQuery = "SELECT * FROM coords WHERE uuid = ? AND coordname = ?";
|
||||
PreparedStatement validatePstmt = connection.prepareStatement(validateQuery);
|
||||
validatePstmt.setString(1, playerUUID);
|
||||
validatePstmt.setString(2, coordname);
|
||||
ResultSet validateResult = validatePstmt.executeQuery();
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void doShowSubcommand(Player player, String subarg, Connection connection) throws SQLException {
|
||||
// Prepare SQL query
|
||||
String query = "SELECT X, Y, Z FROM coords WHERE coordname = ? AND uuid = ?";
|
||||
PreparedStatement pstmt = connection.prepareStatement(query);
|
||||
pstmt.setString(1, subarg);
|
||||
pstmt.setString(2, player.getUniqueId().toString());
|
||||
|
||||
// Execute SQL query
|
||||
ResultSet result = pstmt.executeQuery();
|
||||
|
||||
// Check if query returned something
|
||||
if (result.getString("X") == null){
|
||||
// Building error message
|
||||
final TextComponent errorMessage = text()
|
||||
.content("No entry with that name").color(color(RED))
|
||||
.build();
|
||||
//Sending error message
|
||||
player.sendMessage(errorMessage);
|
||||
}else {
|
||||
// Building return message
|
||||
final TextComponent returnMessage = text()
|
||||
.content("The coordinates for ")
|
||||
.append(text(subarg))
|
||||
.append(text(" are "))
|
||||
.append(text(" X: " + result.getString("X")).color(color(LIGHT_PURPLE)))
|
||||
.append(text(" Y: " + result.getString("Y")).color(color(LIGHT_PURPLE)))
|
||||
.append(text(" Z: " + result.getString("Z")).color(color(LIGHT_PURPLE)))
|
||||
.build();
|
||||
//sending return message to player
|
||||
player.sendMessage(returnMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void doListSubcommand(Player player, Connection connection) throws SQLException {
|
||||
String query = "SELECT * FROM coords WHERE uuid = ?";
|
||||
PreparedStatement pstmt = connection.prepareStatement(query);
|
||||
pstmt.setString(1, player.getUniqueId().toString());
|
||||
ResultSet results= pstmt.executeQuery();
|
||||
if (results.getString("coordname") == null){
|
||||
final TextComponent errorMessage = text()
|
||||
.content("No entry's").color(color(RED))
|
||||
.build();
|
||||
player.sendMessage(errorMessage);
|
||||
}else {
|
||||
while (results.next()){
|
||||
// Building return message
|
||||
final TextComponent returnMessage = text()
|
||||
.content(results.getString("coordname")).color(color(BLUE))
|
||||
.build();
|
||||
//sending return message to player
|
||||
player.sendMessage(returnMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void doRemoveSubcommand(Player player, String arg, Connection connection) throws SQLException {
|
||||
String query = "SELECT X FROM coords WHERE uuid = ? AND coordname = ?";
|
||||
PreparedStatement pstmt = connection.prepareStatement(query);
|
||||
pstmt.setString(1, player.getUniqueId().toString());
|
||||
pstmt.setString(2, arg);
|
||||
ResultSet result = pstmt.executeQuery();
|
||||
if (result.getString("X") == null){
|
||||
//Building error message
|
||||
final TextComponent errorMessage = text()
|
||||
.content("No entry with the name ").color(color(RED))
|
||||
.append(text(arg).color(color(RED)))
|
||||
.append(text(" exists").color(color(RED)))
|
||||
.build();
|
||||
|
||||
//Sending the text component
|
||||
player.sendMessage(errorMessage);
|
||||
}else {
|
||||
String deleteQuery = "DELETE FROM coords WHERE uuid = ? AND coordname = ?";
|
||||
PreparedStatement pstmtEX = connection.prepareStatement(deleteQuery);
|
||||
pstmtEX.setString(1, player.getUniqueId().toString());
|
||||
pstmtEX.setString(2, arg);
|
||||
pstmtEX.executeUpdate();
|
||||
|
||||
final TextComponent returnMessage = text()
|
||||
.content("The entry ")
|
||||
.append(text(arg).color(color(BLUE)))
|
||||
.append(text(" was deleted!"))
|
||||
.build();
|
||||
|
||||
//Sending return message
|
||||
player.sendMessage(returnMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package dev.protron.coordsave;
|
||||
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -10,11 +8,13 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.*;
|
||||
import static net.kyori.adventure.text.format.TextColor.color;
|
||||
@@ -50,120 +50,7 @@ public class CoordSave extends JavaPlugin {
|
||||
getLogger().info("CoordSave has been enabled");
|
||||
}
|
||||
|
||||
public void doSaveSubcommand(Player player, String coordname) throws SQLException {
|
||||
Location location = player.getLocation();
|
||||
String playerUUID = player.getUniqueId().toString();
|
||||
|
||||
// Preparing the query string
|
||||
String query = "INSERT INTO coords (uuid, coordname, X, Y, Z) VALUES(?, ?, ?, ?, ?)";
|
||||
PreparedStatement pstmt = connection.prepareStatement(query);
|
||||
pstmt.setString(1, playerUUID);
|
||||
pstmt.setString(2, coordname);
|
||||
pstmt.setFloat(3, location.getBlockX());
|
||||
pstmt.setFloat(4, location.getBlockY());
|
||||
pstmt.setFloat(5, location.getBlockZ());
|
||||
|
||||
// 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();
|
||||
|
||||
// Sending the message component to player
|
||||
player.sendMessage(conformationMessage);
|
||||
}
|
||||
|
||||
public void doShowSubcommand(Player player, String subarg) throws SQLException {
|
||||
// Prepare SQL query
|
||||
String query = "SELECT X, Y, Z FROM coords WHERE coordname = ? AND uuid = ?";
|
||||
PreparedStatement pstmt = connection.prepareStatement(query);
|
||||
pstmt.setString(1, subarg);
|
||||
pstmt.setString(2, player.getUniqueId().toString());
|
||||
|
||||
// Execute SQL query
|
||||
ResultSet result = pstmt.executeQuery();
|
||||
|
||||
// Check if query returned something
|
||||
if (result.getString("X") == null){
|
||||
// Building error message
|
||||
final TextComponent errorMessage = text()
|
||||
.content("No entry with that name").color(color(RED))
|
||||
.build();
|
||||
//Sending error message
|
||||
player.sendMessage(errorMessage);
|
||||
}else {
|
||||
// Building return message
|
||||
final TextComponent returnMessage = text()
|
||||
.content("The coordinates for ")
|
||||
.append(text(subarg))
|
||||
.append(text(" are "))
|
||||
.append(text(" X: " + result.getString("X")).color(color(LIGHT_PURPLE)))
|
||||
.append(text(" Y: " + result.getString("Y")).color(color(LIGHT_PURPLE)))
|
||||
.append(text(" Z: " + result.getString("Z")).color(color(LIGHT_PURPLE)))
|
||||
.build();
|
||||
//sending return message to player
|
||||
player.sendMessage(returnMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public void doListSubcommand(Player player) throws SQLException {
|
||||
String query = "SELECT * FROM coords WHERE uuid = ?";
|
||||
PreparedStatement pstmt = connection.prepareStatement(query);
|
||||
pstmt.setString(1, player.getUniqueId().toString());
|
||||
ResultSet results= pstmt.executeQuery();
|
||||
if (results.getString("coordname") == null){
|
||||
final TextComponent errorMessage = text()
|
||||
.content("No entry's").color(color(RED))
|
||||
.build();
|
||||
player.sendMessage(errorMessage);
|
||||
}else {
|
||||
while (results.next()){
|
||||
// Building return message
|
||||
final TextComponent returnMessage = text()
|
||||
.content(results.getString("coordname")).color(color(BLUE))
|
||||
.build();
|
||||
//sending return message to player
|
||||
player.sendMessage(returnMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doRemoveSubcommand(Player player, String arg) throws SQLException {
|
||||
String query = "SELECT X FROM coords WHERE uuid = ? AND coordname = ?";
|
||||
PreparedStatement pstmt = connection.prepareStatement(query);
|
||||
pstmt.setString(1, player.getUniqueId().toString());
|
||||
pstmt.setString(2, arg);
|
||||
ResultSet result = pstmt.executeQuery();
|
||||
if (result.getString("X") == null){
|
||||
//Building error message
|
||||
final TextComponent errorMessage = text()
|
||||
.content("No entry with the name ").color(color(RED))
|
||||
.append(text(arg).color(color(RED)))
|
||||
.append(text(" exists").color(color(RED)))
|
||||
.build();
|
||||
|
||||
//Sending the text component
|
||||
player.sendMessage(errorMessage);
|
||||
}else {
|
||||
String deleteQuery = "DELETE FROM coords WHERE uuid = ? AND coordname = ?";
|
||||
PreparedStatement pstmtEX = connection.prepareStatement(deleteQuery);
|
||||
pstmtEX.setString(1, player.getUniqueId().toString());
|
||||
pstmtEX.setString(2, arg);
|
||||
pstmtEX.executeUpdate();
|
||||
|
||||
final TextComponent returnMessage = text()
|
||||
.content("The entry ")
|
||||
.append(text(arg).color(color(BLUE)))
|
||||
.append(text(" was deleted!"))
|
||||
.build();
|
||||
|
||||
//Sending return message
|
||||
player.sendMessage(returnMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, Command cmd, @NotNull String label, String[] args){
|
||||
@@ -176,12 +63,11 @@ public class CoordSave extends JavaPlugin {
|
||||
final TextComponent errorMessage = text()
|
||||
.content("No name provided").color(color(RED))
|
||||
.build();
|
||||
|
||||
player.sendMessage(errorMessage);
|
||||
yield false;
|
||||
}
|
||||
try {
|
||||
doSaveSubcommand(player, args[1]);
|
||||
Commands.doSaveSubcommand(player, args[1], connection);
|
||||
} catch (SQLException e) {
|
||||
getLogger().warning(e.getMessage());
|
||||
}
|
||||
@@ -197,7 +83,7 @@ public class CoordSave extends JavaPlugin {
|
||||
yield false;
|
||||
}
|
||||
try {
|
||||
doShowSubcommand(player, args[1]);
|
||||
Commands.doShowSubcommand(player, args[1], connection);
|
||||
} catch (SQLException e) {
|
||||
getLogger().warning(e.getMessage());
|
||||
}
|
||||
@@ -213,7 +99,7 @@ public class CoordSave extends JavaPlugin {
|
||||
yield false;
|
||||
}
|
||||
try {
|
||||
doListSubcommand(player);
|
||||
Commands.doListSubcommand(player, connection);
|
||||
} catch (SQLException e) {
|
||||
getLogger().warning(e.getMessage());
|
||||
}
|
||||
@@ -229,7 +115,7 @@ public class CoordSave extends JavaPlugin {
|
||||
yield false;
|
||||
}
|
||||
try {
|
||||
doRemoveSubcommand(player, args[1]);
|
||||
Commands.doRemoveSubcommand(player, args[1], connection);
|
||||
} catch (SQLException e) {
|
||||
getLogger().warning(e.getMessage());
|
||||
}
|
||||
@@ -255,6 +141,7 @@ public class CoordSave extends JavaPlugin {
|
||||
return false;
|
||||
}
|
||||
sender.sendMessage("Not a Player");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: CoordSave
|
||||
version: 0.0.4
|
||||
version: 0.0.5-dev
|
||||
main: dev.protron.coordsave.CoordSave
|
||||
description: A plugin to simply save your Coordinates
|
||||
author: Doc
|
||||
|
||||
Reference in New Issue
Block a user