diff --git a/src/main/java/dev/csutter/race/Plugin.java b/src/main/java/dev/csutter/race/Plugin.java index 4007dff..d0167e7 100755 --- a/src/main/java/dev/csutter/race/Plugin.java +++ b/src/main/java/dev/csutter/race/Plugin.java @@ -46,6 +46,7 @@ public void onEnable() getCommand("StopRace").setExecutor(new StopRaceCommand()); getCommand("ActiveRaces").setExecutor(new ActiveRaceCommand()); getCommand("Editor").setExecutor(new EditorCommand()); + getCommand("Rename").setExecutor(new RenameCommand()); getServer().getPluginManager().registerEvents(new EditorGUI(), this); diff --git a/src/main/java/dev/csutter/race/commands/RenameCommand.java b/src/main/java/dev/csutter/race/commands/RenameCommand.java new file mode 100755 index 0000000..dca1918 --- /dev/null +++ b/src/main/java/dev/csutter/race/commands/RenameCommand.java @@ -0,0 +1,40 @@ +package dev.csutter.race.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import dev.csutter.race.models.Course; +import dev.csutter.race.utils.CourseUtils; + +public class RenameCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if (!(sender instanceof Player)) { + sender.sendMessage("You must be a player to use this command"); + return true; + } + + if (args.length != 2) return false; + + Course course = CourseUtils.getCourse(args[0]); + if (course == null) { + sender.sendMessage("Couldn't find the course you were looking for"); + return false; + } + + if (!CourseUtils.checkIfOwner(course, (Player) sender)) { + sender.sendMessage("You must be the player who created the track"); + return false; + } + + CourseUtils.renameCourse(course, args[1]); + sender.sendMessage("Course has been successfully renamed"); + + + return true; + } +} \ No newline at end of file diff --git a/src/main/java/dev/csutter/race/utils/CourseUtils.java b/src/main/java/dev/csutter/race/utils/CourseUtils.java index a9405b9..d36c57b 100755 --- a/src/main/java/dev/csutter/race/utils/CourseUtils.java +++ b/src/main/java/dev/csutter/race/utils/CourseUtils.java @@ -97,6 +97,15 @@ public static Course updateCourse(String id, Course newCourse) { return null; } + public static Course renameCourse(Course course, String newName) { + courses.remove(course); + + course.setCourseName(newName); + courses.add(course); + + return course; + } + public static String getCourseNames() { String str = ""; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ad252b8..8290c59 100755 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -49,4 +49,8 @@ commands: descrition: Creates a course editor usage: / + rename: + descrition: Renames a course + usage: / + \ No newline at end of file