Skip to content

Commit

Permalink
Added a rename command
Browse files Browse the repository at this point in the history
  • Loading branch information
CSutter5 committed Jul 24, 2023
1 parent 6b9bab7 commit 45a4ecf
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/dev/csutter/race/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
40 changes: 40 additions & 0 deletions src/main/java/dev/csutter/race/commands/RenameCommand.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
9 changes: 9 additions & 0 deletions src/main/java/dev/csutter/race/utils/CourseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ commands:
descrition: Creates a course editor
usage: /<command> <course name>

rename:
descrition: Renames a course
usage: /<command> <og course name> <new course name>


0 comments on commit 45a4ecf

Please sign in to comment.