Add better control over expression timeouts. (#451)

Add better control over expression timeouts.
* //timeout command can be used to change player's current timeout.
* Config now also has a max timeout, can be bypassed with permission
* Timeout of < 0 will let expressions run indefinitely.
* Said expressions won't run on a separate thread, slightly reducing the
  overhead from context switching. For large //gen commands, for example,
  this can actually increase speed.
This commit is contained in:
wizjany
2019-03-06 19:58:32 -05:00
committed by GitHub
parent f84f3c6f85
commit de08c8b8c7
21 changed files with 301 additions and 76 deletions

View File

@ -57,9 +57,9 @@ public class GeneralCommands {
@Command(
aliases = { "/limit" },
usage = "<limit>",
usage = "[limit]",
desc = "Modify block change limit",
min = 1,
min = 0,
max = 1
)
@CommandPermissions("worldedit.limit")
@ -68,7 +68,7 @@ public class GeneralCommands {
LocalConfiguration config = worldEdit.getConfiguration();
boolean mayDisable = player.hasPermission("worldedit.limit.unrestricted");
int limit = Math.max(-1, args.getInteger(0));
int limit = args.argsLength() == 0 ? config.defaultChangeLimit : Math.max(-1, args.getInteger(0));
if (!mayDisable && config.maxChangeLimit > -1) {
if (limit > config.maxChangeLimit) {
player.printError("Your maximum allowable limit is " + config.maxChangeLimit + ".");
@ -78,13 +78,43 @@ public class GeneralCommands {
session.setBlockChangeLimit(limit);
if (limit != -1) {
player.print("Block change limit set to " + limit + ". (Use //limit -1 to go back to the default.)");
if (limit != config.defaultChangeLimit) {
player.print("Block change limit set to " + limit + ". (Use //limit to go back to the default.)");
} else {
player.print("Block change limit set to " + limit + ".");
}
}
@Command(
aliases = { "/timeout" },
usage = "[time]",
desc = "Modify evaluation timeout time.",
min = 0,
max = 1
)
@CommandPermissions("worldedit.timeout")
public void timeout(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
LocalConfiguration config = worldEdit.getConfiguration();
boolean mayDisable = player.hasPermission("worldedit.timeout.unrestricted");
int limit = args.argsLength() == 0 ? config.calculationTimeout : Math.max(-1, args.getInteger(0));
if (!mayDisable && config.maxCalculationTimeout > -1) {
if (limit > config.maxCalculationTimeout) {
player.printError("Your maximum allowable timeout is " + config.maxCalculationTimeout + " ms.");
return;
}
}
session.setTimeout(limit);
if (limit != config.calculationTimeout) {
player.print("Timeout time set to " + limit + " ms. (Use //timeout to go back to the default.)");
} else {
player.print("Timeout time set to " + limit + " ms.");
}
}
@Command(
aliases = { "/fast" },
usage = "[on|off]",