Merge pull request #99 from DRE2N/cmd-import

Added import command
This commit is contained in:
Daniel Saukel 2016-07-01 03:14:21 +02:00 committed by GitHub
commit ccdd5e67d2
5 changed files with 89 additions and 5 deletions

View File

@ -370,6 +370,7 @@ public class DungeonsXL extends BRPlugin {
new EscapeCommand(),
new GameCommand(),
new GroupCommand(),
new ImportCommand(),
new InviteCommand(),
new JoinCommand(),
new EnterCommand(),

View File

@ -63,7 +63,7 @@ public class CreateCommand extends BRCommand {
if (sender instanceof ConsoleCommandSender) {
// Msg create
MessageUtil.log(plugin, DMessages.LOG_NEW_DUNGEON.getMessage());
MessageUtil.log(plugin, DMessages.LOG_NEW_MAP.getMessage());
MessageUtil.log(plugin, DMessages.LOG_GENERATE_NEW_WORLD.getMessage());
// Create World
@ -85,7 +85,7 @@ public class CreateCommand extends BRCommand {
}
// Msg create
MessageUtil.log(plugin, DMessages.LOG_NEW_DUNGEON.getMessage());
MessageUtil.log(plugin, DMessages.LOG_NEW_MAP.getMessage());
MessageUtil.log(plugin, DMessages.LOG_GENERATE_NEW_WORLD.getMessage());
// Create World

View File

@ -0,0 +1,78 @@
/*
* 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.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.DResourceWorld;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
/**
* @author Frank Baumann, Daniel Saukel
*/
public class ImportCommand extends BRCommand {
DungeonsXL plugin = DungeonsXL.getInstance();
public ImportCommand() {
setMinArgs(1);
setMaxArgs(1);
setCommand("import");
setHelp(DMessages.HELP_CMD_IMPORT.getMessage());
setPermission(DPermissions.IMPORT.getNode());
setPlayerCommand(true);
setConsoleCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
File target = new File(DungeonsXL.MAPS, args[1]);
File source = new File(Bukkit.getWorldContainer(), args[1]);
if (!source.exists()) {
MessageUtil.sendMessage(sender, DMessages.ERROR_NO_SUCH_MAP.getMessage(args[1]));
return;
}
if (target.exists()) {
MessageUtil.sendMessage(sender, DMessages.ERROR_NAME_IN_USE.getMessage(args[1]));
return;
}
World world = Bukkit.getWorld(args[1]);
if (world != null) {
world.save();
}
MessageUtil.log(plugin, DMessages.LOG_NEW_MAP.getMessage());
MessageUtil.log(plugin, DMessages.LOG_IMPORT_WORLD.getMessage());
FileUtil.copyDirectory(source, target, new String[]{"playerdata", "stats"});
plugin.getDWorlds().addResource(new DResourceWorld(plugin.getDWorlds(), args[1]));
MessageUtil.sendMessage(sender, DMessages.CMD_IMPORT_SUCCESS.getMessage(args[1]));
}
}

View File

@ -37,6 +37,7 @@ public enum DMessages implements Messages {
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_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_INVITE_SUCCESS("Cmd_Invite_Success", "&6Player &4&v1&6 was successfully invited to edit the map &4&v2&6."),
CMD_LEAVE_SUCCESS("Cmd_Leave_Success", "&6You have successfully left your group!"),
CMD_LIVES("Cmd_Lives", "&4&v1&6 has &4&v2 &6lives left."),
@ -76,6 +77,7 @@ public enum DMessages implements Messages {
ERROR_NO_PLAYER_COMMAND("Error_NoPlayerCommand", "&6/dxl &v1&4 cannot be executed as player!"),
ERROR_NO_PROTECTED_BLOCK("Error_NoDXLBlock", "&4This is not a block protected by DungeonsXL!"),
ERROR_NO_SUCH_GROUP("Error_NoSuchGroup", "&4The group &6&v1&4 does not exist!"),
ERROR_NO_SUCH_MAP("Error_NoSuchMap", "&4The world &6&v1&4 does not exist!"),
ERROR_NO_SUCH_PLAYER("Error_NoSuchPlayer", "&4The player &6&v1&4 does not exist!"),
ERROR_NOT_CAPTAIN("Error_NotCaptain", "&4You are not the captain of your group!"),
ERROR_NOT_IN_DUNGEON("Error_NotInDungeon", "&4You are not in a dungeon!"),
@ -93,7 +95,7 @@ public enum DMessages implements Messages {
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_CREATE("Help_Cmd_Create", "/dxl create [name] - Creates a new dungeon map"),
HELP_CMD_EDIT("Help_Cmd_Edit", "/dxl edit [name] - Edit an existing dungeon map"),
HELP_CMD_EDIT("Help_Cmd_Edit", "/dxl edit [map] - Edit an existing dungeon map"),
HELP_CMD_ESCAPE("Help_Cmd_Escape", "/dxl escape - Leaves the current edit world without saving"),
HELP_CMD_GAME("Help_Cmd_Game", "/dxl game - Shows information about the current game session"),
HELP_CMD_GROUP("Help_Cmd_Group", "/dxl group - Shows group command help"),
@ -105,6 +107,7 @@ public enum DMessages implements Messages {
HELP_CMD_GROUP_KICK("Help_Cmd_GroupKick", "/dxl group kick [player] - Kicks a player"),
HELP_CMD_GROUP_SHOW("Help_Cmd_GroupShow", "/dxl group show [group] - Shows a group"),
HELP_CMD_HELP("Help_Cmd_Help", "/dxl help [page] - Shows the help page"),
HELP_CMD_IMPORT("Help_Cmd_Import", "/dxl import [world] - Imports a world from the world container as a dungeon map."),
HELP_CMD_INVITE("Help_Cmd_Invite", "/dxl invite [player] [dungeon] - Invite a player to edit a dungeon"),
HELP_CMD_JOIN("Help_Cmd_Join", "/dxl join [announcement] - Opens the GUI to join a group in an upcoming game"),
HELP_CMD_ENTER("Help_Cmd_Enter", "/dxl enter ([joining group]) [target group] - Let the joining group enter the game of the target group"),
@ -132,8 +135,9 @@ public enum DMessages implements Messages {
LOG_ERROR_MOB_ENCHANTMENT("Log_Error_MobEnchantment", "&4Error at loading mob.yml: Enchantment &6&v1&4 doesn't exist!"),
LOG_ERROR_MOBTYPE("Log_Error_MobType", "&4Error at loading mob.yml: Mob &6&v1&4 doesn't exist!"),
LOG_ERROR_NO_CONSOLE_COMMAND("Log_Error_NoConsoleCommand", "&6/dxl &v1&4 can not be executed as console!"),
LOG_GENERATE_NEW_WORLD("Log_GenerateNewWorld", "&6Generate new world..."),
LOG_NEW_DUNGEON("Log_NewDungeon", "&6New dungeon"),
LOG_GENERATE_NEW_WORLD("Log_GenerateNewWorld", "&6Generating new world..."),
LOG_IMPORT_WORLD("Log_ImportWorld", "&6Importing world..."),
LOG_NEW_MAP("Log_NewDungeon", "&6Creating new map."),
LOG_NEW_PLAYER_DATA("Log_NewPlayerData", "&6A new player data file has been created and saved as &v1."),
LOG_WORLD_GENERATION_FINISHED("Log_WorldGenerationFinished", "&6World generation finished!"),
PLAYER_BLOCK_INFO("Player_BlockInfo", "&6Block ID: &2&v1"),

View File

@ -47,6 +47,7 @@ public enum DPermissions {
HELP("help", TRUE),
IGNORE_REQUIREMENTS("ignorerequirements", OP),
IGNORE_TIME_LIMIT("ignoretimelimit", OP),
IMPORT("IMPORT", OP),
INVITE("invite", OP),
INSECURE("insecure", OP),
JOIN("join", TRUE),