Search in sources :

Example 61 with WarningMessage

use of com.magmaguy.elitemobs.utils.WarningMessage in project EliteMobs by MagmaGuy.

the class ConfigurationImporter method initializeConfigs.

public static void initializeConfigs() {
    Path configurationsPath = Paths.get(MetadataHandler.PLUGIN.getDataFolder().getAbsolutePath());
    if (!Files.isDirectory(Paths.get(configurationsPath.normalize() + "" + File.separatorChar + "imports"))) {
        try {
            Files.createDirectory(Paths.get(configurationsPath.normalize() + "" + File.separatorChar + "imports"));
        } catch (Exception exception) {
            new WarningMessage("Failed to create import directory! Tell the dev!");
            exception.printStackTrace();
        }
        return;
    }
    File importsFile = null;
    try {
        importsFile = new File(Paths.get(MetadataHandler.PLUGIN.getDataFolder().getCanonicalPath() + File.separatorChar + "imports").toString());
    } catch (Exception ex) {
        new WarningMessage("Failed to get imports folder! Report this to the dev!");
        return;
    }
    if (importsFile.listFiles().length == 0)
        return;
    boolean importedModels = false;
    for (File zippedFile : importsFile.listFiles()) {
        File unzippedFile;
        try {
            if (zippedFile.getName().contains(".zip"))
                unzippedFile = ZipFile.unzip(zippedFile.getName());
            else
                unzippedFile = zippedFile;
        } catch (Exception e) {
            new WarningMessage("Failed to unzip config file " + zippedFile.getName() + " ! Tell the dev!");
            e.printStackTrace();
            continue;
        }
        try {
            for (File file : unzippedFile.listFiles()) {
                switch(file.getName()) {
                    case "custombosses":
                        moveDirectory(file, Paths.get(configurationsPath.normalize() + "" + File.separatorChar + "custombosses"));
                        break;
                    case "customitems":
                        moveDirectory(file, Paths.get(configurationsPath.normalize() + "" + File.separatorChar + "customitems"));
                        break;
                    case "customtreasurechests":
                        moveDirectory(file, Paths.get(configurationsPath.normalize() + "" + File.separatorChar + "customtreasurechests"));
                        break;
                    case "dungeonpackages":
                        moveDirectory(file, Paths.get(configurationsPath.normalize() + "" + File.separatorChar + "dungeonpackages"));
                        break;
                    case "customevents":
                        moveDirectory(file, Paths.get(configurationsPath.normalize() + "" + File.separatorChar + "customevents"));
                        break;
                    case "customspawns":
                        moveDirectory(file, Paths.get(configurationsPath.normalize() + "" + File.separatorChar + "customspawns"));
                        break;
                    case "customquests":
                        moveDirectory(file, Paths.get(configurationsPath.normalize() + "" + File.separatorChar + "customquests"));
                        break;
                    case "npcs":
                        moveDirectory(file, Paths.get(configurationsPath.normalize() + "" + File.separatorChar + "npcs"));
                        break;
                    case "wormholes":
                        moveDirectory(file, Paths.get(configurationsPath.normalize() + "" + File.separatorChar + "wormholes"));
                        break;
                    case "worldcontainer":
                        moveWorlds(file);
                        break;
                    case "ModelEngine":
                        if (Bukkit.getPluginManager().isPluginEnabled("ModelEngine")) {
                            moveDirectory(file, Paths.get(file.getParentFile().getParentFile().getParentFile().getParentFile().toString() + File.separatorChar + "ModelEngine" + File.separatorChar + "blueprints"));
                            importedModels = true;
                        } else
                            new WarningMessage("You need ModelEngine to install custom models!");
                        break;
                    case "schematics":
                        if (Bukkit.getPluginManager().isPluginEnabled("FastAsyncWorldEdit")) {
                            moveDirectory(file, Paths.get(file.getParentFile().getParentFile().getParentFile().getParentFile().toString() + File.separatorChar + "FastAsyncWorldEdit" + File.separatorChar + "schematics"));
                        } else if (Bukkit.getPluginManager().isPluginEnabled("WorldEdit")) {
                            moveDirectory(file, Paths.get(file.getParentFile().getParentFile().getParentFile().getParentFile().toString() + File.separatorChar + "WorldEdit" + File.separatorChar + "schematics"));
                        } else
                            new WarningMessage("You need WorldGuard or FastAsyncWorldEdit to install schematic-based minidungeons!");
                        break;
                    default:
                        new WarningMessage("Directory " + file.getName() + " for zipped file " + zippedFile.getName() + " was not a recognized directory for the file import system! Was the zipped file packaged correctly?");
                }
                deleteDirectory(file);
            }
        } catch (Exception e) {
            new WarningMessage("Failed to move files from " + zippedFile.getName() + " ! Tell the dev!");
            e.printStackTrace();
            continue;
        }
        try {
            unzippedFile.delete();
            zippedFile.delete();
        } catch (Exception ex) {
            new WarningMessage("Failed to delete zipped file " + zippedFile.getName() + "! Tell the dev!");
            ex.printStackTrace();
        }
    }
    if (importedModels) {
        CustomModel.reloadModels();
        for (Player player : Bukkit.getOnlinePlayers()) if (player.hasPermission("elitemobs.*"))
            player.spigot().sendMessage(SpigotMessage.commandHoverMessage(ChatColorConverter.convert("&8[EliteMobs] &fEliteMobs just detected that recently imported files had Custom Models in them! " + "&2Click here to generate the EliteMobs resource pack for those models!"), "Clicking will run the command /em generateresourcepack", "/em generateresourcepack"));
    }
}
Also used : Path(java.nio.file.Path) WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) Player(org.bukkit.entity.Player) File(java.io.File) ZipFile(com.magmaguy.elitemobs.utils.ZipFile)

Example 62 with WarningMessage

use of com.magmaguy.elitemobs.utils.WarningMessage in project EliteMobs by MagmaGuy.

the class ConfigurationImporter method moveWorlds.

private static void moveWorlds(File worldcontainerFile) {
    for (File file : worldcontainerFile.listFiles()) try {
        File destinationFile = new File(Paths.get(Bukkit.getWorldContainer().getCanonicalPath() + File.separatorChar + file.getName()).normalize().toString());
        if (destinationFile.exists()) {
            new InfoMessage("Overriding existing directory " + destinationFile.getPath());
            if (Bukkit.getWorld(file.getName()) != null) {
                Bukkit.unloadWorld(file.getName(), false);
                new WarningMessage("Unloaded world " + file.getName() + " for safe replacement!");
            }
            deleteDirectory(destinationFile);
        }
        FileUtils.moveDirectory(file, destinationFile);
    } catch (Exception exception) {
        new WarningMessage("Failed to move worlds for " + file.getName() + "! Tell the dev!");
        exception.printStackTrace();
    }
}
Also used : WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) InfoMessage(com.magmaguy.elitemobs.utils.InfoMessage) File(java.io.File) ZipFile(com.magmaguy.elitemobs.utils.ZipFile)

Example 63 with WarningMessage

use of com.magmaguy.elitemobs.utils.WarningMessage in project EliteMobs by MagmaGuy.

the class ConfigurationImporter method moveDirectory.

private static void moveDirectory(File unzippedDirectory, Path targetPath) {
    for (File file : unzippedDirectory.listFiles()) try {
        new InfoMessage("Adding " + file.getCanonicalPath());
        moveFile(file, targetPath);
    } catch (Exception exception) {
        new WarningMessage("Failed to move directories for " + file.getName() + "! Tell the dev!");
        exception.printStackTrace();
    }
}
Also used : WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) InfoMessage(com.magmaguy.elitemobs.utils.InfoMessage) File(java.io.File) ZipFile(com.magmaguy.elitemobs.utils.ZipFile)

Example 64 with WarningMessage

use of com.magmaguy.elitemobs.utils.WarningMessage in project EliteMobs by MagmaGuy.

the class CustomConfigFields method processWorldList.

/**
 * This not only gets a list of worlds, but gets a list of already loaded worlds. This might cause issues if the worlds
 * aren't loaded when the code for getting worlds runs.
 *
 * @param path          Configuration path
 * @param pluginDefault Default value - should be null or empty
 * @return Worlds from the list that are loaded at the time this runs, probably on startup
 */
protected List<World> processWorldList(String path, List<World> value, List<World> pluginDefault, boolean forceWriteDefault) {
    if (!configHas(path)) {
        if (value != null && (forceWriteDefault || value != pluginDefault))
            processStringList(path, worldListToStringListConverter(value), worldListToStringListConverter(pluginDefault), forceWriteDefault);
        return value;
    }
    try {
        List<String> validWorldStrings = processStringList(path, worldListToStringListConverter(pluginDefault), worldListToStringListConverter(value), forceWriteDefault);
        List<World> validWorlds = new ArrayList<>();
        if (!validWorldStrings.isEmpty())
            for (String string : validWorldStrings) {
                World world = Bukkit.getWorld(string);
                if (world != null)
                    validWorlds.add(world);
            }
        return validWorlds;
    } catch (Exception ex) {
        new WarningMessage("File " + filename + " has an incorrect entry for " + path);
        new WarningMessage("Entry: " + value);
    }
    return value;
}
Also used : WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage)

Example 65 with WarningMessage

use of com.magmaguy.elitemobs.utils.WarningMessage in project EliteMobs by MagmaGuy.

the class CustomConfigFields method processItemStack.

public ItemStack processItemStack(String path, ItemStack value, ItemStack pluginDefault, boolean forceWriteDefault) {
    if (!configHas(path)) {
        if (forceWriteDefault || value != pluginDefault)
            processString(path, itemStackDeserializer(value), itemStackDeserializer(pluginDefault), forceWriteDefault);
        return value;
    }
    try {
        String materialString = processString(path, itemStackDeserializer(value), itemStackDeserializer(pluginDefault), forceWriteDefault);
        if (materialString == null)
            return null;
        if (materialString.matches("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}")) {
            ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD);
            SkullMeta skullMeta = (SkullMeta) playerHead.getItemMeta();
            skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(materialString)));
            playerHead.setItemMeta(skullMeta);
            return playerHead;
        }
        if (materialString.contains(":")) {
            ItemStack itemStack = ItemStackGenerator.generateItemStack(Material.getMaterial(materialString.split(":")[0]));
            if (materialString.split(":")[1].contains("leather_") || materialString.split(":")[1].contains("LEATHER_")) {
                LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) itemStack.getItemMeta();
                leatherArmorMeta.setColor(Color.fromRGB(Integer.parseInt(materialString.split(":")[1])));
                itemStack.setItemMeta(leatherArmorMeta);
            } else {
                ItemMeta itemMeta = itemStack.getItemMeta();
                itemMeta.setCustomModelData(Integer.parseInt(materialString.split(":")[1]));
                itemStack.setItemMeta(itemMeta);
            }
            return itemStack;
        } else
            return ItemStackGenerator.generateItemStack(Material.getMaterial(materialString));
    } catch (Exception ex) {
        new WarningMessage("File " + filename + " has an incorrect entry for " + path);
        new WarningMessage("Entry: " + value);
    }
    return value;
}
Also used : WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

WarningMessage (com.magmaguy.elitemobs.utils.WarningMessage)76 InfoMessage (com.magmaguy.elitemobs.utils.InfoMessage)11 Vector (org.bukkit.util.Vector)11 Item (org.bukkit.entity.Item)10 File (java.io.File)9 CustomBossEntity (com.magmaguy.elitemobs.mobconstructor.custombosses.CustomBossEntity)8 FlagConflictException (com.sk89q.worldguard.protection.flags.registry.FlagConflictException)7 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)6 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)6 ArrayList (java.util.ArrayList)6 ZipFile (com.magmaguy.elitemobs.utils.ZipFile)5 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)5 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)5 Location (org.bukkit.Location)5 ItemStack (org.bukkit.inventory.ItemStack)5 CustomBossesConfigFields (com.magmaguy.elitemobs.config.custombosses.CustomBossesConfigFields)3 Minidungeon (com.magmaguy.elitemobs.dungeons.Minidungeon)3 IOException (java.io.IOException)3 Material (org.bukkit.Material)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3