Search in sources :

Example 1 with LibraryFile

use of riskyken.armourersWorkshop.common.library.LibraryFile in project Armourers-Workshop by RiskyKen.

the class GuiSkinLibrary method fileExists.

private boolean fileExists(String path, String name) {
    LibraryFileList fileList = getFileList(fileSwitchType);
    ArrayList<LibraryFile> files = fileList.getFileList();
    for (int i = 0; i < files.size(); i++) {
        LibraryFile file = files.get(i);
        if (file.getFullName().equalsIgnoreCase(path + name)) {
            return true;
        }
    }
    return false;
}
Also used : LibraryFileList(riskyken.armourersWorkshop.common.library.LibraryFileList) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile)

Example 2 with LibraryFile

use of riskyken.armourersWorkshop.common.library.LibraryFile in project Armourers-Workshop by RiskyKen.

the class CommonProxy method skinLibraryCommand.

public void skinLibraryCommand(EntityPlayerMP player, SkinLibraryCommand command, LibraryFile file, boolean publicList) {
    if (!publicList) {
    // file = new LibraryFile(file.fileName, "/private/" + player.getUniqueID().toString() + file.filePath, file.skinType, file.isDirectory());
    }
    switch(command) {
        case DELETE:
            if (!publicList) {
                File dir = new File(SkinIOUtils.getSkinLibraryDirectory(), file.filePath);
                if (file.isDirectory()) {
                    dir = new File(dir, file.fileName + "/");
                } else {
                    dir = new File(dir, file.fileName + SkinIOUtils.SKIN_FILE_EXTENSION);
                }
                if (dir.isDirectory() == file.isDirectory()) {
                    if (dir.exists()) {
                        if (file.isDirectory()) {
                            try {
                                FileUtils.deleteDirectory(dir);
                                libraryManager.reloadLibrary();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        } else {
                            clearFiles.add(file);
                            ModLogger.log("deleting skin " + dir.getAbsolutePath());
                            dir.delete();
                            libraryManager.removeFileFromListType(file, LibraryFileType.SERVER_PRIVATE, player);
                            libraryManager.reloadLibrary(this);
                        }
                    }
                }
            } else {
                ModLogger.log("public delete");
            }
            break;
        case NEW_FOLDER:
            if (!publicList) {
                File dir = new File(SkinIOUtils.getSkinLibraryDirectory(), file.filePath);
                ModLogger.log(dir.getAbsolutePath());
                dir = new File(dir, file.fileName);
                if (!dir.exists()) {
                    dir.mkdir();
                }
                // TODO don't reload the library just add the folder
                libraryManager.reloadLibrary();
                ModLogger.log(String.format("making folder call %s in %s", file.fileName, file.filePath));
                ModLogger.log("full path: " + dir.getAbsolutePath());
            } else {
                ModLogger.log("public new folder");
            }
            break;
    }
}
Also used : IOException(java.io.IOException) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile) File(java.io.File)

Example 3 with LibraryFile

use of riskyken.armourersWorkshop.common.library.LibraryFile in project Armourers-Workshop by RiskyKen.

the class SkinIdentifierSerializer method readFromCompound.

public static SkinIdentifier readFromCompound(NBTTagCompound compound) {
    int localId = 0;
    ILibraryFile libraryFile = null;
    int globalId = 0;
    ISkinType skinType = null;
    NBTTagCompound idDataCompound = compound.getCompoundTag(TAG_SKIN_ID_DATA);
    localId = idDataCompound.getInteger(TAG_SKIN_LOCAL_ID);
    if (idDataCompound.hasKey(TAG_SKIN_LIBRARY_FILE, NBT.TAG_STRING)) {
        libraryFile = new LibraryFile(idDataCompound.getString(TAG_SKIN_LIBRARY_FILE));
    }
    globalId = idDataCompound.getInteger(TAG_SKIN_GLOBAL_ID);
    skinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(idDataCompound.getString(TAG_SKIN_TYPE));
    if (compound.hasKey(TAG_SKIN_OLD_ID, NBT.TAG_INT)) {
        localId = compound.getInteger(TAG_SKIN_OLD_ID);
    }
    if (compound.hasKey(TAG_SKIN_TYPE, NBT.TAG_STRING)) {
        skinType = SkinTypeRegistry.INSTANCE.getSkinTypeFromRegistryName(compound.getString(TAG_SKIN_TYPE));
    }
    return new SkinIdentifier(localId, libraryFile, globalId, skinType);
}
Also used : ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ILibraryFile(riskyken.armourersWorkshop.api.common.library.ILibraryFile) ILibraryFile(riskyken.armourersWorkshop.api.common.library.ILibraryFile) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile) ISkinIdentifier(riskyken.armourersWorkshop.api.common.skin.data.ISkinIdentifier) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)

Example 4 with LibraryFile

use of riskyken.armourersWorkshop.common.library.LibraryFile in project Armourers-Workshop by RiskyKen.

the class EntitySkinHandler method getRandomSkinOfType.

public LibraryFile getRandomSkinOfType(ISkinType skinType) {
    ILibraryManager libraryManager = ArmourersWorkshop.getProxy().libraryManager;
    LibraryFileList fileList = null;
    if (ArmourersWorkshop.isDedicated()) {
        fileList = libraryManager.getServerPublicFileList();
    } else {
        fileList = libraryManager.getClientPublicFileList();
    }
    ArrayList<LibraryFile> typeList = fileList.getCachedFileListForSkinType(skinType);
    if (typeList == null) {
        return null;
    }
    ArrayList<LibraryFile> validFiles = new ArrayList<LibraryFile>();
    for (int i = 0; i < typeList.size(); i++) {
        if (typeList.get(i).filePath.startsWith(ConfigHandler.enitiySpawnSkinTargetPath)) {
            validFiles.add(typeList.get(i));
        }
    }
    // touhou
    Random random = new Random();
    if (!validFiles.isEmpty()) {
        return validFiles.get(random.nextInt(validFiles.size()));
    }
    return null;
}
Also used : Random(java.util.Random) LibraryFileList(riskyken.armourersWorkshop.common.library.LibraryFileList) ILibraryManager(riskyken.armourersWorkshop.common.library.ILibraryManager) ArrayList(java.util.ArrayList) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile)

Example 5 with LibraryFile

use of riskyken.armourersWorkshop.common.library.LibraryFile in project Armourers-Workshop by RiskyKen.

the class EntitySkinHandler method giveRandomSkin.

public void giveRandomSkin(ExPropsEntityEquipmentData entityEquipmentData) {
    if (entityEquipmentData == null) {
        return;
    }
    if (ConfigHandler.enitiySpawnWithSkinsChance <= 0) {
        return;
    }
    ArrayList<ISkinType> skinTypes = entityEquipmentData.getSkinInventory().getSkinTypes();
    for (int i = 0; i < skinTypes.size(); i++) {
        int rnd = entityEquipmentData.getEntity().worldObj.rand.nextInt(99) + 1;
        if (rnd >= ConfigHandler.enitiySpawnWithSkinsChance) {
            continue;
        }
        ISkinType skinType = skinTypes.get(i);
        LibraryFile libraryFile = getRandomSkinOfType(skinType);
        if (libraryFile == null) {
            continue;
        }
        SkinIdentifier identifier = new SkinIdentifier(0, libraryFile, 0, skinType);
        ItemStack skinStack = SkinNBTHelper.makeEquipmentSkinStack(new SkinPointer(identifier));
        if (skinStack == null) {
            continue;
        }
        entityEquipmentData.getSkinInventory().setInventorySlotContents(i, skinStack);
    }
}
Also used : ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) SkinPointer(riskyken.armourersWorkshop.common.skin.data.SkinPointer) ISkinPointer(riskyken.armourersWorkshop.api.common.skin.data.ISkinPointer) LibraryFile(riskyken.armourersWorkshop.common.library.LibraryFile) ItemStack(net.minecraft.item.ItemStack) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)

Aggregations

LibraryFile (riskyken.armourersWorkshop.common.library.LibraryFile)15 Skin (riskyken.armourersWorkshop.common.skin.data.Skin)8 SkinIdentifier (riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)8 SkinPointer (riskyken.armourersWorkshop.common.skin.data.SkinPointer)7 ItemStack (net.minecraft.item.ItemStack)6 ISkinType (riskyken.armourersWorkshop.api.common.skin.type.ISkinType)3 ItemSkin (riskyken.armourersWorkshop.common.items.ItemSkin)3 ILibraryManager (riskyken.armourersWorkshop.common.library.ILibraryManager)3 MessageServerLibrarySendSkin (riskyken.armourersWorkshop.common.network.messages.server.MessageServerLibrarySendSkin)3 Color (java.awt.Color)2 File (java.io.File)2 IOException (java.io.IOException)2 WrongUsageException (net.minecraft.command.WrongUsageException)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 GuiFileListItem (riskyken.armourersWorkshop.client.gui.controls.GuiFileListItem)2 LibraryFileList (riskyken.armourersWorkshop.common.library.LibraryFileList)2 MessageClientGuiLoadSaveArmour (riskyken.armourersWorkshop.common.network.messages.client.MessageClientGuiLoadSaveArmour)2 SkinDye (riskyken.armourersWorkshop.common.skin.data.SkinDye)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1