From 79dac4c6fd2bfaae30d8da9bd3bf349adc734b6a Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 26 Jun 2016 12:05:00 +0200 Subject: [PATCH 1/2] Added import command --- .../dungeonsxl/command/CreateCommand.java | 4 +- .../dungeonsxl/command/ImportCommand.java | 78 +++++++++++++++++++ .../dre2n/dungeonsxl/config/DMessages.java | 10 ++- .../dre2n/dungeonsxl/player/DPermissions.java | 1 + 4 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/command/ImportCommand.java diff --git a/src/main/java/io/github/dre2n/dungeonsxl/command/CreateCommand.java b/src/main/java/io/github/dre2n/dungeonsxl/command/CreateCommand.java index 10b14973..38de60bc 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/command/CreateCommand.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/command/CreateCommand.java @@ -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 diff --git a/src/main/java/io/github/dre2n/dungeonsxl/command/ImportCommand.java b/src/main/java/io/github/dre2n/dungeonsxl/command/ImportCommand.java new file mode 100644 index 00000000..67411d8d --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/command/ImportCommand.java @@ -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 . + */ +package io.github.dre2n.dungeonsxl.command; + +import io.github.dre2n.commons.command.BRCommand; +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.ResourceWorld; +import io.github.dre2n.itemsxl.util.commons.util.FileUtil; +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"}); + + new ResourceWorld(args[1]); + + MessageUtil.sendMessage(sender, DMessages.CMD_IMPORT_SUCCESS.getMessage(args[1])); + } + +} diff --git a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index 0c572d55..5f110688 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -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"), diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java index 0535bbf4..d8857ff0 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java @@ -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), From a45fff42b1c512c5ac9cb6233a56f35d9934c120 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Fri, 1 Jul 2016 03:13:12 +0200 Subject: [PATCH 2/2] Applied some fixes (rebasing) --- src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java | 1 + .../io/github/dre2n/dungeonsxl/command/ImportCommand.java | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index 7a669833..365b5cd6 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -370,6 +370,7 @@ public class DungeonsXL extends BRPlugin { new EscapeCommand(), new GameCommand(), new GroupCommand(), + new ImportCommand(), new InviteCommand(), new JoinCommand(), new EnterCommand(), diff --git a/src/main/java/io/github/dre2n/dungeonsxl/command/ImportCommand.java b/src/main/java/io/github/dre2n/dungeonsxl/command/ImportCommand.java index 67411d8d..8def1763 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/command/ImportCommand.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/command/ImportCommand.java @@ -17,12 +17,12 @@ 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.ResourceWorld; -import io.github.dre2n.itemsxl.util.commons.util.FileUtil; +import io.github.dre2n.dungeonsxl.world.DResourceWorld; import java.io.File; import org.bukkit.Bukkit; import org.bukkit.World; @@ -70,7 +70,7 @@ public class ImportCommand extends BRCommand { FileUtil.copyDirectory(source, target, new String[]{"playerdata", "stats"}); - new ResourceWorld(args[1]); + plugin.getDWorlds().addResource(new DResourceWorld(plugin.getDWorlds(), args[1])); MessageUtil.sendMessage(sender, DMessages.CMD_IMPORT_SUCCESS.getMessage(args[1])); }