Files
RS-Taxi/src/main/java/com/rsscripting/rstaxi/stops/StopManager.java
T
BigPappa 3566555893 Initial Development
- Add Stop Complete
2026-10-11 09:03:11 -05:00

68 lines
1.8 KiB
Java

package com.rsscripting.rstaxi.stops;
import com.rsscripting.rstaxi.RSTaxi;
import org.bukkit.Location;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public final class StopManager {
private final RSTaxi plugin;
public StopManager(RSTaxi plugin) {
this.plugin = plugin;
}
public boolean exists(String name) throws SQLException {
String sql = "SELECT 1 FROM stops WHERE name = ?";
try (PreparedStatement statement = connection()
.prepareStatement(sql)) {
statement.setString(1, name);
try (ResultSet results = statement.executeQuery()) {
return results.next();
}
}
}
public boolean add(
String name,
String icon,
Location location
) throws SQLException {
String sql = """
INSERT OR IGNORE INTO stops
(name, icon, world, x, y, z, yaw, pitch)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""";
try (PreparedStatement statement = connection()
.prepareStatement(sql)) {
statement.setString(1, name);
statement.setString(2, icon);
statement.setString(
3, location.getWorld().getName()
);
statement.setDouble(4, location.getX());
statement.setDouble(5, location.getY());
statement.setDouble(6, location.getZ());
statement.setFloat(7, location.getYaw());
statement.setFloat(8, location.getPitch());
return statement.executeUpdate() == 1;
}
}
private Connection connection() {
return plugin.getDatabaseManager().getConnection();
}
}