Initial Development
- /cab list complete.
This commit is contained in:
1 parent
3566555893
commit
c31ec9b8a8
8 files changed
+117
-27
No files matched your search
@@ -159,13 +159,19 @@ public final class CabCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
} catch (SQLException | IllegalArgumentException e) {
|
||||
plugin.getLogger().severe(
|
||||
"Failed to create taxi stop: " + e.getMessage()
|
||||
plugin.getLogger().log(
|
||||
java.util.logging.Level.SEVERE,
|
||||
"Failed to create taxi stop.",
|
||||
e
|
||||
);
|
||||
|
||||
sender.sendMessage(
|
||||
plugin.getLanguageManager()
|
||||
.getMessage("stop.creation-error")
|
||||
);
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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."
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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."
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user