64 lines
2.4 KiB
Java
64 lines
2.4 KiB
Java
package me.arcodeskel.uwpmcutils.commands;
|
|
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.Listener;
|
|
|
|
import java.sql.*;
|
|
|
|
|
|
public class SetSpawn implements Listener, CommandExecutor {
|
|
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender sender, Command cmd, String s, String[] strings) {
|
|
|
|
if (sender instanceof Player) {
|
|
Player p = (Player) sender;
|
|
double x = p.getLocation().getX();
|
|
double y = p.getLocation().getY();
|
|
double z = p.getLocation().getZ();
|
|
float pitch = p.getLocation().getPitch();
|
|
float yaw = p.getLocation().getYaw();
|
|
|
|
try (Connection connection = DatabaseConnection.getConnection()) {
|
|
// Delete existing spawn records
|
|
String deleteSpawn = "DELETE FROM spawn";
|
|
try (PreparedStatement psDelete = connection.prepareStatement(deleteSpawn)) {
|
|
psDelete.executeUpdate();
|
|
}
|
|
|
|
// Insert new spawn values
|
|
String insertSpawn = "INSERT INTO spawn (x, y, z) VALUES (?, ?, ?)";
|
|
try (PreparedStatement psInsert = connection.prepareStatement(insertSpawn)) {
|
|
psInsert.setDouble(1, 0); // Replace 0 with appropriate x value if needed
|
|
psInsert.setDouble(2, 0); // Replace 0 with appropriate y value if needed
|
|
psInsert.setDouble(3, 0); // Replace 0 with appropriate z value if needed
|
|
psInsert.executeUpdate();
|
|
}
|
|
|
|
// Update spawn coordinates and rotation
|
|
String updateSpawn = "UPDATE spawn SET x = ?, y = ?, z = ?, pitch = ?, yaw = ?";
|
|
try (PreparedStatement psUpdate = connection.prepareStatement(updateSpawn)) {
|
|
psUpdate.setDouble(1, x);
|
|
psUpdate.setDouble(2, y);
|
|
psUpdate.setDouble(3, z);
|
|
psUpdate.setFloat(4, pitch);
|
|
psUpdate.setFloat(5, yaw);
|
|
psUpdate.executeUpdate();
|
|
}
|
|
} catch (SQLException e) {
|
|
e.printStackTrace(); // Handle exception
|
|
}
|
|
|
|
p.sendMessage("Spawn updated to your position.");
|
|
|
|
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|