mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Add demo SetBlockCommand
This commit is contained in:
parent
65e4aad416
commit
9c97302a06
@ -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)));
|
||||
|
||||
|
22
src/test/java/demo/commands/SetBlockCommand.java
Normal file
22
src/test/java/demo/commands/SetBlockCommand.java
Normal 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"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user