Initial Development
- /cab list complete.
This commit is contained in:
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) {
|
} catch (SQLException | IllegalArgumentException e) {
|
||||||
plugin.getLogger().severe(
|
plugin.getLogger().log(
|
||||||
"Failed to create taxi stop: " + e.getMessage()
|
java.util.logging.Level.SEVERE,
|
||||||
);
|
"Failed to create taxi stop.",
|
||||||
sender.sendMessage(plugin.getLanguageManager()
|
e
|
||||||
.getMessage("stop.creation-error"));
|
);
|
||||||
}
|
|
||||||
|
sender.sendMessage(
|
||||||
|
plugin.getLanguageManager()
|
||||||
|
.getMessage("stop.creation-error")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -191,10 +197,64 @@ public final class CabCommand implements CommandExecutor {
|
|||||||
return checkPermission(sender, "rs-cab.delete");
|
return checkPermission(sender, "rs-cab.delete");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean handleList(CommandSender sender) {
|
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(
|
private boolean checkPermission(
|
||||||
CommandSender sender,
|
CommandSender sender,
|
||||||
String permission
|
String permission
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import java.sql.Connection;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public final class StopManager {
|
public final class StopManager {
|
||||||
|
|
||||||
@@ -17,6 +19,9 @@ public final class StopManager {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public record StopEntry(String name, String icon) {
|
||||||
|
}
|
||||||
|
|
||||||
public boolean exists(String name) throws SQLException {
|
public boolean exists(String name) throws SQLException {
|
||||||
String sql = "SELECT 1 FROM stops WHERE name = ?";
|
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() {
|
private Connection connection() {
|
||||||
return plugin.getDatabaseManager().getConnection();
|
return plugin.getDatabaseManager().getConnection();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,27 +14,27 @@ database:
|
|||||||
connection-error: "&cCould not connect to the database."
|
connection-error: "&cCould not connect to the database."
|
||||||
|
|
||||||
stop:
|
stop:
|
||||||
added: "&aStop &e%stop% &ahas been created."
|
added: "&aDestination &e%stop% &ahas been created."
|
||||||
updated: "&aStop &e%stop% &ahas been moved to your current location."
|
updated: "&aDestination &e%stop% &ahas been moved to your current location."
|
||||||
edited: "&aStop &e%stop% &ahas been updated."
|
edited: "&aDestination &e%stop% &ahas been updated."
|
||||||
deleted: "&aStop &e%stop% &ahas been removed."
|
deleted: "&aDestination &e%stop% &ahas been removed."
|
||||||
already-exists: "&cA stop named &e%stop% &calready exists."
|
already-exists: "&cA destination named &e%stop% &calready exists."
|
||||||
invalid-icon: "&cThe icon &e%icon% &cis invalid."
|
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:
|
teleport:
|
||||||
success: "&aYou have arrived at &e%stop%&a."
|
success: "&aYou have arrived at &e%stop%&a."
|
||||||
|
|
||||||
confirmation:
|
confirmation:
|
||||||
update: "&eAre you sure you want to move 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 stop &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."
|
expired: "&cThat confirmation has expired."
|
||||||
|
|
||||||
list:
|
list:
|
||||||
header: "&6Available Taxi Stops:"
|
header: "&6Available Taxi Destinations:"
|
||||||
entry: "&e%icon% &f%stop%"
|
entry: "&e%icon% &f%stop%"
|
||||||
|
error: "&cUnable to retrieve taxi destinations. Check the server logs."
|
||||||
|
|
||||||
platform:
|
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."
|
connection-error: "&cCould not connect to the database."
|
||||||
|
|
||||||
stop:
|
stop:
|
||||||
added: "&aStop &e%stop% &ahas been created."
|
added: "&aDestination &e%stop% &ahas been created."
|
||||||
updated: "&aStop &e%stop% &ahas been moved to your current location."
|
updated: "&aDestination &e%stop% &ahas been moved to your current location."
|
||||||
edited: "&aStop &e%stop% &ahas been updated."
|
edited: "&aDestination &e%stop% &ahas been updated."
|
||||||
deleted: "&aStop &e%stop% &ahas been removed."
|
deleted: "&aDestination &e%stop% &ahas been removed."
|
||||||
already-exists: "&cA stop named &e%stop% &calready exists."
|
already-exists: "&cA destination named &e%stop% &calready exists."
|
||||||
invalid-icon: "&cThe icon &e%icon% &cis invalid."
|
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:
|
teleport:
|
||||||
success: "&aYou have arrived at &e%stop%&a."
|
success: "&aYou have arrived at &e%stop%&a."
|
||||||
|
|
||||||
confirmation:
|
confirmation:
|
||||||
update: "&eAre you sure you want to move 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 stop &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."
|
expired: "&cThat confirmation has expired."
|
||||||
|
|
||||||
list:
|
list:
|
||||||
header: "&6Available Taxi Stops:"
|
header: "&6Available Taxi Destinations:"
|
||||||
entry: "&e%icon% &f%stop%"
|
entry: "&e%icon% &f%stop%"
|
||||||
|
error: "&cUnable to retrieve taxi destinations. Check the server logs."
|
||||||
|
|
||||||
platform:
|
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\stops\StopManager.class
|
||||||
com\rsscripting\rstaxi\platform\PlatformValidator.class
|
com\rsscripting\rstaxi\platform\PlatformValidator.class
|
||||||
com\rsscripting\rstaxi\RSTaxi.class
|
com\rsscripting\rstaxi\RSTaxi.class
|
||||||
|
com\rsscripting\rstaxi\stops\StopManager$StopEntry.class
|
||||||
com\rsscripting\rstaxi\commands\CabCommand.class
|
com\rsscripting\rstaxi\commands\CabCommand.class
|
||||||
com\rsscripting\rstaxi\database\DatabaseManager.class
|
com\rsscripting\rstaxi\database\DatabaseManager.class
|
||||||
com\rsscripting\rstaxi\language\LanguageManager.class
|
com\rsscripting\rstaxi\language\LanguageManager.class
|
||||||
Reference in new issue
Block a user