From 05088c10630f9f474c8484e2b8da92c27c4f333a Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Wed, 18 Aug 2021 10:09:25 +0200 Subject: [PATCH 01/21] Matter & save --- .../volmit/iris/core/decrees/DecObject.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/main/java/com/volmit/iris/core/decrees/DecObject.java b/src/main/java/com/volmit/iris/core/decrees/DecObject.java index d428238eb..c6f206e79 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecObject.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecObject.java @@ -1,9 +1,12 @@ package com.volmit.iris.core.decrees; +import com.volmit.iris.Iris; import com.volmit.iris.core.command.object.CommandIrisObjectUndo; import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.engine.object.common.IObjectPlacer; +import com.volmit.iris.engine.object.dimensional.IrisDimension; import com.volmit.iris.engine.object.objects.IrisObject; import com.volmit.iris.engine.object.objects.IrisObjectPlacement; import com.volmit.iris.engine.object.objects.IrisObjectPlacementScaleInterpolator; @@ -17,6 +20,8 @@ import com.volmit.iris.util.decree.annotations.Param; import com.volmit.iris.util.format.C; import com.volmit.iris.util.math.Direction; import com.volmit.iris.util.math.RNG; +import com.volmit.iris.util.matter.Matter; +import com.volmit.iris.util.matter.WorldMatter; import com.volmit.iris.util.scheduling.Queue; import org.bukkit.*; import org.bukkit.block.Block; @@ -26,6 +31,8 @@ import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.io.File; +import java.io.IOException; import java.text.NumberFormat; import java.util.*; import java.util.stream.Collectors; @@ -302,4 +309,44 @@ public class DecObject implements DecreeExecutor { }; } + //@Decree(description = "Paste a matter object", aliases = "matterpaste") + public void mpaste( + @Param(description = "The matter object to paste") + Matter object + ){ + WorldMatter.placeMatter(object, player().getLocation()); + } + + @Decree(description = "Save an object") + public void save( + @Param(description = "The dimension to store the object in", contextual = true) + IrisDimension dimension, + @Param(description = "The file to store it in, can use / for subfolders") + String fileName, + @Param(description = "Overwrite existing object files", defaultValue = "false") + boolean overwrite + ){ + IrisObject o = WandSVC.createSchematic(player().getInventory().getItemInMainHand()); + + if (o == null) { + sender().sendMessage(C.YELLOW + "You need to hold your wand!"); + return; + } + + File file = Iris.service(StudioSVC.class).getWorkspaceFile(dimension.getLoadKey(), "objects", fileName + ".iob"); + + if (file.exists() && !overwrite) { + sender().sendMessage(C.RED + "File already exists. Set overwrite=true to overwrite it."); + return; + } + try { + o.write(file); + } catch (IOException e){ + sender().sendMessage(C.RED + "Failed to save object because of an IOException: " + e.getMessage()); + Iris.reportError(e); + } + + sender().playSound(Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); + sender().sendMessage(C.GREEN + "Successfully object to saved: " + dimension.getLoadKey() + "/objects/" + fileName); + } } From fc096dc6fa52a00ca574aa37fa99a2bcf8076d41 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Wed, 18 Aug 2021 12:58:45 +0200 Subject: [PATCH 02/21] See description - No-parameter command nodes are now on-click-runnable - Parameters are now sorted by: name *and then* required --- .../volmit/iris/util/decree/DecreeNode.java | 18 +++++++++++++++--- .../volmit/iris/util/plugin/VolmitSender.java | 14 ++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeNode.java b/src/main/java/com/volmit/iris/util/decree/DecreeNode.java index 884ec3aff..92d8ac0fc 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeNode.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeNode.java @@ -47,13 +47,25 @@ public class DecreeNode { * @return The list of parameters if ALL are annotated by @{@link Param}, else null */ public KList getParameters() { - KList p = new KList<>(); + KList required = new KList<>(); + KList optional = new KList<>(); for (Parameter i : method.getParameters()) { - p.add(new DecreeParameter(i)); + DecreeParameter p = new DecreeParameter(i); + if (p.isRequired()){ + required.add(p); + } else { + optional.add(p); + } } - return p; + required.sort(); + + optional.sort(); + + required.addAll(optional); + + return required; } public String getName() { diff --git a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java index b211bc62d..206b30f21 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java @@ -21,6 +21,7 @@ package com.volmit.iris.util.plugin; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.decree.DecreeParameter; import com.volmit.iris.util.decree.virtual.VirtualDecreeCommand; import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.Form; @@ -42,6 +43,7 @@ import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.Plugin; import java.time.Duration; +import java.util.Comparator; import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -432,7 +434,7 @@ public class VolmitSender implements CommandSender { ? ((i.getNode().getParameters().isEmpty() ? "There are no parameters." : "Hover over all of the parameters to learn more." + "\n")) - : "This is a command category. Run <#98eda5>" + i.getPath()) + : "This is a command category. Click to run <#98eda5>" + i.getPath()) + (i.isNode() ? (i.getNode().getParameters().isNotEmpty()) ? "<#aebef2>✦ <#5ef288>" @@ -445,10 +447,10 @@ public class VolmitSender implements CommandSender { : "" : "") + (i.isNode() ? "" + pickRandoms(Math.min(i.getNode().getParameters().size() + 1, 5), i) + "" : "") - + "'>" + + "'>" + "<#46826a>⇀ " + i.getName() + "" + (i.isNode() ? - " " + i.getNode().getParameters().convert((f) + " " + i.getNode().getParameters().sort().convert((f) -> " "<#d665f0>" + ff).toString(", ") + "\n" + "<#3fe05a>✎ <#6ad97d>" + f.getDescription() + "\n" @@ -460,10 +462,10 @@ public class VolmitSender implements CommandSender { + (f.isContextual() ? "<#ff9900>➱ <#ffcc00>The value may be derived from environment context \n" : "") + "<#cc00ff>✢ <#ff33cc>This parameter is of type " + f.getType().getSimpleName() + "'>" - + (f.isRequired() ? "[" : "") + + (f.isRequired() ? "[" : "<#4f4f4f>⊰") + "" + f.getName() - + (f.isRequired() ? "]" : "") - + "").toString(" ") + + (f.isRequired() ? "] " : "<#4f4f4f>⊱") + "" + + "").toString("") : " - Category of Commands" ) ); From 44d02e6dfd7bda2073e0636b1eeabfb34af9ca89 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Wed, 18 Aug 2021 12:58:59 +0200 Subject: [PATCH 03/21] Aliases, colors & patches --- .../java/com/volmit/iris/core/decrees/DecIris.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/decrees/DecIris.java b/src/main/java/com/volmit/iris/core/decrees/DecIris.java index b86d1dc8f..eaed496e1 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -46,7 +46,7 @@ public class DecIris implements DecreeExecutor { private DecObject object; - @Decree(description = "Create a new world", aliases = "+") + @Decree(description = "Create a new world", aliases = {"+", "c"}) public void create( @Param(aliases = "world-name", description = "The name of the world to create", defaultValue = "IrisWorld") String name, @@ -86,7 +86,7 @@ public class DecIris implements DecreeExecutor { @Decree(description = "Print version information") public void version() { - sender().sendMessage("Iris v" + Iris.instance.getDescription().getVersion() + " by Volmit Software"); + sender().sendMessage(C.GREEN + "Iris v" + Iris.instance.getDescription().getVersion() + " by Volmit Software"); } @Decree(description = "Set aura spins") @@ -109,7 +109,7 @@ public class DecIris implements DecreeExecutor { public void bitwise( @Param(description = "The first value to run calculations on") int value1, - @Param(description = "The operator: | & ^ >> << %") + @Param(description = "The operator: | & ^ ≺≺ ≻≻ %") String operator, @Param(description = "The second value to run calculations on") int value2 @@ -127,7 +127,7 @@ public class DecIris implements DecreeExecutor { sender().sendMessage(C.RED + "The operator you entered: (" + operator + ") is invalid!"); return; } - sender().sendMessage(C.GREEN + "" + value1 + " " + C.GREEN + operator.replaceAll("<", "≺").replaceAll(">", "≻") + " " + C.GREEN + value2 + C.GREEN + " returns " + C.GREEN + v); + sender().sendMessage(C.GREEN + "" + value1 + " " + C.GREEN + operator.replaceAll("<", "≺").replaceAll(">", "≻").replaceAll("%", "%") + " " + C.GREEN + value2 + C.GREEN + " returns " + C.GREEN + v); } @Decree(description = "Toggle debug") @@ -138,7 +138,7 @@ public class DecIris implements DecreeExecutor { IrisSettings.get().getGeneral().setDebug(on); } - @Decree(description = "Download a project.") + @Decree(description = "Download a project.", aliases = "dl") public void download( @Param(name = "pack", description = "The pack to download", defaultValue = "overworld", aliases = "project") String pack, From b32db945be55b6f2f2a0d979dc5ff5735b17594b Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Wed, 18 Aug 2021 13:05:19 +0200 Subject: [PATCH 04/21] patch debug --- .../com/volmit/iris/core/decrees/DecIris.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/decrees/DecIris.java b/src/main/java/com/volmit/iris/core/decrees/DecIris.java index eaed496e1..4ae7360b3 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -25,8 +25,11 @@ import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.object.dimensional.IrisDimension; import com.volmit.iris.util.decree.DecreeExecutor; import com.volmit.iris.util.decree.DecreeOrigin; +import com.volmit.iris.util.decree.DecreeSystem; import com.volmit.iris.util.decree.annotations.Decree; import com.volmit.iris.util.decree.annotations.Param; +import com.volmit.iris.util.decree.exceptions.DecreeParsingException; +import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import com.volmit.iris.util.format.C; import com.volmit.iris.util.math.M; @@ -132,10 +135,23 @@ public class DecIris implements DecreeExecutor { @Decree(description = "Toggle debug") public void debug( - @Param(name = "on", description = "Whether or not debug should be on", defaultValue = "true") - boolean on + @Param(name = "on", description = "Whether or not debug should be on", defaultValue = "toggle") + String on ) { - IrisSettings.get().getGeneral().setDebug(on); + Boolean val; + try { + val = (Boolean) DecreeSystem.getHandler(boolean.class).parse(on); + } catch (Throwable e) { + if (on.equals("toggle")){ + val = !IrisSettings.get().getGeneral().isDebug(); + } else { + sender().sendMessage(C.RED + "Failed to convert input: " + on + " to a true or false value"); + Iris.reportError(e); + return; + } + } + sender().sendMessage(C.GREEN + "Set debug to " + val); + IrisSettings.get().getGeneral().setDebug(val); } @Decree(description = "Download a project.", aliases = "dl") From 2de5bc2855d16ee5597c8aac510bd252bf118476 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Wed, 18 Aug 2021 13:14:29 +0200 Subject: [PATCH 05/21] Dont sort subvalues to allow better control --- src/main/java/com/volmit/iris/util/decree/DecreeNode.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeNode.java b/src/main/java/com/volmit/iris/util/decree/DecreeNode.java index 92d8ac0fc..ab512b3c0 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeNode.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeNode.java @@ -58,11 +58,7 @@ public class DecreeNode { optional.add(p); } } - - required.sort(); - - optional.sort(); - + required.addAll(optional); return required; From 10da9182d118ea9a52553f761062de79caeaa823 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Wed, 18 Aug 2021 13:14:41 +0200 Subject: [PATCH 06/21] Improve boolean handling in DecIris --- .../com/volmit/iris/core/decrees/DecIris.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/decrees/DecIris.java b/src/main/java/com/volmit/iris/core/decrees/DecIris.java index 4ae7360b3..dc56b2a2f 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -32,6 +32,7 @@ import com.volmit.iris.util.decree.exceptions.DecreeParsingException; import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import com.volmit.iris.util.format.C; import com.volmit.iris.util.math.M; +import lombok.val; import java.io.File; import java.io.FileOutputStream; @@ -51,7 +52,7 @@ public class DecIris implements DecreeExecutor { @Decree(description = "Create a new world", aliases = {"+", "c"}) public void create( - @Param(aliases = "world-name", description = "The name of the world to create", defaultValue = "IrisWorld") + @Param(aliases = "world-name", description = "The name of the world to create") String name, @Param(aliases = "dimension", description = "The dimension type to create the world with", defaultValue = "overworld") IrisDimension type, @@ -139,18 +140,18 @@ public class DecIris implements DecreeExecutor { String on ) { Boolean val; - try { - val = (Boolean) DecreeSystem.getHandler(boolean.class).parse(on); - } catch (Throwable e) { - if (on.equals("toggle")){ - val = !IrisSettings.get().getGeneral().isDebug(); - } else { + if (on.equals("toggle") || on.equals("t")) { + val = !IrisSettings.get().getGeneral().isDebug(); + } else { + try { + val = (Boolean) DecreeSystem.getHandler(boolean.class).parse(on); + } catch (Throwable e){ sender().sendMessage(C.RED + "Failed to convert input: " + on + " to a true or false value"); Iris.reportError(e); return; } } - sender().sendMessage(C.GREEN + "Set debug to " + val); + sender().sendMessage(C.GREEN + "Set debug to " +val); IrisSettings.get().getGeneral().setDebug(val); } From a4190672d36b1c27052ca3ce98cff8776f682e52 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Wed, 18 Aug 2021 13:14:53 +0200 Subject: [PATCH 07/21] Don't sort values again (done in getParams) --- src/main/java/com/volmit/iris/util/plugin/VolmitSender.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java index 206b30f21..082da56f9 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java @@ -450,7 +450,7 @@ public class VolmitSender implements CommandSender { + "'>" + "<#46826a>⇀ " + i.getName() + "" + (i.isNode() ? - " " + i.getNode().getParameters().sort().convert((f) + " " + i.getNode().getParameters().convert((f) -> " "<#d665f0>" + ff).toString(", ") + "\n" + "<#3fe05a>✎ <#6ad97d>" + f.getDescription() + "\n" From aba5add7f90848aac3386edf340ecfb0e89a1300 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Wed, 18 Aug 2021 15:05:31 +0200 Subject: [PATCH 08/21] Engine check --- src/main/java/com/volmit/iris/core/decrees/DecStudio.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java index 7a243f2aa..cd5efd934 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java @@ -288,6 +288,11 @@ public class DecStudio implements DecreeExecutor { @Decree(description = "Charges all spawners in the area", aliases = "zzt", origin = DecreeOrigin.PLAYER) public void charge() { + if (!IrisToolbelt.isIrisWorld(world())){ + sender().sendMessage(C.RED + "You must be in an Iris world to charge spawners!"); + return; + } + sender().sendMessage(C.GREEN + "Charging spawners!"); engine().getWorldManager().chargeEnergy(); } From 5a236e3bea8e98e3c770175b530ac8ef312931be Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Wed, 18 Aug 2021 15:05:47 +0200 Subject: [PATCH 09/21] Fuck that builder. Yeet --- .../volmit/iris/util/plugin/VolmitSender.java | 140 ++++++++++++------ 1 file changed, 92 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java index 082da56f9..3d5ad1e18 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java @@ -425,55 +425,99 @@ public class VolmitSender implements CommandSender { public void sendDecreeHelpNode(VirtualDecreeCommand i){ if (isPlayer()) { - //@builder - String s = ( - " "<#42ecf5>" + f).toString(", ") + "\n" - + "<#3fe05a>✎ <#6ad97d>" + i.getDescription() + "\n" - + "<#bbe03f>✒ <#a8e0a2>" + (i.isNode() - ? ((i.getNode().getParameters().isEmpty() - ? "There are no parameters." - : "Hover over all of the parameters to learn more." + "\n")) - : "This is a command category. Click to run <#98eda5>" + i.getPath()) - + (i.isNode() - ? (i.getNode().getParameters().isNotEmpty()) - ? "<#aebef2>✦ <#5ef288>" - + i.getParentPath() - + " <#42ecf5>" - + i.getName() + " " - + i.getNode().getParameters().convert((f) - -> "<#d665f0>" + f.example()) - .toString(" ") + "\n" - : "" - : "") - + (i.isNode() ? "" + pickRandoms(Math.min(i.getNode().getParameters().size() + 1, 5), i) + "" : "") - + "'>" - + "<#46826a>⇀ " + i.getName() + "" - + (i.isNode() ? - " " + i.getNode().getParameters().convert((f) - -> " "<#d665f0>" + ff).toString(", ") + "\n" - + "<#3fe05a>✎ <#6ad97d>" + f.getDescription() + "\n" - + (f.isRequired() - ? "<#db4321>⚠ <#faa796>This parameter is required." - : (f.hasDefault() - ? "<#2181db>✔ <#78dcf0>Defaults to \""+f.getParam().defaultValue()+"\" if undefined." - : "<#a73abd>✔ <#78dcf0>This parameter is optional.")) + "\n" - + (f.isContextual() ? "<#ff9900>➱ <#ffcc00>The value may be derived from environment context \n" : "") - + "<#cc00ff>✢ <#ff33cc>This parameter is of type " + f.getType().getSimpleName() - + "'>" - + (f.isRequired() ? "[" : "<#4f4f4f>⊰") - + "" + f.getName() - + (f.isRequired() ? "] " : "<#4f4f4f>⊱") + "" - + "").toString("") - : " - Category of Commands" - ) - ); - //@done - sendMessageRaw(s); - System.out.println(s); + + String newline = "\n"; + + /// Command + // Contains main command & aliases + String title = i.getPath() + " >" + "<#46826a>⇀ " + i.getName(); + String hoverTitle = i.getNames().copy().reverse().convert((f) -> "<#42ecf5>" + f).toString(", "); + String description = "<#3fe05a>✎ <#6ad97d>" + i.getDescription(); + String usage = "<#bbe03f>✒ <#a8e0a2>"; + String onClick = ""; + + String suggestion = ""; + String suggestions = ""; + if (i.isNode() && i.getNode().getParameters().isNotEmpty()) { + suggestion += newline + "<#aebef2>✦ <#5ef288>" + i.getParentPath() + " <#42ecf5>" + i.getName() + " " + + i.getNode().getParameters().convert((f) -> "<#d665f0>" + f.example()).toString(" "); + suggestions += newline + "" + pickRandoms(Math.min(i.getNode().getParameters().size() + 1, 5), i); + } + + /// Params + StringBuilder nodes = new StringBuilder(); + if (i.isNode()){ + for (DecreeParameter p : i.getNode().getParameters()) { + + String nTitle = "" + p.getName(); + String nHoverTitle = p.getNames().convert((ff) -> "<#d665f0>" + ff).toString(", "); + String nDescription = "<#3fe05a>✎ <#6ad97d>" + p.getDescription(); + String nUsage; + String context = ""; + if (p.isRequired()){ + nUsage = "<#db4321>⚠ <#faa796>This parameter is required."; + } else if (p.hasDefault()) { + nUsage = "<#2181db>✔ <#78dcf0>Defaults to \""+ p.getParam().defaultValue()+"\" if undefined."; + } else { + nUsage = "<#a73abd>✔ <#78dcf0>This parameter is optional."; + } + if (p.isContextual()){ + context = "<#ff9900>➱ <#ffcc00>The value may be derived from environment context" + newline; + } + String type = "<#cc00ff>✢ <#ff33cc>This parameter is of type " + p.getType().getSimpleName(); + String fullTitle; + if (p.isRequired()){ + fullTitle = "[" + nTitle + "] "; + } else { + fullTitle = "<#4f4f4f>⊰" + nTitle + "<#4f4f4f>⊱"; + } + + nodes + .append("") + .append(fullTitle) + .append(""); + } + } else { + nodes = new StringBuilder(" - Category of Commands"); + } + + /// Wrapper + StringBuilder wrapper = new StringBuilder() + .append("") + .append(onClick) + .append("") + .append(" ") + .append(nodes); + + sendMessageRaw(wrapper.toString()); + System.out.println(wrapper); } else { - sendMessage(i.getPath() + "()"); + sendMessage(i.getPath()); } } From 11d0274a1bbfc3d5430271a18b5539690b83593f Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Thu, 19 Aug 2021 09:54:21 +0200 Subject: [PATCH 10/21] Simple null check --- .../com/volmit/iris/core/decrees/DecIris.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/decrees/DecIris.java b/src/main/java/com/volmit/iris/core/decrees/DecIris.java index dc56b2a2f..b4282cc37 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -136,23 +136,14 @@ public class DecIris implements DecreeExecutor { @Decree(description = "Toggle debug") public void debug( - @Param(name = "on", description = "Whether or not debug should be on", defaultValue = "toggle") - String on + @Param(description = "Whether or not debug should be on", defaultValue = "toggle") + Boolean on ) { - Boolean val; - if (on.equals("toggle") || on.equals("t")) { - val = !IrisSettings.get().getGeneral().isDebug(); - } else { - try { - val = (Boolean) DecreeSystem.getHandler(boolean.class).parse(on); - } catch (Throwable e){ - sender().sendMessage(C.RED + "Failed to convert input: " + on + " to a true or false value"); - Iris.reportError(e); - return; - } + if (on == null){ + on = !IrisSettings.get().getGeneral().isDebug(); } - sender().sendMessage(C.GREEN + "Set debug to " +val); - IrisSettings.get().getGeneral().setDebug(val); + sender().sendMessage(C.GREEN + "Set debug to " + on); + IrisSettings.get().getGeneral().setDebug(on); } @Decree(description = "Download a project.", aliases = "dl") From ade88a60552627f3330083faf883df219a9a1bcb Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Thu, 19 Aug 2021 09:54:33 +0200 Subject: [PATCH 11/21] rename fileName + alias force --- .../com/volmit/iris/core/decrees/DecObject.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/decrees/DecObject.java b/src/main/java/com/volmit/iris/core/decrees/DecObject.java index c6f206e79..a70ab1703 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecObject.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecObject.java @@ -309,21 +309,13 @@ public class DecObject implements DecreeExecutor { }; } - //@Decree(description = "Paste a matter object", aliases = "matterpaste") - public void mpaste( - @Param(description = "The matter object to paste") - Matter object - ){ - WorldMatter.placeMatter(object, player().getLocation()); - } - @Decree(description = "Save an object") public void save( @Param(description = "The dimension to store the object in", contextual = true) IrisDimension dimension, @Param(description = "The file to store it in, can use / for subfolders") - String fileName, - @Param(description = "Overwrite existing object files", defaultValue = "false") + String name, + @Param(description = "Overwrite existing object files", defaultValue = "false", aliases = "force") boolean overwrite ){ IrisObject o = WandSVC.createSchematic(player().getInventory().getItemInMainHand()); @@ -333,7 +325,7 @@ public class DecObject implements DecreeExecutor { return; } - File file = Iris.service(StudioSVC.class).getWorkspaceFile(dimension.getLoadKey(), "objects", fileName + ".iob"); + File file = Iris.service(StudioSVC.class).getWorkspaceFile(dimension.getLoadKey(), "objects", name + ".iob"); if (file.exists() && !overwrite) { sender().sendMessage(C.RED + "File already exists. Set overwrite=true to overwrite it."); @@ -347,6 +339,6 @@ public class DecObject implements DecreeExecutor { } sender().playSound(Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); - sender().sendMessage(C.GREEN + "Successfully object to saved: " + dimension.getLoadKey() + "/objects/" + fileName); + sender().sendMessage(C.GREEN + "Successfully object to saved: " + dimension.getLoadKey() + "/objects/" + name); } } From 6abef569e81db45fa9c432a5c9df261c87d4eb81 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Thu, 19 Aug 2021 09:54:51 +0200 Subject: [PATCH 12/21] Further simplifications of sender for clarity --- .../volmit/iris/util/plugin/VolmitSender.java | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java index 3d5ad1e18..73e1cee1e 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java @@ -430,24 +430,23 @@ public class VolmitSender implements CommandSender { /// Command // Contains main command & aliases - String title = i.getPath() + " >" + "<#46826a>⇀ " + i.getName(); + String realText = i.getPath() + " >" + "<#46826a>⇀ " + i.getName(); String hoverTitle = i.getNames().copy().reverse().convert((f) -> "<#42ecf5>" + f).toString(", "); String description = "<#3fe05a>✎ <#6ad97d>" + i.getDescription(); - String usage = "<#bbe03f>✒ <#a8e0a2>"; - String onClick = ""; String suggestion = ""; String suggestions = ""; @@ -501,21 +500,24 @@ public class VolmitSender implements CommandSender { } /// Wrapper - StringBuilder wrapper = new StringBuilder() - .append("") - .append(onClick) - .append("") - .append(" ") - .append(nodes); + String wrapper = + "" + + "" + + "" + + " " + + nodes; - sendMessageRaw(wrapper.toString()); - System.out.println(wrapper); + sendMessageRaw(wrapper); } else { sendMessage(i.getPath()); } From 30f9348c26b905c5245c6392817aa0356d72986c Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Thu, 19 Aug 2021 09:56:35 +0200 Subject: [PATCH 13/21] doc --- src/main/java/com/volmit/iris/util/plugin/VolmitSender.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java index 25912ef04..9110d849f 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java @@ -505,8 +505,8 @@ public class VolmitSender implements CommandSender { hoverTitle + newline + description + newline + usage + - suggestion + - suggestions + + suggestion + //Newlines for suggestions are added when they're built, to prevent blanklines. + suggestions + // ^ "'>" + " Date: Thu, 19 Aug 2021 11:28:30 +0200 Subject: [PATCH 14/21] Shift --- .../volmit/iris/core/decrees/DecObject.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/com/volmit/iris/core/decrees/DecObject.java b/src/main/java/com/volmit/iris/core/decrees/DecObject.java index a70ab1703..f1adb831c 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecObject.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecObject.java @@ -341,4 +341,30 @@ public class DecObject implements DecreeExecutor { sender().playSound(Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); sender().sendMessage(C.GREEN + "Successfully object to saved: " + dimension.getLoadKey() + "/objects/" + name); } + + @Decree(description = "Shift a selection in your looking direction", aliases = "-") + public void shift( + @Param(description = "The amount to shift by", defaultValue = "1") + int amount + ){ + if (!WandSVC.isHoldingWand(player())) { + sender().sendMessage("Hold your wand."); + return; + } + + Location[] b = WandSVC.getCuboid(player().getInventory().getItemInMainHand()); + Location a1 = b[0].clone(); + Location a2 = b[1].clone(); + Direction d = Direction.closest(player().getLocation().getDirection()).reverse(); + a1.add(d.toVector().multiply(amount)); + a2.add(d.toVector().multiply(amount)); + Cuboid cursor = new Cuboid(a1, a2); + b[0] = cursor.getLowerNE(); + b[1] = cursor.getUpperSW(); + player().getInventory().setItemInMainHand(WandSVC.createWand(b[0], b[1])); + player().updateInventory(); + sender().playSound(Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); + } + + } From 7347300f05464072ba1a64fe8308a5b79fd4ab15 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Thu, 19 Aug 2021 11:57:56 +0200 Subject: [PATCH 15/21] Rework undo for Decree Undo now in a service. No longer per-player, collective history We're not worledit - Dan Removes the need for deprecated offlinePlayer calls as well. --- .../object/CommandIrisObjectPaste.java | 3 +- .../command/object/CommandIrisObjectUndo.java | 54 ++------------- .../volmit/iris/core/decrees/DecObject.java | 14 +++- .../volmit/iris/core/service/ObjectSVC.java | 67 +++++++++++++++++++ 4 files changed, 86 insertions(+), 52 deletions(-) create mode 100644 src/main/java/com/volmit/iris/core/service/ObjectSVC.java diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectPaste.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectPaste.java index 9dab1b2ab..714cb9927 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectPaste.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectPaste.java @@ -21,6 +21,7 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.core.service.ObjectSVC; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.core.tools.IrisToolbelt; @@ -185,7 +186,7 @@ public class CommandIrisObjectPaste extends MortarCommand { Map futureChanges = new HashMap<>(); obj.place(block.getBlockX(), block.getBlockY() + (int) obj.getCenter().getY(), block.getBlockZ(), createPlacer(sender.player(), block.getWorld(), futureChanges), placement, new RNG(), null); - CommandIrisObjectUndo.addChanges(sender.player(), futureChanges); + Iris.service(ObjectSVC.class).addChanges(futureChanges); if (intoWand) { ItemStack newWand = WandSVC.createWand(block.clone().subtract(obj.getCenter()).add(obj.getW() - 1, diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectUndo.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectUndo.java index dea27478a..343df19e0 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectUndo.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectUndo.java @@ -20,6 +20,7 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; +import com.volmit.iris.core.service.ObjectSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; @@ -34,7 +35,6 @@ import java.util.*; public class CommandIrisObjectUndo extends MortarCommand { - private static final Map>> undos = new HashMap<>(); public CommandIrisObjectUndo() { super("undo", "u", "revert"); @@ -101,14 +101,14 @@ public class CommandIrisObjectUndo extends MortarCommand { sender.sendMessage("Please specify an amount greater than 0!"); return true; } - - if (!undos.containsKey(player) || undos.get(player).size() == 0) { + ObjectSVC service = Iris.service(ObjectSVC.class); + if (service.getUndos().size() == 0) { sender.sendMessage("No pastes to undo"); return true; } - int actualReverts = Math.min(undos.get(player).size(), amount); - revertChanges(player, amount); + int actualReverts = Math.min(service.getUndos().size(), amount); + service.revertChanges(actualReverts); sender.sendMessage("Reverted " + actualReverts + " pastes!"); return true; @@ -118,48 +118,4 @@ public class CommandIrisObjectUndo extends MortarCommand { protected String getArgsUsage() { return "[-number [num]] [-user [username]]"; } - - public static void addChanges(Player player, Map oldBlocks) { - if (!undos.containsKey(player.getUniqueId())) { - undos.put(player.getUniqueId(), new ArrayDeque<>()); - } - - undos.get(player.getUniqueId()).add(oldBlocks); - } - - public static void revertChanges(UUID player, int amount) { - loopChange(player, amount); - } - - private static void loopChange(UUID uuid, int amount) { - Deque> queue = undos.get(uuid); - if (queue != null && queue.size() > 0) { - revert(queue.pollLast()); - if (amount > 1) { - J.s(() -> loopChange(uuid, amount - 1), 2); - } - } - } - - /** - * Reverts all the block changes provided, 200 blocks per tick - * - * @param blocks The blocks to remove - */ - private static void revert(Map blocks) { - int amount = 0; - Iterator> it = blocks.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry entry = it.next(); - BlockData data = entry.getValue(); - entry.getKey().setBlockData(data, false); - it.remove(); - - amount++; - - if (amount > 200) { - J.s(() -> revert(blocks), 1); - } - } - } } diff --git a/src/main/java/com/volmit/iris/core/decrees/DecObject.java b/src/main/java/com/volmit/iris/core/decrees/DecObject.java index f1adb831c..7cafdb2ec 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecObject.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecObject.java @@ -3,6 +3,7 @@ package com.volmit.iris.core.decrees; import com.volmit.iris.Iris; import com.volmit.iris.core.command.object.CommandIrisObjectUndo; import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.core.service.ObjectSVC; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.engine.object.common.IObjectPlacer; @@ -221,7 +222,7 @@ public class DecObject implements DecreeExecutor { object = object.scaled(scale, interpolator); object.place(block.getBlockX(), block.getBlockY() + (int) object.getCenter().getY(), block.getBlockZ(), createPlacer(block.getWorld(), futureChanges), placement, new RNG(), null); - CommandIrisObjectUndo.addChanges(player(), futureChanges); + Iris.service(ObjectSVC.class).addChanges(futureChanges); if (edit) { ItemStack newWand = WandSVC.createWand(block.clone().subtract(object.getCenter()).add(object.getW() - 1, @@ -366,5 +367,14 @@ public class DecObject implements DecreeExecutor { sender().playSound(Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); } - + @Decree(description = "Undo a number of pastes", aliases = "-") + public void undo( + @Param(description = "The amount of pastes to undo", defaultValue = "1") + int amount + ){ + ObjectSVC service = Iris.service(ObjectSVC.class); + int actualReverts = Math.min(service.getUndos().size(), amount); + service.revertChanges(actualReverts); + sender().sendMessage("Reverted " + actualReverts + " pastes!"); + } } diff --git a/src/main/java/com/volmit/iris/core/service/ObjectSVC.java b/src/main/java/com/volmit/iris/core/service/ObjectSVC.java new file mode 100644 index 000000000..4450a67b8 --- /dev/null +++ b/src/main/java/com/volmit/iris/core/service/ObjectSVC.java @@ -0,0 +1,67 @@ +package com.volmit.iris.core.service; + +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.plugin.IrisService; +import com.volmit.iris.util.scheduling.J; +import lombok.Getter; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Player; + +import java.util.*; + +public class ObjectSVC implements IrisService { + + @Getter + private final Deque> undos = new ArrayDeque<>(); + + + @Override + public void onEnable() { + + } + + @Override + public void onDisable() { + + } + + public void addChanges(Map oldBlocks) { + undos.add(oldBlocks); + } + + public void revertChanges(int amount) { + loopChange(amount); + } + + private void loopChange(int amount) { + if (undos.size() > 0) { + revert(undos.pollLast()); + if (amount > 1) { + J.s(() -> loopChange(amount - 1), 2); + } + } + } + + /** + * Reverts all the block changes provided, 200 blocks per tick + * + * @param blocks The blocks to remove + */ + private void revert(Map blocks) { + int amount = 0; + Iterator> it = blocks.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + BlockData data = entry.getValue(); + entry.getKey().setBlockData(data, false); + it.remove(); + + amount++; + + if (amount > 200) { + J.s(() -> revert(blocks), 1); + } + } + } +} From 4f7bfd14c0980d3ce44d569bc05300920de4504e Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Thu, 19 Aug 2021 12:02:30 +0200 Subject: [PATCH 16/21] alias O in object because studiO was taking priority --- src/main/java/com/volmit/iris/core/decrees/DecObject.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/volmit/iris/core/decrees/DecObject.java b/src/main/java/com/volmit/iris/core/decrees/DecObject.java index 7cafdb2ec..c52077410 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecObject.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecObject.java @@ -38,7 +38,7 @@ import java.text.NumberFormat; import java.util.*; import java.util.stream.Collectors; -@Decree(name = "object", origin = DecreeOrigin.PLAYER, studio = true, description = "Iris object manipulation") +@Decree(name = "object", aliases = "o", origin = DecreeOrigin.PLAYER, studio = true, description = "Iris object manipulation") public class DecObject implements DecreeExecutor { @Decree(description = "Check the composition of an object") From 2e661cb2f8d5bfafefeea0970a14dd3a7b78327b Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Thu, 19 Aug 2021 12:37:30 +0200 Subject: [PATCH 17/21] Patch object handlers --- .../volmit/iris/core/decrees/DecObject.java | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/decrees/DecObject.java b/src/main/java/com/volmit/iris/core/decrees/DecObject.java index c52077410..f4deb7b97 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecObject.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecObject.java @@ -1,7 +1,6 @@ package com.volmit.iris.core.decrees; import com.volmit.iris.Iris; -import com.volmit.iris.core.command.object.CommandIrisObjectUndo; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.core.service.ObjectSVC; import com.volmit.iris.core.service.StudioSVC; @@ -18,18 +17,16 @@ 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.decree.specialhandlers.ObjectHandler; import com.volmit.iris.util.format.C; import com.volmit.iris.util.math.Direction; import com.volmit.iris.util.math.RNG; -import com.volmit.iris.util.matter.Matter; -import com.volmit.iris.util.matter.WorldMatter; import com.volmit.iris.util.scheduling.Queue; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.TileState; import org.bukkit.block.data.BlockData; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.io.File; @@ -43,13 +40,14 @@ public class DecObject implements DecreeExecutor { @Decree(description = "Check the composition of an object") public void analyze( - @Param(description = "The object to analyze") - IrisObject object + @Param(description = "The object to analyze", customHandler = ObjectHandler.class) + String object ) { - sender().sendMessage("Object Size: " + object.getW() + " * " + object.getH() + " * " + object.getD() + ""); - sender().sendMessage("Blocks Used: " + NumberFormat.getIntegerInstance().format(object.getBlocks().size())); + IrisObject o = IrisData.loadAnyObject(object); + sender().sendMessage("Object Size: " + o.getW() + " * " + o.getH() + " * " + o.getD() + ""); + sender().sendMessage("Blocks Used: " + NumberFormat.getIntegerInstance().format(o.getBlocks().size())); - Queue queue = object.getBlocks().enqueueValues(); + Queue queue = o.getBlocks().enqueueValues(); Map> unsorted = new HashMap<>(); Map amounts = new HashMap<>(); Map materials = new HashMap<>(); @@ -192,19 +190,21 @@ public class DecObject implements DecreeExecutor { Material.POPPY, Material.DANDELION); @Decree(description = "Paste an object") public void paste( - @Param(description = "The object to paste") - IrisObject object, + @Param(description = "The object to paste", customHandler = ObjectHandler.class) + String object, @Param(description = "Whether or not to edit the object (need to hold wand)", defaultValue = "false") boolean edit, @Param(description = "The amount of degrees to rotate by", defaultValue = "0") int rotate, @Param(description = "The factor by which to scale the object placement", defaultValue = "1") - double scale, - @Param(description = "The scale interpolator to use", defaultValue = "none") - IrisObjectPlacementScaleInterpolator interpolator + double scale +// , +// @Param(description = "The scale interpolator to use", defaultValue = "none") +// IrisObjectPlacementScaleInterpolator interpolator ){ - double maxScale = Double.max(10 - object.getBlocks().size() / 10000d, 1); - if (scale < maxScale){ + IrisObject o = IrisData.loadAnyObject(object); + double maxScale = Double.max(10 - o.getBlocks().size() / 10000d, 1); + if (scale > maxScale){ sender().sendMessage(C.YELLOW + "Indicated scale exceeds maximum. Downscaled to maximum: " + maxScale); scale = maxScale; } @@ -219,30 +219,30 @@ public class DecObject implements DecreeExecutor { Map futureChanges = new HashMap<>(); - object = object.scaled(scale, interpolator); - object.place(block.getBlockX(), block.getBlockY() + (int) object.getCenter().getY(), block.getBlockZ(), createPlacer(block.getWorld(), futureChanges), placement, new RNG(), null); + o = o.scaled(scale, IrisObjectPlacementScaleInterpolator.TRICUBIC); + o.place(block.getBlockX(), block.getBlockY() + (int) o.getCenter().getY(), block.getBlockZ(), createPlacer(block.getWorld(), futureChanges), placement, new RNG(), null); Iris.service(ObjectSVC.class).addChanges(futureChanges); if (edit) { - ItemStack newWand = WandSVC.createWand(block.clone().subtract(object.getCenter()).add(object.getW() - 1, - object.getH() + object.getCenter().clone().getY() - 1, object.getD() - 1), block.clone().subtract(object.getCenter().clone().setY(0))); + ItemStack newWand = WandSVC.createWand(block.clone().subtract(o.getCenter()).add(o.getW() - 1, + o.getH() + o.getCenter().clone().getY() - 1, o.getD() - 1), block.clone().subtract(o.getCenter().clone().setY(0))); if (WandSVC.isWand(wand)) { wand = newWand; player().getInventory().setItemInMainHand(wand); - sender().sendMessage("Updated wand for " + "objects/" + object.getLoadKey() + ".iob"); + sender().sendMessage("Updated wand for " + "objects/" + o.getLoadKey() + ".iob "); } else { int slot = WandSVC.findWand(player().getInventory()); if (slot == -1) { player().getInventory().addItem(newWand); - sender().sendMessage("Given new wand for " + "objects/" + object.getLoadKey() + ".iob"); + sender().sendMessage("Given new wand for " + "objects/" + o.getLoadKey() + ".iob "); } else { player().getInventory().setItem(slot, newWand); - sender().sendMessage("Updated wand for " + "objects/" + object.getLoadKey() + ".iob"); + sender().sendMessage("Updated wand for " + "objects/" + o.getLoadKey() + ".iob "); } } } else { - sender().sendMessage("Placed " + "objects/" + object.getLoadKey() + ".iob"); + sender().sendMessage("Placed " + "objects/" + o.getLoadKey() + ".iob "); } } From 9963ff9c8e486a54ab1a8878eb8a4a95b2553bb5 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Wed, 25 Aug 2021 13:08:54 +0200 Subject: [PATCH 18/21] Auto stash before merge of "DecreeCommands" and "upstream/master" --- .../volmit/iris/util/decree/handlers/VectorHandler.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java index fb31842e5..53944a4fd 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java @@ -43,14 +43,7 @@ public class VectorHandler implements DecreeParameterHandler { @Override public KList getPossibilities() { - KList vx = new KList<>(); - VolmitSender s = DecreeContext.get(); - - if (s.isPlayer()) { - vx.add(s.player().getLocation().toVector()); - } - - return vx; + return null; } @Override From d07c8c88519b114ff37919b9ee6987b8ef18915c Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Sat, 28 Aug 2021 16:18:53 +0200 Subject: [PATCH 19/21] What & debug fix --- .../command/what/CommandIrisWhatBlock.java | 39 --- .../command/what/CommandIrisWhatObjects.java | 9 +- .../core/command/world/CommandIrisVerify.java | 4 +- .../com/volmit/iris/core/decrees/DecIris.java | 14 +- .../com/volmit/iris/core/decrees/DecWhat.java | 315 ++++++++++++++++++ .../volmit/iris/core/service/CommandSVC.java | 3 +- .../util/decree/handlers/BooleanHandler.java | 3 + src/main/resources/plugin.yml | 2 + 8 files changed, 334 insertions(+), 55 deletions(-) create mode 100644 src/main/java/com/volmit/iris/core/decrees/DecWhat.java diff --git a/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatBlock.java b/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatBlock.java index 818d1ecb3..6018562f8 100644 --- a/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatBlock.java +++ b/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatBlock.java @@ -46,46 +46,7 @@ public class CommandIrisWhatBlock extends MortarCommand { if (sender.isPlayer()) { BlockData bd; Player p = sender.player(); - try { - bd = p.getTargetBlockExact(128, FluidCollisionMode.NEVER).getBlockData(); - } catch (NullPointerException e) { - Iris.reportError(e); - sender.sendMessage("Please look at any block, not at the sky"); - bd = null; - } - if (bd != null) { - sender.sendMessage("Material: " + C.GREEN + bd.getMaterial().name()); - sender.sendMessage("Full: " + C.WHITE + bd.getAsString(true)); - - if (B.isStorage(bd)) { - sender.sendMessage(C.YELLOW + "* Storage Block (Loot Capable)"); - } - - if (B.isLit(bd)) { - sender.sendMessage(C.YELLOW + "* Lit Block (Light Capable)"); - } - - if (B.isFoliage(bd)) { - sender.sendMessage(C.YELLOW + "* Foliage Block"); - } - - if (B.isDecorant(bd)) { - sender.sendMessage(C.YELLOW + "* Decorant Block"); - } - - if (B.isFluid(bd)) { - sender.sendMessage(C.YELLOW + "* Fluid Block"); - } - - if (B.isFoliagePlantable(bd)) { - sender.sendMessage(C.YELLOW + "* Plantable Foliage Block"); - } - - if (B.isSolid(bd)) { - sender.sendMessage(C.YELLOW + "* Solid Block"); - } - } } else { sender.sendMessage("Players only."); } diff --git a/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatObjects.java b/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatObjects.java index 83659a91b..fa9d5ca6b 100644 --- a/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatObjects.java +++ b/src/main/java/com/volmit/iris/core/command/what/CommandIrisWhatObjects.java @@ -61,7 +61,6 @@ public class CommandIrisWhatObjects extends MortarCommand { } - @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") @Override public boolean handle(VolmitSender sender, String[] args) { if (sender.isPlayer()) { @@ -81,11 +80,9 @@ public class CommandIrisWhatObjects extends MortarCommand { try { Location l = p.getTargetBlockExact(48, FluidCollisionMode.NEVER).getLocation(); - if (l != null) { - int cx = l.getChunk().getX(); - int cz = l.getChunk().getZ(); - new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + cx, z + cz))).drain(); - } + int cx = l.getChunk().getX(); + int cz = l.getChunk().getZ(); + new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + cx, z + cz))).drain(); } catch (Throwable e) { Iris.reportError(e); } diff --git a/src/main/java/com/volmit/iris/core/command/world/CommandIrisVerify.java b/src/main/java/com/volmit/iris/core/command/world/CommandIrisVerify.java index 42bb4aef4..890f79fdd 100644 --- a/src/main/java/com/volmit/iris/core/command/world/CommandIrisVerify.java +++ b/src/main/java/com/volmit/iris/core/command/world/CommandIrisVerify.java @@ -60,8 +60,8 @@ public class CommandIrisVerify extends MortarCommand { MCAFile file = null; try { file = MCAUtil.read(i); - int rx = Integer.valueOf(i.getName().split("\\Q.\\E")[1]); - int rz = Integer.valueOf(i.getName().split("\\Q.\\E")[2]); + int rx = Integer.parseInt(i.getName().split("\\Q.\\E")[1]); + int rz = Integer.parseInt(i.getName().split("\\Q.\\E")[2]); for (int j = 0; j < 32; j++) { for (int k = 0; k < 32; k++) { f.incrementAndGet(); diff --git a/src/main/java/com/volmit/iris/core/decrees/DecIris.java b/src/main/java/com/volmit/iris/core/decrees/DecIris.java index c14854b6c..5976f97fe 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -33,6 +33,7 @@ import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import com.volmit.iris.util.format.C; import java.io.File; +import java.util.Objects; @Decree(name = "irisd", aliases = {"ird"}, description = "Basic Command") public class DecIris implements DecreeExecutor { @@ -44,7 +45,9 @@ public class DecIris implements DecreeExecutor { private DecObject object; - @Decree(description = "Create a new world", aliases = {"+", "c"}) + private DecWhat what; + + @Decree(description = "Create a new world", aliases = "+") public void create( @Param(aliases = "world-name", description = "The name of the world to create") String name, @@ -130,14 +133,11 @@ public class DecIris implements DecreeExecutor { @Decree(description = "Toggle debug") public void debug( - @Param(description = "Whether or not debug should be on", defaultValue = "toggle") + @Param(name = "on", description = "Whether or not debug should be on", defaultValue = "other") Boolean on ) { - if (on == null){ - on = !IrisSettings.get().getGeneral().isDebug(); - } - sender().sendMessage(C.GREEN + "Set debug to " + on); - IrisSettings.get().getGeneral().setDebug(on); + IrisSettings.get().getGeneral().setDebug(Objects.requireNonNullElseGet(on, () -> !IrisSettings.get().getGeneral().isDebug())); + sender().sendMessage(); } @Decree(description = "Download a project.", aliases = "dl") diff --git a/src/main/java/com/volmit/iris/core/decrees/DecWhat.java b/src/main/java/com/volmit/iris/core/decrees/DecWhat.java new file mode 100644 index 000000000..7401f85f4 --- /dev/null +++ b/src/main/java/com/volmit/iris/core/decrees/DecWhat.java @@ -0,0 +1,315 @@ +package com.volmit.iris.core.decrees; + +import com.google.gson.Gson; +import com.volmit.iris.Iris; +import com.volmit.iris.core.nms.INMS; +import com.volmit.iris.core.tools.IrisToolbelt; +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.object.biome.IrisBiome; +import com.volmit.iris.engine.object.feature.IrisFeaturePositional; +import com.volmit.iris.engine.object.objects.IrisObject; +import com.volmit.iris.engine.object.objects.IrisObjectPlacement; +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.collection.KMap; +import com.volmit.iris.util.collection.KSet; +import com.volmit.iris.util.data.B; +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.format.C; +import com.volmit.iris.util.format.Form; +import com.volmit.iris.util.json.JSONObject; +import com.volmit.iris.util.math.M; +import com.volmit.iris.util.math.Spiraler; +import com.volmit.iris.util.plugin.VolmitSender; +import io.papermc.lib.PaperLib; +import org.bukkit.*; +import org.bukkit.block.Biome; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Player; +import org.bukkit.util.BlockVector; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.attribute.FileTime; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.Date; +import java.util.Objects; + +@Decree(name = "what", aliases = "?", description = "Find information on the world around you", origin = DecreeOrigin.PLAYER) +public class DecWhat implements DecreeExecutor { + + @Decree(description = "Get information about the biome your are currently in") + public void biome() { + if (IrisToolbelt.isIrisWorld(player().getWorld())) { + IrisBiome b = engine().getBiome(player().getLocation()); + sender().sendMessage(C.GREEN + "IrisBiome: " + b.getLoadKey() + " (" + b.getDerivative().name() + ")"); + } else { + sender().sendMessage(C.YELLOW + "Non-Iris Biome: " + player().getLocation().getBlock().getBiome().name()); + if (player().getLocation().getBlock().getBiome().equals(Biome.CUSTOM)) { + try { + sender().sendMessage(C.YELLOW + "Data Pack Biome: " + INMS.get().getTrueBiomeBaseKey(player().getLocation()) + " (ID: " + INMS.get().getTrueBiomeBaseId(INMS.get().getTrueBiomeBase(player().getLocation())) + ")"); + } catch (Throwable ee) { + Iris.reportError(ee); + } + } + } + } + + @Decree(description = "Get information about the block you are looking at") + public void block() { + Block target = player().getTargetBlockExact(128, FluidCollisionMode.NEVER); + if (target == null) { + sender().sendMessage(C.YELLOW + "Please look at a block, not at the sky"); + return; + } + + BlockData bd = target.getBlockData(); + + + sender().sendMessage("Material: " + C.GREEN + bd.getMaterial().name()); + sender().sendMessage("Full: " + C.WHITE + bd.getAsString(true)); + + if (B.isStorage(bd)) { + sender().sendMessage(C.YELLOW + "* Storage Block (Loot Capable)"); + } + + if (B.isLit(bd)) { + sender().sendMessage(C.YELLOW + "* Lit Block (Light Capable)"); + } + + if (B.isFoliage(bd)) { + sender().sendMessage(C.YELLOW + "* Foliage Block"); + } + + if (B.isDecorant(bd)) { + sender().sendMessage(C.YELLOW + "* Decorant Block"); + } + + if (B.isFluid(bd)) { + sender().sendMessage(C.YELLOW + "* Fluid Block"); + } + + if (B.isFoliagePlantable(bd)) { + sender().sendMessage(C.YELLOW + "* Plantable Foliage Block"); + } + + if (B.isSolid(bd)) { + sender().sendMessage(C.YELLOW + "* Solid Block"); + } + } + + @Decree(aliases = "nf", description = "Get the noise feature data in your chunk") + public void features() { + + if (!IrisToolbelt.isIrisWorld(player().getWorld())){ + sender().sendMessage(C.RED + "Iris worlds only"); + return; + } + + int n = 0; + + for (IrisFeaturePositional irisFeaturePositional : engine().getMantle().getFeaturesInChunk(player().getLocation().getChunk())) { + sender().sendMessage("#" + n++ + " " + new JSONObject(new Gson().toJson(irisFeaturePositional)).toString(4)); + } + } + + @Decree(description = "Get information about the item you are holding", sync = true) + public void hand() { + BlockData bd = player().getInventory().getItemInMainHand().getType().createBlockData(); + + if (bd.getMaterial().equals(Material.AIR)){ + sender().sendMessage(C.YELLOW + "Please hold a block/item"); + return; + } + + sender().sendMessage("Material: " + C.GREEN + bd.getMaterial().name()); + sender().sendMessage("Full: " + C.WHITE + bd.getAsString(true)); + + } + + @Decree(aliases = "capture", description = "Get information about nearby structures") + public void objects() { + if (!IrisToolbelt.isIrisWorld(player().getWorld())){ + sender().sendMessage(C.RED + "You must be in an Iris world"); + return; + } + + World world = player().getWorld(); + + if (!IrisToolbelt.isIrisWorld(world)) { + sender().sendMessage("You must be in an iris world."); + return; + } + KList chunks = new KList<>(); + int bx = player().getLocation().getChunk().getX(); + int bz = player().getLocation().getChunk().getZ(); + + try { + Location l = player().getTargetBlockExact(48, FluidCollisionMode.NEVER).getLocation(); + + int cx = l.getChunk().getX(); + int cz = l.getChunk().getZ(); + new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + cx, z + cz))).drain(); + } catch (Throwable e) { + Iris.reportError(e); + } + + new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + bx, z + bz))).drain(); + sender().sendMessage("Capturing IGenData from " + chunks.size() + " nearby chunks."); + try { + File ff = Iris.instance.getDataFile("reports/" + M.ms() + ".txt"); + PrintWriter pw = new PrintWriter(ff); + pw.println("=== Iris Chunk Report ==="); + pw.println("== General Info =="); + pw.println("Iris Version: " + Iris.instance.getDescription().getVersion()); + pw.println("Bukkit Version: " + Bukkit.getBukkitVersion()); + pw.println("MC Version: " + Bukkit.getVersion()); + pw.println("PaperSpigot: " + (PaperLib.isPaper() ? "Yup!" : "Nope!")); + pw.println("Report Captured At: " + new Date()); + pw.println("Chunks: (" + chunks.size() + "): "); + + for (Chunk i : chunks) { + pw.println("- [" + i.getX() + ", " + i.getZ() + "]"); + } + + int regions = 0; + long size = 0; + String age = "No idea..."; + + try { + for (File i : Objects.requireNonNull(new File(world.getWorldFolder(), "region").listFiles())) { + if (i.isFile()) { + size += i.length(); + } + } + } catch (Throwable e) { + Iris.reportError(e); + } + + try { + FileTime creationTime = (FileTime) Files.getAttribute(world.getWorldFolder().toPath(), "creationTime"); + age = hrf(Duration.of(M.ms() - creationTime.toMillis(), ChronoUnit.MILLIS)); + } catch (IOException e) { + Iris.reportError(e); + } + + KList biomes = new KList<>(); + KList caveBiomes = new KList<>(); + KMap>> objects = new KMap<>(); + + for (Chunk i : chunks) { + for (int j = 0; j < 16; j += 3) { + + for (int k = 0; k < 16; k += 3) { + + assert engine() != null; + IrisBiome bb = engine().getSurfaceBiome((i.getX() * 16) + j, (i.getZ() * 16) + k); + IrisBiome bxf = engine().getCaveBiome((i.getX() * 16) + j, (i.getZ() * 16) + k); + biomes.addIfMissing(bb.getName() + " [" + Form.capitalize(bb.getInferredType().name().toLowerCase()) + "] " + " (" + bb.getLoadFile().getName() + ")"); + caveBiomes.addIfMissing(bxf.getName() + " (" + bxf.getLoadFile().getName() + ")"); + exportObjects(bb, pw, engine(), objects); + exportObjects(bxf, pw, engine(), objects); + } + } + } + + regions = Objects.requireNonNull(new File(world.getWorldFolder().getPath() + "/region").list()).length; + + pw.println(); + pw.println("== World Info =="); + pw.println("World Name: " + world.getName()); + pw.println("Age: " + age); + pw.println("Folder: " + world.getWorldFolder().getPath()); + pw.println("Regions: " + Form.f(regions)); + pw.println("Chunks: max. " + Form.f(regions * 32 * 32)); + pw.println("World Size: min. " + Form.fileSize(size)); + pw.println(); + pw.println("== Biome Info =="); + pw.println("Found " + biomes.size() + " Biome(s): "); + + for (String i : biomes) { + pw.println("- " + i); + } + pw.println(); + + pw.println("== Object Info =="); + + for (String i : objects.k()) { + pw.println("- " + i); + + for (String j : objects.get(i).k()) { + pw.println(" @ " + j); + + for (String k : objects.get(i).get(j)) { + pw.println(" * " + k); + } + } + } + + pw.println(); + pw.close(); + + sender().sendMessage("Reported to: " + ff.getPath()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + Iris.reportError(e); + } + } + + private void exportObjects(IrisBiome bb, PrintWriter pw, Engine g, KMap>> objects) { + String n1 = bb.getName() + " [" + Form.capitalize(bb.getInferredType().name().toLowerCase()) + "] " + " (" + bb.getLoadFile().getName() + ")"; + int m = 0; + KSet stop = new KSet<>(); + for (IrisObjectPlacement f : bb.getObjects()) { + m++; + String n2 = "Placement #" + m + " (" + f.getPlace().size() + " possible objects)"; + + for (String i : f.getPlace()) { + String nn3 = i + ": [ERROR] Failed to find object!"; + + try { + if (stop.contains(i)) { + continue; + } + + File ff = g.getData().getObjectLoader().findFile(i); + BlockVector sz = IrisObject.sampleSize(ff); + nn3 = i + ": size=[" + sz.getBlockX() + "," + sz.getBlockY() + "," + sz.getBlockZ() + "] location=[" + ff.getPath() + "]"; + stop.add(i); + } catch (Throwable e) { + Iris.reportError(e); + } + + String n3 = nn3; + + objects.compute(n1, (k1, v1) -> + { + //noinspection ReplaceNullCheck + if (v1 == null) { + return new KMap<>(); + } + + return v1; + }).compute(n2, (k, v) -> + { + if (v == null) { + return new KList().qaddIfMissing(n3); + } + + v.addIfMissing(n3); + return v; + }); + } + } + } + + public static String hrf(Duration duration) { + return duration.toString().substring(2).replaceAll("(\\d[HMS])(?!$)", "$1 ").toLowerCase(); + } +} diff --git a/src/main/java/com/volmit/iris/core/service/CommandSVC.java b/src/main/java/com/volmit/iris/core/service/CommandSVC.java index 793100629..2bc017fb1 100644 --- a/src/main/java/com/volmit/iris/core/service/CommandSVC.java +++ b/src/main/java/com/volmit/iris/core/service/CommandSVC.java @@ -18,6 +18,7 @@ package com.volmit.iris.core.service; +import com.volmit.iris.Iris; import com.volmit.iris.core.decrees.DecIris; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.util.collection.KList; @@ -28,7 +29,7 @@ import com.volmit.iris.util.plugin.IrisService; public class CommandSVC implements IrisService, DecreeSystem { @Override public void onEnable() { - // TODO Iris.instance.getCommand("irisd").setExecutor(this); + Iris.instance.getCommand("irisd").setExecutor(this); } @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java index e61de78ad..d53bb1555 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java @@ -37,6 +37,9 @@ public class BooleanHandler implements DecreeParameterHandler { @Override public Boolean parse(String in) throws DecreeParsingException { try { + if (in.equals("null") || in.equals("other") || in.equals("flip")) { + return null; + } return Boolean.parseBoolean(in); } catch (Throwable e) { throw new DecreeParsingException("Unable to parse boolean \"" + in + "\""); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 14d43c307..0d540b7b7 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -20,5 +20,7 @@ libraries: commands: iris: aliases: [ ir, irs ] + irisd: + aliases: [ ird, id ] api-version: ${apiversion} hotload-dependencies: false \ No newline at end of file From 0465d047e74e2f6e1b8e320e3a9ccf369e97e5b1 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Sat, 28 Aug 2021 17:59:56 +0200 Subject: [PATCH 20/21] Update Commands with patches --- .../object/CommandIrisObjectPaste.java | 1 + .../com/volmit/iris/core/decrees/DecIris.java | 5 +- .../volmit/iris/core/decrees/DecObject.java | 98 ++++++++++++++++++- .../volmit/iris/core/decrees/DecStudio.java | 62 +++++++++--- .../com/volmit/iris/core/decrees/DecWhat.java | 87 +++------------- .../volmit/iris/core/project/IrisProject.java | 40 ++++---- .../volmit/iris/core/service/StudioSVC.java | 7 +- .../util/decree/handlers/BiomeHandler.java | 3 + .../util/decree/handlers/RegionHandler.java | 3 + .../util/decree/handlers/WorldHandler.java | 8 +- 10 files changed, 203 insertions(+), 111 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectPaste.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectPaste.java index 452297be6..d263c26c8 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectPaste.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectPaste.java @@ -21,6 +21,7 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.loader.IrisData; +import com.volmit.iris.core.service.ObjectSVC; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.core.tools.IrisToolbelt; diff --git a/src/main/java/com/volmit/iris/core/decrees/DecIris.java b/src/main/java/com/volmit/iris/core/decrees/DecIris.java index 5976f97fe..057580bef 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -136,8 +136,9 @@ public class DecIris implements DecreeExecutor { @Param(name = "on", description = "Whether or not debug should be on", defaultValue = "other") Boolean on ) { - IrisSettings.get().getGeneral().setDebug(Objects.requireNonNullElseGet(on, () -> !IrisSettings.get().getGeneral().isDebug())); - sender().sendMessage(); + boolean to = on == null ? !IrisSettings.get().getGeneral().isDebug() : on; + IrisSettings.get().getGeneral().setDebug(to); + sender().sendMessage(C.GREEN + "Set debug to: " + to); } @Decree(description = "Download a project.", aliases = "dl") diff --git a/src/main/java/com/volmit/iris/core/decrees/DecObject.java b/src/main/java/com/volmit/iris/core/decrees/DecObject.java index f6f658b1b..3da95e599 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecObject.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecObject.java @@ -1,7 +1,9 @@ package com.volmit.iris.core.decrees; -import com.volmit.iris.core.command.object.CommandIrisObjectUndo; +import com.volmit.iris.Iris; import com.volmit.iris.core.loader.IrisData; +import com.volmit.iris.core.service.ObjectSVC; +import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.engine.object.common.IObjectPlacer; import com.volmit.iris.engine.object.dimensional.IrisDimension; @@ -26,6 +28,7 @@ import org.bukkit.block.BlockState; import org.bukkit.block.TileState; import org.bukkit.block.data.BlockData; import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; import java.io.File; import java.io.IOException; @@ -188,7 +191,7 @@ public class DecObject implements DecreeExecutor { private static final Set skipBlocks = Set.of(Material.GRASS, Material.SNOW, Material.VINE, Material.TORCH, Material.DEAD_BUSH, Material.POPPY, Material.DANDELION); - @Decree(description = "Paste an object") + @Decree(description = "Paste an object", sync = true) public void paste( @Param(description = "The object to paste", customHandler = ObjectHandler.class) String object, @@ -382,4 +385,95 @@ public class DecObject implements DecreeExecutor { service.revertChanges(actualReverts); sender().sendMessage("Reverted " + actualReverts + " pastes!"); } + + @Decree(description = "Get an object wand", sync = true) + public void wand() { + player().getInventory().addItem(WandSVC.createWand()); + sender().playSound(Sound.ITEM_ARMOR_EQUIP_NETHERITE, 1f, 1.5f); + sender().sendMessage(C.GREEN + "Poof! Good luck building!"); + } + + @Decree(name = "x&y", description = "Autoselect up, down & out", sync = true) + public void xay(){ + if (!WandSVC.isHoldingWand(player())){ + sender().sendMessage(C.YELLOW + "Hold your wand!"); + return; + } + + Location[] b = WandSVC.getCuboid(player().getInventory().getItemInMainHand()); + Location a1 = b[0].clone(); + Location a2 = b[1].clone(); + Location a1x = b[0].clone(); + Location a2x = b[1].clone(); + Cuboid cursor = new Cuboid(a1, a2); + Cuboid cursorx = new Cuboid(a1, a2); + + while (!cursor.containsOnly(Material.AIR)) { + a1.add(new org.bukkit.util.Vector(0, 1, 0)); + a2.add(new org.bukkit.util.Vector(0, 1, 0)); + cursor = new Cuboid(a1, a2); + } + + a1.add(new org.bukkit.util.Vector(0, -1, 0)); + a2.add(new org.bukkit.util.Vector(0, -1, 0)); + + while (!cursorx.containsOnly(Material.AIR)) { + a1x.add(new org.bukkit.util.Vector(0, -1, 0)); + a2x.add(new org.bukkit.util.Vector(0, -1, 0)); + cursorx = new Cuboid(a1x, a2x); + } + + a1x.add(new org.bukkit.util.Vector(0, 1, 0)); + a2x.add(new Vector(0, 1, 0)); + b[0] = a1; + b[1] = a2x; + cursor = new Cuboid(b[0], b[1]); + cursor = cursor.contract(Cuboid.CuboidDirection.North); + cursor = cursor.contract(Cuboid.CuboidDirection.South); + cursor = cursor.contract(Cuboid.CuboidDirection.East); + cursor = cursor.contract(Cuboid.CuboidDirection.West); + b[0] = cursor.getLowerNE(); + b[1] = cursor.getUpperSW(); + player().getInventory().setItemInMainHand(WandSVC.createWand(b[0], b[1])); + player().updateInventory(); + sender().playSound(Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); + sender().sendMessage(C.GREEN + "Auto-select complete!"); + } + + @Decree(name = "x+y", description = "Autoselect up & out", sync = true) + public void xpy() { + if (!WandSVC.isHoldingWand(player())) { + sender().sendMessage(C.YELLOW + "Hold your wand!"); + return; + } + + Location[] b = WandSVC.getCuboid(player().getInventory().getItemInMainHand()); + b[0].add(new Vector(0, 1, 0)); + b[1].add(new Vector(0, 1, 0)); + Location a1 = b[0].clone(); + Location a2 = b[1].clone(); + Cuboid cursor = new Cuboid(a1, a2); + + while (!cursor.containsOnly(Material.AIR)) { + a1.add(new Vector(0, 1, 0)); + a2.add(new Vector(0, 1, 0)); + cursor = new Cuboid(a1, a2); + } + + a1.add(new Vector(0, -1, 0)); + a2.add(new Vector(0, -1, 0)); + b[0] = a1; + a2 = b[1]; + cursor = new Cuboid(a1, a2); + cursor = cursor.contract(Cuboid.CuboidDirection.North); + cursor = cursor.contract(Cuboid.CuboidDirection.South); + cursor = cursor.contract(Cuboid.CuboidDirection.East); + cursor = cursor.contract(Cuboid.CuboidDirection.West); + b[0] = cursor.getLowerNE(); + b[1] = cursor.getUpperSW(); + player().getInventory().setItemInMainHand(WandSVC.createWand(b[0], b[1])); + player().updateInventory(); + sender().playSound(Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); + sender().sendMessage(C.GREEN + "Auto-select complete!"); + } } diff --git a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java index 00d9505aa..b117652e8 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java @@ -92,7 +92,16 @@ public class DecStudio implements DecreeExecutor { Iris.service(StudioSVC.class).open(sender(), seed, dimension.getLoadKey()); } - @Decree(description = "Close an open studio project", aliases = "x", sync = true) + @Decree(description = "Open VSCode for a dimension", aliases = {"vsc", "edit"}) + public void vscode( + @Param(defaultValue = "overworld", description = "The dimension to open VSCode for", aliases = "dim") + IrisDimension dimension + ) { + sender().sendMessage(C.GREEN + "Opening VSCode for the \"" + dimension.getName() + "\" pack"); + Iris.service(StudioSVC.class).openVSCode(sender(), dimension.getLoadKey()); + } + + @Decree(description = "Close an open studio project", aliases = {"x", "c"}, sync = true) public void close() { if (!Iris.service(StudioSVC.class).isProjectOpen()) { sender().sendMessage(C.RED + "No open studio projects."); @@ -317,9 +326,9 @@ public class DecStudio implements DecreeExecutor { @Decree(description = "Find any biome or region", aliases = {"goto", "g"}, origin = DecreeOrigin.PLAYER) public void find( - @Param(description = "The biome to find", contextual = true) + @Param(description = "The biome or region to find", defaultValue = "null") IrisBiome biome, - @Param(description = "The region to find", contextual = true) + @Param(description = "The region to find", defaultValue = "null") IrisRegion region ) { if (!IrisToolbelt.isIrisWorld(world())) { @@ -328,35 +337,45 @@ public class DecStudio implements DecreeExecutor { } if (biome == null && region == null) { - sender().sendMessage(C.RED + "You must specify a biome or region!"); + sender().sendMessage(C.RED + "You must specify a biome= or region=!"); return; } - IrisPosition l = null; + IrisPosition regionPosition = null; if (region != null) { - l = engine().lookForRegion(region, 10000, (v) -> sender().sendMessage("Looking for the " + C.BOLD + C.WHITE + region.getName() + C.RESET + C.GRAY + " region: Checked " + Form.f(v) + " Places")); - if (l == null) { + regionPosition = engine().lookForRegion(region, 10000, (v) -> sender().sendMessage("Looking for the " + C.BOLD + C.WHITE + region.getName() + C.RESET + C.GRAY + " region: Checked " + Form.f(v) + " Places")); + if (regionPosition == null) { sender().sendMessage(C.YELLOW + "Couldn't find the " + region.getName() + " region."); } else { sender().sendMessage(C.GREEN + "Found the " + region.getName() + " region!."); } } - if (l == null && biome != null) { - l = engine().lookForBiome(biome, 10000, (v) -> sender().sendMessage("Looking for the " + C.BOLD + C.WHITE + biome.getName() + C.RESET + C.GRAY + " biome: Checked " + Form.f(v) + " Places")); - if (l == null) { + IrisPosition biomePosition = null; + if (biome != null) { + biomePosition = engine().lookForBiome(biome, 10000, (v) -> sender().sendMessage("Looking for the " + C.BOLD + C.WHITE + biome.getName() + C.RESET + C.GRAY + " biome: Checked " + Form.f(v) + " Places")); + if (biomePosition == null) { sender().sendMessage(C.YELLOW + "Couldn't find the " + biome.getName() + " biome."); } else { sender().sendMessage(C.GREEN + "Found the " + biome.getName() + " biome!."); } } - if (l == null) { - sender().sendMessage(C.RED + "Could not find the region and / or biome you specified."); - return; + if (regionPosition == null && region != null) { + sender().sendMessage(C.RED + "Could not find the region you specified."); + } else if (regionPosition != null){ + sender().sendMessage(C.GREEN + "Found the region at: " + regionPosition.toString()); + } + if (biomePosition == null && biome != null) { + sender().sendMessage(C.RED + "Could not find the biome you specified."); + } else if (biomePosition != null){ + sender().sendMessage(C.GREEN + "Found the biome at: " + biomePosition.toString()); } - final IrisPosition finalL = l; + final IrisPosition finalL = regionPosition == null ? biomePosition : regionPosition; + if (finalL == null) { + return; + } J.s(() -> player().teleport(finalL.toLocation(world()))); } @@ -365,6 +384,7 @@ public class DecStudio implements DecreeExecutor { if (noStudio()) return; access().hotload(); + sender().sendMessage(C.GREEN + "Hotloaded"); } @Decree(description = "Show loot if a chest were right here", origin = DecreeOrigin.PLAYER, sync = true) @@ -681,8 +701,17 @@ public class DecStudio implements DecreeExecutor { @Param(description = "Whether or not to show information about the block you are holding", defaultValue = "true") boolean hand ) { + if (engine() == null) { + sender().sendMessage(C.RED + "You must be in an Iris world!"); + return; + } // Data - BlockData handHeld = player().getInventory().getItemInMainHand().getType().createBlockData(); + BlockData handHeld = null; + try { + handHeld = player().getInventory().getItemInMainHand().getType().createBlockData(); + } catch (Throwable e) { + sender().sendMessage("Could not get data for hand-held item"); + } Block targetBlock = player().getTargetBlockExact(128, FluidCollisionMode.NEVER); BlockData targetBlockData; if (targetBlock == null) { @@ -744,6 +773,9 @@ public class DecStudio implements DecreeExecutor { } // Hand-held + if (handHeld == null){ + return; + } if (!handHeld.getMaterial().equals(Material.AIR)) { sender().sendMessage(C.YELLOW + "No block held"); } else if (hand) { diff --git a/src/main/java/com/volmit/iris/core/decrees/DecWhat.java b/src/main/java/com/volmit/iris/core/decrees/DecWhat.java index 7401f85f4..2349ab703 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecWhat.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecWhat.java @@ -16,6 +16,7 @@ import com.volmit.iris.util.data.B; 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.json.JSONObject; @@ -44,66 +45,6 @@ import java.util.Objects; @Decree(name = "what", aliases = "?", description = "Find information on the world around you", origin = DecreeOrigin.PLAYER) public class DecWhat implements DecreeExecutor { - @Decree(description = "Get information about the biome your are currently in") - public void biome() { - if (IrisToolbelt.isIrisWorld(player().getWorld())) { - IrisBiome b = engine().getBiome(player().getLocation()); - sender().sendMessage(C.GREEN + "IrisBiome: " + b.getLoadKey() + " (" + b.getDerivative().name() + ")"); - } else { - sender().sendMessage(C.YELLOW + "Non-Iris Biome: " + player().getLocation().getBlock().getBiome().name()); - if (player().getLocation().getBlock().getBiome().equals(Biome.CUSTOM)) { - try { - sender().sendMessage(C.YELLOW + "Data Pack Biome: " + INMS.get().getTrueBiomeBaseKey(player().getLocation()) + " (ID: " + INMS.get().getTrueBiomeBaseId(INMS.get().getTrueBiomeBase(player().getLocation())) + ")"); - } catch (Throwable ee) { - Iris.reportError(ee); - } - } - } - } - - @Decree(description = "Get information about the block you are looking at") - public void block() { - Block target = player().getTargetBlockExact(128, FluidCollisionMode.NEVER); - if (target == null) { - sender().sendMessage(C.YELLOW + "Please look at a block, not at the sky"); - return; - } - - BlockData bd = target.getBlockData(); - - - sender().sendMessage("Material: " + C.GREEN + bd.getMaterial().name()); - sender().sendMessage("Full: " + C.WHITE + bd.getAsString(true)); - - if (B.isStorage(bd)) { - sender().sendMessage(C.YELLOW + "* Storage Block (Loot Capable)"); - } - - if (B.isLit(bd)) { - sender().sendMessage(C.YELLOW + "* Lit Block (Light Capable)"); - } - - if (B.isFoliage(bd)) { - sender().sendMessage(C.YELLOW + "* Foliage Block"); - } - - if (B.isDecorant(bd)) { - sender().sendMessage(C.YELLOW + "* Decorant Block"); - } - - if (B.isFluid(bd)) { - sender().sendMessage(C.YELLOW + "* Fluid Block"); - } - - if (B.isFoliagePlantable(bd)) { - sender().sendMessage(C.YELLOW + "* Plantable Foliage Block"); - } - - if (B.isSolid(bd)) { - sender().sendMessage(C.YELLOW + "* Solid Block"); - } - } - @Decree(aliases = "nf", description = "Get the noise feature data in your chunk") public void features() { @@ -119,18 +60,20 @@ public class DecWhat implements DecreeExecutor { } } - @Decree(description = "Get information about the item you are holding", sync = true) - public void hand() { - BlockData bd = player().getInventory().getItemInMainHand().getType().createBlockData(); - - if (bd.getMaterial().equals(Material.AIR)){ - sender().sendMessage(C.YELLOW + "Please hold a block/item"); - return; - } - - sender().sendMessage("Material: " + C.GREEN + bd.getMaterial().name()); - sender().sendMessage("Full: " + C.WHITE + bd.getAsString(true)); - + @Decree(description = "Get information about the world around you", aliases = "location", studio = true) + public void me( + @Param(description = "Whether or not to show dimension information", defaultValue = "true") + boolean dimension, + @Param(description = "Whether or not to show region information", defaultValue = "true") + boolean region, + @Param(description = "Whether or not to show biome information", defaultValue = "true") + boolean biome, + @Param(description = "Whether or not to show information about the block you are looking at", defaultValue = "true") + boolean look, + @Param(description = "Whether or not to show information about the block you are holding", defaultValue = "true") + boolean hand + ) { + new DecStudio().what(dimension, region, biome, look, hand); } @Decree(aliases = "capture", description = "Get information about nearby structures") diff --git a/src/main/java/com/volmit/iris/core/project/IrisProject.java b/src/main/java/com/volmit/iris/core/project/IrisProject.java index 654cbd0bc..1ee3f5b0a 100644 --- a/src/main/java/com/volmit/iris/core/project/IrisProject.java +++ b/src/main/java/com/volmit/iris/core/project/IrisProject.java @@ -106,25 +106,9 @@ public class IrisProject { }); } - public void open(VolmitSender sender, long seed, Consumer onDone) throws IrisException { - if (isOpen()) { - close(); - } - - boolean hasError = false; - - if (hasError) { - return; - } + public void openVSCode(VolmitSender sender) { IrisDimension d = IrisData.loadAnyDimension(getName()); - if (d == null) { - sender.sendMessage("Can't find dimension: " + getName()); - return; - } else if (sender.isPlayer()) { - sender.player().setGameMode(GameMode.SPECTATOR); - } - J.attemptAsync(() -> { try { @@ -171,6 +155,28 @@ public class IrisProject { e.printStackTrace(); } }); + } + + public void open(VolmitSender sender, long seed, Consumer onDone) throws IrisException { + if (isOpen()) { + close(); + } + + boolean hasError = false; + + if (hasError) { + return; + } + + IrisDimension d = IrisData.loadAnyDimension(getName()); + if (d == null) { + sender.sendMessage("Can't find dimension: " + getName()); + return; + } else if (sender.isPlayer()) { + sender.player().setGameMode(GameMode.SPECTATOR); + } + + openVSCode(sender); J.a(() -> { diff --git a/src/main/java/com/volmit/iris/core/service/StudioSVC.java b/src/main/java/com/volmit/iris/core/service/StudioSVC.java index aad2a367e..0e67227c2 100644 --- a/src/main/java/com/volmit/iris/core/service/StudioSVC.java +++ b/src/main/java/com/volmit/iris/core/service/StudioSVC.java @@ -323,8 +323,7 @@ public class StudioSVC implements IrisService { public void open(VolmitSender sender, long seed, String dimm) { try { - open(sender, seed, dimm, (w) -> { - }); + open(sender, seed, dimm, (w) -> {}); } catch (Exception e) { Iris.reportError(e); sender.sendMessage("Error when creating studio world:"); @@ -342,6 +341,10 @@ public class StudioSVC implements IrisService { project.open(sender, seed, onDone); } + public void openVSCode(VolmitSender sender, String dim) { + new IrisProject(new File(getWorkspaceFolder(), dim)).openVSCode(sender); + } + public File getWorkspaceFolder(String... sub) { return Iris.instance.getDataFolderList(WORKSPACE_NAME, sub); } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/BiomeHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/BiomeHandler.java index d142cea4d..1f03ae93f 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/BiomeHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/BiomeHandler.java @@ -56,6 +56,9 @@ public class BiomeHandler implements DecreeParameterHandler { @Override public IrisBiome parse(String in) throws DecreeParsingException, DecreeWhichException { + if (in.equals("null")) { + return null; + } try { KList options = getPossibilities(in); diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/RegionHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/RegionHandler.java index 8f205af9a..36e80a83b 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/RegionHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/RegionHandler.java @@ -56,6 +56,9 @@ public class RegionHandler implements DecreeParameterHandler { @Override public IrisRegion parse(String in) throws DecreeParsingException, DecreeWhichException { + if (in.equals("null")) { + return null; + } try { KList options = getPossibilities(in); diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java index de7438c5e..1f79f4248 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java @@ -28,7 +28,13 @@ import org.bukkit.World; public class WorldHandler implements DecreeParameterHandler { @Override public KList getPossibilities() { - return new KList<>(Bukkit.getWorlds()); + KList options = new KList<>(); + for (World world : Bukkit.getWorlds()) { + if (!world.getName().toLowerCase().startsWith("iris/")){ + options.add(world); + } + } + return options; } @Override From d8900341ac69d57d8544e175739fba86acd2ffa4 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Sat, 28 Aug 2021 18:01:24 +0200 Subject: [PATCH 21/21] remove what --- .../com/volmit/iris/core/decrees/DecIris.java | 2 - .../volmit/iris/core/decrees/DecStudio.java | 212 ++++++++++++++ .../com/volmit/iris/core/decrees/DecWhat.java | 258 ------------------ 3 files changed, 212 insertions(+), 260 deletions(-) delete mode 100644 src/main/java/com/volmit/iris/core/decrees/DecWhat.java diff --git a/src/main/java/com/volmit/iris/core/decrees/DecIris.java b/src/main/java/com/volmit/iris/core/decrees/DecIris.java index 057580bef..fc696e274 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -45,8 +45,6 @@ public class DecIris implements DecreeExecutor { private DecObject object; - private DecWhat what; - @Decree(description = "Create a new world", aliases = "+") public void create( @Param(aliases = "world-name", description = "The name of the world to create") diff --git a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java index b117652e8..37af6c9a7 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java @@ -18,6 +18,7 @@ package com.volmit.iris.core.decrees; +import com.google.gson.Gson; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.gui.NoiseExplorerGUI; @@ -27,12 +28,14 @@ import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.service.ConversionSVC; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.tools.IrisToolbelt; +import com.volmit.iris.engine.framework.Engine; 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.feature.IrisFeaturePositional; import com.volmit.iris.engine.object.loot.IrisLootTable; import com.volmit.iris.engine.object.meta.InventorySlotType; import com.volmit.iris.engine.object.noise.IrisGenerator; @@ -40,9 +43,11 @@ 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.objects.IrisObjectPlacement; 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.collection.KSet; import com.volmit.iris.util.data.B; import com.volmit.iris.util.decree.DecreeExecutor; import com.volmit.iris.util.decree.DecreeOrigin; @@ -56,7 +61,9 @@ 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.M; import com.volmit.iris.util.math.RNG; +import com.volmit.iris.util.math.Spiraler; import com.volmit.iris.util.noise.CNG; import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.scheduling.J; @@ -66,16 +73,26 @@ 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 io.papermc.lib.PaperLib; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.util.BlockVector; import org.bukkit.util.Vector; import java.awt.*; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.attribute.FileTime; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.Date; +import java.util.Objects; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.function.Supplier; @@ -786,6 +803,201 @@ public class DecStudio implements DecreeExecutor { } } + @Decree(aliases = {"find-features", "nf"}, description = "Get the noise feature data in your chunk") + public void features() { + + if (!IrisToolbelt.isIrisWorld(player().getWorld())){ + sender().sendMessage(C.RED + "Iris worlds only"); + return; + } + + int n = 0; + + for (IrisFeaturePositional irisFeaturePositional : engine().getMantle().getFeaturesInChunk(player().getLocation().getChunk())) { + sender().sendMessage("#" + n++ + " " + new JSONObject(new Gson().toJson(irisFeaturePositional)).toString(4)); + } + } + + @Decree(aliases = "find-objects", description = "Get information about nearby structures") + public void objects() { + if (!IrisToolbelt.isIrisWorld(player().getWorld())){ + sender().sendMessage(C.RED + "You must be in an Iris world"); + return; + } + + World world = player().getWorld(); + + if (!IrisToolbelt.isIrisWorld(world)) { + sender().sendMessage("You must be in an iris world."); + return; + } + KList chunks = new KList<>(); + int bx = player().getLocation().getChunk().getX(); + int bz = player().getLocation().getChunk().getZ(); + + try { + Location l = player().getTargetBlockExact(48, FluidCollisionMode.NEVER).getLocation(); + + int cx = l.getChunk().getX(); + int cz = l.getChunk().getZ(); + new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + cx, z + cz))).drain(); + } catch (Throwable e) { + Iris.reportError(e); + } + + new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + bx, z + bz))).drain(); + sender().sendMessage("Capturing IGenData from " + chunks.size() + " nearby chunks."); + try { + File ff = Iris.instance.getDataFile("reports/" + M.ms() + ".txt"); + PrintWriter pw = new PrintWriter(ff); + pw.println("=== Iris Chunk Report ==="); + pw.println("== General Info =="); + pw.println("Iris Version: " + Iris.instance.getDescription().getVersion()); + pw.println("Bukkit Version: " + Bukkit.getBukkitVersion()); + pw.println("MC Version: " + Bukkit.getVersion()); + pw.println("PaperSpigot: " + (PaperLib.isPaper() ? "Yup!" : "Nope!")); + pw.println("Report Captured At: " + new Date()); + pw.println("Chunks: (" + chunks.size() + "): "); + + for (Chunk i : chunks) { + pw.println("- [" + i.getX() + ", " + i.getZ() + "]"); + } + + int regions = 0; + long size = 0; + String age = "No idea..."; + + try { + for (File i : Objects.requireNonNull(new File(world.getWorldFolder(), "region").listFiles())) { + if (i.isFile()) { + size += i.length(); + } + } + } catch (Throwable e) { + Iris.reportError(e); + } + + try { + FileTime creationTime = (FileTime) Files.getAttribute(world.getWorldFolder().toPath(), "creationTime"); + age = hrf(Duration.of(M.ms() - creationTime.toMillis(), ChronoUnit.MILLIS)); + } catch (IOException e) { + Iris.reportError(e); + } + + KList biomes = new KList<>(); + KList caveBiomes = new KList<>(); + KMap>> objects = new KMap<>(); + + for (Chunk i : chunks) { + for (int j = 0; j < 16; j += 3) { + + for (int k = 0; k < 16; k += 3) { + + assert engine() != null; + IrisBiome bb = engine().getSurfaceBiome((i.getX() * 16) + j, (i.getZ() * 16) + k); + IrisBiome bxf = engine().getCaveBiome((i.getX() * 16) + j, (i.getZ() * 16) + k); + biomes.addIfMissing(bb.getName() + " [" + Form.capitalize(bb.getInferredType().name().toLowerCase()) + "] " + " (" + bb.getLoadFile().getName() + ")"); + caveBiomes.addIfMissing(bxf.getName() + " (" + bxf.getLoadFile().getName() + ")"); + exportObjects(bb, pw, engine(), objects); + exportObjects(bxf, pw, engine(), objects); + } + } + } + + regions = Objects.requireNonNull(new File(world.getWorldFolder().getPath() + "/region").list()).length; + + pw.println(); + pw.println("== World Info =="); + pw.println("World Name: " + world.getName()); + pw.println("Age: " + age); + pw.println("Folder: " + world.getWorldFolder().getPath()); + pw.println("Regions: " + Form.f(regions)); + pw.println("Chunks: max. " + Form.f(regions * 32 * 32)); + pw.println("World Size: min. " + Form.fileSize(size)); + pw.println(); + pw.println("== Biome Info =="); + pw.println("Found " + biomes.size() + " Biome(s): "); + + for (String i : biomes) { + pw.println("- " + i); + } + pw.println(); + + pw.println("== Object Info =="); + + for (String i : objects.k()) { + pw.println("- " + i); + + for (String j : objects.get(i).k()) { + pw.println(" @ " + j); + + for (String k : objects.get(i).get(j)) { + pw.println(" * " + k); + } + } + } + + pw.println(); + pw.close(); + + sender().sendMessage("Reported to: " + ff.getPath()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + Iris.reportError(e); + } + } + + private void exportObjects(IrisBiome bb, PrintWriter pw, Engine g, KMap>> objects) { + String n1 = bb.getName() + " [" + Form.capitalize(bb.getInferredType().name().toLowerCase()) + "] " + " (" + bb.getLoadFile().getName() + ")"; + int m = 0; + KSet stop = new KSet<>(); + for (IrisObjectPlacement f : bb.getObjects()) { + m++; + String n2 = "Placement #" + m + " (" + f.getPlace().size() + " possible objects)"; + + for (String i : f.getPlace()) { + String nn3 = i + ": [ERROR] Failed to find object!"; + + try { + if (stop.contains(i)) { + continue; + } + + File ff = g.getData().getObjectLoader().findFile(i); + BlockVector sz = IrisObject.sampleSize(ff); + nn3 = i + ": size=[" + sz.getBlockX() + "," + sz.getBlockY() + "," + sz.getBlockZ() + "] location=[" + ff.getPath() + "]"; + stop.add(i); + } catch (Throwable e) { + Iris.reportError(e); + } + + String n3 = nn3; + + objects.compute(n1, (k1, v1) -> + { + //noinspection ReplaceNullCheck + if (v1 == null) { + return new KMap<>(); + } + + return v1; + }).compute(n2, (k, v) -> + { + if (v == null) { + return new KList().qaddIfMissing(n3); + } + + v.addIfMissing(n3); + return v; + }); + } + } + } + + public static String hrf(Duration duration) { + return duration.toString().substring(2).replaceAll("(\\d[HMS])(?!$)", "$1 ").toLowerCase(); + } + /** * @return true if server GUIs are not enabled */ diff --git a/src/main/java/com/volmit/iris/core/decrees/DecWhat.java b/src/main/java/com/volmit/iris/core/decrees/DecWhat.java deleted file mode 100644 index 2349ab703..000000000 --- a/src/main/java/com/volmit/iris/core/decrees/DecWhat.java +++ /dev/null @@ -1,258 +0,0 @@ -package com.volmit.iris.core.decrees; - -import com.google.gson.Gson; -import com.volmit.iris.Iris; -import com.volmit.iris.core.nms.INMS; -import com.volmit.iris.core.tools.IrisToolbelt; -import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.object.biome.IrisBiome; -import com.volmit.iris.engine.object.feature.IrisFeaturePositional; -import com.volmit.iris.engine.object.objects.IrisObject; -import com.volmit.iris.engine.object.objects.IrisObjectPlacement; -import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.collection.KMap; -import com.volmit.iris.util.collection.KSet; -import com.volmit.iris.util.data.B; -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.json.JSONObject; -import com.volmit.iris.util.math.M; -import com.volmit.iris.util.math.Spiraler; -import com.volmit.iris.util.plugin.VolmitSender; -import io.papermc.lib.PaperLib; -import org.bukkit.*; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.entity.Player; -import org.bukkit.util.BlockVector; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.PrintWriter; -import java.nio.file.Files; -import java.nio.file.attribute.FileTime; -import java.time.Duration; -import java.time.temporal.ChronoUnit; -import java.util.Date; -import java.util.Objects; - -@Decree(name = "what", aliases = "?", description = "Find information on the world around you", origin = DecreeOrigin.PLAYER) -public class DecWhat implements DecreeExecutor { - - @Decree(aliases = "nf", description = "Get the noise feature data in your chunk") - public void features() { - - if (!IrisToolbelt.isIrisWorld(player().getWorld())){ - sender().sendMessage(C.RED + "Iris worlds only"); - return; - } - - int n = 0; - - for (IrisFeaturePositional irisFeaturePositional : engine().getMantle().getFeaturesInChunk(player().getLocation().getChunk())) { - sender().sendMessage("#" + n++ + " " + new JSONObject(new Gson().toJson(irisFeaturePositional)).toString(4)); - } - } - - @Decree(description = "Get information about the world around you", aliases = "location", studio = true) - public void me( - @Param(description = "Whether or not to show dimension information", defaultValue = "true") - boolean dimension, - @Param(description = "Whether or not to show region information", defaultValue = "true") - boolean region, - @Param(description = "Whether or not to show biome information", defaultValue = "true") - boolean biome, - @Param(description = "Whether or not to show information about the block you are looking at", defaultValue = "true") - boolean look, - @Param(description = "Whether or not to show information about the block you are holding", defaultValue = "true") - boolean hand - ) { - new DecStudio().what(dimension, region, biome, look, hand); - } - - @Decree(aliases = "capture", description = "Get information about nearby structures") - public void objects() { - if (!IrisToolbelt.isIrisWorld(player().getWorld())){ - sender().sendMessage(C.RED + "You must be in an Iris world"); - return; - } - - World world = player().getWorld(); - - if (!IrisToolbelt.isIrisWorld(world)) { - sender().sendMessage("You must be in an iris world."); - return; - } - KList chunks = new KList<>(); - int bx = player().getLocation().getChunk().getX(); - int bz = player().getLocation().getChunk().getZ(); - - try { - Location l = player().getTargetBlockExact(48, FluidCollisionMode.NEVER).getLocation(); - - int cx = l.getChunk().getX(); - int cz = l.getChunk().getZ(); - new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + cx, z + cz))).drain(); - } catch (Throwable e) { - Iris.reportError(e); - } - - new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + bx, z + bz))).drain(); - sender().sendMessage("Capturing IGenData from " + chunks.size() + " nearby chunks."); - try { - File ff = Iris.instance.getDataFile("reports/" + M.ms() + ".txt"); - PrintWriter pw = new PrintWriter(ff); - pw.println("=== Iris Chunk Report ==="); - pw.println("== General Info =="); - pw.println("Iris Version: " + Iris.instance.getDescription().getVersion()); - pw.println("Bukkit Version: " + Bukkit.getBukkitVersion()); - pw.println("MC Version: " + Bukkit.getVersion()); - pw.println("PaperSpigot: " + (PaperLib.isPaper() ? "Yup!" : "Nope!")); - pw.println("Report Captured At: " + new Date()); - pw.println("Chunks: (" + chunks.size() + "): "); - - for (Chunk i : chunks) { - pw.println("- [" + i.getX() + ", " + i.getZ() + "]"); - } - - int regions = 0; - long size = 0; - String age = "No idea..."; - - try { - for (File i : Objects.requireNonNull(new File(world.getWorldFolder(), "region").listFiles())) { - if (i.isFile()) { - size += i.length(); - } - } - } catch (Throwable e) { - Iris.reportError(e); - } - - try { - FileTime creationTime = (FileTime) Files.getAttribute(world.getWorldFolder().toPath(), "creationTime"); - age = hrf(Duration.of(M.ms() - creationTime.toMillis(), ChronoUnit.MILLIS)); - } catch (IOException e) { - Iris.reportError(e); - } - - KList biomes = new KList<>(); - KList caveBiomes = new KList<>(); - KMap>> objects = new KMap<>(); - - for (Chunk i : chunks) { - for (int j = 0; j < 16; j += 3) { - - for (int k = 0; k < 16; k += 3) { - - assert engine() != null; - IrisBiome bb = engine().getSurfaceBiome((i.getX() * 16) + j, (i.getZ() * 16) + k); - IrisBiome bxf = engine().getCaveBiome((i.getX() * 16) + j, (i.getZ() * 16) + k); - biomes.addIfMissing(bb.getName() + " [" + Form.capitalize(bb.getInferredType().name().toLowerCase()) + "] " + " (" + bb.getLoadFile().getName() + ")"); - caveBiomes.addIfMissing(bxf.getName() + " (" + bxf.getLoadFile().getName() + ")"); - exportObjects(bb, pw, engine(), objects); - exportObjects(bxf, pw, engine(), objects); - } - } - } - - regions = Objects.requireNonNull(new File(world.getWorldFolder().getPath() + "/region").list()).length; - - pw.println(); - pw.println("== World Info =="); - pw.println("World Name: " + world.getName()); - pw.println("Age: " + age); - pw.println("Folder: " + world.getWorldFolder().getPath()); - pw.println("Regions: " + Form.f(regions)); - pw.println("Chunks: max. " + Form.f(regions * 32 * 32)); - pw.println("World Size: min. " + Form.fileSize(size)); - pw.println(); - pw.println("== Biome Info =="); - pw.println("Found " + biomes.size() + " Biome(s): "); - - for (String i : biomes) { - pw.println("- " + i); - } - pw.println(); - - pw.println("== Object Info =="); - - for (String i : objects.k()) { - pw.println("- " + i); - - for (String j : objects.get(i).k()) { - pw.println(" @ " + j); - - for (String k : objects.get(i).get(j)) { - pw.println(" * " + k); - } - } - } - - pw.println(); - pw.close(); - - sender().sendMessage("Reported to: " + ff.getPath()); - } catch (FileNotFoundException e) { - e.printStackTrace(); - Iris.reportError(e); - } - } - - private void exportObjects(IrisBiome bb, PrintWriter pw, Engine g, KMap>> objects) { - String n1 = bb.getName() + " [" + Form.capitalize(bb.getInferredType().name().toLowerCase()) + "] " + " (" + bb.getLoadFile().getName() + ")"; - int m = 0; - KSet stop = new KSet<>(); - for (IrisObjectPlacement f : bb.getObjects()) { - m++; - String n2 = "Placement #" + m + " (" + f.getPlace().size() + " possible objects)"; - - for (String i : f.getPlace()) { - String nn3 = i + ": [ERROR] Failed to find object!"; - - try { - if (stop.contains(i)) { - continue; - } - - File ff = g.getData().getObjectLoader().findFile(i); - BlockVector sz = IrisObject.sampleSize(ff); - nn3 = i + ": size=[" + sz.getBlockX() + "," + sz.getBlockY() + "," + sz.getBlockZ() + "] location=[" + ff.getPath() + "]"; - stop.add(i); - } catch (Throwable e) { - Iris.reportError(e); - } - - String n3 = nn3; - - objects.compute(n1, (k1, v1) -> - { - //noinspection ReplaceNullCheck - if (v1 == null) { - return new KMap<>(); - } - - return v1; - }).compute(n2, (k, v) -> - { - if (v == null) { - return new KList().qaddIfMissing(n3); - } - - v.addIfMissing(n3); - return v; - }); - } - } - } - - public static String hrf(Duration duration) { - return duration.toString().substring(2).replaceAll("(\\d[HMS])(?!$)", "$1 ").toLowerCase(); - } -}