mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Upgrade pregen command. PregenTask now takes width & height ins o radius
This commit is contained in:
parent
d9cd0257ba
commit
be3d7ef11d
@ -21,6 +21,7 @@ package com.volmit.iris.core.command;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.command.jigsaw.CommandIrisJigsaw;
|
||||
import com.volmit.iris.core.command.object.CommandIrisObject;
|
||||
import com.volmit.iris.core.command.pregen.CommandIrisPregen;
|
||||
import com.volmit.iris.core.command.studio.CommandIrisStudio;
|
||||
import com.volmit.iris.core.command.what.CommandIrisWhat;
|
||||
import com.volmit.iris.core.command.world.*;
|
||||
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.core.command.pregen;
|
||||
|
||||
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.Command;
|
||||
import com.volmit.iris.util.plugin.MortarCommand;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
|
||||
public class CommandIrisPregen extends MortarCommand {
|
||||
@Command
|
||||
private CommandIrisPregenCreate start;
|
||||
|
||||
@Command
|
||||
private CommandIrisPregenStop stop;
|
||||
|
||||
@Command
|
||||
private CommandIrisPregenToggle toggle;
|
||||
|
||||
public CommandIrisPregen() {
|
||||
super("pregen", "preg", "p");
|
||||
requiresPermission(Iris.perm);
|
||||
setCategory("Pregen");
|
||||
setDescription("Pregeneration Commands");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTabOptions(VolmitSender sender, String[] args, KList<String> list) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(VolmitSender sender, String[] args) {
|
||||
if (!IrisToolbelt.isIrisWorld(sender.player().getWorld())){
|
||||
sender.sendMessage("Pregen only works in Iris worlds!");
|
||||
}
|
||||
|
||||
sender.sendMessage("Iris Pregen Commands:");
|
||||
printHelp(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArgsUsage() {
|
||||
return "[subcommand]";
|
||||
}
|
||||
}
|
@ -0,0 +1,174 @@
|
||||
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;
|
||||
import com.volmit.iris.util.plugin.MortarCommand;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
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");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTabOptions(VolmitSender sender, String[] args, KList<String> list) {
|
||||
|
||||
list.add("5000");
|
||||
list.add("size=5000 world=IrisWorld x=500 z=-1000");
|
||||
list.add("5000 world=IrisWorld x=500 z=-1000");
|
||||
list.add("world=IrisWorld x=500 z=-1000");
|
||||
for (World w : Bukkit.getServer().getWorlds()) {
|
||||
list.add(w.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArgsUsage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(VolmitSender sender, String[] args) {
|
||||
|
||||
if (PregeneratorJob.getInstance() != null) {
|
||||
sender.sendMessage("Pregeneration task already ongoing. You can stop it with /ir p stop");
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = null;
|
||||
int width = -1;
|
||||
int height = -1;
|
||||
int x = 0;
|
||||
int z = 0;
|
||||
|
||||
KList<String> failed = new KList<>();
|
||||
for (String a : args) {
|
||||
if (a.contains("=")) {
|
||||
String pre = a.split("=")[0];
|
||||
String val = a.split("=")[1];
|
||||
if (pre.equals("world")){
|
||||
world = Bukkit.getWorld(val);
|
||||
} else if (!isVal(val)){
|
||||
sender.sendMessage("Parameters other than `world=<name>` require a number (+ c|chunk|r|region|k), given: '" + a + "' is invalid");
|
||||
} else {
|
||||
switch (pre) {
|
||||
case "width" -> width = getVal(val);
|
||||
case "height" -> height = getVal(val);
|
||||
case "radius" -> {
|
||||
width = getVal(val);
|
||||
height = getVal(val);
|
||||
}
|
||||
case "x" -> x = getVal(val);
|
||||
case "z" -> z = getVal(val);
|
||||
}
|
||||
}
|
||||
} else if (isVal(a)) {
|
||||
width = getVal(a);
|
||||
height = getVal(a);
|
||||
} else {
|
||||
failed.add(a);
|
||||
}
|
||||
}
|
||||
|
||||
if (width == -1 || height == -1){
|
||||
sender.sendMessage("Size not specified");
|
||||
sender.sendMessage(getArgsUsage());
|
||||
}
|
||||
|
||||
world = world == null ? sender.player().getWorld() : world;
|
||||
|
||||
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
|
||||
);
|
||||
|
||||
|
||||
if (pregenerate(world, width, height, x, z)){
|
||||
sender.sendMessage("Successfully started pregen");
|
||||
} else {
|
||||
sender.sendMessage("Failed to start pregen. Doublecheck your arguments!");
|
||||
}
|
||||
sender.sendMessage(details.array());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pregenerate a
|
||||
* @param world world with a
|
||||
* @param width and
|
||||
* @param height with center
|
||||
* @param x and
|
||||
* @param z coords
|
||||
* @return true if successful
|
||||
*/
|
||||
private boolean pregenerate(World world, int width, int height, int x, int z){
|
||||
try {
|
||||
IrisToolbelt.pregenerate(PregenTask
|
||||
.builder()
|
||||
.center(new Position2(x, z))
|
||||
.width(width >> 9 + 1)
|
||||
.height(height >> 9 + 1)
|
||||
.build(), world);
|
||||
} catch (Throwable e){
|
||||
Iris.reportError(e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getVal(String arg) {
|
||||
|
||||
if (arg.toLowerCase().endsWith("c") || arg.toLowerCase().endsWith("chunks")) {
|
||||
return Integer.parseInt(arg.toLowerCase().replaceAll("\\Qc\\E", "").replaceAll("\\Qchunks\\E", "")) * 16;
|
||||
}
|
||||
|
||||
if (arg.toLowerCase().endsWith("r") || arg.toLowerCase().endsWith("regions")) {
|
||||
return Integer.parseInt(arg.toLowerCase().replaceAll("\\Qr\\E", "").replaceAll("\\Qregions\\E", "")) * 512;
|
||||
}
|
||||
|
||||
if (arg.toLowerCase().endsWith("k")) {
|
||||
return Integer.parseInt(arg.toLowerCase().replaceAll("\\Qk\\E", "")) * 1000;
|
||||
}
|
||||
|
||||
return Integer.parseInt(arg.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the
|
||||
* @param arg argument
|
||||
* @return is valid -> true
|
||||
*/
|
||||
private boolean isVal(String arg) {
|
||||
try {
|
||||
Integer.parseInt(
|
||||
arg.toLowerCase()
|
||||
.replace("chunks", "")
|
||||
.replace("c", "")
|
||||
.replace("regions", "")
|
||||
.replace("r", "")
|
||||
.replace("k", "")
|
||||
);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
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;
|
||||
import com.volmit.iris.util.plugin.MortarCommand;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class CommandIrisPregenStop extends MortarCommand {
|
||||
|
||||
public CommandIrisPregenStop() {
|
||||
super("stop", "s", "x", "close");
|
||||
requiresPermission(Iris.perm);
|
||||
setCategory("Pregen");
|
||||
setDescription("Stop an ongoing pregeneration task");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(VolmitSender sender, String[] args) {
|
||||
if (PregeneratorJob.shutdownInstance()){
|
||||
sender.sendMessage("Stopped pregeneration task");
|
||||
} else {
|
||||
sender.sendMessage("No active pregeneration tasks to stop");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTabOptions(VolmitSender sender, String[] args, KList<String> list) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArgsUsage() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.volmit.iris.core.command.pregen;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.gui.PregeneratorJob;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.plugin.MortarCommand;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
|
||||
public class CommandIrisPregenToggle extends MortarCommand {
|
||||
|
||||
public CommandIrisPregenToggle() {
|
||||
super("toggle", "t", "pause", "continue", "p", "c");
|
||||
requiresPermission(Iris.perm);
|
||||
setCategory("Pregen");
|
||||
setDescription("Toggle an ongoing pregeneration task");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(VolmitSender sender, String[] args) {
|
||||
if (PregeneratorJob.pauseResume()){
|
||||
sender.sendMessage("Toggled pregeneration task, now: " + (PregeneratorJob.isPaused() ? "Paused" : "Running"));
|
||||
} else {
|
||||
sender.sendMessage("No active pregeneration tasks to toggle");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTabOptions(VolmitSender sender, String[] args, KList<String> list) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArgsUsage() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,185 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.core.command.world;
|
||||
|
||||
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;
|
||||
import com.volmit.iris.util.plugin.MortarCommand;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class CommandIrisPregen extends MortarCommand {
|
||||
public CommandIrisPregen() {
|
||||
super("pregen", "preg", "p");
|
||||
setDescription(
|
||||
"""
|
||||
Pregen this world with optional parameters:\s
|
||||
'1k' = 1000 * 2 by 1000 * 2 blocks, '1c' = 2 by 2 chunks, and '1r' = 64 by 64 chunks.
|
||||
If you are using the console or want to pregen a world you're not in:
|
||||
also specify the name of the world. E.g. /ir pregen 5k world"""
|
||||
);
|
||||
requiresPermission(Iris.perm.studio);
|
||||
setCategory("Pregen");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTabOptions(VolmitSender sender, String[] args, KList<String> list) {
|
||||
list.add("stop");
|
||||
list.add("pause");
|
||||
list.add("resume");
|
||||
list.add("500");
|
||||
list.add("1000");
|
||||
list.add("10k");
|
||||
list.add("25k");
|
||||
list.add("10c");
|
||||
list.add("25c");
|
||||
list.add("5r");
|
||||
list.add("10r");
|
||||
for (World w : Bukkit.getServer().getWorlds()) {
|
||||
list.add(w.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(VolmitSender sender, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage("/iris pregen <radius|stop|pause|resume>");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("stop") || args[0].equalsIgnoreCase("x")) {
|
||||
if (PregeneratorJob.shutdownInstance()) {
|
||||
sender.sendMessage("Stopped Pregen. Finishing last region file before shutting down...");
|
||||
} else {
|
||||
sender.sendMessage("No Active Pregens.");
|
||||
}
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("pause") || args[0].equalsIgnoreCase("resume")) {
|
||||
if (PregeneratorJob.getInstance() != null) {
|
||||
PregeneratorJob.pauseResume();
|
||||
|
||||
if (PregeneratorJob.isPaused()) {
|
||||
sender.sendMessage("Pregen Paused");
|
||||
} else {
|
||||
sender.sendMessage("Pregen Resumed");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("No Active Pregens");
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (sender.isPlayer()) {
|
||||
Player p = sender.player();
|
||||
World world;
|
||||
if (args.length != 2) {
|
||||
world = p.getWorld();
|
||||
} else {
|
||||
try {
|
||||
world = Bukkit.getWorld(args[1]);
|
||||
} catch (Exception e) {
|
||||
Iris.reportError(e);
|
||||
sender.sendMessage("Could not find specified world");
|
||||
sender.sendMessage("Please doublecheck your command. E.g. /ir pregen 5k world");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
try {
|
||||
IrisToolbelt.pregenerate(PregenTask
|
||||
.builder()
|
||||
.center(new Position2(0, 0))
|
||||
.radius(((getVal(args[0]) >> 4) >> 5) + 1)
|
||||
.build(), world);
|
||||
} catch (NumberFormatException e) {
|
||||
Iris.reportError(e);
|
||||
sender.sendMessage("Invalid argument in command");
|
||||
return true;
|
||||
} catch (NullPointerException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
sender.sendMessage("No radius specified (check error in console)");
|
||||
} catch (HeadlessException e) {
|
||||
Iris.reportError(e);
|
||||
sender.sendMessage("If you are seeing this and are using a hosted server, please turn off 'useServerLaunchedGUIs' in the settings");
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
if (args.length < 1) {
|
||||
sender.sendMessage("Please specify the radius of the pregen and the name of the world. E.g. /ir pregen 5k world");
|
||||
return true;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage("Please specify the name of the world after the command. E.g. /ir pregen 5k world");
|
||||
return true;
|
||||
}
|
||||
World world = Bukkit.getWorld(args[1]);
|
||||
try {
|
||||
new PregeneratorJob(PregenTask
|
||||
.builder()
|
||||
.center(new Position2(0, 0))
|
||||
.radius(((getVal(args[0]) >> 4) >> 5) + 1)
|
||||
.build(),
|
||||
new HybridPregenMethod(world, Runtime.getRuntime().availableProcessors()));
|
||||
} catch (NumberFormatException e) {
|
||||
Iris.reportError(e);
|
||||
sender.sendMessage("Invalid argument in command");
|
||||
return true;
|
||||
} catch (NullPointerException e) {
|
||||
Iris.reportError(e);
|
||||
sender.sendMessage("Not all required parameters specified");
|
||||
} catch (HeadlessException e) {
|
||||
Iris.reportError(e);
|
||||
sender.sendMessage("If you are seeing this and are using a hosted server, please turn off 'useServerLaunchedGUIs' in the settings");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private int getVal(String arg) {
|
||||
|
||||
if (arg.toLowerCase().endsWith("c") || arg.toLowerCase().endsWith("chunks")) {
|
||||
return Integer.parseInt(arg.toLowerCase().replaceAll("\\Qc\\E", "").replaceAll("\\Qchunks\\E", "")) * 16;
|
||||
}
|
||||
|
||||
if (arg.toLowerCase().endsWith("r") || arg.toLowerCase().endsWith("regions")) {
|
||||
return Integer.parseInt(arg.toLowerCase().replaceAll("\\Qr\\E", "").replaceAll("\\Qregions\\E", "")) * 512;
|
||||
}
|
||||
|
||||
if (arg.toLowerCase().endsWith("k")) {
|
||||
return Integer.parseInt(arg.toLowerCase().replaceAll("\\Qk\\E", "")) * 1000;
|
||||
}
|
||||
|
||||
return Integer.parseInt(arg.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArgsUsage() {
|
||||
return "[radius]";
|
||||
}
|
||||
}
|
@ -103,9 +103,9 @@ public class PregeneratorJob implements PregenListener {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void pauseResume() {
|
||||
public static boolean pauseResume() {
|
||||
if (instance == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isPaused()) {
|
||||
@ -113,6 +113,7 @@ public class PregeneratorJob implements PregenListener {
|
||||
} else {
|
||||
instance.pregenerator.pause();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isPaused() {
|
||||
|
@ -34,12 +34,15 @@ public class PregenTask {
|
||||
private Position2 center = new Position2(0, 0);
|
||||
|
||||
@Builder.Default
|
||||
private int radius = 1;
|
||||
private int width = 1;
|
||||
|
||||
@Builder.Default
|
||||
private int height = 1;
|
||||
|
||||
private static final KList<Position2> order = computeChunkOrder();
|
||||
|
||||
public void iterateRegions(Spiraled s) {
|
||||
new Spiraler(radius * 2, radius * 2, s)
|
||||
new Spiraler(getWidth() * 2, getHeight() * 2, s)
|
||||
.setOffset(center.getX(), center.getZ()).drain();
|
||||
}
|
||||
|
||||
@ -50,7 +53,7 @@ public class PregenTask {
|
||||
}
|
||||
|
||||
public void iterateAllChunks(Spiraled s) {
|
||||
new Spiraler(radius * 2, radius * 2, (x, z) -> iterateRegion(x, z, s))
|
||||
new Spiraler(getWidth() * 2, getHeight() * 2, (x, z) -> iterateRegion(x, z, s))
|
||||
.setOffset(center.getX(), center.getZ()).drain();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user