Search in sources :

Example 1 with ILibraryFile

use of riskyken.armourersWorkshop.api.common.library.ILibraryFile 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 2 with ILibraryFile

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

the class SkinCacheLocalFile method get.

public Skin get(SkinRequestMessage requestMessage, boolean softLoad) {
    ISkinIdentifier identifier = requestMessage.getSkinIdentifier();
    ILibraryFile libraryFile = identifier.getSkinLibraryFile();
    synchronized (cacheMapLock) {
        if (!cacheMapFileLink.containsKey(libraryFile)) {
            if (softLoad) {
                synchronized (skinLoadQueueLock) {
                    skinLoadQueue.add(requestMessage);
                }
                return null;
            } else {
                load(identifier);
            }
        }
        if (cacheMapFileLink.containsKey(libraryFile)) {
            int id = cacheMapFileLink.get(libraryFile);
            SkinIdentifier newIdentifier = new SkinIdentifier(id, requestMessage.getSkinIdentifier().getSkinLibraryFile(), 0, requestMessage.getSkinIdentifier().getSkinType());
            Skin skin = cacheLocalDatabase.get(newIdentifier, false);
            if (skin != null) {
                return skin;
            } else {
                ModLogger.log(Level.WARN, "Somehow failed to load a skin that we should have. ID was " + id);
            }
        } else {
            if (requestMessage.getPlayer() != null) {
                ModLogger.log(Level.ERROR, "Skin [" + libraryFile.getFullName() + "] was requested by " + requestMessage.getPlayer().getCommandSenderName() + " but was not found.");
            } else {
                ModLogger.log(Level.ERROR, "Skin [" + libraryFile.getFullName() + "] was requested but was not found.");
            }
        }
    }
    return null;
}
Also used : ISkinIdentifier(riskyken.armourersWorkshop.api.common.skin.data.ISkinIdentifier) ILibraryFile(riskyken.armourersWorkshop.api.common.library.ILibraryFile) Skin(riskyken.armourersWorkshop.common.skin.data.Skin) ISkinIdentifier(riskyken.armourersWorkshop.api.common.skin.data.ISkinIdentifier) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)

Example 3 with ILibraryFile

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

the class CommonSkinCache method itemExpired.

@Override
public void itemExpired(Skin mapItem) {
    if (mapItem == null) {
        return;
    }
    // TODO Work out why things are not always getting removed from the cache.
    int skinId = mapItem.lightHash();
    if (cacheLocalFile.containsValue(skinId)) {
        ILibraryFile libraryFile = cacheLocalFile.getBackward(skinId);
        cacheLocalFile.remove(libraryFile);
    }
    if (cacheGlobal.containsValue(skinId)) {
        int globalId = cacheGlobal.getBackward(skinId);
        cacheGlobal.remove(globalId);
    }
}
Also used : ILibraryFile(riskyken.armourersWorkshop.api.common.library.ILibraryFile)

Example 4 with ILibraryFile

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

the class CommonSkinCache method getFullIdentifier.

public SkinIdentifier getFullIdentifier(Skin skin, ISkinIdentifier skinIdentifier) {
    int localId = skin.lightHash();
    ISkinType skinType = skin.getSkinType();
    ILibraryFile libraryFile = null;
    int globalId = 0;
    try {
        if (cacheLocalFile.containsValue(skin.lightHash())) {
            libraryFile = cacheLocalFile.getBackward(skin.lightHash());
        }
        if (cacheGlobal.containsValue(skin.lightHash())) {
            globalId = cacheGlobal.getBackward(skin.lightHash());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return new SkinIdentifier(localId, libraryFile, globalId, skinType);
}
Also used : ISkinType(riskyken.armourersWorkshop.api.common.skin.type.ISkinType) ILibraryFile(riskyken.armourersWorkshop.api.common.library.ILibraryFile) ISkinIdentifier(riskyken.armourersWorkshop.api.common.skin.data.ISkinIdentifier) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)

Aggregations

ILibraryFile (riskyken.armourersWorkshop.api.common.library.ILibraryFile)4 ISkinIdentifier (riskyken.armourersWorkshop.api.common.skin.data.ISkinIdentifier)3 SkinIdentifier (riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)3 ISkinType (riskyken.armourersWorkshop.api.common.skin.type.ISkinType)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 LibraryFile (riskyken.armourersWorkshop.common.library.LibraryFile)1 Skin (riskyken.armourersWorkshop.common.skin.data.Skin)1