use of riskyken.armourersWorkshop.common.network.messages.client.MessageClientGuiSkinLibraryCommand in project Armourers-Workshop by RiskyKen.
the class GuiSkinLibrary method dialogResult.
@Override
public void dialogResult(AbstractGuiDialog dialog, DialogResult result) {
if (result == DialogResult.OK) {
if (dialog instanceof GuiDialogNewFolder) {
GuiDialogNewFolder newFolderDialog = (GuiDialogNewFolder) dialog;
if (fileSwitchType == LibraryFileType.LOCAL) {
File dir = new File(SkinIOUtils.getSkinLibraryDirectory(), currentFolder);
dir = new File(dir, newFolderDialog.getFolderName());
if (!dir.exists()) {
dir.mkdir();
}
reloadLocalLibrary();
ModLogger.log(String.format("making folder call %s in %s", newFolderDialog.getFolderName(), currentFolder));
ModLogger.log("full path: " + dir.getAbsolutePath());
} else {
MessageClientGuiSkinLibraryCommand message = new MessageClientGuiSkinLibraryCommand();
message.newFolder(new LibraryFile(newFolderDialog.getFolderName(), currentFolder, null, true), fileSwitchType == LibraryFileType.SERVER_PUBLIC);
PacketHandler.networkWrapper.sendToServer(message);
}
}
if (dialog instanceof GuiDialogDelete) {
GuiDialogDelete deleteDialog = (GuiDialogDelete) dialog;
boolean isFolder = deleteDialog.isFolder();
String name = deleteDialog.getFileName();
if (fileSwitchType == LibraryFileType.LOCAL) {
File dir = new File(SkinIOUtils.getSkinLibraryDirectory(), currentFolder);
if (deleteDialog.isFolder()) {
dir = new File(dir, name + "/");
} else {
dir = new File(dir, name + SkinIOUtils.SKIN_FILE_EXTENSION);
}
if (dir.isDirectory() == isFolder) {
if (dir.exists()) {
if (isFolder) {
try {
FileUtils.deleteDirectory(dir);
reloadLocalLibrary();
} catch (IOException e) {
e.printStackTrace();
}
} else {
LibraryFile libraryFile = new LibraryFile(currentFolder + deleteDialog.getFileName());
ClientSkinCache.INSTANCE.markSkinAsDirty(new SkinIdentifier(0, libraryFile, 0, null));
dir.delete();
reloadLocalLibrary();
}
}
}
} else {
MessageClientGuiSkinLibraryCommand message = new MessageClientGuiSkinLibraryCommand();
message.delete(new LibraryFile(deleteDialog.getFileName(), currentFolder, null, isFolder), fileSwitchType == LibraryFileType.SERVER_PUBLIC);
PacketHandler.networkWrapper.sendToServer(message);
// ClientSkinCache.INSTANCE.clearIdForFileName(currentFolder + deleteDialog.getName());
}
}
if (dialog instanceof GuiDialogOverwrite) {
GuiDialogOverwrite overwriteDialog = (GuiDialogOverwrite) dialog;
MessageClientGuiLoadSaveArmour message;
boolean clientLoad = false;
boolean publicList = true;
if (fileSwitchType == LibraryFileType.LOCAL && !mc.isIntegratedServerRunning()) {
// Is playing on a server.
clientLoad = true;
}
if (fileSwitchType == LibraryFileType.SERVER_PRIVATE) {
publicList = false;
}
if (clientLoad) {
message = new MessageClientGuiLoadSaveArmour(overwriteDialog.getFileName(), currentFolder, LibraryPacketType.CLIENT_SAVE, false, trackFile);
PacketHandler.networkWrapper.sendToServer(message);
} else {
message = new MessageClientGuiLoadSaveArmour(overwriteDialog.getFileName(), currentFolder, LibraryPacketType.SERVER_SAVE, publicList, trackFile);
PacketHandler.networkWrapper.sendToServer(message);
}
LibraryFile libraryFile = new LibraryFile(currentFolder + overwriteDialog.getFileName());
ClientSkinCache.INSTANCE.markSkinAsDirty(new SkinIdentifier(0, libraryFile, 0, null));
// reloadLocalLibrary();
// TODO clear name lookup list on clients or just removed this one name
}
}
super.dialogResult(dialog, result);
}
Aggregations