From 67e426354cb4bebe5d4d110a55b8a778024d0962 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 17 Aug 2021 00:35:25 +0200 Subject: [PATCH 1/7] Small fixes --- src/main/java/com/volmit/iris/core/decrees/DecIris.java | 4 ++-- src/main/java/com/volmit/iris/util/plugin/VolmitSender.java | 4 ++-- 2 files changed, 4 insertions(+), 4 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 e147490d9..9a1b27271 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -114,11 +114,11 @@ public class DecIris implements DecreeExecutor case ">>" -> v = value1 >> value2; case "<<" -> v = value1 << value2; }; - if (v == null){ + if (v == null) { sender().sendMessage(C.RED + "The operator you entered: (" + operator + ") is invalid!"); return; } - sender().sendMessage(C.GREEN + "" + value1 + " " + operator + " " + value2 + " => " + v); + sender().sendMessage(C.GREEN + "" + value1 + " " + C.GREEN + operator.replaceAll("<", "≺").replaceAll(">", "≻") + " " + C.GREEN + value2 + C.GREEN + " returns " + C.GREEN + v); } @Decree(description = "Toggle debug") 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 5d98877db..7e7a14b8c 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java @@ -434,7 +434,7 @@ public class VolmitSender implements CommandSender { + "<#bbe03f>✒ <#a8e0a2>" + (i.isNode() ? ((i.getNode().getParameters().isEmpty() ? "There are no parameters." - : "Hover over all of the parameters to learn more.") + "\n") + : "Hover over all of the parameters to learn more." + "\n")) : "This is a command category. Run <#98eda5>" + i.getPath()) + (i.isNode() ? (i.getNode().getParameters().isNotEmpty()) @@ -461,7 +461,7 @@ public class VolmitSender implements CommandSender { ? "<#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() + "\n" + + "<#cc00ff>✢ <#ff33cc>This parameter is of type " + f.getType().getSimpleName() + "'>" + (f.isRequired() ? "[" : "") + "" + f.getName() From e6e3953a85142799909815083b29349267a7b148 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 17 Aug 2021 16:17:40 +0200 Subject: [PATCH 2/7] Auto stash before merge of "DecreeCommands" and "upstream/master" --- src/main/java/com/volmit/iris/core/decrees/DecIris.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 610d6c9a3..f491a764e 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -145,7 +145,7 @@ public class DecIris implements DecreeExecutor { @Param(name = "overwrite", description = "Whether or not to overwrite the pack with the downloaded one", aliases = "force", defaultValue = "false") boolean overwrite ) { - sender().sendMessage(C.GREEN + "Downloading pack: " + pack + "/" + branch + (trim ? " trimmed" : "")); + sender().sendMessage(C.GREEN + "Downloading pack: " + pack + "/" + branch + (trim ? " trimmed" : "") + (overwrite ? " overwriting" : "")); Iris.service(StudioSVC.class).downloadSearch(sender(), "IrisDimensions/" + pack + "/" + branch, trim, overwrite); } From d04c95514ed5e7dd6e792cf5e3fff702ac4f7255 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 17 Aug 2021 16:55:33 +0200 Subject: [PATCH 3/7] Studio patches --- .../java/com/volmit/iris/core/decrees/DecStudio.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 8c899e58f..d8f4175b3 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java @@ -66,14 +66,12 @@ import com.volmit.iris.util.scheduling.jobs.Job; import com.volmit.iris.util.scheduling.jobs.JobCollection; import com.volmit.iris.util.scheduling.jobs.QueueJob; import com.volmit.iris.util.scheduling.jobs.SingleJob; -import org.bukkit.Bukkit; -import org.bukkit.FluidCollisionMode; -import org.bukkit.GameMode; -import org.bukkit.Material; +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.Vector; import java.awt.*; import java.io.File; @@ -622,7 +620,9 @@ public class DecStudio implements DecreeExecutor { @Decree(description = "Summon an Iris Entity", origin = DecreeOrigin.PLAYER) public void summon( @Param(description = "The Iris Entity to spawn") - IrisEntity entity + IrisEntity entity, + @Param(description = "The location at which to spawn the entity", defaultValue = "self") + Vector location ) { if (!sender().isPlayer()) { sender().sendMessage(C.RED + "Players only (this is a config error. Ask support to add DecreeOrigin.PLAYER to the command you tried to run)"); @@ -633,7 +633,7 @@ public class DecStudio implements DecreeExecutor { return; } sender().sendMessage(C.GREEN + "Spawning entity"); - entity.spawn(engine(), player().getLocation().clone().add(0, 2, 0)); + entity.spawn(engine(), new Location(world(), location.getX(), location.getY(), location.getZ())); } @Decree(description = "Teleport to the active studio world", aliases = "stp", origin = DecreeOrigin.PLAYER, sync = true) From 7d859661ba710d4889e783917a15ecba1c62b6bf Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 17 Aug 2021 17:22:27 +0200 Subject: [PATCH 4/7] Sorry for merge conflicts :) --- .../object/CommandIrisObjectAnalyze.java | 66 ----------- .../core/command/world/CommandLocate.java | 72 ------------ .../com/volmit/iris/core/decrees/DecIris.java | 4 + .../volmit/iris/core/decrees/DecObject.java | 86 ++++++++++++++ .../volmit/iris/core/service/LocateSVC.java | 33 ++++++ .../util/decree/handlers/ObjectHandler.java | 67 +++++++++++ .../volmit/iris/util/plugin/VolmitSender.java | 106 +++++++++--------- 7 files changed, 245 insertions(+), 189 deletions(-) delete mode 100644 src/main/java/com/volmit/iris/core/command/world/CommandLocate.java create mode 100644 src/main/java/com/volmit/iris/core/decrees/DecObject.java create mode 100644 src/main/java/com/volmit/iris/core/service/LocateSVC.java create mode 100644 src/main/java/com/volmit/iris/util/decree/handlers/ObjectHandler.java diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java index 88e541d0a..fa8e99db0 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java @@ -86,73 +86,7 @@ public class CommandIrisObjectAnalyze extends MortarCommand { Player p = sender.player(); J.a(() -> { - IrisObject obj = IrisData.loadAnyObject(args[0]); - if (obj == null || obj.getLoadFile() == null) { - sender.sendMessage("Can't find " + args[0] + " in the " + StudioSVC.WORKSPACE_NAME + " folder"); - return; - } - - sender.sendMessage("Object Size: " + obj.getW() + " * " + obj.getH() + " * " + obj.getD() + ""); - sender.sendMessage("Blocks Used: " + NumberFormat.getIntegerInstance().format(obj.getBlocks().size())); - - Queue queue = obj.getBlocks().enqueueValues(); - Map> unsorted = new HashMap<>(); - Map amounts = new HashMap<>(); - Map materials = new HashMap<>(); - while (queue.hasNext()) { - BlockData block = queue.next(); - - //unsorted.put(block.getMaterial(), block); - - if (!amounts.containsKey(block)) { - amounts.put(block, 1); - - - } else - amounts.put(block, amounts.get(block) + 1); - - if (!materials.containsKey(block.getMaterial())) { - materials.put(block.getMaterial(), 1); - unsorted.put(block.getMaterial(), new HashSet<>()); - unsorted.get(block.getMaterial()).add(block); - } else { - materials.put(block.getMaterial(), materials.get(block.getMaterial()) + 1); - unsorted.get(block.getMaterial()).add(block); - } - - } - - List sortedMatsList = amounts.keySet().stream().map(BlockData::getMaterial) - .sorted().collect(Collectors.toList()); - Set sortedMats = new TreeSet<>(Comparator.comparingInt(materials::get).reversed()); - sortedMats.addAll(sortedMatsList); - sender.sendMessage("== Blocks in object =="); - - int n = 0; - for (Material mat : sortedMats) { - int amount = materials.get(mat); - List set = new ArrayList<>(unsorted.get(mat)); - set.sort(Comparator.comparingInt(amounts::get).reversed()); - BlockData data = set.get(0); - int dataAmount = amounts.get(data); - - String string = " - " + mat.toString() + "*" + amount; - if (data.getAsString(true).contains("[")) { - string = string + " --> [" + data.getAsString(true).split("\\[")[1] - .replaceAll("true", ChatColor.GREEN + "true" + ChatColor.GRAY) - .replaceAll("false", ChatColor.RED + "false" + ChatColor.GRAY) + "*" + dataAmount; - } - - sender.sendMessage(string); - - n++; - - if (n >= 10) { - sender.sendMessage(" + " + (sortedMats.size() - n) + " other block types"); - return; - } - } }); return true; diff --git a/src/main/java/com/volmit/iris/core/command/world/CommandLocate.java b/src/main/java/com/volmit/iris/core/command/world/CommandLocate.java deleted file mode 100644 index ac8a59636..000000000 --- a/src/main/java/com/volmit/iris/core/command/world/CommandLocate.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2021 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.volmit.iris.core.command.world; - -import com.volmit.iris.Iris; -import com.volmit.iris.core.tools.IrisToolbelt; -import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.plugin.MortarCommand; -import com.volmit.iris.util.plugin.VolmitSender; -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - -import java.util.Arrays; - -public class CommandLocate extends MortarCommand implements Listener { - - @EventHandler - public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) { - if (IrisToolbelt.isIrisWorld(event.getPlayer().getWorld())) { - - // Make sure the command starts with /locate and does not locate stronghold - if (event.getMessage().contains("/locate") && event.getMessage().contains("stronghold")) { - return; - } - if (event.getMessage().contains("/locate")) { - event.setCancelled(true); // Cancel the vanilla command process - String command = event.getMessage().replace("/locate", "ir std goto"); - Bukkit.dispatchCommand(event.getPlayer(), command); - } - } - } - - public CommandLocate() { - super("locate"); - requiresPermission(Iris.perm); - Iris.instance.registerListener(this); - } - - @Override - public boolean handle(VolmitSender sender, String[] args) { - Bukkit.dispatchCommand(sender, "/ir std goto " + Arrays.toString(args)); - return true; - } - - @Override - public void addTabOptions(VolmitSender sender, String[] args, KList list) { - - } - - @Override - protected String getArgsUsage() { - return "[biome/region/structure]"; - } -} 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 f491a764e..b86d1dc8f 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -42,6 +42,10 @@ public class DecIris implements DecreeExecutor { private DecPregen pregen; + private DecSettings settings; + + private DecObject object; + @Decree(description = "Create a new world", aliases = "+") public void create( @Param(aliases = "world-name", description = "The name of the world to create", defaultValue = "IrisWorld") diff --git a/src/main/java/com/volmit/iris/core/decrees/DecObject.java b/src/main/java/com/volmit/iris/core/decrees/DecObject.java new file mode 100644 index 000000000..5cc763a9b --- /dev/null +++ b/src/main/java/com/volmit/iris/core/decrees/DecObject.java @@ -0,0 +1,86 @@ +package com.volmit.iris.core.decrees; + +import com.volmit.iris.engine.object.objects.IrisObject; +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.scheduling.Queue; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; + +import java.text.NumberFormat; +import java.util.*; +import java.util.stream.Collectors; + +@Decree(name = "object", origin = DecreeOrigin.PLAYER, description = "Iris object manipulation") +public class DecObject implements DecreeExecutor { + + @Decree(description = "Check the composition of an object") + public void analyze( + @Param(description = "The object to analyze") + IrisObject object + ) { + sender().sendMessage("Object Size: " + object.getW() + " * " + object.getH() + " * " + object.getD() + ""); + sender().sendMessage("Blocks Used: " + NumberFormat.getIntegerInstance().format(object.getBlocks().size())); + + Queue queue = object.getBlocks().enqueueValues(); + Map> unsorted = new HashMap<>(); + Map amounts = new HashMap<>(); + Map materials = new HashMap<>(); + while (queue.hasNext()) { + BlockData block = queue.next(); + + //unsorted.put(block.getMaterial(), block); + + if (!amounts.containsKey(block)) { + amounts.put(block, 1); + + + } else + amounts.put(block, amounts.get(block) + 1); + + if (!materials.containsKey(block.getMaterial())) { + materials.put(block.getMaterial(), 1); + unsorted.put(block.getMaterial(), new HashSet<>()); + unsorted.get(block.getMaterial()).add(block); + } else { + materials.put(block.getMaterial(), materials.get(block.getMaterial()) + 1); + unsorted.get(block.getMaterial()).add(block); + } + + } + + List sortedMatsList = amounts.keySet().stream().map(BlockData::getMaterial) + .sorted().collect(Collectors.toList()); + Set sortedMats = new TreeSet<>(Comparator.comparingInt(materials::get).reversed()); + sortedMats.addAll(sortedMatsList); + sender().sendMessage("== Blocks in object =="); + + int n = 0; + for (Material mat : sortedMats) { + int amount = materials.get(mat); + List set = new ArrayList<>(unsorted.get(mat)); + set.sort(Comparator.comparingInt(amounts::get).reversed()); + BlockData data = set.get(0); + int dataAmount = amounts.get(data); + + String string = " - " + mat.toString() + "*" + amount; + if (data.getAsString(true).contains("[")) { + string = string + " --> [" + data.getAsString(true).split("\\[")[1] + .replaceAll("true", ChatColor.GREEN + "true" + ChatColor.GRAY) + .replaceAll("false", ChatColor.RED + "false" + ChatColor.GRAY) + "*" + dataAmount; + } + + sender().sendMessage(string); + + n++; + + if (n >= 10) { + sender().sendMessage(" + " + (sortedMats.size() - n) + " other block types"); + return; + } + } + } +} diff --git a/src/main/java/com/volmit/iris/core/service/LocateSVC.java b/src/main/java/com/volmit/iris/core/service/LocateSVC.java new file mode 100644 index 000000000..1d862a34c --- /dev/null +++ b/src/main/java/com/volmit/iris/core/service/LocateSVC.java @@ -0,0 +1,33 @@ +package com.volmit.iris.core.service; + +import com.volmit.iris.core.tools.IrisToolbelt; +import com.volmit.iris.util.format.C; +import com.volmit.iris.util.plugin.IrisService; +import com.volmit.iris.util.plugin.VolmitSender; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +public class LocateSVC implements IrisService { + + @EventHandler + public void on(final PlayerCommandPreprocessEvent event) { + if (IrisToolbelt.isIrisWorld(event.getPlayer().getWorld())) { + VolmitSender sender = new VolmitSender(event.getPlayer()); + sender.sendMessage(C.YELLOW + "You cannot locate structures in Iris worlds through vanilla commands"); + sender.sendMessage("You can use:"); + // TODO: Convert this to have the correct command prefix + Bukkit.dispatchCommand(event.getPlayer(), "/ird studio find"); + } + } + + @Override + public void onEnable() { + + } + + @Override + public void onDisable() { + + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/ObjectHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/ObjectHandler.java new file mode 100644 index 000000000..b4a8ce78a --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/handlers/ObjectHandler.java @@ -0,0 +1,67 @@ +package com.volmit.iris.util.decree.handlers; + +import com.volmit.iris.Iris; +import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.engine.object.objects.IrisObject; +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.collection.KMap; +import com.volmit.iris.util.decree.DecreeParameterHandler; +import com.volmit.iris.util.decree.exceptions.DecreeParsingException; +import com.volmit.iris.util.decree.exceptions.DecreeWhichException; + +import java.io.File; + +public class ObjectHandler implements DecreeParameterHandler { + @Override + public KList getPossibilities() { + KMap p = new KMap<>(); + + //noinspection ConstantConditions + for (File i : Iris.instance.getDataFolder("packs").listFiles()) { + if (i.isDirectory()) { + IrisData data = new IrisData(i, true); + for (IrisObject j : data.getObjectLoader().loadAll(data.getObjectLoader().getPossibleKeys())) { + p.putIfAbsent(j.getLoadKey(), j); + } + + data.close(); + } + } + + return p.v(); + } + + @Override + public String toString(IrisObject irisObject) { + return irisObject.getLoadKey(); + } + + @Override + public IrisObject parse(String in) throws DecreeParsingException, DecreeWhichException { + try { + KList options = getPossibilities(in); + + if (options.isEmpty()) { + throw new DecreeParsingException("Unable to find Object \"" + in + "\""); + } else if (options.size() > 1) { + throw new DecreeWhichException(); + } + + return options.get(0); + } catch (DecreeParsingException e) { + throw e; + } catch (Throwable e) { + throw new DecreeParsingException("Unable to find Object \"" + in + "\" because of an uncaught exception: " + e); + } + } + + @Override + public boolean supports(Class type) { + return type.equals(IrisObject.class); + } + + @Override + public String getRandomDefault() { + return "object"; + } +} 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 39731ee1e..504f3a381 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java @@ -413,60 +413,64 @@ public class VolmitSender implements CommandSender { } for (VirtualDecreeCommand i : v.getNodes()) { - 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. 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() ? "[" : "") - + "" + f.getName() - + (f.isRequired() ? "]" : "") - + "").toString(" ") - : " - Category of Commands" - ) - ); - //@done - sendMessageRaw(s); - System.out.println(s); - } else { - sendMessage(i.getPath() + "()"); - } + sendDecreeHelpNode(i); } } else { sendMessage(C.RED + "There are no subcommands in this group! Contact support, this is a command design issue!"); } } + + 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. 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() ? "[" : "") + + "" + f.getName() + + (f.isRequired() ? "]" : "") + + "").toString(" ") + : " - Category of Commands" + ) + ); + //@done + sendMessageRaw(s); + System.out.println(s); + } else { + sendMessage(i.getPath() + "()"); + } + } } From 198820d95d96b025b59248718420d3d58f9fc425 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 17 Aug 2021 18:04:09 +0200 Subject: [PATCH 5/7] PlaySound in volmitsender --- .../command/object/CommandIrisObjectDust.java | 2 +- .../command/object/CommandIrisObjectWand.java | 2 +- .../volmit/iris/core/decrees/DecObject.java | 122 +++++++++++++++++- .../util/decree/handlers/VectorHandler.java | 11 +- .../iris/util/plugin/MortarCommand.java | 2 +- .../volmit/iris/util/plugin/VolmitSender.java | 7 + 6 files changed, 141 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectDust.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectDust.java index 247fe232a..f77cbc910 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectDust.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectDust.java @@ -52,7 +52,7 @@ public class CommandIrisObjectDust extends MortarCommand { } sender.player().getInventory().addItem(WandSVC.createDust()); - sender.player().playSound(sender.player().getLocation(), Sound.AMBIENT_SOUL_SAND_VALLEY_ADDITIONS, 1f, 1.5f); + sender.playSound(Sound.AMBIENT_SOUL_SAND_VALLEY_ADDITIONS, 1f, 1.5f); return true; } diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectWand.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectWand.java index d8c476c91..2d938e120 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectWand.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectWand.java @@ -53,7 +53,7 @@ public class CommandIrisObjectWand extends MortarCommand { } sender.player().getInventory().addItem(WandSVC.createWand()); - sender.player().playSound(sender.player().getLocation(), Sound.ITEM_ARMOR_EQUIP_NETHERITE, 1f, 1.5f); + sender.playSound(Sound.ITEM_ARMOR_EQUIP_NETHERITE, 1f, 1.5f); return true; } 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 5cc763a9b..dfc7af2b2 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecObject.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecObject.java @@ -1,20 +1,30 @@ package com.volmit.iris.core.decrees; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.engine.object.objects.IrisObject; +import com.volmit.iris.engine.object.objects.IrisObjectPlacement; +import com.volmit.iris.engine.object.objects.IrisObjectPlacementScaleInterpolator; +import com.volmit.iris.engine.object.objects.IrisObjectRotation; +import com.volmit.iris.util.data.Cuboid; 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.math.Direction; import com.volmit.iris.util.scheduling.Queue; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Sound; import org.bukkit.block.data.BlockData; +import org.bukkit.inventory.ItemStack; import java.text.NumberFormat; import java.util.*; import java.util.stream.Collectors; -@Decree(name = "object", origin = DecreeOrigin.PLAYER, description = "Iris object manipulation") +@Decree(name = "object", origin = DecreeOrigin.PLAYER, studio = true, description = "Iris object manipulation") public class DecObject implements DecreeExecutor { @Decree(description = "Check the composition of an object") @@ -83,4 +93,114 @@ public class DecObject implements DecreeExecutor { } } } + + @Decree(description = "Get a powder that reveals objects", studio = true) + public void dust() { + player().getInventory().addItem(WandSVC.createDust()); + sender().playSound(Sound.AMBIENT_SOUL_SAND_VALLEY_ADDITIONS, 1f, 1.5f); + } + + @Decree(description = "Contract a selection based on your looking direction", aliases = "-") + public void contract( + @Param(description = "The amount to inset 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(); + Cuboid cursor = new Cuboid(a1, a2); + Direction d = Direction.closest(player().getLocation().getDirection()).reverse(); + assert d != null; + cursor = cursor.expand(d, -amount); + 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); + } + + @Decree(description = "Set point 1 to look", aliases = "p1") + public void position1( + @Param(description = "Whether to use your current position, or where you look", defaultValue = "true") + boolean here + ){ + if (!WandSVC.isHoldingWand(player())) { + sender().sendMessage("Ready your Wand."); + return; + } + + ItemStack wand = player().getInventory().getItemInMainHand(); + + if (WandSVC.isWand(wand)) { + Location[] g = WandSVC.getCuboid(wand); + + if (!here) { + // TODO: WARNING HEIGHT + g[1] = player().getTargetBlock(null, 256).getLocation().clone(); + } else { + g[1] = player().getLocation().getBlock().getLocation().clone().add(0, -1, 0); + } + player().setItemInHand(WandSVC.createWand(g[0], g[1])); + } + } + + @Decree(description = "Set point 2 to look", aliases = "p2") + public void position2( + @Param(description = "Whether to use your current position, or where you look", defaultValue = "true") + boolean here + ){ + if (!WandSVC.isHoldingWand(player())) { + sender().sendMessage("Ready your Wand."); + return; + } + + ItemStack wand = player().getInventory().getItemInMainHand(); + + if (WandSVC.isWand(wand)) { + Location[] g = WandSVC.getCuboid(wand); + + if (!here) { + // TODO: WARNING HEIGHT + g[0] = player().getTargetBlock(null, 256).getLocation().clone(); + } else { + g[0] = player().getLocation().getBlock().getLocation().clone().add(0, -1, 0); + } + player().setItemInHand(WandSVC.createWand(g[0], g[1])); + } + } + + @Decree(description = "Paste an object") + public void paste( + @Param(description = "The object to paste") + IrisObject 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 maxScale = getMaxScale(object); + if (scale < maxScale){ + sender().sendMessage(C.YELLOW + "Indicated scale exceeds maximum. Downscaled to maximum: " + maxScale); + scale = maxScale; + } + + IrisObjectPlacement placement = new IrisObjectPlacement(); + placement.setRotation(IrisObjectRotation.of(0, rotate, 0)); + sender().player().getWorld().playSound(sender().player().getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); + + } + + private double getMaxScale(IrisObject object){ + return Double.max(10 - object.getBlocks().size() / 10000d, 1); + } } 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 f99f55d2a..64550b482 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 @@ -33,6 +33,15 @@ import org.bukkit.util.BlockVector; import org.bukkit.util.Vector; public class VectorHandler implements DecreeParameterHandler { + + private static final KList randoms = new KList<>( + "here", + "0,0,0", + "0,0", + "look", + "player:" + ); + @Override public KList getPossibilities() { KList vx = new KList<>(); @@ -107,6 +116,6 @@ public class VectorHandler implements DecreeParameterHandler { @Override public String getRandomDefault() { - return M.r(0.5) ? "0,0" : "0,0,0"; + return randoms.getRandom(); } } diff --git a/src/main/java/com/volmit/iris/util/plugin/MortarCommand.java b/src/main/java/com/volmit/iris/util/plugin/MortarCommand.java index c5fb3e30d..d3f5decdf 100644 --- a/src/main/java/com/volmit/iris/util/plugin/MortarCommand.java +++ b/src/main/java/com/volmit/iris/util/plugin/MortarCommand.java @@ -73,7 +73,7 @@ public abstract class MortarCommand implements ICommand { } if (sender.isPlayer() && IrisSettings.get().getGeneral().isCommandSounds()) { - sender.player().playSound(sender.player().getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 0.25f, 1.7f); + sender.playSound(Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 0.25f, 1.7f); } return v; 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 504f3a381..b211bc62d 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java @@ -33,6 +33,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.title.Title; import org.bukkit.Server; +import org.bukkit.Sound; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; @@ -473,4 +474,10 @@ public class VolmitSender implements CommandSender { sendMessage(i.getPath() + "()"); } } + + public void playSound(Sound sound, float volume, float pitch) { + if (isPlayer()) { + player().playSound(player().getLocation(), sound, volume, pitch); + } + } } From 01479a82def51d12fe3a837e2720276e94d81df2 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 17 Aug 2021 18:07:38 +0200 Subject: [PATCH 6/7] More merge conflicts please --- .../iris/core/command/object/CommandIrisObjectContract.java | 2 +- .../iris/core/command/object/CommandIrisObjectExpand.java | 2 +- .../iris/core/command/object/CommandIrisObjectPaste.java | 2 +- .../iris/core/command/object/CommandIrisObjectSave.java | 2 +- .../iris/core/command/object/CommandIrisObjectSaveMatter.java | 2 +- .../iris/core/command/object/CommandIrisObjectShift.java | 2 +- .../volmit/iris/core/command/object/CommandIrisObjectXAY.java | 2 +- .../volmit/iris/core/command/object/CommandIrisObjectXPY.java | 2 +- src/main/java/com/volmit/iris/core/decrees/DecObject.java | 2 +- src/main/java/com/volmit/iris/util/plugin/MortarCommand.java | 4 ++-- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectContract.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectContract.java index 127c4381e..ba9d11d8a 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectContract.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectContract.java @@ -74,7 +74,7 @@ public class CommandIrisObjectContract extends MortarCommand { b[1] = cursor.getUpperSW(); p.getInventory().setItemInMainHand(WandSVC.createWand(b[0], b[1])); p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); + sender.playSound(Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); return true; } diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectExpand.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectExpand.java index 106c372fe..de6e919f7 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectExpand.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectExpand.java @@ -74,7 +74,7 @@ public class CommandIrisObjectExpand extends MortarCommand { b[1] = cursor.getUpperSW(); p.getInventory().setItemInMainHand(WandSVC.createWand(b[0], b[1])); p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); + sender.playSound(Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); return true; } 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 958d2cff1..9dab1b2ab 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 @@ -174,7 +174,7 @@ public class CommandIrisObjectPaste extends MortarCommand { Iris.debug("Loaded object for placement: " + "objects/" + args[0] + ".iob"); - sender.player().getWorld().playSound(sender.player().getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); + sender.playSound(Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); Set skipBlocks = Set.of(Material.GRASS, Material.SNOW, Material.VINE, Material.TORCH, Material.DEAD_BUSH, Material.POPPY, Material.DANDELION); diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSave.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSave.java index a5dc75080..73c4ae88c 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSave.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSave.java @@ -88,7 +88,7 @@ public class CommandIrisObjectSave extends MortarCommand { o.write(file); sender.sendMessage("Saved " + args[1]); - p.getWorld().playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); + sender.playSound(Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); } catch (Throwable e) { Iris.reportError(e); sender.sendMessage("Failed to save " + args[1] + ". Are you holding your wand?"); diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSaveMatter.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSaveMatter.java index 45a599486..4824d0972 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSaveMatter.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectSaveMatter.java @@ -88,7 +88,7 @@ public class CommandIrisObjectSaveMatter extends MortarCommand { o.write(file); sender.sendMessage("Saved " + args[1]); - p.getWorld().playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); + sender.playSound(Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); } catch (Throwable e) { Iris.reportError(e); sender.sendMessage("Failed to save " + args[1] + ". Are you holding your wand?"); diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectShift.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectShift.java index e106704e6..46c605970 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectShift.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectShift.java @@ -75,7 +75,7 @@ public class CommandIrisObjectShift extends MortarCommand { b[1] = cursor.getUpperSW(); p.getInventory().setItemInMainHand(WandSVC.createWand(b[0], b[1])); p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); + sender.playSound(Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); return true; } diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXAY.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXAY.java index 3c3a65f98..e048d2ff5 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXAY.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXAY.java @@ -101,7 +101,7 @@ public class CommandIrisObjectXAY extends MortarCommand { b[1] = cursor.getUpperSW(); p.getInventory().setItemInMainHand(WandSVC.createWand(b[0], b[1])); p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); + sender.playSound(Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); return true; } diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXPY.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXPY.java index 1ec4fc96d..beeb4c4bb 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXPY.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectXPY.java @@ -89,7 +89,7 @@ public class CommandIrisObjectXPY extends MortarCommand { b[1] = cursor.getUpperSW(); p.getInventory().setItemInMainHand(WandSVC.createWand(b[0], b[1])); p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); + sender.playSound(Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); return true; } 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 dfc7af2b2..f31da5ece 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecObject.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecObject.java @@ -196,7 +196,7 @@ public class DecObject implements DecreeExecutor { IrisObjectPlacement placement = new IrisObjectPlacement(); placement.setRotation(IrisObjectRotation.of(0, rotate, 0)); - sender().player().getWorld().playSound(sender().player().getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); + sender().playSound(Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); } diff --git a/src/main/java/com/volmit/iris/util/plugin/MortarCommand.java b/src/main/java/com/volmit/iris/util/plugin/MortarCommand.java index d3f5decdf..f941eb9a7 100644 --- a/src/main/java/com/volmit/iris/util/plugin/MortarCommand.java +++ b/src/main/java/com/volmit/iris/util/plugin/MortarCommand.java @@ -100,8 +100,8 @@ public abstract class MortarCommand implements ICommand { } if (sender.isPlayer() && IrisSettings.get().getGeneral().isCommandSounds()) { - sender.player().getWorld().playSound(sender.player().getLocation(), Sound.ITEM_BOOK_PAGE_TURN, 0.28f, 1.4f); - sender.player().getWorld().playSound(sender.player().getLocation(), Sound.ITEM_AXE_STRIP, 0.35f, 1.7f); + sender.playSound(Sound.ITEM_BOOK_PAGE_TURN, 0.28f, 1.4f); + sender.playSound(Sound.ITEM_AXE_STRIP, 0.35f, 1.7f); } } From d241a57d3860b27f4bff20f0c155c27d350ac2a5 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 17 Aug 2021 18:17:13 +0200 Subject: [PATCH 7/7] Object --- .../volmit/iris/core/decrees/DecObject.java | 119 ++++++++++++++++-- 1 file changed, 109 insertions(+), 10 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 f31da5ece..d428238eb 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecObject.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecObject.java @@ -1,10 +1,14 @@ package com.volmit.iris.core.decrees; +import com.volmit.iris.core.command.object.CommandIrisObjectUndo; +import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.core.service.WandSVC; +import com.volmit.iris.engine.object.common.IObjectPlacer; import com.volmit.iris.engine.object.objects.IrisObject; import com.volmit.iris.engine.object.objects.IrisObjectPlacement; import com.volmit.iris.engine.object.objects.IrisObjectPlacementScaleInterpolator; import com.volmit.iris.engine.object.objects.IrisObjectRotation; +import com.volmit.iris.engine.object.tile.TileData; import com.volmit.iris.util.data.Cuboid; import com.volmit.iris.util.decree.DecreeExecutor; import com.volmit.iris.util.decree.DecreeOrigin; @@ -12,12 +16,14 @@ 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.math.Direction; +import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.scheduling.Queue; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; +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.text.NumberFormat; @@ -174,7 +180,8 @@ public class DecObject implements DecreeExecutor { player().setItemInHand(WandSVC.createWand(g[0], g[1])); } } - + 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") public void paste( @Param(description = "The object to paste") @@ -188,19 +195,111 @@ public class DecObject implements DecreeExecutor { @Param(description = "The scale interpolator to use", defaultValue = "none") IrisObjectPlacementScaleInterpolator interpolator ){ - double maxScale = getMaxScale(object); + double maxScale = Double.max(10 - object.getBlocks().size() / 10000d, 1); if (scale < maxScale){ sender().sendMessage(C.YELLOW + "Indicated scale exceeds maximum. Downscaled to maximum: " + maxScale); scale = maxScale; } - IrisObjectPlacement placement = new IrisObjectPlacement(); - placement.setRotation(IrisObjectRotation.of(0, rotate, 0)); sender().playSound(Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); + IrisObjectPlacement placement = new IrisObjectPlacement(); + placement.setRotation(IrisObjectRotation.of(0, rotate, 0)); + + ItemStack wand = player().getInventory().getItemInMainHand(); + Location block = player().getTargetBlock(skipBlocks, 256).getLocation().clone().add(0, 1, 0); + + 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); + + CommandIrisObjectUndo.addChanges(player(), 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))); + if (WandSVC.isWand(wand)) { + wand = newWand; + player().getInventory().setItemInMainHand(wand); + sender().sendMessage("Updated wand for " + "objects/" + object.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"); + } else { + player().getInventory().setItem(slot, newWand); + sender().sendMessage("Updated wand for " + "objects/" + object.getLoadKey() + ".iob"); + } + } + } else { + sender().sendMessage("Placed " + "objects/" + object.getLoadKey() + ".iob"); + } } - private double getMaxScale(IrisObject object){ - return Double.max(10 - object.getBlocks().size() / 10000d, 1); + public static IObjectPlacer createPlacer(World world, Map futureBlockChanges) { + + return new IObjectPlacer() { + @Override + public int getHighest(int x, int z, IrisData data) { + return world.getHighestBlockYAt(x, z); + } + + @Override + public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) { + return world.getHighestBlockYAt(x, z, ignoreFluid ? HeightMap.OCEAN_FLOOR : HeightMap.MOTION_BLOCKING); + } + + @Override + public void set(int x, int y, int z, BlockData d) { + Block block = world.getBlockAt(x, y, z); + + //Prevent blocks being set in or bellow bedrock + if (y <= world.getMinHeight() || block.getType() == Material.BEDROCK) return; + + futureBlockChanges.put(block, block.getBlockData()); + + block.setBlockData(d); + } + + @Override + public BlockData get(int x, int y, int z) { + return world.getBlockAt(x, y, z).getBlockData(); + } + + @Override + public boolean isPreventingDecay() { + return false; + } + + @Override + public boolean isSolid(int x, int y, int z) { + return world.getBlockAt(x, y, z).getType().isSolid(); + } + + @Override + public boolean isUnderwater(int x, int z) { + return false; + } + + @Override + public int getFluidHeight() { + return 63; + } + + @Override + public boolean isDebugSmartBore() { + return false; + } + + @Override + public void setTile(int xx, int yy, int zz, TileData tile) { + BlockState state = world.getBlockAt(xx, yy, zz).getState(); + tile.toBukkitTry(state); + state.update(); + } + }; } + }