use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.
the class GenerationCommands method blobBrush.
@Command(name = "/blob", aliases = { "/rock" }, desc = "Creates a distorted sphere")
@Logging(PLACEMENT)
@CommandPermissions("worldedit.generation.blob")
public int blobBrush(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "Pattern") Pattern pattern, @Arg(desc = "size", def = "5") double size, @Arg(desc = "radius", def = "5") Vector3 radius, @Arg(name = "roundness", desc = "roundness", def = "100") double sphericity, @Arg(desc = "double", def = "30") double frequency, @Arg(desc = "double", def = "50") double amplitude) throws WorldEditException {
double max = MathMan.max(radius.getX(), radius.getY(), radius.getZ());
worldEdit.checkMaxRadius(max);
BlockVector3 pos = session.getPlacementPosition(actor);
int affected = editSession.makeBlob(pos, pattern, size, frequency / 100, amplitude / 100, radius.divide(max), sphericity / 100);
if (actor instanceof Player) {
((Player) actor).findFreePosition();
}
actor.print(Caption.of("worldedit.sphere.created", TextComponent.of(affected)));
return affected;
}
use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.
the class HistorySubCommands method list.
@Command(name = "list", desc = "List your history")
@CommandPermissions("worldedit.history.list")
public void list(Player player, LocalSession session, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @ArgFlag(name = 'p', desc = "Page to view.", def = "") Integer page) {
int index = session.getHistoryIndex();
List<Supplier<? extends ChangeSet>> history = Lists.transform(session.getHistory(), (Function<ChangeSet, Supplier<ChangeSet>>) input -> () -> input);
Location origin = player.getLocation();
String pageCommand = "/" + arguments.get().replaceAll("-p [0-9]+", "").trim();
Reference<PaginationBox> cached = player.getMeta(pageCommand);
PaginationBox pages = cached == null ? null : cached.get();
if (page == null || pages == null) {
pages = list(database, pageCommand, history, origin.toBlockPoint());
page = 1;
}
player.print(pages.create(page));
}
use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.
the class RegionCommands method deform.
@Command(name = "/deform", desc = "Deforms a selected region with an expression", descFooter = "The expression is executed for each block and is expected\n" + "to modify the variables x, y and z to point to a new block\n" + "to fetch. For details, see https://ehub.to/we/expr")
@CommandPermissions("worldedit.region.deform")
@Logging(ALL)
@Preload(Preload.PreloadCheck.PRELOAD)
@Confirm(Confirm.Processor.REGION)
public int deform(Actor actor, LocalSession session, EditSession editSession, @Selection Region region, @Arg(desc = "The expression to use", variable = true) List<String> expression, @Switch(name = 'r', desc = "Use the game's coordinate origin") boolean useRawCoords, @Switch(name = 'o', desc = "Use the placement's coordinate origin") boolean offset, @Switch(name = 'c', desc = "Use the selection's center as origin") boolean offsetCenter) throws WorldEditException {
final Vector3 zero;
Vector3 unit;
if (useRawCoords) {
zero = Vector3.ZERO;
unit = Vector3.ONE;
} else if (offsetCenter) {
final Vector3 min = region.getMinimumPoint().toVector3();
final Vector3 max = region.getMaximumPoint().toVector3();
zero = max.add(min).multiply(0.5);
unit = Vector3.ONE;
} else if (offset) {
zero = session.getPlacementPosition(actor).toVector3();
unit = Vector3.ONE;
} else {
final Vector3 min = region.getMinimumPoint().toVector3();
final Vector3 max = region.getMaximumPoint().toVector3();
zero = max.add(min).divide(2);
unit = max.subtract(zero);
if (unit.getX() == 0) {
unit = unit.withX(1.0);
}
if (unit.getY() == 0) {
unit = unit.withY(1.0);
}
if (unit.getZ() == 0) {
unit = unit.withZ(1.0);
}
}
final Vector3 unit1 = unit;
try {
final int affected = editSession.deformRegion(region, zero, unit1, String.join(" ", expression), session.getTimeout());
if (actor instanceof Player) {
((Player) actor).findFreePosition();
}
actor.print(Caption.of("worldedit.deform.deformed", TextComponent.of(affected)));
return affected;
} catch (ExpressionException e) {
actor.printError(TextComponent.of(e.getMessage()));
return 0;
}
}
use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.
the class PlatformCommandManager method initializeInjectedValues.
// FAWE end
// FAWE start - Event & suggestions, make method public
public MemoizingValueAccess initializeInjectedValues(Arguments arguments, Actor actor, Event event, boolean isSuggestions) {
// FAWE end
InjectedValueStore store = MapBackedValueStore.create();
store.injectValue(Key.of(Actor.class), ValueProvider.constant(actor));
if (actor instanceof Player) {
store.injectValue(Key.of(Player.class), ValueProvider.constant((Player) actor));
} else {
store.injectValue(Key.of(Player.class), context -> {
throw new CommandException(Caption.of("worldedit.command.player-only"), ImmutableList.of());
});
}
store.injectValue(Key.of(Arguments.class), ValueProvider.constant(arguments));
store.injectValue(Key.of(LocalSession.class), context -> {
LocalSession localSession = worldEdit.getSessionManager().get(actor);
localSession.tellVersion(actor);
return Optional.of(localSession);
});
store.injectValue(Key.of(boolean.class), context -> Optional.of(isSuggestions));
store.injectValue(Key.of(InjectedValueStore.class), ValueProvider.constant(store));
store.injectValue(Key.of(Event.class), ValueProvider.constant(event));
// FAWE start - allow giving editsessions
if (event instanceof CommandEvent) {
EditSession session = ((CommandEvent) event).getSession();
if (session != null) {
store.injectValue(Key.of(EditSession.class), context -> Optional.of(session));
}
}
// FAWE end
return MemoizingValueAccess.wrap(MergedValueAccess.of(store, globalInjectedValues));
}
use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.
the class PlatformManager method handlePlayerInput.
// FAWE end
@Subscribe
public void handlePlayerInput(PlayerInputEvent event) {
// Create a proxy actor with a potentially different world for
// making changes to the world
Player player = createProxyActor(event.getPlayer());
LocalSession session = worldEdit.getSessionManager().get(player);
try {
switch(event.getInputType()) {
case PRIMARY:
{
Tool tool = session.getTool(player);
if (tool instanceof DoubleActionTraceTool && tool.canUse(player)) {
// FAWE start - run async
player.runAsyncIfFree(() -> reset((DoubleActionTraceTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session));
// FAWE end
event.setCancelled(true);
return;
}
break;
}
case SECONDARY:
{
Tool tool = session.getTool(player);
if (tool instanceof TraceTool && tool.canUse(player)) {
// FAWE start - run async
// todo this needs to be fixed so the event is canceled after actPrimary is used and returns true
player.runAction(() -> reset((TraceTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session), false, true);
// FAWE end
event.setCancelled(true);
return;
}
break;
}
}
// FAWE start - add own message
} catch (Throwable e) {
FaweException faweException = FaweException.get(e);
if (faweException != null) {
player.print(Caption.of("fawe.cancel.reason", faweException.getComponent()));
} else {
player.print(Caption.of("worldedit.command.error.report"));
player.print(TextComponent.of(e.getClass().getName() + ": " + e.getMessage()));
e.printStackTrace();
}
// FAWE end
} finally {
Request.reset();
}
}
Aggregations