Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.pulchraprospectus.installer;
- public class InstallerCallback {
- private final InstallerFrame callbackFrame;
- private final InstallerCallback.ListenerType type;
- public InstallerCallback (InstallerFrame frame, Installer installer, InstallerCallback.ListenerType listenerType) {
- this.callbackFrame = frame;
- this.type = listenerType;
- installer.addCallbackListener(this);
- }
- public void installerEventFired (InstallerEvent event) {
- if (this.type.test(event)) {
- this.type.onEvent(event);
- }
- }
- public static class ListenerType implements Predicate {
- public static final ListenerType VERIFY_LISTENER = new ListenerType(Installer::staticOnVerify, "Verify Listener");
- public static final ListenerType DOWNLOAD_LISTENER = new ListenerType(Installer::staticOnDownload, "Download Listener");
- public static final ListenerType UNPACK_LISTENER = new ListenerType(Installer::staticOnUnpack, "Unpack Listener");
- public static final ListenerType BACKUP_LISTENER = new ListenerType(Installer::staticOnBackup, "Backup Listener");
- public static final ListenerType INSTALL_LISTENER = new ListenerType(Installer::staticOnInstall, "Install Listener");
- private final Consumer<InstallerEvent> function;
- private final String name;
- public ListenerType (Consumer<InstallerEvent> trigger, String title) {
- this.function = trigger;
- this.predicate = predicate;
- this.name = title;
- }
- public boolean test (InstallerEvent event) {
- return event.getListenerType().getName() == this.getName();
- }
- public void onEvent (InstallerEvent event) {
- this.function.accept(event);
- }
- }
- }
- package net.pulchraprospectus.installer;
- public class Installer {
- public Installer (File installDirectory) {
- if (instance != null) {
- this = instance;
- } else {
- this.dir = installDirectory;
- }
- }
- public Installer setCallback (InstallerCallback callback) {
- this.callback = callback;
- return this;
- }
- public Installer getInstance () {
- return instance;
- }
- static void setInstance (Installer installer) {
- if (!installer.file.exists() || !installer.file.isDirectory() || !Verifier.verifyMinecraftIntegrity(installer.file) || !Verifier.verifyForgeIntegrity(installer.file)) throw new java.nio.file.FileSystemNotFoundException("Minecraft directory not present, or is not a directory.");
- else {
- instance = installer;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement