This commit is contained in:
cyberpwn 2021-08-27 01:35:23 -04:00
parent 08865dc218
commit a5270ccea8
4 changed files with 33 additions and 9 deletions

View File

@ -19,10 +19,14 @@
package com.volmit.iris.core.command; package com.volmit.iris.core.command;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.core.pack.IrisPack;
import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.exceptions.IrisException;
import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.MortarCommand;
import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.plugin.VolmitSender;
import java.util.concurrent.ExecutionException;
public class CommandIrisBitwise extends MortarCommand { public class CommandIrisBitwise extends MortarCommand {
public CommandIrisBitwise() { public CommandIrisBitwise() {
super("bitwise", "bits", "bw"); super("bitwise", "bits", "bw");

View File

@ -30,6 +30,7 @@ import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.io.IO; import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.json.JSONArray; import com.volmit.iris.util.json.JSONArray;
import com.volmit.iris.util.json.JSONObject; import com.volmit.iris.util.json.JSONObject;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.plugin.VolmitSender;
import com.volmit.iris.util.scheduling.PrecisionStopwatch; import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import lombok.Data; import lombok.Data;
@ -39,6 +40,8 @@ import org.zeroturnaround.zip.commons.FileUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
/** /**
* Represents an Iris pack that exists * Represents an Iris pack that exists
@ -93,7 +96,7 @@ public class IrisPack {
* @return the iris pack * @return the iris pack
* @throws IrisException fails * @throws IrisException fails
*/ */
public static IrisPack from(VolmitSender sender, String url) throws IrisException { public static Future<IrisPack> from(VolmitSender sender, String url) throws IrisException {
IrisPackRepository repo = IrisPackRepository.from(url); IrisPackRepository repo = IrisPackRepository.from(url);
if(repo == null) if(repo == null)
{ {
@ -316,9 +319,12 @@ public class IrisPack {
* @return the pack * @return the pack
* @throws MalformedURLException shit happens * @throws MalformedURLException shit happens
*/ */
public static IrisPack from(VolmitSender sender, IrisPackRepository repo) throws MalformedURLException { public static Future<IrisPack> from(VolmitSender sender, IrisPackRepository repo) throws MalformedURLException {
repo.install(sender); CompletableFuture<IrisPack> pack = new CompletableFuture<>();
return new IrisPack(repo.getRepo()); repo.install(sender, () -> {
pack.complete(new IrisPack(repo.getRepo()));
});
return pack;
} }
/** /**
@ -338,7 +344,10 @@ public class IrisPack {
File fd = new File(f, "dimensions/" + name + ".json"); File fd = new File(f, "dimensions/" + name + ".json");
fd.getParentFile().mkdirs(); fd.getParentFile().mkdirs();
try { try {
IO.writeAll(fd, "{}"); IO.writeAll(fd, "{\n" +
" \"name\": \""+Form.capitalize(name)+"\",\n" +
" \"version\": 1\n" +
"}\n");
} catch (IOException e) { } catch (IOException e) {
throw new IrisException(e.getMessage(), e); throw new IrisException(e.getMessage(), e);
} }
@ -348,9 +357,14 @@ public class IrisPack {
return pack; return pack;
} }
/**
* Get a packs pack folder for a name. Such that overworld would resolve as Iris/packs/overworld
* @param name the name
* @return the file path
*/
public static File packsPack(String name) public static File packsPack(String name)
{ {
return Iris.instance.getDataFolder(StudioSVC.WORKSPACE_NAME, name); return Iris.instance.getDataFolderNoCreate(StudioSVC.WORKSPACE_NAME, name);
} }
private static KList<File> collectFiles(File f, String fileExtension) { private static KList<File> collectFiles(File f, String fileExtension) {

View File

@ -111,8 +111,8 @@ public class IrisPackRepository {
return "https://codeload.github.com/" + user + "/" + repo + "/zip/refs/heads/" + branch; return "https://codeload.github.com/" + user + "/" + repo + "/zip/refs/heads/" + branch;
} }
public void install(VolmitSender sender) throws MalformedURLException { public void install(VolmitSender sender, Runnable whenComplete) throws MalformedURLException {
File pack = Iris.instance.getDataFolder(StudioSVC.WORKSPACE_NAME, getRepo()); File pack = Iris.instance.getDataFolderNoCreate(StudioSVC.WORKSPACE_NAME, getRepo());
if (!pack.exists()) { if (!pack.exists()) {
File dl = new File(Iris.getTemp(), "dltk-" + UUID.randomUUID() + ".zip"); File dl = new File(Iris.getTemp(), "dltk-" + UUID.randomUUID() + ".zip");
@ -126,7 +126,7 @@ public class IrisPackRepository {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
})).execute(sender); })).execute(sender, whenComplete);
} }
else else

View File

@ -48,7 +48,12 @@ public interface Job {
return (double) getWorkCompleted() / (double) getTotalWork(); return (double) getWorkCompleted() / (double) getTotalWork();
} }
default void execute(VolmitSender sender) { default void execute(VolmitSender sender) {
execute(sender, () -> {});
}
default void execute(VolmitSender sender, Runnable whenComplete) {
PrecisionStopwatch p = PrecisionStopwatch.start(); PrecisionStopwatch p = PrecisionStopwatch.start();
CompletableFuture<?> f = J.afut(this::execute); CompletableFuture<?> f = J.afut(this::execute);
int c = J.ar(() -> { int c = J.ar(() -> {
@ -61,6 +66,7 @@ public interface Job {
f.whenComplete((fs, ff) -> { f.whenComplete((fs, ff) -> {
J.car(c); J.car(c);
sender.sendMessage("Completed " + getName() + " in " + Form.duration(p.getMilliseconds(), 1)); sender.sendMessage("Completed " + getName() + " in " + Form.duration(p.getMilliseconds(), 1));
whenComplete.run();
}); });
} }
} }