summaryrefslogtreecommitdiff
path: root/src/main/java/net/benjidial/nswp/commands/RenameWaypoint.java
blob: 44af06ca5be9666480a7d78eb5f811fceb2a73aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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;
    }

}