diff --git a/uwp-utils/commands/DatabaseConnection.java b/uwp-utils/commands/DatabaseConnection.java new file mode 100644 index 0000000..14bd045 --- /dev/null +++ b/uwp-utils/commands/DatabaseConnection.java @@ -0,0 +1,33 @@ +package me.arcodeskel.uwpmcutils.commands; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; + +import java.sql.Connection; +import java.sql.SQLException; + + + public class DatabaseConnection { + private static final HikariDataSource dataSource; + + static { + HikariConfig config = new HikariConfig(); + config.setJdbcUrl("jdbc:sqlite:data.db"); // Your SQLite database path + config.setUsername(""); // Not needed for SQLite + config.setPassword(""); // Not needed for SQLite + config.setMaximumPoolSize(10); // Adjust as needed + config.setConnectionTestQuery("SELECT 1"); // Test query + + dataSource = new HikariDataSource(config); + } + + public static Connection getConnection() throws SQLException { + return dataSource.getConnection(); + } + + public static void close() { + if (dataSource != null) { + dataSource.close(); + } + } + } + diff --git a/uwp-utils/commands/Help.java b/uwp-utils/commands/Help.java new file mode 100644 index 0000000..c1c4f78 --- /dev/null +++ b/uwp-utils/commands/Help.java @@ -0,0 +1,37 @@ +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; + +public class Help implements Listener, CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String s, String[] strings) { + + if (sender instanceof Player) { + Player p = (Player) sender; + p.sendMessage(""" + + Commands: + - /spawn (go to spawn) + - /rtp (random teleport) + - /sethome (set a home) + - /home (teleport home) + - /claimlist (see list of claims) + - /abandonallclaims (unclaim everything) + - /abandonclaim (abandon a specific claim you're standing in) + - /trust [name] (grant a player access to your claim) + - /untrust [name] (revoke a player access to your claim) + - /trade (trade with a player) + + + """); + } + + + return true; + } +} diff --git a/uwp-utils/commands/Maps.java b/uwp-utils/commands/Maps.java new file mode 100644 index 0000000..3b24625 --- /dev/null +++ b/uwp-utils/commands/Maps.java @@ -0,0 +1,14 @@ +package me.arcodeskel.uwpmcutils.commands; + +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.*; + +public interface Maps { + public final Set frozenPlayers = new HashSet<>(); + public final Map originalVelocity = new HashMap<>(); + public final Map sneakingPlayers = new HashMap<>(); + public final Set activeCommands = new HashSet<>(); + public final Set enteringEndPortal = new HashSet<>(); +} diff --git a/uwp-utils/commands/SetSpawn.java b/uwp-utils/commands/SetSpawn.java new file mode 100644 index 0000000..4ca5347 --- /dev/null +++ b/uwp-utils/commands/SetSpawn.java @@ -0,0 +1,63 @@ +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; + } +} diff --git a/uwp-utils/commands/tpbuild.java b/uwp-utils/commands/tpbuild.java new file mode 100644 index 0000000..b52bcec --- /dev/null +++ b/uwp-utils/commands/tpbuild.java @@ -0,0 +1,101 @@ +package me.arcodeskel.uwpmcutils.commands; + +import me.arcodeskel.uwpmcutils.Main; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +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 org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.util.Vector; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.Objects; + +public class tpbuild implements Listener, CommandExecutor, Maps { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player p = (Player) sender; + activeCommands.add(p.getPlayer()); + p.setWalkSpeed(0); + frozenPlayers.add(p.getPlayer()); + originalVelocity.put(p.getPlayer(), p.getVelocity().length()); + p.setVelocity(new Vector(0, -1.0, 0)); + String statement = "SELECT rank FROM rank WHERE username='" + p.getName() + "'"; + try (Connection connection = DatabaseConnection.getConnection()) { + PreparedStatement preparedStatement = connection.prepareStatement(statement); + if (!preparedStatement.executeQuery().getString("rank").contains("builder")) { + p.sendMessage("You do not have permission to execute this command."); + activeCommands.remove(p.getPlayer()); + frozenPlayers.remove(p.getPlayer()); + double velocity = originalVelocity.get(p.getPlayer()); + p.getPlayer().setVelocity(p.getPlayer().getLocation().getDirection().multiply(velocity)); + originalVelocity.remove(p.getPlayer()); + p.setWalkSpeed(0.2F); + } + preparedStatement.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + + if (activeCommands.contains(p.getPlayer())) { + p.sendMessage(ChatColor.YELLOW + "Warping to builder in 10 seconds... Sneak to cancel teleportation request (shift)"); + } + + + new BukkitRunnable() { + @Override + public void run() { + + if (Objects.requireNonNull(p.getPlayer()).isSneaking() && !activeCommands.contains(p.getPlayer())) { + cancel(); + } + // Check if the player is sneaking + if (Objects.requireNonNull(p.getPlayer()).isSneaking() && activeCommands.contains(p.getPlayer())) { + p.getPlayer().sendMessage(ChatColor.RED + "Command execution canceled because you are sneaking!"); + double velocity = originalVelocity.get(p.getPlayer()); + p.getPlayer().setVelocity(p.getPlayer().getLocation().getDirection().multiply(velocity)); + frozenPlayers.remove(p.getPlayer()); + originalVelocity.remove(p.getPlayer()); + sneakingPlayers.remove(p.getPlayer()); + p.getPlayer().setWalkSpeed(0.2F); + activeCommands.remove(p.getPlayer()); // Clean up + cancel(); // Stop the runnable + } + } + }.runTaskTimer(JavaPlugin.getPlugin(Main.class), 0, 1); // Check every tick + + new BukkitRunnable() { + @Override + public void run() { + + if (!activeCommands.contains(p.getPlayer())) { + cancel(); + return; + } + + Location location = new Location(Bukkit.getWorld("builder"), 0, -60, 0); + p.teleport(location); + p.sendMessage(ChatColor.GREEN + "Sent to builder"); + p.setWalkSpeed(0.2F); + double velocity = originalVelocity.get(p.getPlayer()); + p.getPlayer().setVelocity(p.getPlayer().getLocation().getDirection().multiply(velocity)); + p.setWalkSpeed(0.2F); + frozenPlayers.remove(p.getPlayer()); + originalVelocity.remove(p.getPlayer()); + activeCommands.remove(p.getPlayer()); + } + }.runTaskLater(JavaPlugin.getPlugin(Main.class), 200); + + } + return true; + } +}