use of org.spongepowered.api.world.Location in project LanternServer by LanternPowered.
the class CommandTeleport method completeSpec.
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
specBuilder.arguments(// TODO: Replace with entity selector
GenericArguments.player(Text.of("target")), GenericArguments.flags().valueFlag(GenericArguments.world(CommandHelper.WORLD_KEY), "-world", "w").buildWith(GenericArguments.none()), GenericArguments.vector3d(Text.of("position")), GenericArguments.optional(GenericArguments.seq(GenericArguments2.relativeDoubleNum(Text.of("y-rot")), GenericArguments2.relativeDoubleNum(Text.of("x-rot"))))).executor((src, args) -> {
// TODO: Replace with selected entities
final Entity target = args.<Entity>getOne("target").get();
final World world = CommandHelper.getWorld(src, args);
final Location<World> location = new Location<>(world, args.<Vector3d>getOne("position").get());
if (args.hasAny("y-rot")) {
RelativeDouble yRot = args.<RelativeDouble>getOne("y-rot").get();
RelativeDouble xRot = args.<RelativeDouble>getOne("x-rot").get();
boolean rel = yRot.isRelative() || xRot.isRelative();
if (rel && !(src instanceof Locatable)) {
throw new CommandException(t("Relative rotation specified but source does not have a rotation."));
}
double xRot0 = xRot.getValue();
double yRot0 = yRot.getValue();
double zRot0 = 0;
// is locatable, just handle it then as absolute
if (src instanceof Entity) {
final Vector3d rot = ((Entity) src).getRotation();
xRot0 = xRot.applyToValue(rot.getX());
yRot0 = yRot.applyToValue(rot.getY());
zRot0 = rot.getZ();
}
target.setLocationAndRotation(location, new Vector3d(xRot0, yRot0, zRot0));
} else {
target.setLocation(location);
}
src.sendMessage(t("commands.teleport.success.coordinates", location.getX(), location.getY(), location.getZ()));
return CommandResult.success();
});
}
use of org.spongepowered.api.world.Location in project LanternServer by LanternPowered.
the class PlayerInteractionHandler method handleBrokenBlock.
private void handleBrokenBlock() {
final Location<World> location = new Location<>(this.player.getWorld(), this.diggingBlock);
final CauseStack causeStack = CauseStack.current();
try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
frame.pushCause(this.player);
// Add context
frame.addContext(EventContextKeys.PLAYER, this.player);
frame.addContext(ContextKeys.INTERACTION_LOCATION, location);
frame.addContext(ContextKeys.BLOCK_LOCATION, location);
final BehaviorContextImpl context = new BehaviorContextImpl(causeStack);
final BlockState blockState = location.getBlock();
final LanternBlockType blockType = (LanternBlockType) blockState.getType();
if (context.process(blockType.getPipeline().pipeline(BreakBlockBehavior.class), (ctx, behavior) -> behavior.tryBreak(blockType.getPipeline(), ctx)).isSuccess()) {
context.accept();
this.diggingBlock = null;
this.diggingBlockType = null;
} else {
context.revert();
// TODO: Resend tile entity data, action data, ... ???
this.player.sendBlockChange(this.diggingBlock, blockState);
}
if (this.lastBreakState != -1) {
sendBreakUpdate(-1);
}
}
}
use of org.spongepowered.api.world.Location in project LanternServer by LanternPowered.
the class HandlerPlayInTabComplete method handle.
@Override
public void handle(NetworkContext context, MessagePlayInTabComplete message) {
final String text = message.getText();
// The content with normalized spaces, the spaces are trimmed
// from the ends and there are never two spaces directly after eachother
final String textNormalized = StringUtils.normalizeSpace(text);
final Player player = context.getSession().getPlayer();
final Location<World> targetBlock = message.getBlockPosition().map(pos -> new Location<>(player.getWorld(), pos)).orElse(null);
final boolean hasPrefix = textNormalized.startsWith("/");
if (hasPrefix || message.getAssumeCommand()) {
String command = textNormalized;
// Don't include the '/'
if (hasPrefix) {
command = command.substring(1);
}
// Keep the last space, it must be there!
if (text.endsWith(" ")) {
command = command + " ";
}
// Get the suggestions
List<String> suggestions = ((LanternCommandManager) Sponge.getCommandManager()).getSuggestions(player, command, targetBlock, message.getAssumeCommand());
// If the suggestions are for the command and there was a prefix, then append the prefix
if (hasPrefix && command.split(" ").length == 1 && !command.endsWith(" ")) {
suggestions = suggestions.stream().map(suggestion -> '/' + suggestion).collect(ImmutableList.toImmutableList());
}
context.getSession().send(new MessagePlayOutTabComplete(suggestions));
} else {
// Vanilla mc will complete user names if
// no command is being completed
final int index = text.lastIndexOf(' ');
final String part;
if (index == -1) {
part = text;
} else {
part = text.substring(index + 1);
}
if (part.isEmpty()) {
return;
}
final String part1 = part.toLowerCase();
final List<String> suggestions = Sponge.getServer().getOnlinePlayers().stream().map(CommandSource::getName).filter(n -> n.toLowerCase().startsWith(part1)).collect(Collectors.toList());
final Cause cause = Cause.of(EventContext.empty(), context.getSession().getPlayer());
final TabCompleteEvent.Chat event = SpongeEventFactory.createTabCompleteEventChat(cause, ImmutableList.copyOf(suggestions), suggestions, text, Optional.ofNullable(targetBlock), false);
if (!Sponge.getEventManager().post(event)) {
context.getSession().send(new MessagePlayOutTabComplete(suggestions));
}
}
}
use of org.spongepowered.api.world.Location in project LanternServer by LanternPowered.
the class LanternChunk method createSnapshot.
@Override
public BlockSnapshot createSnapshot(int x, int y, int z) {
final BlockState state = getBlock(x, y, z);
final Location<World> loc = new Location<>(this.world, x, y, z);
// TODO: Tile entity data
return new LanternBlockSnapshot(loc, state, ((LanternBlockType) state.getType()).getExtendedBlockStateProvider().get(state, loc, null), getCreator(x, y, z), getNotifier(x, y, z), ImmutableMap.of());
}
use of org.spongepowered.api.world.Location in project LanternServer by LanternPowered.
the class LanternChunk method getBlockSelectionBox.
@Override
public Optional<AABB> getBlockSelectionBox(int x, int y, int z) {
final BlockState block = getBlock(x, y, z);
if (block.getType() == BlockTypes.AIR) {
return Optional.empty();
}
final ObjectProvider<AABB> aabbObjectProvider = ((LanternBlockType) block.getType()).getBoundingBoxProvider();
if (aabbObjectProvider == null) {
return Optional.empty();
}
final AABB aabb;
if (aabbObjectProvider instanceof ConstantObjectProvider || aabbObjectProvider instanceof CachedSimpleObjectProvider || aabbObjectProvider instanceof SimpleObjectProvider) {
aabb = aabbObjectProvider.get(block, null, null);
} else {
aabb = aabbObjectProvider.get(block, new Location<>(this.world, x, y, z), null);
}
return aabb == null ? Optional.empty() : Optional.of(aabb.offset(x, y, z));
}
Aggregations