mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-02 17:00:19 +01:00
Added delete command; resolves #41
This commit is contained in:
parent
28506adc88
commit
4be232b5b9
@ -33,6 +33,7 @@ public class DCommands extends BRCommands {
|
|||||||
public static EditCommand EDIT = new EditCommand();
|
public static EditCommand EDIT = new EditCommand();
|
||||||
public static EnterCommand ENTER = new EnterCommand();
|
public static EnterCommand ENTER = new EnterCommand();
|
||||||
public static EscapeCommand ESCAPE = new EscapeCommand();
|
public static EscapeCommand ESCAPE = new EscapeCommand();
|
||||||
|
public static DeleteCommand DELETE = new DeleteCommand();
|
||||||
public static GameCommand GAME = new GameCommand();
|
public static GameCommand GAME = new GameCommand();
|
||||||
public static GroupCommand GROUP = new GroupCommand();
|
public static GroupCommand GROUP = new GroupCommand();
|
||||||
public static HelpCommand HELP = new HelpCommand();
|
public static HelpCommand HELP = new HelpCommand();
|
||||||
@ -62,6 +63,7 @@ public class DCommands extends BRCommands {
|
|||||||
CHAT,
|
CHAT,
|
||||||
CHAT_SPY,
|
CHAT_SPY,
|
||||||
CREATE,
|
CREATE,
|
||||||
|
DELETE,
|
||||||
EDIT,
|
EDIT,
|
||||||
ENTER,
|
ENTER,
|
||||||
ESCAPE,
|
ESCAPE,
|
||||||
|
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012-2016 Frank Baumann
|
||||||
|
*
|
||||||
|
* 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 io.github.dre2n.dungeonsxl.command;
|
||||||
|
|
||||||
|
import io.github.dre2n.commons.command.BRCommand;
|
||||||
|
import io.github.dre2n.commons.compatibility.CompatibilityHandler;
|
||||||
|
import io.github.dre2n.commons.util.FileUtil;
|
||||||
|
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||||
|
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||||
|
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||||
|
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||||
|
import io.github.dre2n.dungeonsxl.world.DEditWorld;
|
||||||
|
import io.github.dre2n.dungeonsxl.world.DResourceWorld;
|
||||||
|
import io.github.dre2n.dungeonsxl.world.DWorlds;
|
||||||
|
import java.io.File;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Daniel Saukel
|
||||||
|
*/
|
||||||
|
public class DeleteCommand extends BRCommand {
|
||||||
|
|
||||||
|
DungeonsXL plugin = DungeonsXL.getInstance();
|
||||||
|
|
||||||
|
public DeleteCommand() {
|
||||||
|
setCommand("delete");
|
||||||
|
setMinArgs(1);
|
||||||
|
setMaxArgs(2);
|
||||||
|
setHelp(DMessages.HELP_CMD_DELETE.getMessage());
|
||||||
|
setPermission(DPermissions.DELETE.getNode());
|
||||||
|
setPlayerCommand(true);
|
||||||
|
setConsoleCommand(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExecute(String[] args, CommandSender sender) {
|
||||||
|
DWorlds dWorlds = plugin.getDWorlds();
|
||||||
|
|
||||||
|
DResourceWorld resource = dWorlds.getResourceByName(args[1]);
|
||||||
|
if (resource == null) {
|
||||||
|
MessageUtil.sendMessage(sender, DMessages.ERROR_NO_SUCH_MAP.getMessage(args[1]));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length == 2 && CompatibilityHandler.getInstance().isSpigot() && sender instanceof Player) {
|
||||||
|
ClickEvent onClickConfirm = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/dungeonsxl delete " + args[1] + " true");
|
||||||
|
TextComponent confirm = new TextComponent(ChatColor.GREEN + "[ YES ]");
|
||||||
|
confirm.setClickEvent(onClickConfirm);
|
||||||
|
|
||||||
|
ClickEvent onClickDeny = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/dungeonsxl delete " + args[1] + " false");
|
||||||
|
TextComponent deny = new TextComponent(ChatColor.DARK_RED + "[ NO ]");
|
||||||
|
deny.setClickEvent(onClickDeny);
|
||||||
|
|
||||||
|
MessageUtil.sendMessage(sender, DMessages.CMD_DELETE_BACKUPS.getMessage());
|
||||||
|
((Player) sender).spigot().sendMessage(confirm, new TextComponent(" "), deny);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (DEditWorld editWorld : dWorlds.getEditWorlds()) {
|
||||||
|
if (editWorld.getResource().equals(resource)) {
|
||||||
|
editWorld.delete(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dWorlds.removeResource(resource);
|
||||||
|
FileUtil.removeDirectory(resource.getFolder());
|
||||||
|
|
||||||
|
if (args[2].equalsIgnoreCase("true")) {
|
||||||
|
for (File file : DungeonsXL.BACKUPS.listFiles()) {
|
||||||
|
if (file.getName().startsWith(resource.getName() + "-")) {
|
||||||
|
FileUtil.removeDirectory(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageUtil.sendMessage(sender, DMessages.CMD_DELETE_SUCCESS.getMessage(args[1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -39,6 +39,8 @@ public enum DMessages implements Messages {
|
|||||||
CMD_CHAT_NORMAL_CHAT("Cmd_Chat_NormalChat", "&6You are now in the public chat"),
|
CMD_CHAT_NORMAL_CHAT("Cmd_Chat_NormalChat", "&6You are now in the public chat"),
|
||||||
CMD_CHATSPY_STOPPED("Cmd_Chatspy_Stopped", "&6You stopped to spy the dungeon chat."),
|
CMD_CHATSPY_STOPPED("Cmd_Chatspy_Stopped", "&6You stopped to spy the dungeon chat."),
|
||||||
CMD_CHATSPY_START("Cmd_Chatspy_Start", "&6You started to spy the dungeon chat."),
|
CMD_CHATSPY_START("Cmd_Chatspy_Start", "&6You started to spy the dungeon chat."),
|
||||||
|
CMD_DELETE_BACKUPS("Cmd_Delete_Backups", "&6Do you wish to delete all saved backups as well?"),
|
||||||
|
CMD_DELETE_SUCCESS("Cmd_Delete_Success", "&6Successfully deleted the map &4&v1&6."),
|
||||||
CMD_ENTER_SUCCESS("Cmd_Enter", "&6The group &4&v1 &6successfully entered the game of the group &4&v2&6."),
|
CMD_ENTER_SUCCESS("Cmd_Enter", "&6The group &4&v1 &6successfully entered the game of the group &4&v2&6."),
|
||||||
CMD_IMPORT_SUCCESS("Cmd_Import", "&6Successfully imported the world &4&v1&6."),
|
CMD_IMPORT_SUCCESS("Cmd_Import", "&6Successfully imported the world &4&v1&6."),
|
||||||
CMD_INVITE_SUCCESS("Cmd_Invite_Success", "&6Player &4&v1&6 was successfully invited to edit the map &4&v2&6."),
|
CMD_INVITE_SUCCESS("Cmd_Invite_Success", "&6Player &4&v1&6 was successfully invited to edit the map &4&v2&6."),
|
||||||
@ -106,6 +108,7 @@ public enum DMessages implements Messages {
|
|||||||
HELP_CMD_CHAT("Help_Cmd_Chat", "/dxl chat - Change the chat mode"),
|
HELP_CMD_CHAT("Help_Cmd_Chat", "/dxl chat - Change the chat mode"),
|
||||||
HELP_CMD_CHATSPY("Help_Cmd_Chatspy", "/dxl chatspy - Dis/enables the spymode"),
|
HELP_CMD_CHATSPY("Help_Cmd_Chatspy", "/dxl chatspy - Dis/enables the spymode"),
|
||||||
HELP_CMD_CREATE("Help_Cmd_Create", "/dxl create [name] - Creates a new dungeon map"),
|
HELP_CMD_CREATE("Help_Cmd_Create", "/dxl create [name] - Creates a new dungeon map"),
|
||||||
|
HELP_CMD_DELETE("Help_Cmd_Delete", "/dxl delete [name] - Deletes a dungeon map"),
|
||||||
HELP_CMD_EDIT("Help_Cmd_Edit", "/dxl edit [map] - Edit an existing dungeon map"),
|
HELP_CMD_EDIT("Help_Cmd_Edit", "/dxl edit [map] - Edit an existing dungeon map"),
|
||||||
HELP_CMD_ENTER("Help_Cmd_Enter", "/dxl enter ([joining group]) [target group] - Let the joining group enter the game of the target group"),
|
HELP_CMD_ENTER("Help_Cmd_Enter", "/dxl enter ([joining group]) [target group] - Let the joining group enter the game of the target group"),
|
||||||
HELP_CMD_ESCAPE("Help_Cmd_Escape", "/dxl escape - Leaves the current edit world without saving"),
|
HELP_CMD_ESCAPE("Help_Cmd_Escape", "/dxl escape - Leaves the current edit world without saving"),
|
||||||
|
@ -38,6 +38,7 @@ public enum DPermissions {
|
|||||||
CHAT_SPY("chatspy", OP),
|
CHAT_SPY("chatspy", OP),
|
||||||
CMD_EDIT("cmdedit", OP),
|
CMD_EDIT("cmdedit", OP),
|
||||||
CREATE("create", OP),
|
CREATE("create", OP),
|
||||||
|
DELETE("delete", OP),
|
||||||
EDIT("edit", OP),
|
EDIT("edit", OP),
|
||||||
ENTER("enter", OP),
|
ENTER("enter", OP),
|
||||||
ESCAPE("escape", TRUE),
|
ESCAPE("escape", TRUE),
|
||||||
@ -86,7 +87,7 @@ public enum DPermissions {
|
|||||||
// Kits
|
// Kits
|
||||||
ADMINISTRATOR("*", OP),
|
ADMINISTRATOR("*", OP),
|
||||||
HALF_EDITOR("halfeditor", OP, ESCAPE, LIST, MESSAGE, SAVE),
|
HALF_EDITOR("halfeditor", OP, ESCAPE, LIST, MESSAGE, SAVE),
|
||||||
FULL_EDITOR("fulleditor", OP, HALF_EDITOR, EDIT, PLAY, RENAME, SIGN, TEST),
|
FULL_EDITOR("fulleditor", OP, HALF_EDITOR, DELETE, EDIT, PLAY, RENAME, SIGN, TEST),
|
||||||
HALF_PLAYER("halfplayer", TRUE, CHAT, ESCAPE, GAME, HELP, JOIN, LEAVE, LIVES, MAIN, SETTINGS, SETTINGS_PLAYER),
|
HALF_PLAYER("halfplayer", TRUE, CHAT, ESCAPE, GAME, HELP, JOIN, LEAVE, LIVES, MAIN, SETTINGS, SETTINGS_PLAYER),
|
||||||
FULL_PLAYER("fullplayer", OP, HALF_PLAYER, GROUP);
|
FULL_PLAYER("fullplayer", OP, HALF_PLAYER, GROUP);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user