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