Initial Development

- /cab list complete.
This commit is contained in:
BigPappa committed 2026-10-11 09:39:10 -05:00
1 parent 3566555893
commit c31ec9b8a8
8 files changed
+119 -29

No files matched your search

@@ -159,12 +159,18 @@ public final class CabCommand implements CommandExecutor {
}
} catch (SQLException | IllegalArgumentException e) {
plugin.getLogger().severe(
"Failed to create taxi stop: " + e.getMessage()
);
sender.sendMessage(plugin.getLanguageManager()
.getMessage("stop.creation-error"));
}
plugin.getLogger().log(
java.util.logging.Level.SEVERE,
"Failed to create taxi stop.",
e
);
sender.sendMessage(
plugin.getLanguageManager()
.getMessage("stop.creation-error")
);
}
return true;
}
@@ -191,10 +197,64 @@ public final class CabCommand implements CommandExecutor {
return checkPermission(sender, "rs-cab.delete");
}
private boolean handleList(CommandSender sender) {
return checkPermission(sender, "rs-cab.use");
if (!sender.hasPermission("rs-cab.use")) {
sender.sendMessage(
plugin.getLanguageManager()
.getMessage("general.no-permission")
);
return true;
}
try {
var stops = stopManager.getAllStops();
if (stops.isEmpty()) {
sender.sendMessage(
plugin.getLanguageManager()
.getMessage("general.no-stops")
);
return true;
}
sender.sendMessage(
plugin.getLanguageManager()
.getMessage("list.header")
);
for (StopManager.StopEntry stop : stops) {
sender.sendMessage(
plugin.getLanguageManager()
.getMessage(
"list.entry",
Map.of(
"icon", stop.icon(),
"stop", stop.name()
)
)
);
}
} catch (SQLException e) {
plugin.getLogger().log(
java.util.logging.Level.SEVERE,
"Failed to retrieve taxi destinations.",
e
);
sender.sendMessage(
plugin.getLanguageManager()
.getMessage("list.error")
);
}
return true;
}
private boolean checkPermission(
CommandSender sender,
String permission
@@ -8,6 +8,8 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public final class StopManager {
@@ -17,6 +19,9 @@ public final class StopManager {
this.plugin = plugin;
}
public record StopEntry(String name, String icon) {
}
public boolean exists(String name) throws SQLException {
String sql = "SELECT 1 FROM stops WHERE name = ?";
@@ -61,6 +66,30 @@ public final class StopManager {
}
}
public List<StopEntry> getAllStops() throws SQLException {
String sql = """
SELECT name, icon
FROM stops
ORDER BY name COLLATE NOCASE
""";
List<StopEntry> stops = new ArrayList<>();
try (PreparedStatement statement = connection()
.prepareStatement(sql);
ResultSet results = statement.executeQuery()) {
while (results.next()) {
stops.add(new StopEntry(
results.getString("name"),
results.getString("icon")
));
}
}
return stops;
}
private Connection connection() {
return plugin.getDatabaseManager().getConnection();
}