use of com.sk89q.worldedit.command.util.Logging in project FastAsyncWorldEdit by IntellectualSites.
the class ScriptingCommands method executeLast.
@Command(name = ".s", aliases = { "/.s" }, desc = "Execute last CraftScript")
@CommandPermissions("worldedit.scripting.execute")
@Logging(ALL)
public void executeLast(Player player, LocalSession session, @Arg(desc = "Arguments to the CraftScript", def = "", variable = true) List<String> args) throws WorldEditException {
String lastScript = session.getLastScript();
if (!player.hasPermission("worldedit.scripting.execute." + lastScript)) {
player.print(Caption.of("worldedit.execute.script-permissions"));
return;
}
if (lastScript == null) {
player.print(Caption.of("worldedit.executelast.no-script"));
return;
}
File dir = worldEdit.getWorkingDirectoryPath(worldEdit.getConfiguration().scriptsDir).toFile();
File f = worldEdit.getSafeOpenFile(player, dir, lastScript, "js", "js");
worldEdit.runScript(player, f, Stream.concat(Stream.of(lastScript), args.stream()).toArray(String[]::new));
}
use of com.sk89q.worldedit.command.util.Logging in project FastAsyncWorldEdit by IntellectualSites.
the class ScriptingCommands method execute.
@Command(name = "cs", aliases = { "/cs" }, desc = "Execute a CraftScript")
@CommandPermissions("worldedit.scripting.execute")
@Logging(ALL)
public void execute(Player player, LocalSession session, @Arg(desc = "Filename of the CraftScript to load") String filename, @Arg(desc = "Arguments to the CraftScript", def = "", variable = true) List<String> args) throws WorldEditException {
if (!player.hasPermission("worldedit.scripting.execute." + filename)) {
player.print(Caption.of("worldedit.execute.script-permissions"));
return;
}
session.setLastScript(filename);
File dir = worldEdit.getWorkingDirectoryPath(worldEdit.getConfiguration().scriptsDir).toFile();
File f = worldEdit.getSafeOpenFile(player, dir, filename, "js", "js");
worldEdit.runScript(player, f, Stream.concat(Stream.of(filename), args.stream()).toArray(String[]::new));
}
use of com.sk89q.worldedit.command.util.Logging in project FastAsyncWorldEdit by IntellectualSites.
the class CommandLoggingHandler method beforeCall.
@Override
public void beforeCall(Method method, CommandParameters parameters) {
Logging loggingAnnotation = method.getAnnotation(Logging.class);
Logging.LogMode logMode;
StringBuilder builder = new StringBuilder();
if (loggingAnnotation == null) {
logMode = null;
} else {
logMode = loggingAnnotation.value();
}
Optional<Actor> actorOpt = parameters.injectedValue(Key.of(Actor.class));
if (!actorOpt.isPresent()) {
return;
}
Actor actor = actorOpt.get();
World world;
try {
Optional<World> worldOpt = parameters.injectedValue(Key.of(World.class));
if (!worldOpt.isPresent()) {
return;
}
world = worldOpt.get();
} catch (CommandException ex) {
return;
}
builder.append("WorldEdit: ").append(actor.getName());
builder.append(" (in \"").append(world.getName()).append("\")");
builder.append(": ").append(parameters.getMetadata().getCalledName());
builder.append(": ").append(Stream.concat(Stream.of(parameters.getMetadata().getCalledName()), parameters.getMetadata().getArguments().stream()).collect(Collectors.joining(" ")));
if (logMode != null && actor instanceof Player) {
Player player = (Player) actor;
Vector3 position = player.getLocation().toVector();
LocalSession session = worldEdit.getSessionManager().get(actor);
switch(logMode) {
case PLACEMENT:
try {
position = session.getPlacementPosition(actor).toVector3();
} catch (IncompleteRegionException e) {
break;
}
case POSITION:
builder.append(" - Position: ").append(position);
break;
case ALL:
builder.append(" - Position: ").append(position);
case ORIENTATION_REGION:
builder.append(" - Orientation: ").append(player.getCardinalDirection().name());
case REGION:
try {
builder.append(" - Region: ").append(session.getSelection(world));
} catch (IncompleteRegionException e) {
break;
}
break;
}
}
logger.info(builder.toString());
}
use of com.sk89q.worldedit.command.util.Logging in project FastAsyncWorldEdit by IntellectualSites.
the class SelectionCommands method contract.
@Command(name = "/contract", desc = "Contract the selection area")
@Logging(REGION)
@CommandPermissions("worldedit.selection.contract")
public void contract(Actor actor, World world, LocalSession session, @Arg(desc = "Amount to contract the selection by") int amount, @Arg(desc = "Amount to contract the selection by in the other direction", def = "0") int reverseAmount, @Arg(desc = "Direction to contract", def = Direction.AIM) @MultiDirection List<BlockVector3> direction) throws WorldEditException {
try {
Region region = session.getSelection(world);
long oldSize = region.getVolume();
if (reverseAmount == 0) {
for (BlockVector3 dir : direction) {
region.contract(dir.multiply(amount));
}
} else {
for (BlockVector3 dir : direction) {
region.contract(dir.multiply(amount), dir.multiply(-reverseAmount));
}
}
session.getRegionSelector(world).learnChanges();
long newSize = region.getVolume();
session.getRegionSelector(world).explainRegionAdjust(actor, session);
actor.print(Caption.of("worldedit.contract.contracted", TextComponent.of(oldSize - newSize)));
} catch (RegionOperationException e) {
actor.printError(TextComponent.of(e.getMessage()));
}
}
use of com.sk89q.worldedit.command.util.Logging in project FastAsyncWorldEdit by IntellectualSites.
the class SelectionCommands method chunk.
@Command(name = "/chunk", desc = "Set the selection to your current chunk.", descFooter = "This command selects 256-block-tall areas,\nwhich can be specified by the y-coordinate.\nE.g. -c x,1,z will select from y=256 to y=511.")
@Logging(POSITION)
@CommandPermissions("worldedit.selection.chunk")
public void chunk(Actor actor, World world, LocalSession session, @Arg(desc = "The chunk to select", def = "") BlockVector3 coordinates, @Switch(name = 's', desc = "Expand your selection to encompass all chunks that are part of it") boolean expandSelection, @Switch(name = 'c', desc = "Use chunk coordinates instead of block coordinates") boolean useChunkCoordinates) throws WorldEditException {
final BlockVector3 min;
final BlockVector3 max;
if (expandSelection) {
Region region = session.getSelection(world);
int minChunkY = world.getMinY() >> CHUNK_SHIFTS_Y;
int maxChunkY = world.getMaxY() >> CHUNK_SHIFTS_Y;
BlockVector3 minChunk = ChunkStore.toChunk3d(region.getMinimumPoint()).clampY(minChunkY, maxChunkY);
BlockVector3 maxChunk = ChunkStore.toChunk3d(region.getMaximumPoint()).clampY(minChunkY, maxChunkY);
min = minChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS);
max = maxChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS).add(15, 255, 15);
actor.print(Caption.of("worldedit.chunk.selected-multiple", TextComponent.of(minChunk.getBlockX()), TextComponent.of(minChunk.getBlockY()), TextComponent.of(minChunk.getBlockZ()), TextComponent.of(maxChunk.getBlockX()), TextComponent.of(maxChunk.getBlockY()), TextComponent.of(maxChunk.getBlockZ())));
} else {
BlockVector3 minChunk;
if (coordinates != null) {
// coords specified
minChunk = useChunkCoordinates ? coordinates : ChunkStore.toChunk3d(coordinates);
} else {
// use player loc
if (actor instanceof Locatable) {
minChunk = ChunkStore.toChunk3d(((Locatable) actor).getBlockLocation().toVector().toBlockPoint());
} else {
throw new StopExecutionException(TextComponent.of("A player or coordinates are required."));
}
}
min = minChunk.shl(CHUNK_SHIFTS, CHUNK_SHIFTS_Y, CHUNK_SHIFTS);
max = min.add(15, 255, 15);
actor.print(Caption.of("worldedit.chunk.selected", TextComponent.of(minChunk.getBlockX()), TextComponent.of(minChunk.getBlockY()), TextComponent.of(minChunk.getBlockZ())));
}
final CuboidRegionSelector selector;
if (session.getRegionSelector(world) instanceof ExtendingCuboidRegionSelector) {
selector = new ExtendingCuboidRegionSelector(world);
} else {
selector = new CuboidRegionSelector(world);
}
selector.selectPrimary(min, ActorSelectorLimits.forActor(actor));
selector.selectSecondary(max, ActorSelectorLimits.forActor(actor));
session.setRegionSelector(world, selector);
session.dispatchCUISelection(actor);
}
Aggregations