From e06ee55259b3549a59358a13c095a274bacf6a05 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sat, 30 Dec 2023 14:24:46 -0500 Subject: testing new version --- .../benjidial/nswp/commands/RenameWaypoint.java | 53 ++++++++++++++-------- 1 file changed, 33 insertions(+), 20 deletions(-) (limited to 'src/main/java/net/benjidial/nswp/commands/RenameWaypoint.java') diff --git a/src/main/java/net/benjidial/nswp/commands/RenameWaypoint.java b/src/main/java/net/benjidial/nswp/commands/RenameWaypoint.java index 44af06c..07f255a 100644 --- a/src/main/java/net/benjidial/nswp/commands/RenameWaypoint.java +++ b/src/main/java/net/benjidial/nswp/commands/RenameWaypoint.java @@ -6,32 +6,45 @@ import net.benjidial.nswp.Waypoint; import org.bukkit.entity.Player; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; -public class RenameWaypoint extends WaypointCommand { - public CompletionType getCompletionType() { - return CompletionType.Waypoint; - } +public class RenameWaypoint extends PlayerCommand { + + public List getTabCompletions(Player sender, String[] args) throws SQLException { + if (args.length > 1) + return new ArrayList(); + return searchWaypointsByArg(sender, args, 0); + } - @Override - public boolean body(Player player, String[] args) throws SQLException { - if (args.length != 2) return false; + public boolean doCommand(Player sender, String[] args) throws SQLException { - if (Database.lookupWaypoint(player, args[1]) != null) { - player.sendMessage("Waypoint with that name already exists!"); - return true; - } + if (args.length != 2) + return false; - Waypoint waypoint = Database.lookupWaypoint(player, args[0]); + Database.createWaypointTable(sender); + Waypoint wp = Database.lookupWaypoint(sender, 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); - } + if (wp == null) { + sender.sendMessage("You do not have a waypoint " + args[0] + "."); + return true; + } - return true; + Waypoint otherWP = Database.lookupWaypoint(sender, args[1]); + if (otherWP != null) { + sender.sendMessage("You already have a waypoint " + otherWP.toString() + "."); + return true; } + String oldToString = wp.toString(); + wp.name = args[1]; + + Database.deleteWaypoint(sender, args[0]); + Database.addWaypoint(sender, wp); + + sender.sendMessage("Renamed " + oldToString + " to " + args[1] + "."); + return true; + + } + } -- cgit v1.2.3