From ef65431d405a713b138a55054e78497883f27e54 Mon Sep 17 00:00:00 2001 From: him Date: Sat, 11 Feb 2023 18:23:09 -0500 Subject: Add waypoint renaming Co-authored-by: Flarp Reviewed-on: https://git.benjidial.net/benji/nswp/pulls/1 Co-authored-by: him Co-committed-by: him --- .../benjidial/nswp/commands/RenameWaypoint.java | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/net/benjidial/nswp/commands/RenameWaypoint.java (limited to 'src/main/java/net/benjidial/nswp/commands') diff --git a/src/main/java/net/benjidial/nswp/commands/RenameWaypoint.java b/src/main/java/net/benjidial/nswp/commands/RenameWaypoint.java new file mode 100644 index 0000000..44af06c --- /dev/null +++ b/src/main/java/net/benjidial/nswp/commands/RenameWaypoint.java @@ -0,0 +1,37 @@ +package net.benjidial.nswp.commands; + +import net.benjidial.nswp.Database; +import net.benjidial.nswp.Waypoint; + +import org.bukkit.entity.Player; + +import java.sql.SQLException; + +public class RenameWaypoint extends WaypointCommand { + public CompletionType getCompletionType() { + return CompletionType.Waypoint; + } + + @Override + public boolean body(Player player, String[] args) throws SQLException { + if (args.length != 2) return false; + + if (Database.lookupWaypoint(player, args[1]) != null) { + player.sendMessage("Waypoint with that name already exists!"); + return true; + } + + Waypoint waypoint = Database.lookupWaypoint(player, args[0]); + + if (waypoint == null) { + player.sendMessage("No waypoint with that name."); + } else { + Database.deleteWaypoint(player, args[0]); + waypoint.name = args[1]; + Database.addWaypoint(player, waypoint); + } + + return true; + } + +} -- cgit v1.2.3