From 705c5ce79073c3050bd5f535e3db9ad3bfbdc7ce Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Fri, 6 Aug 2021 22:20:18 +0200 Subject: [PATCH] Fix console sender, add descriptions, add -here --- .../command/pregen/CommandIrisPregen.java | 8 +- .../pregen/CommandIrisPregenCreate.java | 76 +++++++++++++++---- 2 files changed, 66 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregen.java b/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregen.java index ce8e818ff..5b2b4aaed 100644 --- a/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregen.java +++ b/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregen.java @@ -49,8 +49,12 @@ public class CommandIrisPregen extends MortarCommand { @Override public boolean handle(VolmitSender sender, String[] args) { - if (!IrisToolbelt.isIrisWorld(sender.player().getWorld())){ - sender.sendMessage("Pregen only works in Iris worlds!"); + if (sender.isPlayer()) { + if (!IrisToolbelt.isIrisWorld(sender.player().getWorld())) { + sender.sendMessage("Pregen only works in Iris worlds!"); + } + } else { + sender.sendMessage("Note that pregeneration only works in Iris worlds!"); } sender.sendMessage("Iris Pregen Commands:"); diff --git a/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenCreate.java b/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenCreate.java index 24357970b..53f7f682d 100644 --- a/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenCreate.java +++ b/src/main/java/com/volmit/iris/core/command/pregen/CommandIrisPregenCreate.java @@ -3,7 +3,6 @@ package com.volmit.iris.core.command.pregen; import com.volmit.iris.Iris; import com.volmit.iris.core.gui.PregeneratorJob; import com.volmit.iris.core.pregenerator.PregenTask; -import com.volmit.iris.core.pregenerator.methods.HybridPregenMethod; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.Position2; @@ -13,15 +12,28 @@ import org.bukkit.Bukkit; import org.bukkit.World; import org.checkerframework.checker.units.qual.K; -import java.util.Arrays; - public class CommandIrisPregenCreate extends MortarCommand { public CommandIrisPregenCreate() { super("create", "c", "new", "+"); requiresPermission(Iris.perm); setCategory("Pregen"); - setDescription("Create a new pregeneration task"); + setDescription(""" + Create a new pregeneration task. + Command usage & examples: + /iris pregen [radius=] [width=] [height=] [x=] [z=] [world=] [-here] + /iris pregen radius=5000 x=10r z=10r world=IrisWorld + /iris pregen 5k -here + + : Sets both width and height to a value. + & : Give the center point of the pregeneration. + : Specify a specific world name for generation as well (required for console) + -here: If added, the center location is set to your position (player only) + + For all numeric values (radius, centerX, etc.) you may use: + c => 16, r => 512, k => 1000 + Example: entering '1000' is the same as '1k' (1 * 1000) + https://docs.volmit.com/iris/pregeneration"""); } @Override @@ -38,7 +50,7 @@ public class CommandIrisPregenCreate extends MortarCommand { @Override protected String getArgsUsage() { - return null; + return " [width=] [height=] [x=] [z=] [world=] [-here]"; } @Override @@ -54,16 +66,26 @@ public class CommandIrisPregenCreate extends MortarCommand { int height = -1; int x = 0; int z = 0; + boolean here = false; KList failed = new KList<>(); for (String a : args) { - if (a.contains("=")) { + if (a.equals("-here")){ + here = true; + } else if (a.contains("=")) { String pre = a.split("=")[0]; String val = a.split("=")[1]; if (pre.equals("world")){ world = Bukkit.getWorld(val); + if (world == null){ + failed.add(a + " (invalid world)"); + sender.sendMessage("Entered world is " + val + ", but that world does not exist."); + sender.sendMessage("Cancelling the command."); + sender.sendMessage(getDescription()); + return true; + } } else if (!isVal(val)){ - sender.sendMessage("Parameters other than `world=` require a number (+ c|chunk|r|region|k), given: '" + a + "' is invalid"); + failed.add(a + " (non-value)"); } else { switch (pre) { case "width" -> width = getVal(val); @@ -74,31 +96,52 @@ public class CommandIrisPregenCreate extends MortarCommand { } case "x" -> x = getVal(val); case "z" -> z = getVal(val); + default -> failed.add(a + " (no type)"); } } } else if (isVal(a)) { width = getVal(a); height = getVal(a); } else { - failed.add(a); + failed.add(a + " (nothing)"); } } if (width == -1 || height == -1){ - sender.sendMessage("Size not specified"); - sender.sendMessage(getArgsUsage()); + sender.sendMessage("Radius or (width & height) not specified. Cancelling..."); + sender.sendMessage(getDescription()); + return true; } - world = world == null ? sender.player().getWorld() : world; + if (world == null){ + if (sender.isPlayer()){ + world = sender.player().getWorld(); + } else { + sender.sendMessage("Must specify world= if sending from console! Cancelling..."); + sender.sendMessage(getDescription()); + return true; + } + } + + if (here){ + if (sender.isPlayer()) { + x = sender.player().getLocation().getBlockX(); + z = sender.player().getLocation().getBlockZ(); + } else { + sender.sendMessage("Specifying -here does not work from console!"); + } + } KList details = new KList<>( "Pregeneration details:", - " - World > " + world.getName(), - " - Width/Height > " + width + "/" + height, - " - Center x,z > " + x + "," + z, - failed.isEmpty() ? "(No failed arguments)" : "FAILED ARGS: " + failed + " - World > " + world.getName(), + " - Width/Height > " + width + "/" + height, + " - Center x,z > " + x + "," + z, + failed.isEmpty() ? "(No failed arguments)" : "FAILED ARGS:" + ); + failed.forEach(s -> + details.add(" - " + s) ); - if (pregenerate(world, width, height, x, z)){ sender.sendMessage("Successfully started pregen"); @@ -129,6 +172,7 @@ public class CommandIrisPregenCreate extends MortarCommand { .build(), world); } catch (Throwable e){ Iris.reportError(e); + e.printStackTrace(); return false; } return true;