Allow console to execute commands now that editsessions etc. accept actors

- Fixes #724
 - Fixes #1044
This commit is contained in:
dordsor21
2021-09-28 15:59:52 +01:00
parent fa2f50dea8
commit 0ed98729f8
10 changed files with 104 additions and 122 deletions

View File

@ -328,17 +328,17 @@ public class ClipboardCommands {
@Deprecated
@CommandPermissions({"worldedit.clipboard.download"})
public void download(
final Player player,
final Actor actor,
final LocalSession session,
@Arg(name = "format", desc = "String", def = "fast") final String formatName
) throws WorldEditException {
final ClipboardFormat format = ClipboardFormats.findByAlias(formatName);
if (format == null) {
player.print(Caption.of("fawe.worldedit.clipboard.clipboard.invalid.format", formatName));
actor.print(Caption.of("fawe.worldedit.clipboard.clipboard.invalid.format", formatName));
return;
}
player.print(Caption.of("fawe.web.generating.link", formatName));
actor.print(Caption.of("fawe.web.generating.link", formatName));
ClipboardHolder holder = session.getClipboard();
URL url;
@ -388,7 +388,7 @@ public class ClipboardCommands {
// If we have a transform, bake it into the copy
if (!transform.isIdentity()) {
final FlattenedClipboardTransform result = FlattenedClipboardTransform.transform(clipboard, transform);
target = new BlockArrayClipboard(result.getTransformedRegion(), player.getUniqueId());
target = new BlockArrayClipboard(result.getTransformedRegion(), actor.getUniqueId());
target.setOrigin(clipboard.getOrigin());
Operations.completeLegacy(result.copyTo(target));
} else {
@ -407,17 +407,17 @@ public class ClipboardCommands {
}
} else {
if (Settings.IMP.WEB.URL.isEmpty()) {
player.print(Caption.of("fawe.error.setting.disable", "web.url"));
actor.print(Caption.of("fawe.error.setting.disable", "web.url"));
return;
}
url = FaweAPI.upload(target, format);
}
}
if (url == null) {
player.print(Caption.of("fawe.web.generating.link.failed"));
actor.print(Caption.of("fawe.web.generating.link.failed"));
} else {
String urlText = url.toString();
player.print(Caption.of("fawe.web.download.link", urlText).clickEvent(ClickEvent.openUrl(urlText)));
actor.print(Caption.of("fawe.web.download.link", urlText).clickEvent(ClickEvent.openUrl(urlText)));
}
}

View File

@ -460,7 +460,7 @@ public class GeneralCommands {
)
@CommandPermissions("worldedit.global-texture")
public void gtexture(
Player player,
Actor actor,
World worldArg,
LocalSession session,
EditSession editSession,
@ -470,7 +470,7 @@ public class GeneralCommands {
// TODO NOT IMPLEMENTED convert this to an ArgumentConverter
if (arguments.isEmpty()) {
session.setTextureUtil(null);
player.print(Caption.of("fawe.worldedit.general.texture.disabled"));
actor.print(Caption.of("fawe.worldedit.general.texture.disabled"));
} else {
String arg = arguments.get(0);
String argLower = arg.toLowerCase(Locale.ROOT);
@ -503,7 +503,7 @@ public class GeneralCommands {
util = Fawe.get().getTextureUtil();
} else {
ParserContext parserContext = new ParserContext();
parserContext.setActor(player);
parserContext.setActor(actor);
parserContext.setWorld(worldArg);
parserContext.setSession(session);
parserContext.setExtent(editSession);
@ -523,7 +523,7 @@ public class GeneralCommands {
util = new CachedTextureUtil(util);
}
session.setTextureUtil(util);
player.print(Caption.of("fawe.worldedit.general.texture.set", StringMan.join(arguments, " ")));
actor.print(Caption.of("fawe.worldedit.general.texture.set", StringMan.join(arguments, " ")));
}
}
@ -535,16 +535,16 @@ public class GeneralCommands {
)
@CommandPermissions({"worldedit.global-mask", "worldedit.mask.global"})
public void gsmask(
Player player,
Actor actor,
LocalSession session,
EditSession editSession,
@Arg(desc = "The mask to set", def = "") Mask maskOpt
) throws WorldEditException {
session.setSourceMask(maskOpt);
if (maskOpt == null) {
player.print(Caption.of("fawe.worldedit.general.source.mask.disabled"));
actor.print(Caption.of("fawe.worldedit.general.source.mask.disabled"));
} else {
player.print(Caption.of("fawe.worldedit.general.source.mask"));
actor.print(Caption.of("fawe.worldedit.general.source.mask"));
}
}
@ -555,16 +555,16 @@ public class GeneralCommands {
)
@CommandPermissions({"worldedit.global-transform", "worldedit.transform.global"})
public void gtransform(
Player player,
Actor actor,
EditSession editSession,
LocalSession session,
@Arg(desc = "The transform to set", def = "") ResettableExtent transform
) throws WorldEditException {
session.setTransform(transform);
if (transform == null) {
player.print(Caption.of("fawe.worldedit.general.transform.disabled"));
actor.print(Caption.of("fawe.worldedit.general.transform.disabled"));
} else {
player.print(Caption.of("fawe.worldedit.general.transform"));
actor.print(Caption.of("fawe.worldedit.general.transform"));
}
}
@ -574,11 +574,11 @@ public class GeneralCommands {
desc = "Toggle FAWE tips"
)
@CommandPermissions("fawe.tips")
public void tips(Player player, LocalSession session) throws WorldEditException {
if (player.togglePermission("fawe.tips")) {
player.print(Caption.of("fawe.info.worldedit.toggle.tips.on"));
public void tips(Actor actor, LocalSession session) throws WorldEditException {
if (actor.togglePermission("fawe.tips")) {
actor.print(Caption.of("fawe.info.worldedit.toggle.tips.on"));
} else {
player.print(Caption.of("fawe.info.worldedit.toggle.tips.off"));
actor.print(Caption.of("fawe.info.worldedit.toggle.tips.off"));
}
}

View File

@ -140,10 +140,10 @@ public class RegionCommands {
@CommandPermissions("worldedit.region.test")
@Logging(REGION)
public void test(
Player player, EditSession editSession,
Actor actor, EditSession editSession,
@Arg(desc = "test") double testValue
) throws WorldEditException {
player.print(TextComponent.of(testValue));
actor.print(TextComponent.of(testValue));
}
@Command(
@ -151,19 +151,9 @@ public class RegionCommands {
desc = "Get the light at a position"
)
@CommandPermissions("worldedit.light.fix")
public void fixLighting(Player player) throws WorldEditException {
final Location loc = player.getLocation();
Region selection = player.getSelection();
if (selection == null) {
final int cx = loc.getBlockX() >> 4;
final int cz = loc.getBlockZ() >> 4;
selection = new CuboidRegion(
BlockVector3.at(cx - 8, 0, cz - 8).multiply(16),
BlockVector3.at(cx + 8, 0, cz + 8).multiply(16)
);
}
int count = FaweAPI.fixLighting(player.getWorld(), selection, null, RelightMode.ALL);
player.print(Caption.of("fawe.info.lighting.propagate.selection", count));
public void fixLighting(Actor actor, LocalSession session, @Selection Region selection) throws WorldEditException {
int count = FaweAPI.fixLighting(session.getSelectionWorld(), selection, null, RelightMode.ALL);
actor.print(Caption.of("fawe.info.lighting.propagate.selection", count));
}
// @Command(
@ -184,18 +174,9 @@ public class RegionCommands {
desc = "Removing lighting in a selection"
)
@CommandPermissions("worldedit.light.remove")
public void removeLighting(Player player) {
Region selection = player.getSelection();
if (selection == null) {
final int cx = player.getLocation().getBlockX() >> 4;
final int cz = player.getLocation().getBlockZ() >> 4;
selection = new CuboidRegion(
BlockVector3.at(cx - 8, 0, cz - 8).multiply(16),
BlockVector3.at(cx + 8, 0, cz + 8).multiply(16)
);
}
int count = FaweAPI.fixLighting(player.getWorld(), selection, null, RelightMode.NONE);
player.print(Caption.of("fawe.info.updated.lighting.selection", count));
public void removeLighting(Actor actor, LocalSession session, @Selection Region selection) {
int count = FaweAPI.fixLighting(session.getSelectionWorld(), selection, null, RelightMode.NONE);
actor.print(Caption.of("fawe.info.updated.lighting.selection", count));
}
@Command(
@ -224,8 +205,8 @@ public class RegionCommands {
desc = "Set block lighting in a selection"
)
@CommandPermissions("worldedit.light.set")
public void setlighting(Player player, EditSession editSession, @Selection Region region) {
player.print(Caption.of("fawe.info.temporarily-not-working"));
public void setlighting(Actor actor, EditSession editSession, @Selection Region region) {
actor.print(Caption.of("fawe.info.temporarily-not-working"));
}
@Command(
@ -233,8 +214,8 @@ public class RegionCommands {
desc = "Set sky lighting in a selection"
)
@CommandPermissions("worldedit.light.set")
public void setskylighting(Player player, @Selection Region region) {
player.print(Caption.of("fawe.info.temporarily-not-working"));
public void setskylighting(Actor actor, @Selection Region region) {
actor.print(Caption.of("fawe.info.temporarily-not-working"));
}
@Command(
@ -355,7 +336,7 @@ public class RegionCommands {
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public void lay(
Player player,
Actor actor,
EditSession editSession,
@Selection Region region,
@Arg(name = "pattern", desc = "The pattern of blocks to lay") Pattern patternArg
@ -380,7 +361,7 @@ public class RegionCommands {
editSession.setBlock(x, y, z, patternArg);
affected++;
}
player.print(Caption.of("fawe.worldedit.visitor.visitor.block", affected));
actor.print(Caption.of("fawe.worldedit.visitor.visitor.block", affected));
}
@Command(
@ -619,7 +600,7 @@ public class RegionCommands {
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public void fall(
Player player, EditSession editSession, LocalSession session,
Actor actor, EditSession editSession,
@Selection Region region,
@Arg(desc = "BlockStateHolder", def = "air")
BlockStateHolder replace,
@ -627,7 +608,7 @@ public class RegionCommands {
boolean notFullHeight
) throws WorldEditException {
int affected = editSession.fall(region, !notFullHeight, replace);
player.print(Caption.of("fawe.worldedit.visitor.visitor.block", affected));
actor.print(Caption.of("fawe.worldedit.visitor.visitor.block", affected));
}
@Command(

View File

@ -148,7 +148,7 @@ public class SchematicCommands {
@Deprecated
@CommandPermissions({"worldedit.clipboard.load", "worldedit.schematic.load", "worldedit.schematic.load.web", "worldedit.schematic.load.asset"})
public void loadall(
Player player, LocalSession session,
Actor actor, LocalSession session,
@Arg(desc = "Format name.", def = "fast")
String formatName,
@Arg(desc = "File name.")
@ -160,18 +160,18 @@ public class SchematicCommands {
) throws FilenameException {
final ClipboardFormat format = ClipboardFormats.findByAlias(formatName);
if (format == null) {
player.print(Caption.of("fawe.worldedit.clipboard.clipboard.invalid.format", formatName));
actor.print(Caption.of("fawe.worldedit.clipboard.clipboard.invalid.format", formatName));
return;
}
try {
MultiClipboardHolder all = ClipboardFormats.loadAllFromInput(player, filename, null, true);
MultiClipboardHolder all = ClipboardFormats.loadAllFromInput(actor, filename, null, true);
if (all != null) {
if (overwrite) {
session.setClipboard(all);
} else {
session.addClipboard(all);
}
player.print(Caption.of("fawe.worldedit.schematic.schematic.loaded", filename));
actor.print(Caption.of("fawe.worldedit.schematic.schematic.loaded", filename));
}
} catch (IOException e) {
throw new RuntimeException(e);
@ -183,9 +183,9 @@ public class SchematicCommands {
desc = "Clear your clipboard"
)
@CommandPermissions({"worldedit.clipboard.clear", "worldedit.schematic.clear"})
public void clear(Player player, LocalSession session) throws WorldEditException {
public void clear(Actor actor, LocalSession session) throws WorldEditException {
session.setClipboard(null);
player.print(Caption.of("fawe.worldedit.clipboard.clipboard.cleared"));
actor.print(Caption.of("fawe.worldedit.clipboard.clipboard.cleared"));
}
@Command(
@ -194,7 +194,7 @@ public class SchematicCommands {
)
@CommandPermissions({"worldedit.clipboard.clear", "worldedit.schematic.clear"})
public void unload(
Player player, LocalSession session,
Actor actor, LocalSession session,
@Arg(desc = "File name, requires extension.")
String fileName
) throws WorldEditException {
@ -204,7 +204,7 @@ public class SchematicCommands {
} else {
final LocalConfiguration config = this.worldEdit.getConfiguration();
File working = this.worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
File root = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(working, player.getUniqueId().toString()) : working;
File root = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(working, actor.getUniqueId().toString()) : working;
uri = new File(root, fileName).toURI();
}
@ -221,11 +221,11 @@ public class SchematicCommands {
} else {
session.setClipboard(null);
}
player.print(Caption.of("fawe.worldedit.clipboard.clipboard.cleared"));
actor.print(Caption.of("fawe.worldedit.clipboard.clipboard.cleared"));
return;
}
}
player.print(Caption.of("fawe.worldedit.clipboard.clipboard.uri.not.found", fileName));
actor.print(Caption.of("fawe.worldedit.clipboard.clipboard.uri.not.found", fileName));
}
//FAWE start
@ -235,42 +235,42 @@ public class SchematicCommands {
desc = "Move your loaded schematic"
)
@CommandPermissions({"worldedit.schematic.move", "worldedit.schematic.move.other"})
public void move(Player player, LocalSession session, @Arg(desc = "Directory.") String directory) throws WorldEditException,
public void move(Actor actor, LocalSession session, @Arg(desc = "Directory.") String directory) throws WorldEditException,
IOException {
LocalConfiguration config = worldEdit.getConfiguration();
File working = worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
File dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(working, player.getUniqueId().toString()) : working;
File dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(working, actor.getUniqueId().toString()) : working;
File destDir = new File(dir, directory);
if (!MainUtil.isInSubDirectory(working, destDir)) {
player.print(Caption.of("worldedit.schematic.directory-does-not-exist", TextComponent.of(String.valueOf(destDir))));
actor.print(Caption.of("worldedit.schematic.directory-does-not-exist", TextComponent.of(String.valueOf(destDir))));
return;
}
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && !MainUtil.isInSubDirectory(dir, destDir) && !player.hasPermission(
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && !MainUtil.isInSubDirectory(dir, destDir) && !actor.hasPermission(
"worldedit.schematic.move.other")) {
player.print(Caption.of("fawe.error.no-perm", "worldedit.schematic.move.other"));
actor.print(Caption.of("fawe.error.no-perm", "worldedit.schematic.move.other"));
return;
}
ClipboardHolder clipboard = session.getClipboard();
List<File> sources = getFiles(clipboard);
if (sources.isEmpty()) {
player.print(Caption.of("fawe.worldedit.schematic.schematic.none"));
actor.print(Caption.of("fawe.worldedit.schematic.schematic.none"));
return;
}
if (!destDir.exists() && !destDir.mkdirs()) {
player.print(Caption.of("worldedit.schematic.file-perm-fail", TextComponent.of(String.valueOf(destDir))));
actor.print(Caption.of("worldedit.schematic.file-perm-fail", TextComponent.of(String.valueOf(destDir))));
return;
}
for (File source : sources) {
File destFile = new File(destDir, source.getName());
if (destFile.exists()) {
player.print(Caption.of("fawe.worldedit.schematic.schematic.move.exists", destFile));
actor.print(Caption.of("fawe.worldedit.schematic.schematic.move.exists", destFile));
continue;
}
if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && (!MainUtil.isInSubDirectory(
dir,
destFile
) || !MainUtil.isInSubDirectory(dir, source)) && !player.hasPermission("worldedit.schematic.delete.other")) {
player.print(Caption.of("fawe.worldedit.schematic.schematic.move.failed", destFile,
) || !MainUtil.isInSubDirectory(dir, source)) && !actor.hasPermission("worldedit.schematic.delete.other")) {
actor.print(Caption.of("fawe.worldedit.schematic.schematic.move.failed", destFile,
Caption.of("fawe.error.no-perm", ("worldedit.schematic.move.other"))
));
continue;
@ -281,7 +281,7 @@ public class SchematicCommands {
if (cached.exists()) {
Files.move(cached.toPath(), destFile.toPath());
}
player.print(Caption.of("fawe.worldedit.schematic.schematic.move.success", source, destFile));
actor.print(Caption.of("fawe.worldedit.schematic.schematic.move.success", source, destFile));
} catch (IOException e) {
throw new RuntimeException(e);
}

View File

@ -119,7 +119,7 @@ public class UtilityCommands {
desc = "Generate or run a macro"
)
@CommandPermissions("worldedit.macro")
public void macro(Player player, LocalSession session, String name, String argument) throws IOException {
public void macro(Actor actor, LocalSession session, String name, String argument) throws IOException {
}
@ -130,11 +130,11 @@ public class UtilityCommands {
)
@CommandPermissions("fawe.admin")
public void heightmapInterface(
Player player,
Actor actor,
@Arg(name = "min", desc = "int", def = "100") int min,
@Arg(name = "max", desc = "int", def = "200") int max
) throws IOException {
player.print(TextComponent.of("Please wait while we generate the minified heightmaps."));
actor.print(TextComponent.of("Please wait while we generate the minified heightmaps."));
File srcFolder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HEIGHTMAP);
File webSrc = new File(Fawe.imp().getDirectory(), "web" + File.separator + "heightmap");
@ -170,7 +170,7 @@ public class UtilityCommands {
RenderingHints.VALUE_INTERPOLATION_BILINEAR,
true
);
player.print(TextComponent.of(String.format("Writing %s", name)));
actor.print(TextComponent.of(String.format("Writing %s", name)));
File minFile = new File(minImages, name);
File maxFile = new File(maxImages, name);
minFile.getParentFile().mkdirs();
@ -195,9 +195,9 @@ public class UtilityCommands {
config.append("// The local source for the image (used in commands)\n");
config.append("var src_local = \"file://\";\n");
File configFile = new File(webSrc, "config.js");
player.print(TextComponent.of(String.format("Writing %s", configFile)));
actor.print(TextComponent.of(String.format("Writing %s", configFile)));
Files.write(configFile.toPath(), config.toString().getBytes());
player.print(TextComponent.of("Done! See: `FastAsyncWorldEdit/web/heightmap`"));
actor.print(TextComponent.of("Done! See: `FastAsyncWorldEdit/web/heightmap`"));
}
@Command(
@ -206,9 +206,9 @@ public class UtilityCommands {
desc = "Cancel your current command"
)
@CommandPermissions(value = "fawe.cancel", queued = false)
public void cancel(Player player) {
int cancelled = player.cancel(false);
player.print(Caption.of("fawe.cancel.worldedit.cancel.count", cancelled));
public void cancel(Actor actor) {
int cancelled = actor.cancel(false);
actor.print(Caption.of("fawe.cancel.worldedit.cancel.count", cancelled));
}
@Command(
@ -825,9 +825,9 @@ public class UtilityCommands {
desc = "Confirm a command"
)
@CommandPermissions(value = "fawe.confirm", queued = false)
public void confirm(Player player) throws WorldEditException {
if (!player.confirm()) {
player.print(Caption.of("fawe.worldedit.utility.nothing.confirmed"));
public void confirm(Actor actor) throws WorldEditException {
if (!actor.confirm()) {
actor.print(Caption.of("fawe.worldedit.utility.nothing.confirmed"));
}
}