ImageOnMap/src/main/java/fr/moribus/imageonmap/commands/maptool/RenameCommand.java

67 lines
2.2 KiB
Java
Raw Normal View History

/*
* Copyright (C) 2013 Moribus
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.moribus.imageonmap.commands.maptool;
2020-11-07 01:04:24 +01:00
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.map.ImageMap;
2020-12-12 13:47:26 +01:00
import fr.moribus.imageonmap.map.MapManager;
2020-11-15 19:33:16 +01:00
import fr.zcraft.quartzlib.components.commands.CommandException;
import fr.zcraft.quartzlib.components.commands.CommandInfo;
import fr.zcraft.quartzlib.components.i18n.I;
2020-12-12 13:47:26 +01:00
import java.util.ArrayList;
import java.util.List;
2020-12-10 22:13:05 +01:00
import org.bukkit.command.CommandSender;
2020-12-10 22:13:05 +01:00
@CommandInfo(name = "rename", usageParameters = "<original map name> <new map name>")
public class RenameCommand extends IoMCommand {
2020-12-12 13:47:26 +01:00
@Override
2020-12-10 22:13:05 +01:00
protected void run() throws CommandException {
2020-12-12 13:47:26 +01:00
ArrayList<String> argList = getArgs();
if (argList.size() != 2) {
2020-11-07 01:04:24 +01:00
warning(I.t("Not enough or too many arguments! Usage: /maptool rename <map name> <new map name>"));
return;
}
2020-12-12 13:47:26 +01:00
ImageMap map = MapManager.getMap(playerSender().getUniqueId(), argList.get(0));
if (map == null) {
error(I.t("This map does not exist."));
return;
}
map.rename(argList.get(1));
}
2020-12-10 22:13:05 +01:00
@Override
2020-12-10 22:13:05 +01:00
protected List<String> complete() throws CommandException {
2020-07-03 10:49:07 +02:00
2020-12-10 22:13:05 +01:00
if (args.length == 1) {
return getMatchingMapNames(playerSender(), args[0]);
2020-12-10 22:13:05 +01:00
}
return null;
}
2020-12-10 22:13:05 +01:00
2020-07-03 10:49:07 +02:00
@Override
2020-12-10 22:13:05 +01:00
public boolean canExecute(CommandSender sender) {
2020-07-03 10:49:07 +02:00
return Permissions.RENAME.grantedTo(sender);
}
}