mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Merge remote-tracking branch 'upstream/master' into DimNameWhenNull
This commit is contained in:
commit
59b637c317
@ -19,13 +19,35 @@
|
|||||||
package com.volmit.iris.core.decrees;
|
package com.volmit.iris.core.decrees;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.IrisSettings;
|
||||||
|
import com.volmit.iris.core.project.IrisProject;
|
||||||
|
import com.volmit.iris.core.project.loader.IrisData;
|
||||||
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.engine.object.dimensional.IrisDimension;
|
import com.volmit.iris.engine.object.dimensional.IrisDimension;
|
||||||
|
import com.volmit.iris.engine.object.objects.IrisObject;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.DecreeExecutor;
|
import com.volmit.iris.util.decree.DecreeExecutor;
|
||||||
|
import com.volmit.iris.util.decree.DecreeOrigin;
|
||||||
import com.volmit.iris.util.decree.annotations.Decree;
|
import com.volmit.iris.util.decree.annotations.Decree;
|
||||||
import com.volmit.iris.util.decree.annotations.Param;
|
import com.volmit.iris.util.decree.annotations.Param;
|
||||||
import com.volmit.iris.util.format.C;
|
import com.volmit.iris.util.format.C;
|
||||||
|
import com.volmit.iris.util.io.IO;
|
||||||
|
import com.volmit.iris.util.json.JSONArray;
|
||||||
|
import com.volmit.iris.util.json.JSONObject;
|
||||||
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
|
import com.volmit.iris.util.scheduling.J;
|
||||||
|
import com.volmit.iris.util.scheduling.jobs.Job;
|
||||||
|
import com.volmit.iris.util.scheduling.jobs.JobCollection;
|
||||||
|
import com.volmit.iris.util.scheduling.jobs.QueueJob;
|
||||||
|
import com.volmit.iris.util.scheduling.jobs.SingleJob;
|
||||||
|
|
||||||
@Decree(name = "studio", aliases = {"std", "s"}, description = "Studio Commands", studio = true)
|
import java.awt.*;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
@Decree(name = "studio", aliases = "std", description = "Studio Commands", studio = true)
|
||||||
public class CMDIrisStudio implements DecreeExecutor
|
public class CMDIrisStudio implements DecreeExecutor
|
||||||
{
|
{
|
||||||
@Decree(description = "Open a new studio world", aliases = "o", sync = true)
|
@Decree(description = "Open a new studio world", aliases = "o", sync = true)
|
||||||
@ -38,6 +60,37 @@ public class CMDIrisStudio implements DecreeExecutor
|
|||||||
Iris.proj.open(sender(), dimension.getLoadKey());
|
Iris.proj.open(sender(), dimension.getLoadKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Decree(description = "Create a new studio project", aliases = "+", sync = true)
|
||||||
|
public void create(
|
||||||
|
@Param(name = "name", required = true, description = "The name of this new Iris Project.")
|
||||||
|
String name,
|
||||||
|
@Param(name = "template", description = "Copy the contents of an existing project in your packs folder and use it as a template in this new project.")
|
||||||
|
IrisDimension template)
|
||||||
|
{
|
||||||
|
if (template != null) {
|
||||||
|
Iris.proj.create(sender(), name, template.getLoadKey());
|
||||||
|
} else {
|
||||||
|
Iris.proj.create(sender(), name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Decree(description = "Edit the biome at your current location", aliases = "eb", sync = true, origin = DecreeOrigin.PLAYER)
|
||||||
|
public void editBiome()
|
||||||
|
{
|
||||||
|
if (!Iris.proj.isProjectOpen()) {
|
||||||
|
sender().sendMessage(C.RED + "No open studio projects.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
try {
|
||||||
|
Desktop.getDesktop().open(Iris.proj.getActiveProject().getActiveProvider().getEngine().getBiome(sender().player().getLocation()).getLoadFile());
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Iris.reportError(e);
|
||||||
|
sender().sendMessage("Cant find the file. Are you in an Iris Studio world?");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Decree(description = "Close an open studio project", aliases = "x", sync = true)
|
@Decree(description = "Close an open studio project", aliases = "x", sync = true)
|
||||||
public void close()
|
public void close()
|
||||||
{
|
{
|
||||||
@ -50,4 +103,184 @@ public class CMDIrisStudio implements DecreeExecutor
|
|||||||
Iris.proj.close();
|
Iris.proj.close();
|
||||||
sender().sendMessage(C.YELLOW + "Project Closed");
|
sender().sendMessage(C.YELLOW + "Project Closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Decree(description = "Clean an Iris Project, optionally beautifying JSON & fixing block ids with missing keys. Also rebuilds the vscode schemas. ")
|
||||||
|
public void clean(
|
||||||
|
@Param(name = "project", required = true, description = "The project to update")
|
||||||
|
IrisDimension project,
|
||||||
|
|
||||||
|
@Param(name = "beautify", defaultValue = "true", description = "Filters all valid JSON files with a beautifier (indentation: 4)")
|
||||||
|
boolean beautify,
|
||||||
|
|
||||||
|
@Param(name = "fix-ids", defaultValue = "true", description = "Fixes any block ids used such as \"dirt\" will be converted to \"minecraft:dirt\"")
|
||||||
|
boolean fixIds,
|
||||||
|
|
||||||
|
@Param(name = "rewriteObjects", defaultValue = "false", description = "Imports all objects and re-writes them cleaning up positions & block data in the process.")
|
||||||
|
boolean rewriteObjects
|
||||||
|
) {
|
||||||
|
KList<Job> jobs = new KList<>();
|
||||||
|
KList<File> files = new KList<File>();
|
||||||
|
files(Iris.instance.getDataFolder("packs", project.getLoadKey()), files);
|
||||||
|
MultiBurst burst = new MultiBurst("Cleaner", Thread.MIN_PRIORITY, Runtime.getRuntime().availableProcessors() * 2);
|
||||||
|
|
||||||
|
jobs.add(new SingleJob("Updating Workspace", () -> {
|
||||||
|
if (!new IrisProject(Iris.proj.getWorkspaceFolder(project.getLoadKey())).updateWorkspace()) {
|
||||||
|
sender().sendMessage(C.GOLD + "Invalid project: " + project.getLoadKey() + ". Try deleting the code-workspace file and try again.");
|
||||||
|
}
|
||||||
|
J.sleep(250);
|
||||||
|
}));
|
||||||
|
|
||||||
|
sender().sendMessage("Files: " + files.size());
|
||||||
|
|
||||||
|
if(fixIds)
|
||||||
|
{
|
||||||
|
QueueJob<File> r = new QueueJob<>() {
|
||||||
|
@Override
|
||||||
|
public void execute(File f) {
|
||||||
|
try {
|
||||||
|
JSONObject p = new JSONObject(IO.readAll(f));
|
||||||
|
fixBlocks(p);
|
||||||
|
J.sleep(1);
|
||||||
|
IO.writeAll(f, p.toString(4));
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Fixing IDs";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
r.queue(files);
|
||||||
|
jobs.add(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(beautify)
|
||||||
|
{
|
||||||
|
QueueJob<File> r = new QueueJob<>() {
|
||||||
|
@Override
|
||||||
|
public void execute(File f) {
|
||||||
|
try {
|
||||||
|
JSONObject p = new JSONObject(IO.readAll(f));
|
||||||
|
IO.writeAll(f, p.toString(4));
|
||||||
|
J.sleep(1);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Beautify";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
r.queue(files);
|
||||||
|
jobs.add(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(rewriteObjects)
|
||||||
|
{
|
||||||
|
QueueJob<Runnable> q = new QueueJob<Runnable>() {
|
||||||
|
@Override
|
||||||
|
public void execute(Runnable runnable) {
|
||||||
|
runnable.run();
|
||||||
|
J.sleep(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Rewriting Objects";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
IrisData data = new IrisData(Iris.proj.getWorkspaceFolder(project.getLoadKey()));
|
||||||
|
for (String f : data.getObjectLoader().getPossibleKeys()) {
|
||||||
|
CompletableFuture<?> gg = burst.complete(() ->{
|
||||||
|
File ff = data.getObjectLoader().findFile(f);
|
||||||
|
IrisObject oo = new IrisObject(0, 0, 0);
|
||||||
|
try {
|
||||||
|
oo.read(ff);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Iris.error("FAILER TO READ: " + f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oo == null) {
|
||||||
|
Iris.error("FAILER TO READ: " + f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
oo.write(ff);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("FAILURE TO WRITE: " + oo.getLoadFile());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
q.queue(() -> {
|
||||||
|
try {
|
||||||
|
gg.get();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
jobs.add(q);
|
||||||
|
}
|
||||||
|
|
||||||
|
jobs.add(new SingleJob("Finishing Up", burst::shutdownNow));
|
||||||
|
|
||||||
|
new JobCollection("Cleaning", jobs).execute(sender());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void files(File clean, KList<File> files)
|
||||||
|
{
|
||||||
|
if (clean.isDirectory()) {
|
||||||
|
for (File i : clean.listFiles()) {
|
||||||
|
files(i, files);
|
||||||
|
}
|
||||||
|
} else if (clean.getName().endsWith(".json")) {
|
||||||
|
try {
|
||||||
|
files.add(clean);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Iris.reportError(e);
|
||||||
|
Iris.error("Failed to beautify " + clean.getAbsolutePath() + " You may have errors in your json!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fixBlocks(JSONObject obj) {
|
||||||
|
for (String i : obj.keySet()) {
|
||||||
|
Object o = obj.get(i);
|
||||||
|
|
||||||
|
if (i.equals("block") && o instanceof String && !o.toString().trim().isEmpty() && !o.toString().contains(":")) {
|
||||||
|
obj.put(i, "minecraft:" + o);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (o instanceof JSONObject) {
|
||||||
|
fixBlocks((JSONObject) o);
|
||||||
|
} else if (o instanceof JSONArray) {
|
||||||
|
fixBlocks((JSONArray) o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fixBlocks(JSONArray obj) {
|
||||||
|
for (int i = 0; i < obj.length(); i++) {
|
||||||
|
Object o = obj.get(i);
|
||||||
|
|
||||||
|
if (o instanceof JSONObject) {
|
||||||
|
fixBlocks((JSONObject) o);
|
||||||
|
} else if (o instanceof JSONArray) {
|
||||||
|
fixBlocks((JSONArray) o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -446,4 +446,62 @@ public class IrisProject {
|
|||||||
sender.sendMessage("Failed!");
|
sender.sendMessage("Failed!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static int clean(VolmitSender s, File clean) {
|
||||||
|
int c = 0;
|
||||||
|
if (clean.isDirectory()) {
|
||||||
|
for (File i : clean.listFiles()) {
|
||||||
|
c += clean(s, i);
|
||||||
|
}
|
||||||
|
} else if (clean.getName().endsWith(".json")) {
|
||||||
|
try {
|
||||||
|
clean(clean);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
Iris.reportError(e);
|
||||||
|
Iris.error("Failed to beautify " + clean.getAbsolutePath() + " You may have errors in your json!");
|
||||||
|
}
|
||||||
|
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clean(File clean) throws IOException {
|
||||||
|
JSONObject obj = new JSONObject(IO.readAll(clean));
|
||||||
|
fixBlocks(obj, clean);
|
||||||
|
|
||||||
|
IO.writeAll(clean, obj.toString(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fixBlocks(JSONObject obj, File f) {
|
||||||
|
for (String i : obj.keySet()) {
|
||||||
|
Object o = obj.get(i);
|
||||||
|
|
||||||
|
if (i.equals("block") && o instanceof String && !o.toString().trim().isEmpty() && !o.toString().contains(":")) {
|
||||||
|
obj.put(i, "minecraft:" + o);
|
||||||
|
Iris.debug("Updated Block Key: " + o + " to " + obj.getString(i) + " in " + f.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (o instanceof JSONObject) {
|
||||||
|
fixBlocks((JSONObject) o, f);
|
||||||
|
} else if (o instanceof JSONArray) {
|
||||||
|
fixBlocks((JSONArray) o, f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void fixBlocks(JSONArray obj, File f) {
|
||||||
|
for (int i = 0; i < obj.length(); i++) {
|
||||||
|
Object o = obj.get(i);
|
||||||
|
|
||||||
|
if (o instanceof JSONObject) {
|
||||||
|
fixBlocks((JSONObject) o, f);
|
||||||
|
} else if (o instanceof JSONArray) {
|
||||||
|
fixBlocks((JSONArray) o, f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,12 @@ public interface DecreeParameterHandler<T> {
|
|||||||
*/
|
*/
|
||||||
default KList<T> getPossibilities(String input)
|
default KList<T> getPossibilities(String input)
|
||||||
{
|
{
|
||||||
|
if(input.trim().isEmpty())
|
||||||
|
{
|
||||||
|
KList<T> f = getPossibilities();
|
||||||
|
return f == null ? new KList<>() : f;
|
||||||
|
}
|
||||||
|
|
||||||
input = input.trim();
|
input = input.trim();
|
||||||
KList<T> possible = getPossibilities();
|
KList<T> possible = getPossibilities();
|
||||||
KList<T> matches = new KList<>();
|
KList<T> matches = new KList<>();
|
||||||
|
@ -47,9 +47,13 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
default List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
default List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||||
return new KList<>();
|
KList<String> enhanced = new KList<>(args);
|
||||||
|
KList<String> v = getRoot().tabComplete(enhanced, enhanced.toString(" "));
|
||||||
|
v.removeDuplicates();
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
J.aBukkit(() -> {
|
J.aBukkit(() -> {
|
||||||
@ -62,6 +66,11 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static KList<String> enhanceArgs(String[] args)
|
static KList<String> enhanceArgs(String[] args)
|
||||||
|
{
|
||||||
|
return enhanceArgs(args, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static KList<String> enhanceArgs(String[] args, boolean trim)
|
||||||
{
|
{
|
||||||
KList<String> a = new KList<>();
|
KList<String> a = new KList<>();
|
||||||
|
|
||||||
@ -73,15 +82,26 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
StringBuilder flat = new StringBuilder();
|
StringBuilder flat = new StringBuilder();
|
||||||
for(String i : args)
|
for(String i : args)
|
||||||
{
|
{
|
||||||
if(i.trim().isEmpty())
|
if(trim)
|
||||||
{
|
{
|
||||||
continue;
|
if(i.trim().isEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
flat.append(" ").append(i.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
flat.append(" ").append(i.trim());
|
else
|
||||||
|
{
|
||||||
|
if(i.endsWith(" "))
|
||||||
|
{
|
||||||
|
flat.append(" ").append(i.trim()).append(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flat = new StringBuilder(flat.substring(1).trim());
|
flat = new StringBuilder(flat.length() > 0 ? trim ? flat.toString().trim().length() > 0 ?flat.substring(1).trim() : flat.toString().trim() : flat.substring(1) : flat);
|
||||||
StringBuilder arg = new StringBuilder();
|
StringBuilder arg = new StringBuilder();
|
||||||
boolean quoting = false;
|
boolean quoting = false;
|
||||||
|
|
||||||
@ -93,7 +113,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
if(i == ' ' && !quoting)
|
if(i == ' ' && !quoting)
|
||||||
{
|
{
|
||||||
if(!arg.toString().trim().isEmpty())
|
if(!arg.toString().trim().isEmpty() && trim)
|
||||||
{
|
{
|
||||||
a.add(arg.toString().trim());
|
a.add(arg.toString().trim());
|
||||||
arg = new StringBuilder();
|
arg = new StringBuilder();
|
||||||
@ -113,7 +133,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
if(hasNext && j == ' ')
|
if(hasNext && j == ' ')
|
||||||
{
|
{
|
||||||
if(!arg.toString().trim().isEmpty())
|
if(!arg.toString().trim().isEmpty() && trim)
|
||||||
{
|
{
|
||||||
a.add(arg.toString().trim());
|
a.add(arg.toString().trim());
|
||||||
arg = new StringBuilder();
|
arg = new StringBuilder();
|
||||||
@ -122,7 +142,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
else if(!hasNext)
|
else if(!hasNext)
|
||||||
{
|
{
|
||||||
if(!arg.toString().trim().isEmpty())
|
if(!arg.toString().trim().isEmpty() && trim)
|
||||||
{
|
{
|
||||||
a.add(arg.toString().trim());
|
a.add(arg.toString().trim());
|
||||||
arg = new StringBuilder();
|
arg = new StringBuilder();
|
||||||
@ -137,7 +157,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!arg.toString().trim().isEmpty())
|
if(!arg.toString().trim().isEmpty() && trim)
|
||||||
{
|
{
|
||||||
a.add(arg.toString().trim());
|
a.add(arg.toString().trim());
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||||
|
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.volmit.iris.util.decree.handlers;
|
||||||
|
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
|
import com.volmit.iris.util.math.M;
|
||||||
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
|
||||||
|
public class BooleanHandler implements DecreeParameterHandler<Boolean> {
|
||||||
|
@Override
|
||||||
|
public KList<Boolean> getPossibilities() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(Boolean aByte) {
|
||||||
|
return aByte.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean parse(String in) throws DecreeParsingException {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Boolean.parseBoolean(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
throw new DecreeParsingException("Unable to parse boolean \"" + in + "\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supports(Class<?> type) {
|
||||||
|
return type.equals(Boolean.class) || type.equals(boolean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRandomDefault()
|
||||||
|
{
|
||||||
|
return M.r(0.5) + "";
|
||||||
|
}
|
||||||
|
}
|
@ -171,6 +171,141 @@ public class VirtualDecreeCommand {
|
|||||||
return node != null;
|
return node != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public KList<String> tabComplete(KList<String> args, String raw)
|
||||||
|
{
|
||||||
|
KList<Integer> skip = new KList<>();
|
||||||
|
KList<String> tabs = new KList<>();
|
||||||
|
invokeTabComplete(args, skip, tabs, raw);
|
||||||
|
return tabs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean invokeTabComplete(KList<String> args, KList<Integer> skip, KList<String> tabs, String raw)
|
||||||
|
{
|
||||||
|
if(isStudio() && !IrisSettings.get().isStudio())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isNode())
|
||||||
|
{
|
||||||
|
tab(args, tabs);
|
||||||
|
skip.add(hashCode());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args.isEmpty())
|
||||||
|
{
|
||||||
|
tab(args, tabs);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String head = args.get(0);
|
||||||
|
|
||||||
|
if (args.size() > 1 || head.endsWith(" "))
|
||||||
|
{
|
||||||
|
VirtualDecreeCommand match = matchNode(head, skip);
|
||||||
|
|
||||||
|
if(match != null)
|
||||||
|
{
|
||||||
|
args.pop();
|
||||||
|
return match.invokeTabComplete(args, skip, tabs, raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
skip.add(hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tab(args, tabs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tab(KList<String> args, KList<String> tabs) {
|
||||||
|
String last = null;
|
||||||
|
KList<DecreeParameter> ignore = new KList<>();
|
||||||
|
Runnable la = () -> {
|
||||||
|
|
||||||
|
};
|
||||||
|
for(String a : args)
|
||||||
|
{
|
||||||
|
la.run();
|
||||||
|
last = a;
|
||||||
|
la = () -> {
|
||||||
|
if(isNode())
|
||||||
|
{
|
||||||
|
String sea = a.contains("=") ? a.split("\\Q=\\E")[0] : a;
|
||||||
|
sea = sea.trim();
|
||||||
|
|
||||||
|
searching: for(DecreeParameter i : getNode().getParameters())
|
||||||
|
{
|
||||||
|
for(String m : i.getNames())
|
||||||
|
{
|
||||||
|
if(m.equalsIgnoreCase(sea) || m.toLowerCase().contains(sea.toLowerCase()) || sea.toLowerCase().contains(m.toLowerCase()))
|
||||||
|
{
|
||||||
|
ignore.add(i);
|
||||||
|
continue searching;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if(last != null)
|
||||||
|
{
|
||||||
|
if (isNode()) {
|
||||||
|
for(DecreeParameter i : getNode().getParameters())
|
||||||
|
{
|
||||||
|
if(ignore.contains(i))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int g = 0;
|
||||||
|
|
||||||
|
if(last.contains("="))
|
||||||
|
{
|
||||||
|
String[] vv = last.trim().split("\\Q=\\E");
|
||||||
|
String vx = vv.length == 2 ? vv[1] : "";
|
||||||
|
for(String f : i.getHandler().getPossibilities(vx).convert((v) -> i.getHandler().toStringForce(v)))
|
||||||
|
{
|
||||||
|
g++;
|
||||||
|
tabs.add(i.getName() +"="+ f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(String f : i.getHandler().getPossibilities("").convert((v) -> i.getHandler().toStringForce(v)))
|
||||||
|
{
|
||||||
|
g++;
|
||||||
|
tabs.add(i.getName() +"="+ f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(g == 0)
|
||||||
|
{
|
||||||
|
tabs.add(i.getName() + "=");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(VirtualDecreeCommand i : getNodes())
|
||||||
|
{
|
||||||
|
String m = i.getName();
|
||||||
|
if(m.equalsIgnoreCase(last) || m.toLowerCase().contains(last.toLowerCase()) || last.toLowerCase().contains(m.toLowerCase()))
|
||||||
|
{
|
||||||
|
tabs.addAll(i.getNames());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private KMap<String, Object> map(VolmitSender sender, KList<String> in)
|
private KMap<String, Object> map(VolmitSender sender, KList<String> in)
|
||||||
{
|
{
|
||||||
KMap<String, Object> data = new KMap<>();
|
KMap<String, Object> data = new KMap<>();
|
||||||
@ -396,8 +531,43 @@ public class VirtualDecreeCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public KList<VirtualDecreeCommand> matchAllNodes(String in)
|
||||||
|
{
|
||||||
|
KList<VirtualDecreeCommand> g = new KList<>();
|
||||||
|
|
||||||
|
if(in.trim().isEmpty())
|
||||||
|
{
|
||||||
|
g.addAll(nodes);
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(VirtualDecreeCommand i : nodes)
|
||||||
|
{
|
||||||
|
if(i.matches(in))
|
||||||
|
{
|
||||||
|
g.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(VirtualDecreeCommand i : nodes)
|
||||||
|
{
|
||||||
|
if(i.deepMatches(in))
|
||||||
|
{
|
||||||
|
g.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g.removeDuplicates();
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
||||||
public VirtualDecreeCommand matchNode(String in, KList<Integer> skip)
|
public VirtualDecreeCommand matchNode(String in, KList<Integer> skip)
|
||||||
{
|
{
|
||||||
|
if(in.trim().isEmpty())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
for(VirtualDecreeCommand i : nodes)
|
for(VirtualDecreeCommand i : nodes)
|
||||||
{
|
{
|
||||||
if(skip.contains(i.hashCode()))
|
if(skip.contains(i.hashCode()))
|
||||||
|
@ -367,14 +367,14 @@ public class VolmitSender implements CommandSender {
|
|||||||
{
|
{
|
||||||
m.add((i.isNode()
|
m.add((i.isNode()
|
||||||
? (i.getNode().getParameters().isNotEmpty())
|
? (i.getNode().getParameters().isNotEmpty())
|
||||||
? "<gradient:#aebef2:#aef0f2>Or: <gradient:#5ef288:#99f25e>"
|
? "<#aebef2>✦ <#5ef288>"
|
||||||
+ i.getParentPath()
|
+ i.getParentPath()
|
||||||
+ " <gradient:#42ecf5:#428df5>"
|
+ " <#42ecf5>"
|
||||||
+ i.getName() + " "
|
+ i.getName() + " "
|
||||||
+ i.getNode().getParameters().shuffleCopy(RNG.r).convert((f)
|
+ i.getNode().getParameters().shuffleCopy(RNG.r).convert((f)
|
||||||
-> (f.isRequired() || RNG.r.b(0.5)
|
-> (f.isRequired() || RNG.r.b(0.5)
|
||||||
? "<gradient:#f2e15e:#c4d45b>" + f.getNames().getRandom() + "="
|
? "<#f2e15e>" + f.getNames().getRandom() + "="
|
||||||
+ "<gradient:#d665f0:#a37feb>" + f.example()
|
+ "<#d665f0>" + f.example()
|
||||||
: ""))
|
: ""))
|
||||||
.toString(" ")
|
.toString(" ")
|
||||||
: ""
|
: ""
|
||||||
@ -384,49 +384,82 @@ public class VolmitSender implements CommandSender {
|
|||||||
return m.removeDuplicates().convert((iff) -> iff.replaceAll("\\Q \\E", " ")).toString("\n");
|
return m.removeDuplicates().convert((iff) -> iff.replaceAll("\\Q \\E", " ")).toString("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void sendHeader(String name, int overrideLength)
|
||||||
|
{
|
||||||
|
int len = overrideLength;
|
||||||
|
int h = name.length() + 2;
|
||||||
|
String s = Form.repeat(" ", len - h - 4);
|
||||||
|
String si = Form.repeat("(", 3);
|
||||||
|
String so = Form.repeat(")", 3);
|
||||||
|
String sf = "[";
|
||||||
|
String se = "]";
|
||||||
|
|
||||||
|
if(name.trim().isEmpty())
|
||||||
|
{
|
||||||
|
sendMessageRaw("<font:minecraft:uniform><strikethrough><gradient:#34eb6b:#32bfad>" + sf + s + "<reset><font:minecraft:uniform><strikethrough><gradient:#32bfad:#34eb6b>" + s + se);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sendMessageRaw("<font:minecraft:uniform><strikethrough><gradient:#34eb6b:#32bfad>" + sf + s + si + "<reset> <gradient:#3299bf:#323bbf>" + name + "<reset> <font:minecraft:uniform><strikethrough><gradient:#32bfad:#34eb6b>" + so + s + se);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendHeader(String name)
|
||||||
|
{
|
||||||
|
sendHeader(name,46);
|
||||||
|
}
|
||||||
|
|
||||||
public void sendDecreeHelp(VirtualDecreeCommand v) {
|
public void sendDecreeHelp(VirtualDecreeCommand v) {
|
||||||
int m = v.getNodes().size();
|
int m = v.getNodes().size();
|
||||||
|
|
||||||
if(v.getNodes().isNotEmpty())
|
if(v.getNodes().isNotEmpty())
|
||||||
{
|
{
|
||||||
|
sendHeader(Form.capitalize(v.getName()) + " Help");
|
||||||
|
if(isPlayer() && v.getParent() != null)
|
||||||
|
{
|
||||||
|
sendMessageRaw("<hover:show_text:'"+"<#b54b38>Click to go back to <#3299bf>" + Form.capitalize(v.getParent().getName()) + " Help" +"'><click:run_command:" + v.getParent().getPath() + "><font:minecraft:uniform><#f58571>〈 Back</click></hover>");
|
||||||
|
}
|
||||||
|
|
||||||
for(VirtualDecreeCommand i : v.getNodes())
|
for(VirtualDecreeCommand i : v.getNodes())
|
||||||
{
|
{
|
||||||
if(isPlayer())
|
if(isPlayer())
|
||||||
{
|
{
|
||||||
//@builder
|
//@builder
|
||||||
sendMessageRaw(
|
String s = (
|
||||||
"<hover:show_text:'"+
|
"<hover:show_text:'"+
|
||||||
i.getNames().copy().reverse().convert((f) -> "<gradient:#42ecf5:#428df5>" + f).toString(", ") + "\n"
|
i.getNames().copy().reverse().convert((f) -> "<#42ecf5>" + f).toString(", ") + "\n"
|
||||||
+ "<gradient:#dbf296:#e7f0ce>" + i.getDescription() + "\n"
|
+ "<#3fe05a>✎ <#6ad97d><font:minecraft:uniform>" + i.getDescription() + "<reset>\n"
|
||||||
+ "<gradient:#a8e0a2:#aef2cd>" + (i.isNode()
|
+ "<#bbe03f>✒ <#a8e0a2>" + (i.isNode()
|
||||||
? ((i.getNode().getParameters().isEmpty()
|
? ((i.getNode().getParameters().isEmpty()
|
||||||
? "There are no parameters."
|
? "<font:minecraft:uniform>There are no parameters.<reset>"
|
||||||
: "Hover over all of the parameters to learn more.") + "\n")
|
: "<font:minecraft:uniform>Hover over all of the parameters to learn more.<reset>") + "\n")
|
||||||
: "This is a command category. Run <gradient:#98eda5:#ccf0bd>" + i.getPath())
|
: "<font:minecraft:uniform>This is a command category. Run <reset><#98eda5>" + i.getPath())
|
||||||
+ (i.isNode()
|
+ (i.isNode()
|
||||||
? (i.getNode().getParameters().isNotEmpty())
|
? (i.getNode().getParameters().isNotEmpty())
|
||||||
? "<gradient:#aebef2:#aef0f2>Usage: <gradient:#5ef288:#99f25e>"
|
? "<#aebef2>✦ <#5ef288><font:minecraft:uniform>"
|
||||||
+ i.getParentPath()
|
+ i.getParentPath()
|
||||||
+ " <gradient:#42ecf5:#428df5>"
|
+ " <#42ecf5>"
|
||||||
+ i.getName() + " "
|
+ i.getName() + " "
|
||||||
+ i.getNode().getParameters().convert((f)
|
+ i.getNode().getParameters().convert((f)
|
||||||
-> "<gradient:#d665f0:#a37feb>" + f.example())
|
-> "<#d665f0>" + f.example())
|
||||||
.toString(" ") + "\n"
|
.toString(" ") + "\n"
|
||||||
: ""
|
: ""
|
||||||
: "")
|
: "")
|
||||||
+ (i.isNode() ? pickRandoms(Math.min(i.getNode().getParameters().size() + 1, 5), i) : "")
|
+ (i.isNode() ? "<font:minecraft:uniform>" + pickRandoms(Math.min(i.getNode().getParameters().size() + 1, 5), i) + "<reset>" : "")
|
||||||
+ "'><click:suggest_command:" + i.getPath() + " >"
|
+ "'><click:" + (i.isNode() ? "suggest_command" : "run_command") + ":" + i.getPath() + " >"
|
||||||
+ "<gradient:#42ecf5:#428df5>" +i.getName() + "</click></hover>"
|
+ "<#46826a>⇀<gradient:#42ecf5:#428df5> " +i.getName() + "</click></hover>"
|
||||||
+ (i.isNode() ?
|
+ (i.isNode() ?
|
||||||
" " + i.getNode().getParameters().convert((f)
|
" " + i.getNode().getParameters().convert((f)
|
||||||
-> "<hover:show_text:'"
|
-> "<hover:show_text:'"
|
||||||
+ f.getNames().convert((ff) -> "<gradient:#d665f0:#a37feb>" + ff).toString(", ") + "\n"
|
+ f.getNames().convert((ff) -> "<#d665f0>" + ff).toString(", ") + "\n"
|
||||||
+ "<gradient:#dbf296:#e7f0ce>" + f.getDescription() + "\n"
|
+ "<#3fe05a>✎ <#6ad97d><font:minecraft:uniform>" + f.getDescription() + "<reset>\n"
|
||||||
+ (f.isRequired()
|
+ (f.isRequired()
|
||||||
? "<gradient:#faa796:#f0ba78>This parameter is required."
|
? "<#db4321>⚠ <#faa796><font:minecraft:uniform>This parameter is required."
|
||||||
: (f.hasDefault()
|
: (f.hasDefault()
|
||||||
? "<gradient:#78dcf0:#baf7e5>Defaults to \""+f.getParam().defaultValue()+"\" if undefined."
|
? "<#2181db>✔ <#78dcf0><font:minecraft:uniform>Defaults to \""+f.getParam().defaultValue()+"\" if undefined."
|
||||||
: "<gradient:#78dcf0:#baf7e5>This parameter is optional."))
|
: "<#a73abd>✔ <#78dcf0><font:minecraft:uniform>This parameter is optional."))
|
||||||
+ "'>"
|
+ "'>"
|
||||||
+ (f.isRequired() ? "<red>[" : "")
|
+ (f.isRequired() ? "<red>[" : "")
|
||||||
+ "<gradient:#d665f0:#a37feb>" + f.getName()
|
+ "<gradient:#d665f0:#a37feb>" + f.getName()
|
||||||
@ -436,6 +469,8 @@ public class VolmitSender implements CommandSender {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
//@done
|
//@done
|
||||||
|
sendMessageRaw(s);
|
||||||
|
System.out.println(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
76
src/main/java/com/volmit/iris/util/scheduling/jobs/Job.java
Normal file
76
src/main/java/com/volmit/iris/util/scheduling/jobs/Job.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||||
|
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.volmit.iris.util.scheduling.jobs;
|
||||||
|
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.format.Form;
|
||||||
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
|
import com.volmit.iris.util.scheduling.J;
|
||||||
|
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public interface Job
|
||||||
|
{
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
void execute();
|
||||||
|
|
||||||
|
void completeWork();
|
||||||
|
|
||||||
|
int getTotalWork();
|
||||||
|
|
||||||
|
default int getWorkRemaining()
|
||||||
|
{
|
||||||
|
return getTotalWork() - getWorkCompleted();
|
||||||
|
}
|
||||||
|
|
||||||
|
int getWorkCompleted();
|
||||||
|
|
||||||
|
default String getProgressString()
|
||||||
|
{
|
||||||
|
return Form.pc(getProgress(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
default double getProgress()
|
||||||
|
{
|
||||||
|
return (double)getWorkCompleted() / (double)getTotalWork();
|
||||||
|
}
|
||||||
|
|
||||||
|
default void execute(VolmitSender sender)
|
||||||
|
{
|
||||||
|
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||||
|
CompletableFuture<?> f = J.afut(this::execute);
|
||||||
|
int c = J.ar(() -> {
|
||||||
|
if(sender.isPlayer())
|
||||||
|
{
|
||||||
|
sender.sendProgress(getProgress(), getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sender.sendMessage(getName() + ": " + getProgressString());
|
||||||
|
}
|
||||||
|
}, sender.isPlayer() ? 0 : 20);
|
||||||
|
f.whenComplete((fs, ff) -> {
|
||||||
|
J.car(c);
|
||||||
|
sender.sendMessage("Completed " + getName() + " in " + Form.duration(p.getMilliseconds(), 1));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||||
|
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.volmit.iris.util.scheduling.jobs;
|
||||||
|
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
|
||||||
|
public class JobCollection implements Job {
|
||||||
|
private final String name;
|
||||||
|
private String status;
|
||||||
|
private final KList<Job> jobs;
|
||||||
|
|
||||||
|
public JobCollection(String name, Job... jobs)
|
||||||
|
{
|
||||||
|
this(name, new KList<>(jobs));
|
||||||
|
}
|
||||||
|
|
||||||
|
public JobCollection(String name, KList<Job> jobs)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
status = null;
|
||||||
|
this.jobs = new KList<>(jobs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return status == null ? name : (name + " 》" + status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
for(Job i : jobs)
|
||||||
|
{
|
||||||
|
status = i.getName();
|
||||||
|
i.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
status = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void completeWork() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalWork() {
|
||||||
|
return jobs.stream().mapToInt(Job::getTotalWork).sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWorkCompleted() {
|
||||||
|
return jobs.stream().mapToInt(Job::getWorkCompleted).sum();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||||
|
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.volmit.iris.util.scheduling.jobs;
|
||||||
|
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
|
||||||
|
public abstract class QueueJob<T> implements Job {
|
||||||
|
private final KList<T> queue;
|
||||||
|
private int totalWork;
|
||||||
|
private int completed;
|
||||||
|
|
||||||
|
public QueueJob()
|
||||||
|
{
|
||||||
|
totalWork = 0;
|
||||||
|
completed = 0;
|
||||||
|
queue = new KList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void queue(T t)
|
||||||
|
{
|
||||||
|
queue.add(t);
|
||||||
|
totalWork++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void queue(KList<T> f)
|
||||||
|
{
|
||||||
|
queue.addAll(f);
|
||||||
|
totalWork += f.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void execute(T t);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
totalWork = queue.size();
|
||||||
|
while(queue.isNotEmpty())
|
||||||
|
{
|
||||||
|
execute(queue.pop());
|
||||||
|
completeWork();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void completeWork() {
|
||||||
|
completed++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalWork() {
|
||||||
|
return totalWork;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWorkCompleted() {
|
||||||
|
return completed;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||||
|
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.volmit.iris.util.scheduling.jobs;
|
||||||
|
|
||||||
|
public class SingleJob implements Job{
|
||||||
|
private boolean done;
|
||||||
|
private final String name;
|
||||||
|
private final Runnable runnable;
|
||||||
|
|
||||||
|
public SingleJob(String name, Runnable runnable)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
done = false;
|
||||||
|
this.runnable = runnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
runnable.run();
|
||||||
|
completeWork();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void completeWork() {
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalWork() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWorkCompleted() {
|
||||||
|
return done ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user