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);
}
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;
}
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);
}
}
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);
}
Aggregations