Add demo SetBlockCommand

This commit is contained in:
TheMode 2021-06-16 14:39:11 +02:00
parent 65e4aad416
commit 9c97302a06
2 changed files with 23 additions and 0 deletions

View File

@ -49,6 +49,7 @@ public class Main {
commandManager.register(new SummonCommand());
commandManager.register(new RemoveCommand());
commandManager.register(new GiveCommand());
commandManager.register(new SetBlockCommand());
commandManager.setUnknownCommandCallback((sender, command) -> sender.sendMessage(Component.text("Unknown command", NamedTextColor.RED)));

View File

@ -0,0 +1,22 @@
package demo.commands;
import net.minestom.server.command.builder.Command;
import net.minestom.server.entity.Player;
import net.minestom.server.instance.block.Block;
import net.minestom.server.utils.location.RelativeVec;
import static net.minestom.server.command.builder.arguments.ArgumentType.BlockState;
import static net.minestom.server.command.builder.arguments.ArgumentType.RelativeVec3;
public class SetBlockCommand extends Command {
public SetBlockCommand() {
super("setblock");
addSyntax((sender, context) -> {
RelativeVec relativeVec = context.get("position");
Block block = context.get("block");
final Player player = sender.asPlayer();
player.getInstance().setBlock(relativeVec.from(player).toPosition().toBlockPosition(), block);
}, RelativeVec3("position"), BlockState("block"));
}
}