Merge pull request #536 from CocoTheOwner/DecreeCommands

Some commands (in studio mainly) WIP
This commit is contained in:
Dan 2021-08-15 14:41:12 -08:00 committed by GitHub
commit d71393cead
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 1045 additions and 313 deletions

View File

@ -19,7 +19,7 @@
package com.volmit.iris.core;
import com.volmit.iris.Iris;
import com.volmit.iris.core.decrees.CMDIris;
import com.volmit.iris.core.decrees.DecIris;
import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.decree.DecreeSystem;
@ -37,7 +37,7 @@ public class CommandManager implements DecreeSystem {
public VirtualDecreeCommand getRoot() {
return commandCache.aquire(() -> {
try {
return VirtualDecreeCommand.createRoot(new CMDIris());
return VirtualDecreeCommand.createRoot(new DecIris());
} catch (Throwable e) {
e.printStackTrace();
}

View File

@ -329,11 +329,7 @@ public class ProjectManager {
public void open(VolmitSender sender, long seed, String dimm) {
try {
open(sender,seed, dimm, () ->
{
if (sender.isPlayer()) {
}
});
open(sender,seed, dimm, () -> {});
} catch (Exception e) {
Iris.reportError(e);
sender.sendMessage("Error when creating studio world:");

View File

@ -73,7 +73,6 @@ public class CommandIrisStudioBeautify extends MortarCommand {
return true;
}
private int clean(VolmitSender s, File clean) {
int c = 0;
if (clean.isDirectory()) {
@ -131,6 +130,7 @@ public class CommandIrisStudioBeautify extends MortarCommand {
}
@Override
protected String getArgsUsage() {
return "[project]";

View File

@ -1,286 +0,0 @@
/*
* 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.core.decrees;
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.objects.IrisObject;
import com.volmit.iris.util.collection.KList;
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.Param;
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;
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
{
@Decree(description = "Open a new studio world", aliases = "o", sync = true)
public void open(
@Param(name = "dimension", defaultValue = "overworld", aliases = "dim", required = true)
IrisDimension dimension,
@Param(name = "seed", defaultValue = "1337", aliases = "s")
long seed)
{
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)
public void close()
{
if (!Iris.proj.isProjectOpen()) {
sender().sendMessage(C.RED + "No open studio projects.");
return;
}
Iris.proj.getActiveProject().getActiveProvider().getTarget().getWorld().evacuate();
Iris.proj.close();
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);
}
}
}
}

View File

@ -18,20 +18,18 @@
package com.volmit.iris.core.decrees;
import com.volmit.iris.Iris;
import com.volmit.iris.util.decree.DecreeExecutor;
import com.volmit.iris.util.decree.annotations.Decree;
import com.volmit.iris.util.decree.annotations.Param;
@Decree(name = "irisd", aliases = {"ird"}, description = "Basic Command")
public class CMDIris implements DecreeExecutor
public class DecIris implements DecreeExecutor
{
private CMDIrisStudio studio;
private DecIrisStudio studio;
@Decree(description = "Ping self", aliases = "p")
public void ping(
@Param(name = "message",defaultValue = "Pong", aliases = {"msg", "m"})
String message)
{
sender().sendMessage(message + "!");
@Decree(description = "Print version information")
public void version(){
sender().sendMessage("Iris v" + Iris.instance.getDescription().getVersion() + " by Volmit Software");
}
}

View File

@ -0,0 +1,724 @@
/*
* 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.core.decrees;
import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.gui.NoiseExplorerGUI;
import com.volmit.iris.core.gui.VisionGUI;
import com.volmit.iris.core.project.IrisProject;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.core.tools.IrisToolbelt;
import com.volmit.iris.engine.object.basic.IrisPosition;
import com.volmit.iris.engine.object.biome.IrisBiome;
import com.volmit.iris.engine.object.biome.IrisBiomePaletteLayer;
import com.volmit.iris.engine.object.common.IrisScript;
import com.volmit.iris.engine.object.dimensional.IrisDimension;
import com.volmit.iris.engine.object.entity.IrisEntity;
import com.volmit.iris.engine.object.loot.IrisLootTable;
import com.volmit.iris.engine.object.meta.InventorySlotType;
import com.volmit.iris.engine.object.noise.IrisGenerator;
import com.volmit.iris.engine.object.noise.IrisInterpolator;
import com.volmit.iris.engine.object.noise.IrisNoiseGenerator;
import com.volmit.iris.engine.object.noise.NoiseStyle;
import com.volmit.iris.engine.object.objects.IrisObject;
import com.volmit.iris.engine.object.regional.IrisRegion;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;
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.Param;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.function.Function2;
import com.volmit.iris.util.function.NoiseProvider;
import com.volmit.iris.util.interpolation.InterpolationMethod;
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.math.RNG;
import com.volmit.iris.util.noise.CNG;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.O;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
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;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;
@Decree(name = "studio", aliases = {"std", "s"}, description = "Studio Commands", studio = true)
public class DecIrisStudio implements DecreeExecutor {
@Decree(description = "Open a new studio world", aliases = "o", sync = true)
public void open(
@Param(name = "dimension", defaultValue = "overworld", description = "The dimension to open a studio for", aliases = "dim")
IrisDimension dimension,
@Param(name = "seed", defaultValue = "1337", description = "The seed to generate the studio with", aliases = "s")
long seed) {
sender().sendMessage(C.GREEN + "Opening studio for the \"" + dimension.getName() + "\" pack (seed: " + seed + ")");
Iris.proj.open(sender(), seed, dimension.getLoadKey());
}
@Decree(description = "Close an open studio project", aliases = "x", sync = true)
public void close() {
if (!Iris.proj.isProjectOpen()) {
sender().sendMessage(C.RED + "No open studio projects.");
return;
}
Iris.proj.close();
sender().sendMessage(C.GREEN + "Project Closed.");
}
@Decree(description = "Create a new studio project", aliases = "+", sync = true)
public void create(
@Param(name = "name", 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 = "Clean an Iris Project, optionally beautifying JSON & fixing block ids with missing keys. Also rebuilds the vscode schemas. ")
public void clean(
@Param(name = "project", 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<>() {
@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;
}
try {
oo.write(ff);
} catch (IOException e) {
Iris.error("FAILURE TO WRITE: " + oo.getLoadFile());
}
});
q.queue(() -> {
try {
gg.get();
} catch (InterruptedException | 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);
}
}
}
@Decree(description = "Get the version of a pack", aliases = {"v", "ver"})
public void version(
@Param(name = "dimension", defaultValue = "overworld", description = "The dimension get the version of", aliases = "dim")
IrisDimension dimension
) {
sender().sendMessage(C.GREEN + "The \"" + dimension.getName() + "\" pack has version: " + dimension.getVersion());
}
@Decree(description = "Convert objects in the \"convert\" folder", aliases = "conv")
public void convert() {
Iris.convert.check(sender());
}
@Decree(description = "Edit the biome you're currently in", aliases = {"ebiome", "eb"}, origin = DecreeOrigin.PLAYER)
public void editbiome() {
if (noStudio()) return;
try {
Desktop.getDesktop().open(Iris.proj.getActiveProject().getActiveProvider().getEngine().getBiome(sender().player().getLocation()).getLoadFile());
} catch (Throwable e) {
Iris.reportError(e);
sender().sendMessage(C.RED + "Cant find the file. Unsure why this happened.");
}
}
@Decree(description = "Execute a script", aliases = {"ex", "exec", "run"}, origin = DecreeOrigin.PLAYER)
public void execute(
@Param(name = "script", description = "The script to run", aliases = {"s", "scr"})
IrisScript script
) {
engine().getExecution().execute(script.getLoadKey());
}
@Decree(description = "Open the noise explorer (External GUI)", aliases = "nmap")
public void noise() {
if (noGUI()) return;
sender().sendMessage(C.GREEN + "Opening Noise Explorer!");
NoiseExplorerGUI.launch();
}
@Decree(description = "Preview noise gens (External GUI)", aliases = {"generator", "gen"})
public void explore(
@Param(name = "generator", description = "The generator to explore", aliases = {"gen", "g"})
IrisGenerator generator,
@Param(name = "seed", description = "The seed to generate with", aliases = "s", defaultValue = "12345")
long seed
){
if (noGUI()) return;
sender().sendMessage(C.GREEN + "Opening Noise Explorer!");
Supplier<Function2<Double, Double, Double>> l = () -> {
if (generator == null) {
return (x, z) -> 0D;
}
return (x, z) -> generator.getHeight(x, z, new RNG(seed).nextParallelRNG(3245).lmax());
};
NoiseExplorerGUI.launch(l, "Custom Generator");
}
@Decree(description = "Find any biome", aliases = {"goto", "g"}, origin = DecreeOrigin.PLAYER)
public void find(
@Param(name = "biome", description = "The biome to find", aliases = "b")
IrisBiome biome
){
if (!IrisToolbelt.isIrisWorld(world())){
sender().sendMessage(C.RED + "You must be in an Iris world to use this command!");
return;
}
IrisPosition l = engine().lookForBiome(biome, 10000, (v) -> sender().sendMessage("Looking for " + C.BOLD + C.WHITE + biome.getName() + C.RESET + C.GRAY + ": Checked " + Form.f(v) + " Places"));
if (l == null) {
sender().sendMessage(C.RED + "Couldn't find " + biome.getName() + ".");
} else {
sender().sendMessage(C.GREEN + "Found " + biome.getName() + "!");
J.s(() -> player().teleport(l.toLocation(world())));
}
}
@Decree(description = "Find any region", aliases = {"goto", "g"}, origin = DecreeOrigin.PLAYER)
public void find(
@Param(name = "region", description = "The region to find", aliases = "r")
IrisRegion region
){
if (!IrisToolbelt.isIrisWorld(world())){
sender().sendMessage(C.RED + "You must be in an Iris world to use this command!");
return;
}
IrisPosition l = engine().lookForRegion(region, 10000, (v) -> sender().sendMessage("Looking for " + C.BOLD + C.WHITE + region.getName() + C.RESET + C.GRAY + ": Checked " + Form.f(v) + " Places"));
if (l == null) {
sender().sendMessage(C.RED + "Couldn't find " + region.getName() + ".");
} else {
sender().sendMessage(C.GREEN + "Found " + region.getName() + "!");
J.s(() -> player().teleport(l.toLocation(world())));
}
}
@Decree(description = "Hotload a studio", aliases = {"hot", "h", "reload"}, origin = DecreeOrigin.PLAYER)
public void hotload() {
if (noStudio()) return;
access().hotload();
}
@Decree(description = "Show loot if a chest were right here", origin = DecreeOrigin.PLAYER, sync = true)
public void loot(
@Param(name = "fast", aliases = "f", description = "Fast insertion of items in virtual inventory (may cause performance drop)", defaultValue = "false")
boolean fast,
@Param(name = "add", aliases = "a", description = "Whether or not to append to the inventory currently open (if false, clears opened inventory)", defaultValue = "true")
boolean add
) {
if (noStudio()) return;
KList<IrisLootTable> tables = engine().getLootTables(RNG.r, player().getLocation().getBlock());
Inventory inv = Bukkit.createInventory(null, 27 * 2);
try {
engine().addItems(true, inv, RNG.r, tables, InventorySlotType.STORAGE, player().getLocation().getBlockX(), player().getLocation().getBlockY(), player().getLocation().getBlockZ(), 1);
} catch (Throwable e){
Iris.reportError(e);
sender().sendMessage(C.RED + "Cannot add items to virtual inventory because of: " + e.getMessage());
return;
}
O<Integer> ta = new O<>();
ta.set(-1);
ta.set(Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, () ->
{
if (!player().getOpenInventory().getType().equals(InventoryType.CHEST)) {
Bukkit.getScheduler().cancelTask(ta.get());
sender().sendMessage(C.GREEN + "Opened inventory!");
return;
}
if (!add) {
inv.clear();
}
engine().addItems(true, inv, new RNG(RNG.r.imax()), tables, InventorySlotType.STORAGE, player().getLocation().getBlockX(), player().getLocation().getBlockY(), player().getLocation().getBlockZ(), 1);
}, 0, fast ? 5 : 35));
sender().sendMessage(C.GREEN + "Opening inventory now!");
player().openInventory(inv);
}
@Decree(description = "Render a world map (External GUI)", aliases = "render")
public void map()
{
if (noStudio()) return;
if (noGUI()) return;
VisionGUI.launch(engine(), 0);
sender().sendMessage(C.GREEN + "Opening map!");
}
@Decree(description = "Package a dimension into a compressed format", aliases = "package")
public void pkg(
@Param(name = "dimension", aliases = {"d", "dim"}, description = "The dimension pack to compress")
IrisDimension dimension,
@Param(name = "obfuscate", aliases = "o", description = "Whether or not to obfuscate the pack", defaultValue = "false")
boolean obfuscate,
@Param(name = "minify", aliases = "m", description = "Whether or not to minify the pack", defaultValue = "true")
boolean minify
){
Iris.proj.compilePackage(sender(), dimension.getLoadKey(), obfuscate, minify);
}
@Decree(description = "Profiles a dimension's performance", origin = DecreeOrigin.PLAYER)
public void profile(
@Param(name = "dimension", aliases = {"d", "dim"}, description = "The dimension to profile")
IrisDimension dimension
){
File pack = dimension.getLoadFile().getParentFile().getParentFile();
File report = Iris.instance.getDataFile("profile.txt");
IrisProject project = new IrisProject(pack);
IrisData data = new IrisData(pack);
KList<String> fileText = new KList<>();
KMap<NoiseStyle, Double> styleTimings = new KMap<>();
KMap<InterpolationMethod, Double> interpolatorTimings = new KMap<>();
KMap<String, Double> generatorTimings = new KMap<>();
KMap<String, Double> biomeTimings = new KMap<>();
KMap<String, Double> regionTimings = new KMap<>();
sender().sendMessage("Calculating Performance Metrics for Noise generators");
for (NoiseStyle i : NoiseStyle.values()) {
CNG c = i.create(new RNG(i.hashCode()));
for (int j = 0; j < 3000; j++) {
c.noise(j, j + 1000, j * j);
c.noise(j, -j);
}
PrecisionStopwatch px = PrecisionStopwatch.start();
for (int j = 0; j < 100000; j++) {
c.noise(j, j + 1000, j * j);
c.noise(j, -j);
}
styleTimings.put(i, px.getMilliseconds());
}
fileText.add("Noise Style Performance Impacts: ");
for (NoiseStyle i : styleTimings.sortKNumber()) {
fileText.add(i.name() + ": " + styleTimings.get(i));
}
fileText.add("");
sender().sendMessage("Calculating Interpolator Timings...");
for (InterpolationMethod i : InterpolationMethod.values()) {
IrisInterpolator in = new IrisInterpolator();
in.setFunction(i);
in.setHorizontalScale(8);
NoiseProvider np = (x, z) -> Math.random();
for (int j = 0; j < 3000; j++) {
in.interpolate(j, -j, np);
}
PrecisionStopwatch px = PrecisionStopwatch.start();
for (int j = 0; j < 100000; j++) {
in.interpolate(j + 10000, -j - 100000, np);
}
interpolatorTimings.put(i, px.getMilliseconds());
}
fileText.add("Noise Interpolator Performance Impacts: ");
for (InterpolationMethod i : interpolatorTimings.sortKNumber()) {
fileText.add(i.name() + ": " + interpolatorTimings.get(i));
}
fileText.add("");
sender().sendMessage("Processing Generator Scores: ");
KMap<String, KList<String>> btx = new KMap<>();
for (String i : data.getGeneratorLoader().getPossibleKeys()) {
KList<String> vv = new KList<>();
IrisGenerator g = data.getGeneratorLoader().load(i);
KList<IrisNoiseGenerator> composites = g.getAllComposites();
double score = 0;
int m = 0;
for (IrisNoiseGenerator j : composites) {
m++;
score += styleTimings.get(j.getStyle().getStyle());
vv.add("Composite Noise Style " + m + " " + j.getStyle().getStyle().name() + ": " + styleTimings.get(j.getStyle().getStyle()));
}
score += interpolatorTimings.get(g.getInterpolator().getFunction());
vv.add("Interpolator " + g.getInterpolator().getFunction().name() + ": " + interpolatorTimings.get(g.getInterpolator().getFunction()));
generatorTimings.put(i, score);
btx.put(i, vv);
}
fileText.add("Project Generator Performance Impacts: ");
for (String i : generatorTimings.sortKNumber()) {
fileText.add(i + ": " + generatorTimings.get(i));
btx.get(i).forEach((ii) -> fileText.add(" " + ii));
}
fileText.add("");
KMap<String, KList<String>> bt = new KMap<>();
for (String i : data.getBiomeLoader().getPossibleKeys()) {
KList<String> vv = new KList<>();
IrisBiome b = data.getBiomeLoader().load(i);
double score = 0;
int m = 0;
for (IrisBiomePaletteLayer j : b.getLayers()) {
m++;
score += styleTimings.get(j.getStyle().getStyle());
vv.add("Palette Layer " + m + ": " + styleTimings.get(j.getStyle().getStyle()));
}
score += styleTimings.get(b.getBiomeStyle().getStyle());
vv.add("Biome Style: " + styleTimings.get(b.getBiomeStyle().getStyle()));
score += styleTimings.get(b.getChildStyle().getStyle());
vv.add("Child Style: " + styleTimings.get(b.getChildStyle().getStyle()));
biomeTimings.put(i, score);
bt.put(i, vv);
}
fileText.add("Project Biome Performance Impacts: ");
for (String i : biomeTimings.sortKNumber()) {
fileText.add(i + ": " + biomeTimings.get(i));
bt.get(i).forEach((ff) -> fileText.add(" " + ff));
}
fileText.add("");
for (String i : data.getRegionLoader().getPossibleKeys()) {
IrisRegion b = data.getRegionLoader().load(i);
double score = 0;
score += styleTimings.get(b.getLakeStyle().getStyle());
score += styleTimings.get(b.getRiverStyle().getStyle());
regionTimings.put(i, score);
}
fileText.add("Project Region Performance Impacts: ");
for (String i : regionTimings.sortKNumber()) {
fileText.add(i + ": " + regionTimings.get(i));
}
fileText.add("");
double m = 0;
for (double i : biomeTimings.v()) {
m += i;
}
m /= biomeTimings.size();
double mm = 0;
for (double i : generatorTimings.v()) {
mm += i;
}
mm /= generatorTimings.size();
m += mm;
double mmm = 0;
for (double i : regionTimings.v()) {
mmm += i;
}
mmm /= regionTimings.size();
m += mmm;
fileText.add("Average Score: " + m);
sender().sendMessage("Score: " + Form.duration(m, 0));
try {
IO.writeAll(report, fileText.toString("\n"));
} catch (IOException e) {
Iris.reportError(e);
e.printStackTrace();
}
sender().sendMessage(C.GREEN + "Done! " + report.getPath());
}
@Decree(description = "Summon an Iris Entity", origin = DecreeOrigin.PLAYER)
public void summon(
@Param(description = "The Iris Entity to spawn", aliases = "e", name = "entity")
IrisEntity entity
) {
if (noStudio()){
return;
}
sender().sendMessage(C.GREEN + "Spawning entity");
entity.spawn(engine(), player().getLocation().clone().add(0, 2, 0));
}
@Decree(description = "Teleport to the active studio world", aliases = {"tps", "stp", "tp"}, origin = DecreeOrigin.PLAYER)
public void tpstudio(){
if (!Iris.proj.isProjectOpen()){
sender().sendMessage(C.RED + "No studio world is open!");
return;
}
if (engine().isStudio()){
sender().sendMessage(C.RED + "You are already in a studio world!");
return;
}
sender().sendMessage(C.GREEN + "Sending you to the studio world!");
player().teleport(Iris.proj.getActiveProject().getActiveProvider().getTarget().getWorld().spawnLocation());
player().setGameMode(GameMode.SPECTATOR);
}
@Decree(description = "Update your dimension project", aliases = {"upd", "u"})
public void update(
@Param(name = "dimension", aliases = {"d", "dim"}, description = "The dimension to update the workspace of")
IrisDimension dimension
){
if (new IrisProject(dimension.getLoadFile().getParentFile().getParentFile()).updateWorkspace()) {
sender().sendMessage(C.GREEN + "Updated Code Workspace for " + dimension.getName());
} else {
sender().sendMessage(C.RED + "Invalid project: " + dimension.getName() + ". Try deleting the code-workspace file and try again.");
}
}
/**
* @return true if server GUIs are not enabled
*/
private boolean noGUI() {
if (!IrisSettings.get().isUseServerLaunchedGuis()){
sender().sendMessage(C.RED + "You must have server launched GUIs enabled in the settings!");
return true;
}
return false;
}
/**
* @return true if no studio is open or the player is not in one
*/
private boolean noStudio(){
if (!sender().isPlayer()){
sender().sendMessage(C.RED + "Players only (this is a config error. Ask support to add DecreeOrigin.PLAYER to the command you tried to run)");
return true;
}
if (!Iris.proj.isProjectOpen()){
sender().sendMessage(C.RED + "No studio world is open!");
return true;
}
if (!engine().isStudio()){
sender().sendMessage(C.RED + "You must be in a studio world!");
return true;
}
return false;
}
}

View File

@ -20,6 +20,7 @@ package com.volmit.iris.engine;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.common.IrisScript;
import com.volmit.iris.engine.scripting.EngineExecutionEnvironment;
import com.volmit.iris.engine.scripting.IrisScriptingAPI;
import com.volmit.iris.util.format.C;
@ -54,9 +55,13 @@ public class IrisExecutionEnvironment implements EngineExecutionEnvironment {
}
public void execute(String script) {
Iris.debug("Execute Script (void) " + C.DARK_GREEN + script);
execute(getEngine().getData().getScriptLoader().load(script));
}
public void execute(IrisScript script) {
Iris.debug("Execute Script (void) " + C.DARK_GREEN + script.getLoadKey());
try {
javaScriptEngine.exec("", 0, 0, getEngine().getData().getScriptLoader().load(script));
javaScriptEngine.exec("", 0, 0, script);
} catch (BSFException e) {
e.printStackTrace();
}

View File

@ -19,6 +19,7 @@
package com.volmit.iris.engine.scripting;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.common.IrisScript;
import org.apache.bsf.BSFManager;
public interface EngineExecutionEnvironment {

View File

@ -21,7 +21,10 @@ package com.volmit.iris.util.decree;
import com.volmit.iris.core.tools.IrisToolbelt;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.plugin.VolmitSender;
import org.bukkit.World;
import org.bukkit.entity.Player;
public interface DecreeExecutor {
default VolmitSender sender()
@ -29,6 +32,11 @@ public interface DecreeExecutor {
return DecreeContext.get();
}
default Player player()
{
return sender().player();
}
default Engine engine()
{
if(sender().isPlayer() && IrisToolbelt.access(sender().player().getWorld()) != null)
@ -42,6 +50,22 @@ public interface DecreeExecutor {
return null;
}
default PlatformChunkGenerator access()
{
if(sender().isPlayer()) {
return IrisToolbelt.access(world());
}
return null;
}
default World world()
{
if (sender().isPlayer()){
return sender().player().getWorld();
}
return null;
}
default <T> T get(T v, T ifUndefined)
{
return v == null ? ifUndefined : v;

View File

@ -25,7 +25,6 @@ import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
import lombok.Data;
import java.lang.reflect.Parameter;
import java.util.Arrays;
@Data
public class DecreeParameter {
@ -57,7 +56,7 @@ public class DecreeParameter {
}
public boolean isRequired() {
return param.required();
return !hasDefault();
}
public KList<String> getNames() {
@ -80,11 +79,11 @@ public class DecreeParameter {
}
public Object getDefaultValue() throws DecreeParsingException, DecreeWhichException {
return param.defaultValue().isEmpty() ? null : getHandler().parse(param.defaultValue());
return param.defaultValue().trim().isEmpty() ? null : getHandler().parse(param.defaultValue().trim());
}
public boolean hasDefault() {
return !param.defaultValue().isEmpty();
return !param.defaultValue().trim().isEmpty();
}
public String example() {

View File

@ -174,8 +174,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
* @param type The type to handle
* @return The corresponding {@link DecreeParameterHandler}, or null
*/
static DecreeParameterHandler<?> getHandler(Class<?> type)
{
static DecreeParameterHandler<?> getHandler(Class<?> type) {
for(DecreeParameterHandler<?> i : handlers)
{
if(i.supports(type))
@ -183,6 +182,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
return i;
}
}
Iris.error("Unhandled type in Decree Parameter: " + type.getName() + ". This is bad!");
return null;
}
}

View File

@ -42,6 +42,10 @@ public @interface Decree {
*/
boolean studio() default false;
/**
* If the node's functions MUST be run in sync, set this to true.<br>
* Defaults to false
*/
boolean sync() default false;
/**

View File

@ -35,8 +35,6 @@ public @interface Param {
*/
String name();
boolean required() default false;
/**
* The description of this parameter, used in help-popups in game.<br>
* The default value is {@link #DEFAULT_DESCRIPTION}

View File

@ -0,0 +1,105 @@
package com.volmit.iris.util.decree.handlers;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.engine.object.dimensional.IrisDimension;
import com.volmit.iris.engine.object.entity.IrisEntity;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.decree.DecreeParameterHandler;
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
import java.io.File;
public class EntityHandler implements DecreeParameterHandler<IrisEntity> {
/**
* Should return the possible values for this type
*
* @return Possibilities for this type.
*/
@Override
public KList<IrisEntity> getPossibilities() {
KMap<String, IrisEntity> p = new KMap<>();
//noinspection ConstantConditions
for(File i : Iris.instance.getDataFolder("packs").listFiles())
{
if(i.isDirectory()) {
IrisData data = new IrisData(i, true);
for (IrisEntity j : data.getEntityLoader().loadAll(data.getEntityLoader().getPossibleKeys()))
{
p.putIfAbsent(j.getLoadKey(), j);
}
data.close();
}
}
return p.v();
}
/**
* Converting the type back to a string (inverse of the {@link #parse(String) parse} method)
*
* @param entity The input of the designated type to convert to a String
* @return The resulting string
*/
@Override
public String toString(IrisEntity entity) {
return entity.getLoadKey();
}
/**
* Should parse a String into the designated type
*
* @param in The string to parse
* @return The value extracted from the string, of the designated type
* @throws DecreeParsingException Thrown when the parsing fails (ex: "oop" translated to an integer throws this)
* @throws DecreeWhichException Thrown when multiple results are possible
*/
@Override
public IrisEntity parse(String in) throws DecreeParsingException, DecreeWhichException {
try
{
KList<IrisEntity> options = getPossibilities(in);
if(options.isEmpty())
{
throw new DecreeParsingException("Unable to find Entity \"" + in + "\"");
}
else if(options.size() > 1)
{
throw new DecreeWhichException();
}
return options.get(0);
}
catch(DecreeParsingException e){
throw e;
}
catch(Throwable e)
{
throw new DecreeParsingException("Unable to find Entity \"" + in + "\" because of an uncaught exception: " + e);
}
}
/**
* Returns whether a certain type is supported by this handler<br>
*
* @param type The type to check
* @return True if supported, false if not
*/
@Override
public boolean supports(Class<?> type) {
return type.equals(IrisEntity.class);
}
@Override
public String getRandomDefault()
{
return "entity";
}
}

View File

@ -0,0 +1,78 @@
package com.volmit.iris.util.decree.handlers;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.engine.object.noise.IrisGenerator;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.decree.DecreeParameterHandler;
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
import java.io.File;
public class GeneratorHandler implements DecreeParameterHandler<IrisGenerator> {
@Override
public KList<IrisGenerator> getPossibilities() {
KMap<String, IrisGenerator> p = new KMap<>();
//noinspection ConstantConditions
for(File i : Iris.instance.getDataFolder("packs").listFiles())
{
if(i.isDirectory()) {
IrisData data = new IrisData(i, true);
for (IrisGenerator j : data.getGeneratorLoader().loadAll(data.getGeneratorLoader().getPossibleKeys()))
{
p.putIfAbsent(j.getLoadKey(), j);
}
data.close();
}
}
return p.v();
}
@Override
public String toString(IrisGenerator gen) {
return gen.getLoadKey();
}
@Override
public IrisGenerator parse(String in) throws DecreeParsingException, DecreeWhichException {
try
{
KList<IrisGenerator> options = getPossibilities(in);
if(options.isEmpty())
{
throw new DecreeParsingException("Unable to find Generator \"" + in + "\"");
}
else if(options.size() > 1)
{
throw new DecreeWhichException();
}
return options.get(0);
}
catch(DecreeParsingException e){
throw e;
}
catch(Throwable e)
{
throw new DecreeParsingException("Unable to find Generator \"" + in + "\" because of an uncaught exception: " + e);
}
}
@Override
public boolean supports(Class<?> type) {
return type.equals(IrisGenerator.class);
}
@Override
public String getRandomDefault()
{
return "generator";
}
}

View File

@ -0,0 +1,78 @@
package com.volmit.iris.util.decree.handlers;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.engine.object.common.IrisScript;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.decree.DecreeParameterHandler;
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
import java.io.File;
public class ScriptHandler implements DecreeParameterHandler<IrisScript> {
@Override
public KList<IrisScript> getPossibilities() {
KMap<String, IrisScript> p = new KMap<>();
//noinspection ConstantConditions
for(File i : Iris.instance.getDataFolder("packs").listFiles())
{
if(i.isDirectory()) {
IrisData data = new IrisData(i, true);
for (IrisScript j : data.getScriptLoader().loadAll(data.getScriptLoader().getPossibleKeys()))
{
p.putIfAbsent(j.getLoadKey(), j);
}
data.close();
}
}
return p.v();
}
@Override
public String toString(IrisScript script) {
return script.getLoadKey();
}
@Override
public IrisScript parse(String in) throws DecreeParsingException, DecreeWhichException {
try
{
KList<IrisScript> options = getPossibilities(in);
if(options.isEmpty())
{
throw new DecreeParsingException("Unable to find Script \"" + in + "\"");
}
else if(options.size() > 1)
{
throw new DecreeWhichException();
}
return options.get(0);
}
catch(DecreeParsingException e){
throw e;
}
catch(Throwable e)
{
throw new DecreeParsingException("Unable to find Script \"" + in + "\" because of an uncaught exception: " + e);
}
}
@Override
public boolean supports(Class<?> type) {
return type.equals(IrisScript.class);
}
@Override
public String getRandomDefault()
{
return "script";
}
}

View File

@ -462,7 +462,7 @@ public class VirtualDecreeCommand {
try
{
if(value == null && !i.getParam().defaultValue().trim().isEmpty())
if(value == null && i.hasDefault())
{
value = i.getDefaultValue();
}
@ -617,6 +617,14 @@ public class VirtualDecreeCommand {
return Objects.hash(getName(), getDescription(), getType(), getPath());
}
@Override
public boolean equals(Object obj){
if (!(obj instanceof VirtualDecreeCommand)){
return false;
}
return this.hashCode() == obj.hashCode();
}
public boolean matches(String in)
{
KList<String> a = getNames();