use of com.sk89q.worldedit.entity.Player 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.entity.Player in project FastAsyncWorldEdit by IntellectualSites.
the class EditSessionBuilder method compile.
/**
* Compile the builder to the settings given. Prepares history, limits, lighting, etc.
*/
public EditSessionBuilder compile() {
if (compiled) {
return this;
}
compiled = true;
wrapped = false;
if (event == null) {
event = new EditSessionEvent(world, actor, -1, null);
}
if (actor == null && event.getActor() != null) {
actor = event.getActor();
}
if (limit == null) {
if (actor == null) {
limit = FaweLimit.MAX;
} else {
limit = actor.getLimit();
}
}
if (fastMode == null) {
if (actor == null) {
fastMode = !Settings.settings().HISTORY.ENABLE_FOR_CONSOLE;
} else {
fastMode = actor.getSession().hasFastMode();
}
}
if (checkMemory == null) {
checkMemory = actor != null && !this.fastMode;
}
if (checkMemory) {
if (MemUtil.isMemoryLimitedSlow()) {
if (Permission.hasPermission(actor, "worldedit.fast")) {
actor.print(Caption.of("fawe.info.worldedit.oom.admin"));
}
throw FaweCache.LOW_MEMORY;
}
}
// this.originalLimit = limit;
this.blockBag = limit.INVENTORY_MODE != 0 ? blockBag : null;
this.limit = limit.copy();
if (extent == null) {
IQueueExtent<IQueueChunk> queue = null;
World unwrapped = WorldWrapper.unwrap(world);
boolean placeChunks = (this.fastMode || this.limit.FAST_PLACEMENT) && (wnaMode == null || !wnaMode);
if (placeChunks) {
wnaMode = false;
if (unwrapped instanceof IQueueExtent) {
extent = queue = (IQueueExtent) unwrapped;
} else if (Settings.settings().QUEUE.PARALLEL_THREADS > 1 && !Fawe.isMainThread()) {
ParallelQueueExtent parallel = new ParallelQueueExtent(Fawe.instance().getQueueHandler(), world, fastMode);
queue = parallel.getExtent();
extent = parallel;
} else {
extent = queue = Fawe.instance().getQueueHandler().getQueue(world);
}
} else {
wnaMode = true;
extent = world;
}
if (combineStages == null) {
combineStages = // If it's enabled in the settings
Settings.settings().HISTORY.COMBINE_STAGES && // If fast placement is disabled, it's slower to perform a copy on each chunk
this.limit.FAST_PLACEMENT && // If the edit uses items from the inventory we can't use a delayed task
this.blockBag == null;
}
extent = this.bypassAll = wrapExtent(extent, eventBus, event, EditSession.Stage.BEFORE_CHANGE);
this.bypassHistory = this.extent = wrapExtent(bypassAll, eventBus, event, EditSession.Stage.BEFORE_REORDER);
if (!this.fastMode || changeSet != null) {
if (changeSet == null) {
if (Settings.settings().HISTORY.USE_DISK) {
UUID uuid = actor == null ? Identifiable.CONSOLE : actor.getUniqueId();
if (Settings.settings().HISTORY.USE_DATABASE) {
changeSet = new RollbackOptimizedHistory(world, uuid);
} else {
changeSet = new DiskStorageHistory(world, uuid);
}
// } else if (combineStages && Settings.settings().HISTORY.COMPRESSION_LEVEL == 0) {
// changeSet = new CPUOptimizedChangeSet(world);
} else {
if (combineStages && Settings.settings().HISTORY.COMPRESSION_LEVEL == 0) {
// TODO add CPUOptimizedChangeSet
}
changeSet = new MemoryOptimizedHistory(world);
}
}
if (this.limit.SPEED_REDUCTION > 0) {
this.extent = this.bypassHistory = new SlowExtent(this.bypassHistory, this.limit.SPEED_REDUCTION);
}
if (command != null && changeSet instanceof RollbackOptimizedHistory) {
((RollbackOptimizedHistory) changeSet).setCommand(this.command);
}
if (!(changeSet instanceof NullChangeSet)) {
if (this.blockBag != null) {
// TODO implement block bag as IBatchProcessor
changeSet = new BlockBagChangeSet(changeSet, blockBag, limit.INVENTORY_MODE == 1);
}
if (combineStages) {
changeTask = changeSet;
this.extent = extent.enableHistory(changeSet);
} else {
this.extent = new HistoryExtent(extent, changeSet);
// if (this.blockBag != null) {
// this.extent = new BlockBagExtent(this.extent, blockBag, limit.INVENTORY_MODE == 1);
// }
}
}
}
if (allowedRegions == null && Settings.settings().REGION_RESTRICTIONS) {
if (actor != null && !actor.hasPermission("fawe.bypass") && !actor.hasPermission("fawe.bypass.regions")) {
if (actor instanceof Player) {
Player player = (Player) actor;
allowedRegions = player.getAllowedRegions();
}
}
}
if (disallowedRegions == null && Settings.settings().REGION_RESTRICTIONS && Settings.settings().REGION_RESTRICTIONS_OPTIONS.ALLOW_BLACKLISTS) {
if (actor != null && !actor.hasPermission("fawe.bypass") && !actor.hasPermission("fawe.bypass.regions")) {
if (actor instanceof Player) {
Player player = (Player) actor;
disallowedRegions = player.getDisallowedRegions();
}
}
}
FaweRegionExtent regionExtent = null;
if (disallowedRegions != null) {
// Always use MultiRegionExtent if we have blacklist regions
regionExtent = new MultiRegionExtent(this.extent, this.limit, allowedRegions, disallowedRegions);
} else if (allowedRegions == null) {
allowedRegions = new Region[] { RegionWrapper.GLOBAL() };
} else {
if (allowedRegions.length == 0) {
regionExtent = new NullExtent(this.extent, FaweCache.NO_REGION);
} else {
if (allowedRegions.length == 1) {
regionExtent = new SingleRegionExtent(this.extent, this.limit, allowedRegions[0]);
} else {
regionExtent = new MultiRegionExtent(this.extent, this.limit, allowedRegions, null);
}
}
}
// There's no need to do lighting (and it'll also just be a pain to implement) if we're not placing chunks
if (placeChunks) {
if (((relightMode != null && relightMode != RelightMode.NONE) || (relightMode == null && Settings.settings().LIGHTING.MODE > 0))) {
relighter = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getRelighterFactory().createRelighter(relightMode, world, queue);
extent.addProcessor(new RelightProcessor(relighter));
}
extent.addProcessor(new HeightmapProcessor(world.getMinY(), world.getMaxY()));
} else {
relighter = NullRelighter.INSTANCE;
}
if (limit != null && !limit.isUnlimited() && regionExtent != null) {
this.extent = new LimitExtent(regionExtent, limit);
} else if (limit != null && !limit.isUnlimited()) {
this.extent = new LimitExtent(this.extent, limit);
} else if (regionExtent != null) {
this.extent = regionExtent;
}
if (this.limit != null && this.limit.STRIP_NBT != null && !this.limit.STRIP_NBT.isEmpty()) {
if (placeChunks) {
extent.addProcessor(new StripNBTExtent(this.extent, this.limit.STRIP_NBT));
} else {
this.extent = new StripNBTExtent(this.extent, this.limit.STRIP_NBT);
}
}
if (this.limit != null && !this.limit.isUnlimited()) {
Set<String> limitBlocks = new HashSet<>();
if ((getActor() == null || getActor().hasPermission("worldedit.anyblock") && this.limit.UNIVERSAL_DISALLOWED_BLOCKS)) {
limitBlocks.addAll(WorldEdit.getInstance().getConfiguration().disallowedBlocks);
}
if (this.limit.DISALLOWED_BLOCKS != null && !this.limit.DISALLOWED_BLOCKS.isEmpty()) {
limitBlocks.addAll(this.limit.DISALLOWED_BLOCKS);
}
Set<PropertyRemap<?>> remaps = this.limit.REMAP_PROPERTIES;
if (!limitBlocks.isEmpty() || (remaps != null && !remaps.isEmpty())) {
if (placeChunks) {
extent.addProcessor(new DisallowedBlocksExtent(this.extent, limitBlocks, remaps));
} else {
this.extent = new DisallowedBlocksExtent(this.extent, limitBlocks, remaps);
}
}
}
this.extent = wrapExtent(this.extent, eventBus, event, EditSession.Stage.BEFORE_HISTORY);
}
return this;
}
use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.
the class HistoryCommands method redo.
@Command(name = "redo", aliases = { "/redo" }, desc = "Redoes the last action (from history)")
@CommandPermissions({ "worldedit.history.redo", "worldedit.history.redo.self" })
public void redo(Actor actor, LocalSession session, @Confirm(Confirm.Processor.LIMIT) @Arg(desc = "Number of redoes to perform", def = "1") int times, @Arg(name = "player", desc = "Redo this player's operations", def = "") String playerName) throws WorldEditException {
times = Math.max(1, times);
LocalSession redoSession = session;
if (playerName != null) {
actor.checkPermission("worldedit.history.redo.other");
redoSession = worldEdit.getSessionManager().findByName(playerName);
if (redoSession == null) {
actor.print(Caption.of("worldedit.session.cant-find-session", TextComponent.of(playerName)));
return;
}
}
int timesRedone = 0;
for (int i = 0; i < times; ++i) {
BlockBag blockBag = actor instanceof Player ? redoSession.getBlockBag((Player) actor) : null;
EditSession redone = redoSession.redo(blockBag, actor);
if (redone != null) {
timesRedone++;
worldEdit.flushBlockBag(actor, redone);
} else {
break;
}
}
if (timesRedone > 0) {
actor.print(Caption.of("worldedit.redo.redone", TextComponent.of(timesRedone)));
} else {
actor.print(Caption.of("worldedit.redo.none"));
}
}
use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.
the class HistoryCommands method undo.
@Command(name = "undo", aliases = { "/undo" }, desc = "Undoes the last action (from history)")
@CommandPermissions({ "worldedit.history.undo", "worldedit.history.undo.self" })
public void undo(Actor actor, LocalSession session, @Confirm(Confirm.Processor.LIMIT) @Arg(desc = "Number of undoes to perform", def = "1") int times, @Arg(name = "player", desc = "Undo this player's operations", def = "") String playerName) throws WorldEditException {
times = Math.max(1, times);
LocalSession undoSession = session;
// FAWE start - Add fastmode check
if (session.hasFastMode()) {
actor.print(Caption.of("fawe.worldedit.history.command.undo.disabled"));
return;
}
// FAWE end
if (playerName != null) {
actor.checkPermission("worldedit.history.undo.other");
undoSession = worldEdit.getSessionManager().findByName(playerName);
if (undoSession == null) {
actor.print(Caption.of("worldedit.session.cant-find-session", TextComponent.of(playerName)));
return;
}
}
int timesUndone = 0;
for (int i = 0; i < times; ++i) {
BlockBag blockBag = actor instanceof Player ? undoSession.getBlockBag((Player) actor) : null;
EditSession undone = undoSession.undo(blockBag, actor);
if (undone != null) {
timesUndone++;
worldEdit.flushBlockBag(actor, undone);
} else {
break;
}
}
if (timesUndone > 0) {
actor.print(Caption.of("worldedit.undo.undone", TextComponent.of(timesUndone)));
} else {
actor.print(Caption.of("worldedit.undo.none"));
}
}
use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.
the class WorldEditListener method onPlayerInteract.
/**
* Called when a player interacts.
*
* @param event Relevant event details
*/
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (!plugin.getInternalPlatform().isHookingEvents()) {
return;
}
if (event.useItemInHand() == Result.DENY) {
return;
}
if (event.getHand() == EquipmentSlot.OFF_HAND) {
return;
}
final Player player = plugin.wrapPlayer(event.getPlayer());
final World world = player.getWorld();
final WorldEdit we = plugin.getWorldEdit();
final Direction direction = BukkitAdapter.adapt(event.getBlockFace());
Action action = event.getAction();
if (action == Action.LEFT_CLICK_BLOCK) {
final Block clickedBlock = event.getClickedBlock();
final Location pos = new Location(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockLeftClick(player, pos, direction)) {
event.setCancelled(true);
}
if (we.handleArmSwing(player)) {
event.setCancelled(true);
}
} else if (action == Action.LEFT_CLICK_AIR) {
if (we.handleArmSwing(player)) {
event.setCancelled(true);
}
} else if (action == Action.RIGHT_CLICK_BLOCK) {
final Block clickedBlock = event.getClickedBlock();
final Location pos = new Location(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockRightClick(player, pos, direction)) {
event.setCancelled(true);
}
if (we.handleRightClick(player)) {
event.setCancelled(true);
}
} else if (action == Action.RIGHT_CLICK_AIR) {
if (we.handleRightClick(player)) {
event.setCancelled(true);
}
}
}
Aggregations