diff --git a/src/main/java/com/rsscripting/rstaxi/commands/CabCommand.java b/src/main/java/com/rsscripting/rstaxi/commands/CabCommand.java index 958b946..eeee74d 100644 --- a/src/main/java/com/rsscripting/rstaxi/commands/CabCommand.java +++ b/src/main/java/com/rsscripting/rstaxi/commands/CabCommand.java @@ -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 diff --git a/src/main/java/com/rsscripting/rstaxi/stops/StopManager.java b/src/main/java/com/rsscripting/rstaxi/stops/StopManager.java index aff4bff..9012c55 100644 --- a/src/main/java/com/rsscripting/rstaxi/stops/StopManager.java +++ b/src/main/java/com/rsscripting/rstaxi/stops/StopManager.java @@ -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 getAllStops() throws SQLException { + String sql = """ + SELECT name, icon + FROM stops + ORDER BY name COLLATE NOCASE + """; + + List 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(); } diff --git a/src/main/resources/language/en_us.yml b/src/main/resources/language/en_us.yml index bc79911..1e52f05 100644 --- a/src/main/resources/language/en_us.yml +++ b/src/main/resources/language/en_us.yml @@ -14,27 +14,27 @@ database: connection-error: "&cCould not connect to the database." stop: - added: "&aStop &e%stop% &ahas been created." - updated: "&aStop &e%stop% &ahas been moved to your current location." - edited: "&aStop &e%stop% &ahas been updated." - deleted: "&aStop &e%stop% &ahas been removed." - already-exists: "&cA stop named &e%stop% &calready exists." + added: "&aDestination &e%stop% &ahas been created." + updated: "&aDestination &e%stop% &ahas been moved to your current location." + edited: "&aDestination &e%stop% &ahas been updated." + deleted: "&aDestination &e%stop% &ahas been removed." + already-exists: "&cA destination named &e%stop% &calready exists." invalid-icon: "&cThe icon &e%icon% &cis invalid." - creation-error: "&cUnable to create the taxi stop. Check the server logs." + creation-error: "&cUnable to create the taxi destination. Check the server logs." teleport: success: "&aYou have arrived at &e%stop%&a." confirmation: - update: "&eAre you sure you want to move stop &6%stop%&e? Confirm the command to proceed." - delete: "&eAre you sure you want to delete stop &6%stop%&e? Confirm the command to proceed." + update: "&eAre you sure you want to move destination &6%stop%&e? Confirm the command to proceed." + delete: "&eAre you sure you want to delete destination &6%stop%&e? Confirm the command to proceed." expired: "&cThat confirmation has expired." list: - header: "&6Available Taxi Stops:" + header: "&6Available Taxi Destinations:" entry: "&e%icon% &f%stop%" + error: "&cUnable to retrieve taxi destinations. Check the server logs." platform: - invalid: "&cYou must stand on a valid taxi platform to create a stop." - + invalid: "&cYou must stand on a valid taxi platform to create a destination." diff --git a/target/RS-Taxi-0.1.0.jar b/target/RS-Taxi-0.1.0.jar index ef7aa07..5860160 100644 Binary files a/target/RS-Taxi-0.1.0.jar and b/target/RS-Taxi-0.1.0.jar differ diff --git a/target/classes/com/rsscripting/rstaxi/commands/CabCommand.class b/target/classes/com/rsscripting/rstaxi/commands/CabCommand.class index e0fecb5..c7bb954 100644 Binary files a/target/classes/com/rsscripting/rstaxi/commands/CabCommand.class and b/target/classes/com/rsscripting/rstaxi/commands/CabCommand.class differ diff --git a/target/classes/com/rsscripting/rstaxi/stops/StopManager.class b/target/classes/com/rsscripting/rstaxi/stops/StopManager.class index 4f8ca08..37e1d5a 100644 Binary files a/target/classes/com/rsscripting/rstaxi/stops/StopManager.class and b/target/classes/com/rsscripting/rstaxi/stops/StopManager.class differ diff --git a/target/classes/language/en_us.yml b/target/classes/language/en_us.yml index bc79911..1e52f05 100644 --- a/target/classes/language/en_us.yml +++ b/target/classes/language/en_us.yml @@ -14,27 +14,27 @@ database: connection-error: "&cCould not connect to the database." stop: - added: "&aStop &e%stop% &ahas been created." - updated: "&aStop &e%stop% &ahas been moved to your current location." - edited: "&aStop &e%stop% &ahas been updated." - deleted: "&aStop &e%stop% &ahas been removed." - already-exists: "&cA stop named &e%stop% &calready exists." + added: "&aDestination &e%stop% &ahas been created." + updated: "&aDestination &e%stop% &ahas been moved to your current location." + edited: "&aDestination &e%stop% &ahas been updated." + deleted: "&aDestination &e%stop% &ahas been removed." + already-exists: "&cA destination named &e%stop% &calready exists." invalid-icon: "&cThe icon &e%icon% &cis invalid." - creation-error: "&cUnable to create the taxi stop. Check the server logs." + creation-error: "&cUnable to create the taxi destination. Check the server logs." teleport: success: "&aYou have arrived at &e%stop%&a." confirmation: - update: "&eAre you sure you want to move stop &6%stop%&e? Confirm the command to proceed." - delete: "&eAre you sure you want to delete stop &6%stop%&e? Confirm the command to proceed." + update: "&eAre you sure you want to move destination &6%stop%&e? Confirm the command to proceed." + delete: "&eAre you sure you want to delete destination &6%stop%&e? Confirm the command to proceed." expired: "&cThat confirmation has expired." list: - header: "&6Available Taxi Stops:" + header: "&6Available Taxi Destinations:" entry: "&e%icon% &f%stop%" + error: "&cUnable to retrieve taxi destinations. Check the server logs." platform: - invalid: "&cYou must stand on a valid taxi platform to create a stop." - + invalid: "&cYou must stand on a valid taxi platform to create a destination." diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index 30b5f53..09b45d3 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -1,6 +1,7 @@ com\rsscripting\rstaxi\stops\StopManager.class com\rsscripting\rstaxi\platform\PlatformValidator.class com\rsscripting\rstaxi\RSTaxi.class +com\rsscripting\rstaxi\stops\StopManager$StopEntry.class com\rsscripting\rstaxi\commands\CabCommand.class com\rsscripting\rstaxi\database\DatabaseManager.class com\rsscripting\rstaxi\language\LanguageManager.class