Search in sources :

Example 1 with Generator

use of com.eintosti.buildsystem.object.world.generator.Generator in project BuildSystem by einTosti.

the class WorldsTabComplete method onTabComplete.

@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
    ArrayList<String> arrayList = new ArrayList<>();
    if (!(sender instanceof Player)) {
        return arrayList;
    }
    Player player = (Player) sender;
    switch(args.length) {
        case 1:
            {
                for (Argument argument : Argument.values()) {
                    String command = argument.getCommand();
                    String permission = argument.getPermission();
                    if (permission == null || player.hasPermission(permission)) {
                        addArgument(args[0], command, arrayList);
                    }
                }
                return arrayList;
            }
        case 2:
            {
                switch(args[0].toLowerCase()) {
                    case "builders":
                    case "delete":
                    case "edit":
                    case "info":
                    case "rename":
                    case "setcreator":
                    case "setitem":
                    case "setpermission":
                    case "setproject":
                    case "setstatus":
                    case "tp":
                    case "unimport":
                        worldManager.getBuildWorlds().forEach(world -> {
                            if (player.hasPermission(world.getPermission()) || world.getPermission().equalsIgnoreCase("-")) {
                                String worldName = world.getName();
                                addArgument(args[1], worldName, arrayList);
                            }
                        });
                        break;
                    case "addbuilder":
                    case "removebuilder":
                        worldManager.getBuildWorlds().forEach(world -> {
                            if (player.hasPermission("buildsystem.admin") || (world.getCreatorId() != null && world.getCreatorId().equals(player.getUniqueId()))) {
                                String worldName = world.getName();
                                addArgument(args[1], worldName, arrayList);
                            }
                        });
                        break;
                    case "import":
                        String[] directories = Bukkit.getWorldContainer().list((dir, name) -> {
                            for (String charString : name.split("")) {
                                if (charString.matches("[^A-Za-z0-9/_-]")) {
                                    return false;
                                }
                            }
                            File worldFolder = new File(dir, name);
                            if (!worldFolder.isDirectory()) {
                                return false;
                            }
                            File levelFile = new File(dir + File.separator + name + File.separator + "level.dat");
                            if (!levelFile.exists()) {
                                return false;
                            }
                            BuildWorld buildWorld = worldManager.getBuildWorld(name);
                            return buildWorld == null;
                        });
                        if (directories == null || directories.length == 0) {
                            return arrayList;
                        }
                        for (String projectName : directories) {
                            addArgument(args[1], projectName, arrayList);
                        }
                        break;
                }
                return arrayList;
            }
        case 3:
            {
                if (args[0].equalsIgnoreCase("import")) {
                    if (args[1].equalsIgnoreCase(" ")) {
                        return arrayList;
                    }
                    arrayList.add("-g");
                    return arrayList;
                }
            }
        case 4:
            {
                if (!args[2].equalsIgnoreCase("-g")) {
                    return arrayList;
                }
                for (Generator value : new Generator[] { Generator.NORMAL, Generator.FLAT, Generator.VOID }) {
                    String valueName = value.name();
                    addArgument(args[3], valueName, arrayList);
                }
                return arrayList;
            }
    }
    return arrayList;
}
Also used : CommandSender(org.bukkit.command.CommandSender) BuildSystem(com.eintosti.buildsystem.BuildSystem) TabCompleter(org.bukkit.command.TabCompleter) Player(org.bukkit.entity.Player) File(java.io.File) ArrayList(java.util.ArrayList) List(java.util.List) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Generator(com.eintosti.buildsystem.object.world.generator.Generator) Command(org.bukkit.command.Command) WorldManager(com.eintosti.buildsystem.manager.WorldManager) NotNull(org.jetbrains.annotations.NotNull) Bukkit(org.bukkit.Bukkit) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) File(java.io.File) Generator(com.eintosti.buildsystem.object.world.generator.Generator)

Example 2 with Generator

use of com.eintosti.buildsystem.object.world.generator.Generator in project BuildSystem by Trichtern.

the class WorldsTabComplete method onTabComplete.

@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
    ArrayList<String> arrayList = new ArrayList<>();
    if (!(sender instanceof Player)) {
        return arrayList;
    }
    Player player = (Player) sender;
    switch(args.length) {
        case 1:
            {
                for (Argument argument : Argument.values()) {
                    String command = argument.getCommand();
                    String permission = argument.getPermission();
                    if (permission == null || player.hasPermission(permission)) {
                        addArgument(args[0], command, arrayList);
                    }
                }
                return arrayList;
            }
        case 2:
            {
                switch(args[0].toLowerCase()) {
                    case "builders":
                    case "edit":
                    case "info":
                    case "rename":
                    case "setcreator":
                    case "setitem":
                    case "setpermission":
                    case "setproject":
                    case "setstatus":
                    case "tp":
                    case "unimport":
                        worldManager.getBuildWorlds().stream().filter(world -> player.hasPermission(world.getPermission()) || world.getPermission().equalsIgnoreCase("-")).forEach(world -> addArgument(args[1], world.getName(), arrayList));
                        break;
                    case "addbuilder":
                    case "delete":
                    case "removebuilder":
                        worldManager.getBuildWorlds().stream().filter(world -> world.isCreator(player) || player.hasPermission(BuildSystem.ADMIN_PERMISSION)).forEach(world -> addArgument(args[1], world.getName(), arrayList));
                        break;
                    case "import":
                        String[] directories = Bukkit.getWorldContainer().list((dir, name) -> {
                            for (String charString : name.split("")) {
                                if (charString.matches("[^A-Za-z0-9/_-]")) {
                                    return false;
                                }
                            }
                            File worldFolder = new File(dir, name);
                            if (!worldFolder.isDirectory()) {
                                return false;
                            }
                            File levelFile = new File(dir + File.separator + name + File.separator + "level.dat");
                            if (!levelFile.exists()) {
                                return false;
                            }
                            BuildWorld buildWorld = worldManager.getBuildWorld(name);
                            return buildWorld == null;
                        });
                        if (directories == null || directories.length == 0) {
                            return arrayList;
                        }
                        for (String projectName : directories) {
                            addArgument(args[1], projectName, arrayList);
                        }
                        break;
                }
                return arrayList;
            }
        case 3:
            {
                if (args[0].equalsIgnoreCase("import")) {
                    if (args[1].equalsIgnoreCase(" ")) {
                        return arrayList;
                    }
                    arrayList.add("-g");
                    return arrayList;
                }
            }
        case 4:
            {
                if (!args[2].equalsIgnoreCase("-g")) {
                    return arrayList;
                }
                for (Generator value : new Generator[] { Generator.NORMAL, Generator.FLAT, Generator.VOID }) {
                    addArgument(args[3], value.name(), arrayList);
                }
                return arrayList;
            }
    }
    return arrayList;
}
Also used : CommandSender(org.bukkit.command.CommandSender) BuildSystem(com.eintosti.buildsystem.BuildSystem) TabCompleter(org.bukkit.command.TabCompleter) Player(org.bukkit.entity.Player) File(java.io.File) ArrayList(java.util.ArrayList) List(java.util.List) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Generator(com.eintosti.buildsystem.object.world.generator.Generator) Command(org.bukkit.command.Command) WorldManager(com.eintosti.buildsystem.manager.WorldManager) NotNull(org.jetbrains.annotations.NotNull) Bukkit(org.bukkit.Bukkit) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) File(java.io.File) Generator(com.eintosti.buildsystem.object.world.generator.Generator)

Example 3 with Generator

use of com.eintosti.buildsystem.object.world.generator.Generator in project BuildSystem by Trichtern.

the class WorldsCommand method onCommand.

@Override
@SuppressWarnings("deprecation")
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
    if (!(sender instanceof Player)) {
        plugin.getLogger().warning(plugin.getString("sender_not_player"));
        return true;
    }
    Player player = (Player) sender;
    if (args.length == 0) {
        if (!player.hasPermission("buildsystem.navigator")) {
            plugin.sendPermissionMessage(player);
            return true;
        }
        plugin.getNavigatorInventory().openInventory(player);
        XSound.BLOCK_CHEST_OPEN.play(player);
        return true;
    }
    // Most command use the structure /worlds <argument> <world> <...> which is why we assume that args[1] is the world name
    // Make sure to change if this is not the case for any specific command
    String worldName = args.length >= 2 ? args[1] : player.getWorld().getName();
    switch(args[0].toLowerCase()) {
        case "addbuilder":
            {
                if (!plugin.isPermitted(player, "buildsystem.addbuilder", worldName)) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_addbuilder_unknown_world"));
                        return true;
                    }
                    if (!buildWorld.isCreator(player) && !player.hasPermission(BuildSystem.ADMIN_PERMISSION)) {
                        player.sendMessage(plugin.getString("worlds_addbuilder_not_creator"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    getAddBuilderInput(player, true);
                } else {
                    player.sendMessage(plugin.getString("worlds_addbuilder_usage"));
                }
                break;
            }
        case "builders":
            {
                if (!plugin.isPermitted(player, "buildsystem.builders", worldName)) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_builders_unknown_world"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    player.openInventory(plugin.getBuilderInventory().getInventory(buildWorld, player));
                } else {
                    player.sendMessage(plugin.getString("worlds_builders_usage"));
                }
                break;
            }
        case "delete":
            {
                if (!plugin.isPermitted(player, "buildsystem.delete", worldName)) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_delete_unknown_world"));
                        return true;
                    }
                    if (!buildWorld.isCreator(player) && !player.hasPermission(BuildSystem.ADMIN_PERMISSION)) {
                        player.sendMessage(plugin.getString("worlds_delete_not_creator"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    plugin.getDeleteInventory().openInventory(player, buildWorld);
                } else {
                    player.sendMessage(plugin.getString("worlds_delete_usage"));
                }
                break;
            }
        case "edit":
            {
                if (!plugin.isPermitted(player, "buildsystem.edit", worldName)) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_edit_unknown_world"));
                        return true;
                    }
                    if (buildWorld.isLoaded()) {
                        playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                        plugin.getEditInventory().openInventory(player, buildWorld);
                    } else {
                        XSound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR.play(player);
                        Titles.sendTitle(player, 5, 70, 20, " ", plugin.getString("world_not_loaded"));
                    }
                } else {
                    player.sendMessage(plugin.getString("worlds_edit_usage"));
                }
                break;
            }
        case "help":
            {
                if (args.length == 1) {
                    sendHelpMessage(player, 1);
                } else if (args.length == 2) {
                    try {
                        int page = Integer.parseInt(args[1]);
                        sendHelpMessage(player, page);
                    } catch (NumberFormatException e) {
                        player.sendMessage(plugin.getString("worlds_help_invalid_page"));
                    }
                } else {
                    player.sendMessage(plugin.getString("worlds_help_usage"));
                }
                break;
            }
        case "import":
            {
                if (!player.hasPermission("buildsystem.import")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length >= 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld != null) {
                        player.sendMessage(plugin.getString("worlds_import_world_is_imported"));
                        return true;
                    }
                    File worldFolder = new File(Bukkit.getWorldContainer(), args[1]);
                    File levelFile = new File(worldFolder.getAbsolutePath() + File.separator + "level.dat");
                    if (!worldFolder.isDirectory() || !levelFile.exists()) {
                        player.sendMessage(plugin.getString("worlds_import_unknown_world"));
                        return true;
                    }
                    if (args.length == 2) {
                        worldManager.importWorld(player, args[1], Generator.VOID);
                    } else if (args.length == 4) {
                        if (!args[2].equalsIgnoreCase("-g")) {
                            player.sendMessage(plugin.getString("worlds_import_usage"));
                            return true;
                        }
                        Generator generator;
                        try {
                            generator = Generator.valueOf(args[3].toUpperCase());
                        } catch (IllegalArgumentException e) {
                            generator = Generator.CUSTOM;
                        }
                        worldManager.importWorld(player, args[1], generator, args[3]);
                    } else {
                        player.sendMessage(plugin.getString("worlds_import_usage"));
                    }
                } else {
                    player.sendMessage(plugin.getString("worlds_import_usage"));
                }
                break;
            }
        case "importall":
            {
                if (!player.hasPermission("buildsystem.import.all")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 1) {
                    File worldContainer = Bukkit.getWorldContainer();
                    String[] directories = worldContainer.list((dir, name) -> {
                        File worldFolder = new File(dir, name);
                        if (!worldFolder.isDirectory()) {
                            return false;
                        }
                        File levelFile = new File(dir + File.separator + name + File.separator + "level.dat");
                        if (!levelFile.exists()) {
                            return false;
                        }
                        BuildWorld buildWorld = worldManager.getBuildWorld(name);
                        return buildWorld == null;
                    });
                    if (directories == null || directories.length == 0) {
                        player.sendMessage(plugin.getString("worlds_importall_no_worlds"));
                        return true;
                    }
                    worldManager.importWorlds(player, directories);
                } else {
                    player.sendMessage(plugin.getString("worlds_importall_usage"));
                }
                break;
            }
        case "info":
            {
                World playerWorld = player.getWorld();
                if (args.length != 2) {
                    // When running /worlds info, use the player's world when checking for permission
                    worldName = playerWorld.getName();
                }
                if (!plugin.isPermitted(player, "buildsystem.info", worldName)) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                BuildWorld buildWorld = worldManager.getBuildWorld(playerWorld.getName());
                if (args.length == 2) {
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_info_unknown_world"));
                        return true;
                    }
                    buildWorld = worldManager.getBuildWorld(args[1]);
                } else {
                    player.sendMessage(plugin.getString("worlds_info_usage"));
                }
                sendInfoMessage(player, buildWorld);
                break;
            }
        case "item":
            {
                if (!player.hasPermission("buildsystem.navigator.item")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                player.getInventory().addItem(inventoryManager.getItemStack(plugin.getConfigValues().getNavigatorItem(), plugin.getString("navigator_item")));
                player.sendMessage(plugin.getString("worlds_item_receive"));
                break;
            }
        case "removebuilder":
            {
                if (!plugin.isPermitted(player, "buildsystem.removebuilder", worldName)) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_removebuilder_unknown_world"));
                        return true;
                    }
                    if (!buildWorld.isCreator(player) && !player.hasPermission(BuildSystem.ADMIN_PERMISSION)) {
                        player.sendMessage(plugin.getString("worlds_removebuilder_not_creator"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    getRemoveBuilderInput(player, true);
                } else {
                    player.sendMessage(plugin.getString("worlds_removebuilder_usage"));
                }
                break;
            }
        case "rename":
            {
                if (!plugin.isPermitted(player, "buildsystem.rename", worldName)) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_rename_unknown_world"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    getRenameInput(player);
                } else {
                    player.sendMessage(plugin.getString("worlds_rename_usage"));
                }
                break;
            }
        case "setcreator":
            {
                if (!plugin.isPermitted(player, "buildsystem.setcreator", worldName)) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_setcreator_unknown_world"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    getCreatorInput(player);
                } else {
                    player.sendMessage(plugin.getString("worlds_setcreator_usage"));
                }
                break;
            }
        case "setitem":
            {
                if (!plugin.isPermitted(player, "buildsystem.setitem", worldName)) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_setitem_unknown_world"));
                        return true;
                    }
                    ItemStack itemStack = player.getItemInHand();
                    if (itemStack.getType().equals(Material.AIR)) {
                        player.sendMessage(plugin.getString("worlds_setitem_hand_empty"));
                        return true;
                    }
                    buildWorld.setMaterial(XMaterial.matchXMaterial(itemStack));
                    player.sendMessage(plugin.getString("worlds_setitem_set").replace("%world%", buildWorld.getName()));
                } else {
                    player.sendMessage(plugin.getString("worlds_setitem_usage"));
                }
                break;
            }
        case "setpermission":
            {
                if (!plugin.isPermitted(player, "buildsystem.setpermission", worldName)) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_setpermission_unknown_world"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    getPermissionInput(player, true);
                } else {
                    player.sendMessage(plugin.getString("worlds_setpermission_usage"));
                }
                break;
            }
        case "setproject":
            {
                if (!plugin.isPermitted(player, "buildsystem.setproject", worldName)) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_setproject_unknown_world"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    getProjectInput(player, true);
                } else {
                    player.sendMessage(plugin.getString("worlds_setproject_usage"));
                }
                break;
            }
        case "setstatus":
            {
                if (!plugin.isPermitted(player, "buildsystem.setstatus", worldName)) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_setstatus_unknown_world"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    plugin.getStatusInventory().openInventory(player);
                } else {
                    player.sendMessage(plugin.getString("worlds_setstatus_usage"));
                }
                break;
            }
        case "setspawn":
            {
                String playerWorldName = player.getWorld().getName();
                if (!plugin.isPermitted(player, "buildsystem.setspawn", playerWorldName)) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                BuildWorld buildWorld = worldManager.getBuildWorld(playerWorldName);
                if (buildWorld == null) {
                    player.sendMessage(plugin.getString("worlds_setspawn_world_not_imported"));
                    return true;
                }
                buildWorld.setCustomSpawn(player.getLocation());
                player.sendMessage(plugin.getString("worlds_setspawn_world_spawn_set").replace("%world%", buildWorld.getName()));
                break;
            }
        case "removespawn":
            {
                String playerWorldName = player.getWorld().getName();
                if (!plugin.isPermitted(player, "buildsystem.removespawn", playerWorldName)) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
                if (buildWorld == null) {
                    player.sendMessage(plugin.getString("worlds_removespawn_world_not_imported"));
                    return true;
                }
                buildWorld.removeCustomSpawn();
                player.sendMessage(plugin.getString("worlds_removespawn_world_spawn_removed").replace("%world%", buildWorld.getName()));
                break;
            }
        case "tp":
            {
                if (!player.hasPermission("buildsystem.worldtp")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_tp_unknown_world"));
                        return true;
                    }
                    World bukkitWorld = Bukkit.getServer().getWorld(args[1]);
                    if (buildWorld.isLoaded() && bukkitWorld == null) {
                        player.sendMessage(plugin.getString("worlds_tp_unknown_world"));
                        return true;
                    }
                    if (player.hasPermission(buildWorld.getPermission()) || buildWorld.getPermission().equalsIgnoreCase("-")) {
                        worldManager.teleport(player, buildWorld);
                    } else {
                        player.sendMessage(plugin.getString("worlds_tp_entry_forbidden"));
                    }
                    return true;
                } else {
                    player.sendMessage(plugin.getString("worlds_tp_usage"));
                }
                break;
            }
        case "unimport":
            {
                if (!player.hasPermission("buildsystem.unimport")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_unimport_unknown_world"));
                        return true;
                    }
                    worldManager.unimportWorld(buildWorld, true);
                    player.sendMessage(plugin.getString("worlds_unimport_finished").replace("%world%", buildWorld.getName()));
                } else {
                    player.sendMessage(plugin.getString("worlds_unimport_usage"));
                }
                break;
            }
        default:
            {
                player.sendMessage(plugin.getString("worlds_unknown_command"));
                break;
            }
    }
    return true;
}
Also used : BuildSystem(com.eintosti.buildsystem.BuildSystem) Builder(com.eintosti.buildsystem.object.world.Builder) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) TextComponent(net.md_5.bungee.api.chat.TextComponent) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) Location(org.bukkit.Location) World(org.bukkit.World) Generator(com.eintosti.buildsystem.object.world.generator.Generator) PlayerChatInput(com.eintosti.buildsystem.util.external.PlayerChatInput) UUIDFetcher(com.eintosti.buildsystem.util.UUIDFetcher) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) XSound(com.cryptomorin.xseries.XSound) CommandSender(org.bukkit.command.CommandSender) InventoryManager(com.eintosti.buildsystem.manager.InventoryManager) PlayerManager(com.eintosti.buildsystem.manager.PlayerManager) UUID(java.util.UUID) CommandExecutor(org.bukkit.command.CommandExecutor) File(java.io.File) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Command(org.bukkit.command.Command) WorldManager(com.eintosti.buildsystem.manager.WorldManager) NotNull(org.jetbrains.annotations.NotNull) XMaterial(com.cryptomorin.xseries.XMaterial) Titles(com.cryptomorin.xseries.messages.Titles) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) World(org.bukkit.World) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) ItemStack(org.bukkit.inventory.ItemStack) File(java.io.File) Generator(com.eintosti.buildsystem.object.world.generator.Generator)

Example 4 with Generator

use of com.eintosti.buildsystem.object.world.generator.Generator in project BuildSystem by einTosti.

the class WorldsCommand method onCommand.

@Override
@SuppressWarnings("deprecation")
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
    if (!(sender instanceof Player)) {
        plugin.getLogger().warning(plugin.getString("sender_not_player"));
        return true;
    }
    Player player = (Player) sender;
    if (args.length == 0) {
        if (!player.hasPermission("buildsystem.gui")) {
            plugin.sendPermissionMessage(player);
            return true;
        }
        plugin.getNavigatorInventory().openInventory(player);
        XSound.BLOCK_CHEST_OPEN.play(player);
        return true;
    }
    switch(args[0].toLowerCase()) {
        case "addbuilder":
            {
                if (!player.hasPermission("buildsystem.addbuilder")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_addbuilder_unknown_world"));
                        return true;
                    }
                    if ((buildWorld.getCreatorId() == null || !buildWorld.getCreatorId().equals(player.getUniqueId())) && !player.hasPermission("buildsystem.admin")) {
                        player.sendMessage(plugin.getString("worlds_addbuilder_not_creator"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    getAddBuilderInput(player, true);
                } else {
                    player.sendMessage(plugin.getString("worlds_addbuilder_usage"));
                }
                break;
            }
        case "builders":
            {
                if (!player.hasPermission("buildsystem.builders")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_builders_unknown_world"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    player.openInventory(plugin.getBuilderInventory().getInventory(buildWorld, player));
                } else {
                    player.sendMessage(plugin.getString("worlds_builders_usage"));
                }
                break;
            }
        case "delete":
            {
                if (!player.hasPermission("buildsystem.delete")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_delete_unknown_world"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    plugin.getDeleteInventory().openInventory(player, buildWorld);
                } else {
                    player.sendMessage(plugin.getString("worlds_delete_usage"));
                }
                break;
            }
        case "edit":
            {
                if (!player.hasPermission("buildsystem.edit")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_edit_unknown_world"));
                        return true;
                    }
                    if (buildWorld.isLoaded()) {
                        playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                        plugin.getEditInventory().openInventory(player, buildWorld);
                    } else {
                        XSound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR.play(player);
                        Titles.sendTitle(player, 5, 70, 20, " ", plugin.getString("world_not_loaded"));
                    }
                } else {
                    player.sendMessage(plugin.getString("worlds_edit_usage"));
                }
                break;
            }
        case "help":
            {
                if (args.length == 1) {
                    sendHelpMessage(player, 1);
                } else if (args.length == 2) {
                    try {
                        int page = Integer.parseInt(args[1]);
                        sendHelpMessage(player, page);
                    } catch (NumberFormatException e) {
                        player.sendMessage(plugin.getString("worlds_help_invalid_page"));
                    }
                } else {
                    player.sendMessage(plugin.getString("worlds_help_usage"));
                }
                break;
            }
        case "import":
            {
                if (!player.hasPermission("buildsystem.import")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length >= 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld != null) {
                        player.sendMessage(plugin.getString("worlds_import_world_is_imported"));
                        return true;
                    }
                    File worldFolder = new File(Bukkit.getWorldContainer(), args[1]);
                    File levelFile = new File(worldFolder.getAbsolutePath() + File.separator + "level.dat");
                    if (!worldFolder.isDirectory() || !levelFile.exists()) {
                        player.sendMessage(plugin.getString("worlds_import_unknown_world"));
                        return true;
                    }
                    if (args.length == 2) {
                        worldManager.importWorld(player, args[1], Generator.VOID);
                    } else if (args.length == 4) {
                        if (!args[2].equalsIgnoreCase("-g")) {
                            player.sendMessage(plugin.getString("worlds_import_usage"));
                            return true;
                        }
                        Generator generator;
                        boolean customGenerator = false;
                        switch(args[3].toLowerCase()) {
                            case "normal":
                                generator = Generator.NORMAL;
                                break;
                            case "flat":
                                generator = Generator.FLAT;
                                break;
                            case "void":
                                generator = Generator.VOID;
                                break;
                            default:
                                generator = Generator.CUSTOM;
                                customGenerator = true;
                                break;
                        }
                        if (!customGenerator) {
                            worldManager.importWorld(player, args[1], generator);
                        } else {
                            worldManager.importWorld(player, args[1], generator, args[3]);
                        }
                    } else {
                        player.sendMessage(plugin.getString("worlds_import_usage"));
                    }
                } else {
                    player.sendMessage(plugin.getString("worlds_import_usage"));
                }
                break;
            }
        case "importall":
            {
                if (!player.hasPermission("buildsystem.import.all")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 1) {
                    File worldContainer = Bukkit.getWorldContainer();
                    String[] directories = worldContainer.list((dir, name) -> {
                        File worldFolder = new File(dir, name);
                        if (!worldFolder.isDirectory()) {
                            return false;
                        }
                        File levelFile = new File(dir + File.separator + name + File.separator + "level.dat");
                        if (!levelFile.exists()) {
                            return false;
                        }
                        BuildWorld buildWorld = worldManager.getBuildWorld(name);
                        return buildWorld == null;
                    });
                    if (directories == null || directories.length == 0) {
                        player.sendMessage(plugin.getString("worlds_importall_no_worlds"));
                        return true;
                    }
                    worldManager.importWorlds(player, directories);
                } else {
                    player.sendMessage(plugin.getString("worlds_importall_usage"));
                }
                break;
            }
        case "info":
            {
                if (!player.hasPermission("buildsystem.info")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
                if (args.length == 2) {
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_info_unknown_world"));
                        return true;
                    }
                    buildWorld = worldManager.getBuildWorld(args[1]);
                } else if (args.length > 2) {
                    player.sendMessage(plugin.getString("worlds_info_usage"));
                }
                sendInfoMessage(player, buildWorld);
                break;
            }
        case "item":
            {
                player.getInventory().addItem(inventoryManager.getItemStack(plugin.getConfigValues().getNavigatorItem(), plugin.getString("navigator_item")));
                player.sendMessage(plugin.getString("worlds_item_receive"));
                break;
            }
        case "removebuilder":
            {
                if (!player.hasPermission("buildsystem.removebuilder")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_removebuilder_unknown_world"));
                        return true;
                    }
                    if ((buildWorld.getCreatorId() == null || !buildWorld.getCreatorId().equals(player.getUniqueId())) && !player.hasPermission("buildsystem.admin")) {
                        player.sendMessage(plugin.getString("worlds_removebuilder_not_creator"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    getRemoveBuilderInput(player, true);
                } else {
                    player.sendMessage(plugin.getString("worlds_removebuilder_usage"));
                }
                break;
            }
        case "rename":
            {
                if (!player.hasPermission("buildsystem.rename")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_rename_unknown_world"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    getRenameInput(player);
                } else {
                    player.sendMessage(plugin.getString("worlds_rename_usage"));
                }
                break;
            }
        case "setcreator":
            {
                if (!player.hasPermission("buildsystem.setcreator")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_setcreator_unknown_world"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    getCreatorInput(player);
                } else {
                    player.sendMessage(plugin.getString("worlds_setcreator_usage"));
                }
                break;
            }
        case "setitem":
            {
                if (!player.hasPermission("buildsystem.setitem")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_setitem_unknown_world"));
                        return true;
                    }
                    ItemStack itemStack = player.getItemInHand();
                    if (itemStack.getType().equals(Material.AIR)) {
                        player.sendMessage(plugin.getString("worlds_setitem_hand_empty"));
                        return true;
                    }
                    buildWorld.setMaterial(XMaterial.matchXMaterial(itemStack));
                    player.sendMessage(plugin.getString("worlds_setitem_set").replace("%world%", buildWorld.getName()));
                } else {
                    player.sendMessage(plugin.getString("worlds_setitem_usage"));
                }
                break;
            }
        case "setpermission":
            {
                if (!player.hasPermission("buildsystem.setpermission")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_setpermission_unknown_world"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    getPermissionInput(player, true);
                } else {
                    player.sendMessage(plugin.getString("worlds_setpermission_usage"));
                }
                break;
            }
        case "setproject":
            {
                if (!player.hasPermission("buildsystem.setproject")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_setproject_unknown_world"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    getProjectInput(player, true);
                } else {
                    player.sendMessage(plugin.getString("worlds_setproject_usage"));
                }
                break;
            }
        case "setstatus":
            {
                if (!player.hasPermission("buildsystem.setstatus")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_setstatus_unknown_world"));
                        return true;
                    }
                    playerManager.getSelectedWorld().put(player.getUniqueId(), buildWorld);
                    plugin.getStatusInventory().openInventory(player);
                } else {
                    player.sendMessage(plugin.getString("worlds_setstatus_usage"));
                }
                break;
            }
        case "setspawn":
            {
                if (!player.hasPermission("buildsystem.setspawn")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
                if (buildWorld == null) {
                    player.sendMessage(plugin.getString("worlds_setspawn_world_not_imported"));
                    return true;
                }
                buildWorld.setCustomSpawn(player.getLocation());
                player.sendMessage(plugin.getString("worlds_setspawn_world_spawn_set").replace("%world%", buildWorld.getName()));
                break;
            }
        case "removespawn":
            {
                if (!player.hasPermission("buildsystem.removespawn")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                BuildWorld buildWorld = worldManager.getBuildWorld(player.getWorld().getName());
                if (buildWorld == null) {
                    player.sendMessage(plugin.getString("worlds_removespawn_world_not_imported"));
                    return true;
                }
                buildWorld.removeCustomSpawn();
                player.sendMessage(plugin.getString("worlds_removespawn_world_spawn_removed").replace("%world%", buildWorld.getName()));
                break;
            }
        case "tp":
            {
                if (!player.hasPermission("buildsystem.worldtp")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_tp_unknown_world"));
                        return true;
                    }
                    World bukkitWorld = Bukkit.getServer().getWorld(args[1]);
                    if (buildWorld.isLoaded() && bukkitWorld == null) {
                        player.sendMessage(plugin.getString("worlds_tp_unknown_world"));
                        return true;
                    }
                    if (player.hasPermission(buildWorld.getPermission()) || buildWorld.getPermission().equalsIgnoreCase("-")) {
                        worldManager.teleport(player, buildWorld);
                    } else {
                        player.sendMessage(plugin.getString("worlds_tp_entry_forbidden"));
                    }
                    return true;
                } else {
                    player.sendMessage(plugin.getString("worlds_tp_usage"));
                }
                break;
            }
        case "unimport":
            {
                if (!player.hasPermission("buildsystem.unimport")) {
                    plugin.sendPermissionMessage(player);
                    return true;
                }
                if (args.length == 2) {
                    BuildWorld buildWorld = worldManager.getBuildWorld(args[1]);
                    if (buildWorld == null) {
                        player.sendMessage(plugin.getString("worlds_unimport_unknown_world"));
                        return true;
                    }
                    worldManager.unimportWorld(buildWorld);
                    player.sendMessage(plugin.getString("worlds_unimport_finished").replace("%world%", buildWorld.getName()));
                } else {
                    player.sendMessage(plugin.getString("worlds_unimport_usage"));
                }
                break;
            }
        default:
            {
                player.sendMessage(plugin.getString("worlds_unknown_command"));
                break;
            }
    }
    return true;
}
Also used : BuildSystem(com.eintosti.buildsystem.BuildSystem) Builder(com.eintosti.buildsystem.object.world.Builder) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) Player(org.bukkit.entity.Player) UUIDFetcher(com.eintosti.buildsystem.util.external.UUIDFetcher) ArrayList(java.util.ArrayList) TextComponent(net.md_5.bungee.api.chat.TextComponent) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) Location(org.bukkit.Location) World(org.bukkit.World) Generator(com.eintosti.buildsystem.object.world.generator.Generator) PlayerChatInput(com.eintosti.buildsystem.util.external.PlayerChatInput) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) XSound(com.cryptomorin.xseries.XSound) CommandSender(org.bukkit.command.CommandSender) InventoryManager(com.eintosti.buildsystem.manager.InventoryManager) PlayerManager(com.eintosti.buildsystem.manager.PlayerManager) UUID(java.util.UUID) CommandExecutor(org.bukkit.command.CommandExecutor) File(java.io.File) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Command(org.bukkit.command.Command) WorldManager(com.eintosti.buildsystem.manager.WorldManager) NotNull(org.jetbrains.annotations.NotNull) XMaterial(com.cryptomorin.xseries.XMaterial) Titles(com.cryptomorin.xseries.messages.Titles) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) World(org.bukkit.World) BuildWorld(com.eintosti.buildsystem.object.world.BuildWorld) File(java.io.File) Generator(com.eintosti.buildsystem.object.world.generator.Generator)

Aggregations

BuildSystem (com.eintosti.buildsystem.BuildSystem)4 WorldManager (com.eintosti.buildsystem.manager.WorldManager)4 BuildWorld (com.eintosti.buildsystem.object.world.BuildWorld)4 Generator (com.eintosti.buildsystem.object.world.generator.Generator)4 File (java.io.File)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Bukkit (org.bukkit.Bukkit)4 Command (org.bukkit.command.Command)4 CommandSender (org.bukkit.command.CommandSender)4 Player (org.bukkit.entity.Player)4 NotNull (org.jetbrains.annotations.NotNull)4 XMaterial (com.cryptomorin.xseries.XMaterial)2 XSound (com.cryptomorin.xseries.XSound)2 Titles (com.cryptomorin.xseries.messages.Titles)2 InventoryManager (com.eintosti.buildsystem.manager.InventoryManager)2 PlayerManager (com.eintosti.buildsystem.manager.PlayerManager)2 Builder (com.eintosti.buildsystem.object.world.Builder)2 PlayerChatInput (com.eintosti.buildsystem.util.external.PlayerChatInput)2 UUID (java.util.UUID)2