use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.
the class PlotSquaredFeature method getMask.
@Override
public FaweMask getMask(Player player, MaskType type, boolean isWhitelist) {
final PlotPlayer<org.bukkit.entity.Player> pp = PlotPlayer.from(BukkitAdapter.adapt(player));
if (pp == null) {
return null;
}
final Set<CuboidRegion> regions;
Plot plot = pp.getCurrentPlot();
if (isAllowed(player, plot, type)) {
regions = plot.getRegions();
} else {
plot = null;
regions = WEManager.getMask(pp);
if (regions.size() == 1) {
CuboidRegion region = regions.iterator().next();
if (region.getMinimumPoint().getX() == Integer.MIN_VALUE && region.getMaximumPoint().getX() == Integer.MAX_VALUE) {
regions.clear();
}
}
}
if (regions.isEmpty()) {
return null;
}
PlotArea area = pp.getApplicablePlotArea();
final Plot finalPlot = plot;
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(finalPlot) || regions.isEmpty()) {
return null;
}
Region maskedRegion;
if (regions.size() == 1) {
int min = area != null ? area.getMinBuildHeight() : player.getWorld().getMinY();
int max = area != null ? Math.min(player.getWorld().getMaxY(), area.getMaxBuildHeight()) : player.getWorld().getMaxY();
final CuboidRegion region = regions.iterator().next();
final BlockVector3 pos1 = BlockVector3.at(region.getMinimumX(), min, region.getMinimumZ());
final BlockVector3 pos2 = BlockVector3.at(region.getMaximumX(), max, region.getMaximumZ());
maskedRegion = new CuboidRegion(pos1, pos2);
} else {
World world = FaweAPI.getWorld(area.getWorldName());
List<Region> weRegions = regions.stream().map(r -> new CuboidRegion(world, BlockVector3.at(r.getMinimumX(), r.getMinimumY(), r.getMinimumZ()), BlockVector3.at(r.getMaximumX(), r.getMaximumY(), r.getMaximumZ()))).collect(Collectors.toList());
maskedRegion = new RegionIntersection(world, weRegions);
}
return new FaweMask(maskedRegion) {
@Override
public boolean isValid(Player player, MaskType type) {
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(finalPlot)) {
return false;
}
return isAllowed(player, finalPlot, type);
}
};
}
use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.
the class BiomeCommands method biomeInfo.
@Command(name = "biomeinfo", desc = "Get the biome of the targeted block.", descFooter = "By default, uses all blocks in your selection.")
@CommandPermissions("worldedit.biome.info")
public void biomeInfo(Actor actor, World world, LocalSession session, @Switch(name = 't', desc = "Use the block you are looking at.") boolean useLineOfSight, @Switch(name = 'p', desc = "Use the block you are currently in.") boolean usePosition) throws WorldEditException {
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
Set<BiomeType> biomes = new HashSet<>();
String messageKey;
if (useLineOfSight) {
if (actor instanceof Player) {
Location blockPosition = ((Player) actor).getBlockTrace(300);
if (blockPosition == null) {
actor.print(Caption.of("worldedit.raytrace.noblock"));
return;
}
BiomeType biome = world.getBiome(blockPosition.toVector().toBlockPoint());
biomes.add(biome);
messageKey = "worldedit.biomeinfo.lineofsight";
} else {
actor.print(Caption.of("worldedit.raytrace.require-player"));
return;
}
} else if (usePosition) {
if (actor instanceof Locatable) {
BiomeType biome = world.getBiome(((Locatable) actor).getLocation().toVector().toBlockPoint());
biomes.add(biome);
messageKey = "worldedit.biomeinfo.position";
} else {
actor.print(Caption.of("worldedit.biomeinfo.not-locatable"));
return;
}
} else {
Region region = session.getSelection(world);
for (BlockVector3 pt : region) {
biomes.add(world.getBiome(pt));
}
messageKey = "worldedit.biomeinfo.selection";
}
List<Component> components = biomes.stream().map(biome -> biomeRegistry.getRichName(biome).hoverEvent(HoverEvent.showText(TextComponent.of(biome.getId())))).collect(Collectors.toList());
actor.print(Caption.of(messageKey, TextUtils.join(components, TextComponent.of(", "))));
}
use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.
the class BrushCommands method set.
public BrushSettings set(InjectedValueAccess context, Brush brush, String permission) throws InvalidToolBindException {
Player player = context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"));
LocalSession session = player.getSession();
BrushSettings bs = new BrushSettings();
BrushTool tool = session.getBrushTool(player, false);
if (tool != null) {
BrushSettings currentContext = tool.getContext();
if (currentContext != null) {
Brush currentBrush = currentContext.getBrush();
if (currentBrush != null && currentBrush.getClass() == brush.getClass()) {
bs = currentContext;
}
}
}
Arguments arguments = context.injectedValue(Key.of(Arguments.class)).orElse(null);
if (arguments != null) {
String args = arguments.get();
bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1));
}
bs.addPermission(permission);
bs.setBrush(brush);
return process(player, arguments, bs);
}
use of com.sk89q.worldedit.entity.Player in project FastAsyncWorldEdit by IntellectualSites.
the class GenerationCommands method sphere.
@Command(name = "/sphere", desc = "Generates a filled sphere.")
@CommandPermissions("worldedit.generation.sphere")
@Logging(PLACEMENT)
public int sphere(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The pattern of blocks to generate") Pattern pattern, @Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W") @Radii(3) List<Double> radii, @Switch(name = 'r', desc = "Raise the bottom of the sphere to the placement position") boolean raised, @Switch(name = 'h', desc = "Make a hollow sphere") boolean hollow) throws WorldEditException {
final double radiusX;
final double radiusY;
final double radiusZ;
switch(radii.size()) {
case 1:
radiusX = radiusY = radiusZ = Math.max(0, radii.get(0));
break;
case 3:
radiusX = Math.max(0, radii.get(0));
radiusY = Math.max(0, radii.get(1));
radiusZ = Math.max(0, radii.get(2));
break;
default:
actor.print(Caption.of("worldedit.sphere.invalid-radius"));
return 0;
}
worldEdit.checkMaxRadius(radiusX);
worldEdit.checkMaxRadius(radiusY);
worldEdit.checkMaxRadius(radiusZ);
BlockVector3 pos = session.getPlacementPosition(actor);
if (raised) {
pos = pos.add(0, (int) radiusY, 0);
}
int affected = editSession.makeSphere(pos, pattern, radiusX, radiusY, radiusZ, !hollow);
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 GenerationCommands method pyramid.
@Command(name = "/pyramid", desc = "Generate a filled pyramid")
@CommandPermissions("worldedit.generation.pyramid")
@Logging(PLACEMENT)
public int pyramid(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The pattern of blocks to set") Pattern pattern, @Confirm(Confirm.Processor.RADIUS) @Arg(desc = "The size of the pyramid") int size, @Switch(name = 'h', desc = "Make a hollow pyramid") boolean hollow) throws WorldEditException {
worldEdit.checkMaxRadius(size);
BlockVector3 pos = session.getPlacementPosition(actor);
int affected = editSession.makePyramid(pos, pattern, size, !hollow);
if (actor instanceof Player) {
((Player) actor).findFreePosition();
}
actor.print(Caption.of("worldedit.pyramid.created", TextComponent.of(affected)));
return affected;
}
Aggregations