mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 10:43:14 +00:00
Fix console sender, add descriptions, add -here
This commit is contained in:
parent
26dee50e68
commit
705c5ce790
@ -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:");
|
||||
|
@ -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=<radius>] [width=<width>] [height=<height>] [x=<centerX>] [z=<centerZ>] [world=<world>] [-here]
|
||||
/iris pregen radius=5000 x=10r z=10r world=IrisWorld
|
||||
/iris pregen 5k -here
|
||||
|
||||
<radius>: Sets both width and height to a value.
|
||||
<x> & <z>: Give the center point of the pregeneration.
|
||||
<world>: 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 "<radius> [width=<width>] [height=<height>] [x=<centerX>] [z=<centerZ>] [world=<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<String> 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=<name>` 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=<name> 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<String> 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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user