All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pepsoft.worldpainter.ExportProgressDialog Maven / Gradle / Ivy

There is a newer version: 2.23.2
Show newest version
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ExportWorldDialog.java
 *
 * Created on Mar 29, 2011, 5:09:50 PM
 */

package org.pepsoft.worldpainter;

import org.pepsoft.minecraft.ChunkFactory;
import org.pepsoft.util.*;
import org.pepsoft.util.Version;
import org.pepsoft.util.ProgressReceiver.OperationCancelled;
import org.pepsoft.util.swing.ProgressTask;
import org.pepsoft.worldpainter.exporting.WorldExportSettings;
import org.pepsoft.worldpainter.exporting.WorldExporter;
import org.pepsoft.worldpainter.plugins.PlatformManager;
import org.pepsoft.worldpainter.util.FileInUseException;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.Map;

import static org.pepsoft.minecraft.Constants.*;
import static org.pepsoft.util.ExceptionUtils.chainContains;
import static org.pepsoft.worldpainter.Constants.V_1_17;
import static org.pepsoft.worldpainter.DefaultPlugin.*;

/**
 *
 * @author pepijn
 */
public class ExportProgressDialog extends MultiProgressDialog> implements WindowListener {
    /** Creates new form ExportWorldDialog */
    public ExportProgressDialog(Window parent, World2 world, WorldExportSettings exportSettings, File baseDir, String name, String acknowledgedWarnings) {
        super(parent, "Exporting");
        this.world = world;
        this.baseDir = baseDir;
        this.name = name;
        this.exportSettings = exportSettings;
        this.acknowledgedWarnings = acknowledgedWarnings;
        addWindowListener(this);

        JButton minimiseButton = new JButton("Minimize");
        minimiseButton.addActionListener(e -> App.getInstance().setState(Frame.ICONIFIED));
        addButton(minimiseButton);
    }

    public boolean isAllowRetry() {
        return allowRetry;
    }

    // WindowListener

    @Override
    public void windowClosed(WindowEvent e) {
        // Make sure to clean up any progress that is still showing
        DesktopUtils.setProgressDone(App.getInstance());
    }

    @Override public void windowClosing(WindowEvent e) {}
    @Override public void windowOpened(WindowEvent e) {}
    @Override public void windowIconified(WindowEvent e) {}
    @Override public void windowDeiconified(WindowEvent e) {}
    @Override public void windowActivated(WindowEvent e) {}
    @Override public void windowDeactivated(WindowEvent e) {}

    // MultiProgressDialog

    @Override
    protected String getVerb() {
        return "Export";
    }

    @Override
    protected String getResultsReport(Map result, long duration) {
        StringBuilder sb = new StringBuilder();
        sb.append("World exported as ").append(new File(baseDir, FileUtils.sanitiseName(name)));
        int hours = (int) (duration / 3600);
        duration = duration - hours * 3600L;
        int minutes = (int) (duration / 60);
        int seconds = (int) (duration - minutes * 60);
        sb.append("
Export took ").append(hours).append(":").append((minutes < 10) ? "0" : "").append(minutes).append(":").append((seconds < 10) ? "0" : "").append(seconds); final Platform platform = world.getPlatform(); final Version mcVersion = platform.getAttribute(ATTRIBUTE_MC_VERSION); if ((platform == JAVA_MCREGION) && (world.getMaxHeight() != DEFAULT_MAX_HEIGHT_MCREGION)) { sb.append("

Please note: this map has a non-standard height! You need to have
an appropriate height mod installed to play it!"); } else if ((mcVersion.isAtLeast(V_1_17)) && ((world.getMaxHeight() - world.getMinHeight()) > 384)) { sb.append("

Please note: this map is more than 384 blocks high.
This may cause performance problems on lower end computers."); } if ((platform == JAVA_ANVIL_1_17) && ((world.getMinHeight() != DEFAULT_MIN_HEIGHT) || (world.getMaxHeight() != DEFAULT_MAX_HEIGHT_ANVIL))) { sb.append("

Please note: this map uses a data pack for a deviating build height.
This data pack is only compatible with Minecraft 1.17.
It is not forward compatible with newer versions of Minecraft."); } else if (((platform == JAVA_ANVIL_1_18) || (platform == JAVA_ANVIL_1_19)) && ((world.getMinHeight() != DEFAULT_MIN_HEIGHT_1_18) || (world.getMaxHeight() != DEFAULT_MAX_HEIGHT_1_18))) { sb.append("

Please note: this map uses a data pack for a deviating build height.
This data pack is only compatible with Minecraft 1.18.2 - 1.20.1.
It may not be forward compatible with newer versions of Minecraft."); } if (result.size() == 1) { ChunkFactory.Stats stats = result.get(result.keySet().iterator().next()); sb.append("

Statistics:
"); dumpStats(sb, stats, world.getMaxHeight() - world.getMinHeight()); } else { for (Map.Entry entry: result.entrySet()) { final int dim = entry.getKey(); final int height; ChunkFactory.Stats stats = entry.getValue(); switch (dim) { case Constants.DIM_NORMAL: sb.append("

Statistics for surface:
"); height = world.getMaxHeight() - world.getMinHeight(); break; case Constants.DIM_NETHER: sb.append("

Statistics for Nether:
"); height = DEFAULT_MAX_HEIGHT_NETHER; break; case Constants.DIM_END: sb.append("

Statistics for End:
"); height = DEFAULT_MAX_HEIGHT_END; break; default: sb.append("

Statistics for dimension " + dim + ":
"); height = world.getMaxHeight() - world.getMinHeight(); break; } dumpStats(sb, stats, height); } } if (backupDir.isDirectory()) { sb.append("
Backup of existing map created in:
").append(backupDir); } if ((acknowledgedWarnings != null) && (! acknowledgedWarnings.trim().isEmpty())) { sb.append("

Previously acknowledged warnings:"); sb.append(acknowledgedWarnings); } sb.append(""); return sb.toString(); } @Override protected String getCancellationMessage() { return "Export cancelled by user.\n\nThe partially exported map is now probably corrupted!\nYou should delete it, or export the map again." + (backupDir.isDirectory() ? ("\n\nBackup of existing map created in:\n" + backupDir) : ""); } @Override protected ProgressTask> getTask() { return new ProgressTask>() { @Override public String getName() { return "Exporting world " + name; } @Override public Map execute(ProgressReceiver progressReceiver) throws OperationCancelled { progressReceiver = new TaskbarProgressReceiver(App.getInstance(), progressReceiver); progressReceiver.setMessage("Exporting world " + name); WorldExporter exporter = PlatformManager.getInstance().getExporter(world, exportSettings); try { backupDir = exporter.selectBackupDir(baseDir, name); return exporter.export(baseDir, name, backupDir, progressReceiver); } catch (IOException e) { throw new RuntimeException("I/O error while exporting world", e); } catch (RuntimeException e) { if (chainContains(e, FileInUseException.class)) { allowRetry = true; } throw e; } } }; } private void dumpStats(final StringBuilder sb, final ChunkFactory.Stats stats, final int height) { final NumberFormat formatter = NumberFormat.getIntegerInstance(); final long duration = stats.time / 1000; if (stats.landArea > 0) { sb.append("Land area: " + formatter.format(stats.landArea) + " blocks
"); } if (stats.waterArea > 0) { sb.append("Water or lava area: " + formatter.format(stats.waterArea) + " blocks
"); if (stats.landArea > 0) { sb.append("Total surface area: " + formatter.format(stats.landArea + stats.waterArea) + " blocks
"); } } final long totalBlocks = stats.surfaceArea * height; if (duration > 0) { sb.append("Generated " + formatter.format(totalBlocks) + " blocks, or " + formatter.format(totalBlocks / duration) + " blocks per second
"); if (stats.size > 0) { final long kbPerSecond = stats.size / duration / 1024; sb.append("Map size: " + formatter.format(stats.size / 1024 / 1024) + " MB, or " + ((kbPerSecond < 1024) ? (formatter.format(kbPerSecond) + " KB") : (formatter.format(kbPerSecond / 1024) + " MB")) + " per second
"); } } else { sb.append("Generated " + formatter.format(totalBlocks) + " blocks
"); if (stats.size > 0) { sb.append("Map size: " + formatter.format(stats.size / 1024 / 1024) + " MB
"); } } } private final World2 world; private final String name, acknowledgedWarnings; private final File baseDir; private final WorldExportSettings exportSettings; private volatile File backupDir; private volatile boolean allowRetry = false; private static final long serialVersionUID = 1L; }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy