diff --git a/src/main/java/com/volmit/iris/core/command/world/CommandIrisRegen.java b/src/main/java/com/volmit/iris/core/command/world/CommandIrisRegen.java deleted file mode 100644 index f90c6ac55..000000000 --- a/src/main/java/com/volmit/iris/core/command/world/CommandIrisRegen.java +++ /dev/null @@ -1,91 +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.util.collection.KList; -import com.volmit.iris.util.plugin.MortarCommand; -import com.volmit.iris.util.plugin.VolmitSender; - -public class CommandIrisRegen extends MortarCommand { - public CommandIrisRegen() { - super("regen"); - setDescription("Regenerate chunks around you (iris worlds only)"); - requiresPermission(Iris.perm.studio); - setCategory("Regen"); - } - - @Override - public void addTabOptions(VolmitSender sender, String[] args, KList list) { - - } - - @Override - public boolean handle(VolmitSender sender, String[] args) { - sender.sendMessage("Iris' /regen command is currently disabled due to maintenance. Apologies."); - return true; - /* This is commented yes - try - { - if(args.length == 0) - { - IrisWorlds.access(sender.player().getWorld()).regenerate( - sender.player().getLocation().getChunk().getX(), - sender.player().getLocation().getChunk().getZ()); - sender.sendMessage("Regenerated your current chunk"); - } - - else - { - try - { - int vx = sender.player().getLocation().getChunk().getX(); - int vz = sender.player().getLocation().getChunk().getZ(); - int rad = Integer.valueOf(args[0]); - int m = (int) Math.pow(rad, 2); - new Spiraler(rad, rad*2, (x,z) -> { - IrisWorlds.access(sender.player().getWorld()).regenerate( - vx + x, - vz + z); - }).drain(); - - sender.sendMessage("Regenerated " + m + " chunks"); - } - - catch(NumberFormatException e) - { - sender.sendMessage(args[0] + " is not a number."); - } - } - } - - catch(Throwable e1) - { - sender.sendMessage("You must be in a regen-capable iris world!"); - } - - return true; - */ - } - - @Override - protected String getArgsUsage() { - return "[size]"; - } -} 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 index e290b2428..e88d436d4 100644 --- a/src/main/java/com/volmit/iris/core/command/world/CommandLocate.java +++ b/src/main/java/com/volmit/iris/core/command/world/CommandLocate.java @@ -31,7 +31,6 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import java.util.Arrays; public class CommandLocate extends MortarCommand implements Listener { - final CommandLocate instance; @EventHandler public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) { @@ -52,7 +51,6 @@ public class CommandLocate extends MortarCommand implements Listener { public CommandLocate() { super("locate"); requiresPermission(Iris.perm); - this.instance = this; } @Override 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 9335c3eb5..2820c75bb 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -19,17 +19,147 @@ package com.volmit.iris.core.decrees; import com.volmit.iris.Iris; +import com.volmit.iris.core.IrisSettings; +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.annotations.Decree; import com.volmit.iris.util.decree.annotations.Param; +import com.volmit.iris.util.format.C; + +import java.io.File; @Decree(name = "irisd", aliases = {"ird"}, description = "Basic Command") public class DecIris implements DecreeExecutor { - private DecIrisStudio studio; + private DecStudio studio; + + private DecPregen pregen; + + 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", defaultValue = "IrisWorld") + String name, + @Param(aliases = "dimension", description = "The dimension type to create the world with", defaultValue = "overworld") + IrisDimension type, + @Param(description = "The seed to generate the world with", defaultValue = "1337") + long seed + ){ + if (name.equals("iris")) { + sender().sendMessage(C.RED + "You cannot use the world name \"iris\" for creating worlds as Iris uses this directory for studio worlds."); + sender().sendMessage(C.RED + "May we suggest the name \"IrisWorld\" instead?"); + return; + } + + if (new File(name).exists()){ + sender().sendMessage(C.RED + "That folder already exists!"); + return; + } + + try { + IrisToolbelt.createWorld() + .dimension(type.getLoadKey()) + .name(name) + .seed(seed) + .sender(sender()) + .studio(false) + .create(); + } catch (Throwable e){ + sender().sendMessage(C.RED + "Exception raised during creation. See the console for more details."); + Iris.error("Exception raised during world creation: " + e.getMessage()); + Iris.reportError(e); + return; + } + + sender().sendMessage(C.GREEN + "Successfully created your world!"); + } @Decree(description = "Print version information") public void version(){ sender().sendMessage("Iris v" + Iris.instance.getDescription().getVersion() + " by Volmit Software"); } + + @Decree(description = "Set aura spins") + public void aura( + @Param(description = "The h color value") + int h, + @Param(description = "The s color value") + int s, + @Param(description = "The b color value") + int b + ) { + IrisSettings.get().getGeneral().setSpinh(h); + IrisSettings.get().getGeneral().setSpins(s); + IrisSettings.get().getGeneral().setSpinb(b); + IrisSettings.get().forceSave(); + sender().sendMessage("Aura Spins updated to " + h + " " + s + " " + b); + } + + @Decree(description = "Bitwise calculations") + public void bitwise( + @Param(description = "The first value to run calculations on") + int value1, + @Param(description = "The operator: | & ^ >> << %") + String operator, + @Param(description = "The second value to run calculations on") + int value2 + ) { + Integer v = null; + switch(operator) { + case "|" -> v = value1 | value2; + case "&" -> v = value1 & value2; + case "^" -> v = value1 ^ value2; + case "%" -> v = value1 % value2; + case ">>" -> v = value1 >> value2; + case "<<" -> v = value1 << value2; + }; + if (v == null){ + sender().sendMessage(C.RED + "The operator you entered: (" + operator + ") is invalid!"); + return; + } + sender().sendMessage(C.GREEN + "" + value1 + " " + operator + " " + value2 + " => " + v); + } + + @Decree(description = "Toggle debug") + public void debug( + @Param(name = "on", description = "Whether or not debug should be on", defaultValue = "true") + boolean on + ) { + IrisSettings.get().getGeneral().setDebug(on); + } + + @Decree(description = "Download a project.") + public void download( + @Param(name = "pack", description = "The pack to download", defaultValue = "overworld", aliases = "project") + String pack, + @Param(name = "branch", description = "The branch to download from", defaultValue = "master") + String branch, + @Param(name = "trim", description = "Whether or not to download a trimmed version (do not enable when you're going to edit)") + boolean trim, + @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" : "")); + Iris.proj.downloadSearch(sender(), "IrisDimensions/" + pack + "/" + branch, trim, overwrite); + } + + @Decree(description = "Get metrics for your world", aliases = "measure", origin = DecreeOrigin.PLAYER) + public void metrics() { + if (!IrisToolbelt.isIrisWorld(world())){ + sender().sendMessage(C.RED + "You must be in an Iris world"); + return; + } + sender().sendMessage(C.GREEN + "Sending metrics..."); + engine().printMetrics(sender()); + } + + @Decree(description = "Reload configuration file (this is also done automatically)") + public void reload() { + IrisSettings.invalidate(); + IrisSettings.get(); + sender().sendMessage(C.GREEN + "Hotloaded settings"); + } } diff --git a/src/main/java/com/volmit/iris/core/decrees/DecPregen.java b/src/main/java/com/volmit/iris/core/decrees/DecPregen.java new file mode 100644 index 000000000..1a97ed063 --- /dev/null +++ b/src/main/java/com/volmit/iris/core/decrees/DecPregen.java @@ -0,0 +1,59 @@ +package com.volmit.iris.core.decrees; + +import com.volmit.iris.Iris; +import com.volmit.iris.core.gui.PregeneratorJob; +import com.volmit.iris.core.pregenerator.PregenTask; +import com.volmit.iris.core.tools.IrisToolbelt; +import com.volmit.iris.util.decree.DecreeExecutor; +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.Position2; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.util.Vector; + +@Decree(name = "pregen", aliases = "pregenerate", description = "Pregenerate your Iris worlds!") +public class DecPregen implements DecreeExecutor { + @Decree(description = "Pregenerate a world") + public void start( + @Param(description = "The world to pregen", contextual = true) + World world, + @Param(description = "The radius of the pregen in blocks", aliases = "size") + int radius, + @Param(aliases = "middle", description = "The center location of the pregen. Use \"me\" for your current location", defaultValue = "0,0") + Vector center + ) { + try { + IrisToolbelt.pregenerate(PregenTask + .builder() + .center(new Position2(center)) + .width((radius >> 9 + 1) * 2) + .height((radius >> 9 + 1) * 2) + .build(), world); + sender().sendMessage(C.GREEN + "Successfully started the pregeneration task!"); + } catch (Throwable e) { + sender().sendMessage(C.RED + "Epic fail"); + Iris.reportError(e); + e.printStackTrace(); + } + } + + @Decree(description = "Stop the active pregeneration task", aliases = "x") + public void stop(){ + if (PregeneratorJob.shutdownInstance()) { + sender().sendMessage(C.GREEN + "Stopped pregeneration task"); + } else { + sender().sendMessage(C.YELLOW + "No active pregeneration tasks to stop"); + } + } + + @Decree(description = "Pause / continue the active pregeneration task", aliases = {"t", "resume", "unpause"}) + public void pause() { + if (PregeneratorJob.pauseResume()) { + sender().sendMessage(C.GREEN + "Paused/unpaused pregeneration task, now: " + (PregeneratorJob.isPaused() ? "Paused" : "Running") + "."); + } else { + sender().sendMessage(C.YELLOW + "No active pregeneration tasks to pause/unpause."); + } + } +} diff --git a/src/main/java/com/volmit/iris/core/decrees/DecIrisStudio.java b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java similarity index 81% rename from src/main/java/com/volmit/iris/core/decrees/DecIrisStudio.java rename to src/main/java/com/volmit/iris/core/decrees/DecStudio.java index 514236ea3..b53006d20 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIrisStudio.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java @@ -76,12 +76,12 @@ import java.util.concurrent.ExecutionException; import java.util.function.Supplier; @Decree(name = "studio", aliases = {"std", "s"}, description = "Studio Commands", studio = true) -public class DecIrisStudio implements DecreeExecutor { +public class DecStudio implements DecreeExecutor { @Decree(description = "Open a new studio world", aliases = "o", sync = true) public void open( - @Param(name = "dimension", defaultValue = "overworld", description = "The dimension to open a studio for", aliases = "dim") + @Param(defaultValue = "overworld", description = "The dimension to open a studio for", aliases = "dim") IrisDimension dimension, - @Param(name = "seed", defaultValue = "1337", description = "The seed to generate the studio with", aliases = "s") + @Param(defaultValue = "1337", description = "The seed to generate the studio with", aliases = "s") long seed) { sender().sendMessage(C.GREEN + "Opening studio for the \"" + dimension.getName() + "\" pack (seed: " + seed + ")"); Iris.proj.open(sender(), seed, dimension.getLoadKey()); @@ -100,9 +100,9 @@ public class DecIrisStudio implements DecreeExecutor { @Decree(description = "Create a new studio project", aliases = "+", sync = true) public void create( - @Param(name = "name", description = "The name of this new Iris Project.") + @Param(description = "The name of this new Iris Project.") String name, - @Param(name = "template", description = "Copy the contents of an existing project in your packs folder and use it as a template in this new project.") + @Param(description = "Copy the contents of an existing project in your packs folder and use it as a template in this new project.", contextual = true) IrisDimension template) { if (template != null) { @@ -114,16 +114,16 @@ public class DecIrisStudio implements DecreeExecutor { @Decree(description = "Clean an Iris Project, optionally beautifying JSON & fixing block ids with missing keys. Also rebuilds the vscode schemas. ") public void clean( - @Param(name = "project", description = "The project to update") + @Param(description = "The project to update", contextual = true) IrisDimension project, - @Param(name = "beautify", defaultValue = "true", description = "Filters all valid JSON files with a beautifier (indentation: 4)") + @Param(defaultValue = "true", description = "Filters all valid JSON files with a beautifier (indentation: 4)") boolean beautify, @Param(name = "fix-ids", defaultValue = "true", description = "Fixes any block ids used such as \"dirt\" will be converted to \"minecraft:dirt\"") boolean fixIds, - @Param(name = "rewriteObjects", defaultValue = "false", description = "Imports all objects and re-writes them cleaning up positions & block data in the process.") + @Param(name = "rewrite-objects", defaultValue = "false", description = "Imports all objects and re-writes them cleaning up positions & block data in the process.") boolean rewriteObjects ) { KList jobs = new KList<>(); @@ -241,80 +241,38 @@ public class DecIrisStudio implements DecreeExecutor { new JobCollection("Cleaning", jobs).execute(sender()); } - public void files(File clean, KList files) - { - if (clean.isDirectory()) { - for (File i : clean.listFiles()) { - files(i, files); - } - } else if (clean.getName().endsWith(".json")) { - try { - files.add(clean); - } catch (Throwable e) { - Iris.reportError(e); - Iris.error("Failed to beautify " + clean.getAbsolutePath() + " You may have errors in your json!"); - } - } - } - - private void fixBlocks(JSONObject obj) { - for (String i : obj.keySet()) { - Object o = obj.get(i); - - if (i.equals("block") && o instanceof String && !o.toString().trim().isEmpty() && !o.toString().contains(":")) { - obj.put(i, "minecraft:" + o); - } - - if (o instanceof JSONObject) { - fixBlocks((JSONObject) o); - } else if (o instanceof JSONArray) { - fixBlocks((JSONArray) o); - } - } - } - - private void fixBlocks(JSONArray obj) { - for (int i = 0; i < obj.length(); i++) { - Object o = obj.get(i); - - if (o instanceof JSONObject) { - fixBlocks((JSONObject) o); - } else if (o instanceof JSONArray) { - fixBlocks((JSONArray) o); - } - } - } - - @Decree(description = "Get the version of a pack", aliases = {"v", "ver"}) + @Decree(description = "Get the version of a pack") public void version( - @Param(name = "dimension", defaultValue = "overworld", description = "The dimension get the version of", aliases = "dim") + @Param(defaultValue = "overworld", description = "The dimension get the version of", aliases = "dim", contextual = true) IrisDimension dimension ) { sender().sendMessage(C.GREEN + "The \"" + dimension.getName() + "\" pack has version: " + dimension.getVersion()); } - @Decree(description = "Convert objects in the \"convert\" folder", aliases = "conv") + @Decree(description = "Convert objects in the \"convert\" folder") public void convert() { Iris.convert.check(sender()); } - @Decree(description = "Edit the biome you're currently in", aliases = {"ebiome", "eb"}, origin = DecreeOrigin.PLAYER) - public void editbiome() { - + @Decree(description = "Edit the biome you are currently in", aliases = {"ebiome", "eb"}, origin = DecreeOrigin.PLAYER) + public void editbiome( + @Param(contextual = true, description = "The biome to edit") + IrisBiome biome + ) { if (noStudio()) return; try { - Desktop.getDesktop().open(Iris.proj.getActiveProject().getActiveProvider().getEngine().getBiome(sender().player().getLocation()).getLoadFile()); + Desktop.getDesktop().open(biome.getLoadFile()); } catch (Throwable e) { Iris.reportError(e); sender().sendMessage(C.RED + "Cant find the file. Unsure why this happened."); } } - @Decree(description = "Execute a script", aliases = {"ex", "exec", "run"}, origin = DecreeOrigin.PLAYER) + @Decree(description = "Execute a script", aliases = "run", origin = DecreeOrigin.PLAYER) public void execute( - @Param(name = "script", description = "The script to run", aliases = {"s", "scr"}) + @Param(description = "The script to run") IrisScript script ) { engine().getExecution().execute(script.getLoadKey()); @@ -327,12 +285,16 @@ public class DecIrisStudio implements DecreeExecutor { NoiseExplorerGUI.launch(); } + @Decree(description = "Charges all spawners in the area", aliases = "zzt", origin = DecreeOrigin.PLAYER) + public void charge() { + engine().getWorldManager().chargeEnergy(); + } @Decree(description = "Preview noise gens (External GUI)", aliases = {"generator", "gen"}) public void explore( - @Param(name = "generator", description = "The generator to explore", aliases = {"gen", "g"}) + @Param(description = "The generator to explore", contextual = true) IrisGenerator generator, - @Param(name = "seed", description = "The seed to generate with", aliases = "s", defaultValue = "12345") + @Param(description = "The seed to generate with", defaultValue = "12345") long seed ){ if (noGUI()) return; @@ -349,29 +311,11 @@ public class DecIrisStudio implements DecreeExecutor { NoiseExplorerGUI.launch(l, "Custom Generator"); } - @Decree(description = "Find any biome", aliases = {"goto", "g"}, origin = DecreeOrigin.PLAYER) + @Decree(description = "Find any biome or region", aliases = {"goto", "g"}, origin = DecreeOrigin.PLAYER) public void find( - @Param(name = "biome", description = "The biome to find", aliases = "b") - IrisBiome biome - ){ - if (!IrisToolbelt.isIrisWorld(world())){ - sender().sendMessage(C.RED + "You must be in an Iris world to use this command!"); - return; - } - - IrisPosition l = engine().lookForBiome(biome, 10000, (v) -> sender().sendMessage("Looking for " + C.BOLD + C.WHITE + biome.getName() + C.RESET + C.GRAY + ": Checked " + Form.f(v) + " Places")); - - if (l == null) { - sender().sendMessage(C.RED + "Couldn't find " + biome.getName() + "."); - } else { - sender().sendMessage(C.GREEN + "Found " + biome.getName() + "!"); - J.s(() -> player().teleport(l.toLocation(world()))); - } - } - - @Decree(description = "Find any region", aliases = {"goto", "g"}, origin = DecreeOrigin.PLAYER) - public void find( - @Param(name = "region", description = "The region to find", aliases = "r") + @Param(description = "The biome to find") + IrisBiome biome, + @Param(description = "The region to find") IrisRegion region ){ if (!IrisToolbelt.isIrisWorld(world())){ @@ -379,17 +323,40 @@ public class DecIrisStudio implements DecreeExecutor { return; } - IrisPosition l = engine().lookForRegion(region, 10000, (v) -> sender().sendMessage("Looking for " + C.BOLD + C.WHITE + region.getName() + C.RESET + C.GRAY + ": Checked " + Form.f(v) + " Places")); + if (biome == null && region == null){ + sender().sendMessage(C.RED + "You must specify a biome or region!"); + return; + } + + IrisPosition l = 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) { + 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) { + 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 + "Couldn't find " + region.getName() + "."); - } else { - sender().sendMessage(C.GREEN + "Found " + region.getName() + "!"); - J.s(() -> player().teleport(l.toLocation(world()))); + sender().sendMessage(C.RED + "Could not find the region and / or biome you specified."); + return; } + + final IrisPosition finalL = l; + J.s(() -> player().teleport(finalL.toLocation(world()))); } - @Decree(description = "Hotload a studio", aliases = {"hot", "h", "reload"}, origin = DecreeOrigin.PLAYER) + @Decree(description = "Hotload a studio", aliases = "reload", origin = DecreeOrigin.PLAYER) public void hotload() { if (noStudio()) return; @@ -398,9 +365,9 @@ public class DecIrisStudio implements DecreeExecutor { @Decree(description = "Show loot if a chest were right here", origin = DecreeOrigin.PLAYER, sync = true) public void loot( - @Param(name = "fast", aliases = "f", description = "Fast insertion of items in virtual inventory (may cause performance drop)", defaultValue = "false") + @Param(description = "Fast insertion of items in virtual inventory (may cause performance drop)", defaultValue = "false") boolean fast, - @Param(name = "add", aliases = "a", description = "Whether or not to append to the inventory currently open (if false, clears opened inventory)", defaultValue = "true") + @Param(description = "Whether or not to append to the inventory currently open (if false, clears opened inventory)", defaultValue = "true") boolean add ) { if (noStudio()) return; @@ -452,19 +419,19 @@ public class DecIrisStudio implements DecreeExecutor { @Decree(description = "Package a dimension into a compressed format", aliases = "package") public void pkg( - @Param(name = "dimension", aliases = {"d", "dim"}, description = "The dimension pack to compress") + @Param(name = "dimension", description = "The dimension pack to compress", contextual = true) IrisDimension dimension, - @Param(name = "obfuscate", aliases = "o", description = "Whether or not to obfuscate the pack", defaultValue = "false") + @Param(name = "obfuscate", description = "Whether or not to obfuscate the pack", defaultValue = "false") boolean obfuscate, - @Param(name = "minify", aliases = "m", description = "Whether or not to minify the pack", defaultValue = "true") + @Param(name = "minify", description = "Whether or not to minify the pack", defaultValue = "true") boolean minify ){ Iris.proj.compilePackage(sender(), dimension.getLoadKey(), obfuscate, minify); } - @Decree(description = "Profiles a dimension's performance", origin = DecreeOrigin.PLAYER) + @Decree(description = "Profiles the performance of a dimension", origin = DecreeOrigin.PLAYER) public void profile( - @Param(name = "dimension", aliases = {"d", "dim"}, description = "The dimension to profile") + @Param(description = "The dimension to profile", contextual = true) IrisDimension dimension ){ File pack = dimension.getLoadFile().getParentFile().getParentFile(); @@ -652,24 +619,29 @@ public class DecIrisStudio implements DecreeExecutor { @Decree(description = "Summon an Iris Entity", origin = DecreeOrigin.PLAYER) public void summon( - @Param(description = "The Iris Entity to spawn", aliases = "e", name = "entity") + @Param(description = "The Iris Entity to spawn") IrisEntity entity ) { - if (noStudio()){ + if (!sender().isPlayer()){ + sender().sendMessage(C.RED + "Players only (this is a config error. Ask support to add DecreeOrigin.PLAYER to the command you tried to run)"); + return; + } + if (IrisToolbelt.isIrisWorld(world())){ + sender().sendMessage(C.RED + "You can only spawn entities in Iris worlds!"); return; } sender().sendMessage(C.GREEN + "Spawning entity"); entity.spawn(engine(), player().getLocation().clone().add(0, 2, 0)); } - @Decree(description = "Teleport to the active studio world", aliases = {"tps", "stp", "tp"}, origin = DecreeOrigin.PLAYER) + @Decree(description = "Teleport to the active studio world", aliases = "stp", origin = DecreeOrigin.PLAYER, sync = true) public void tpstudio(){ if (!Iris.proj.isProjectOpen()){ sender().sendMessage(C.RED + "No studio world is open!"); return; } - if (engine().isStudio()){ + if (IrisToolbelt.isIrisWorld(world()) && engine().isStudio()){ sender().sendMessage(C.RED + "You are already in a studio world!"); return; } @@ -679,9 +651,9 @@ public class DecIrisStudio implements DecreeExecutor { player().setGameMode(GameMode.SPECTATOR); } - @Decree(description = "Update your dimension project", aliases = {"upd", "u"}) + @Decree(description = "Update your dimension project") public void update( - @Param(name = "dimension", aliases = {"d", "dim"}, description = "The dimension to update the workspace of") + @Param(description = "The dimension to update the workspace of", contextual = true) IrisDimension dimension ){ if (new IrisProject(dimension.getLoadFile().getParentFile().getParentFile()).updateWorkspace()) { @@ -691,7 +663,6 @@ public class DecIrisStudio implements DecreeExecutor { } } - /** * @return true if server GUIs are not enabled */ @@ -721,4 +692,50 @@ public class DecIrisStudio implements DecreeExecutor { } return false; } + + + + public void files(File clean, KList files) + { + if (clean.isDirectory()) { + for (File i : clean.listFiles()) { + files(i, files); + } + } else if (clean.getName().endsWith(".json")) { + try { + files.add(clean); + } catch (Throwable e) { + Iris.reportError(e); + Iris.error("Failed to beautify " + clean.getAbsolutePath() + " You may have errors in your json!"); + } + } + } + + private void fixBlocks(JSONObject obj) { + for (String i : obj.keySet()) { + Object o = obj.get(i); + + if (i.equals("block") && o instanceof String && !o.toString().trim().isEmpty() && !o.toString().contains(":")) { + obj.put(i, "minecraft:" + o); + } + + if (o instanceof JSONObject) { + fixBlocks((JSONObject) o); + } else if (o instanceof JSONArray) { + fixBlocks((JSONArray) o); + } + } + } + + private void fixBlocks(JSONArray obj) { + for (int i = 0; i < obj.length(); i++) { + Object o = obj.get(i); + + if (o instanceof JSONObject) { + fixBlocks((JSONObject) o); + } else if (o instanceof JSONArray) { + fixBlocks((JSONArray) o); + } + } + } } 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..50e5815e8 --- /dev/null +++ b/src/main/java/com/volmit/iris/core/decrees/DecWhat.java @@ -0,0 +1,59 @@ +package com.volmit.iris.core.decrees; + +import com.volmit.iris.Iris; +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 org.bukkit.FluidCollisionMode; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; + +@Decree(name = "what", aliases = "?", description = "Get information about the world around you", origin = DecreeOrigin.PLAYER) +public class DecWhat implements DecreeExecutor { + + @Decree(description = "Get information about the block you're looking at") + public void block(){ + + Block b = player().getTargetBlockExact(128, FluidCollisionMode.NEVER); + + if (b == null) { + sender().sendMessage("Please look at any block, not at the sky"); + return; + } + + BlockData bd = b.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"); + } + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/context/GeneratorContextHandler.java b/src/main/java/com/volmit/iris/util/decree/context/GeneratorContextHandler.java new file mode 100644 index 000000000..0e23c0f62 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/context/GeneratorContextHandler.java @@ -0,0 +1,27 @@ +package com.volmit.iris.util.decree.context; + +import com.volmit.iris.core.tools.IrisToolbelt; +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.object.noise.IrisGenerator; +import com.volmit.iris.util.decree.DecreeContextHandler; +import com.volmit.iris.util.plugin.VolmitSender; + +public class GeneratorContextHandler implements DecreeContextHandler { + @Override + public Class getType() { + return IrisGenerator.class; + } + + @Override + public IrisGenerator handle(VolmitSender sender) { + if(sender.isPlayer() + && IrisToolbelt.isIrisWorld(sender.player().getWorld()) + && IrisToolbelt.access(sender.player().getWorld()).getEngine() != null) + { + Engine engine = IrisToolbelt.access(sender.player().getWorld()).getEngine(); + return engine.getData().getGeneratorLoader().load(engine.getBiome(sender.player().getLocation()).getGenerators().getRandom().getGenerator()); + } + + return null; + } +} diff --git a/src/main/java/com/volmit/iris/util/math/Position2.java b/src/main/java/com/volmit/iris/util/math/Position2.java index c1cc093dc..560a254df 100644 --- a/src/main/java/com/volmit/iris/util/math/Position2.java +++ b/src/main/java/com/volmit/iris/util/math/Position2.java @@ -19,6 +19,7 @@ package com.volmit.iris.util.math; import com.volmit.iris.engine.object.basic.IrisPosition; +import org.bukkit.util.Vector; public class Position2 { private int x; @@ -29,6 +30,11 @@ public class Position2 { this.z = z; } + public Position2(Vector center) { + this.x = center.getBlockX(); + this.z = center.getBlockZ(); + } + public int getX() { return x; }