mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-15 23:26:21 +01:00
Added two new commands /summon <entity> <pos> and /remove entities <entities>
This commit is contained in:
parent
a442603067
commit
256ed45fab
@ -49,6 +49,8 @@ public class Main {
|
||||
commandManager.register(new ShootCommand());
|
||||
commandManager.register(new HorseCommand());
|
||||
commandManager.register(new EchoCommand());
|
||||
commandManager.register(new SummonCommand());
|
||||
commandManager.register(new RemoveCommand());
|
||||
|
||||
commandManager.setUnknownCommandCallback((sender, command) -> sender.sendMessage(Component.text("Unknown command", NamedTextColor.RED)));
|
||||
|
||||
|
34
src/test/java/demo/commands/RemoveCommand.java
Normal file
34
src/test/java/demo/commands/RemoveCommand.java
Normal file
@ -0,0 +1,34 @@
|
||||
package demo.commands;
|
||||
|
||||
import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.command.builder.CommandContext;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.command.builder.arguments.minecraft.ArgumentEntity;
|
||||
import net.minestom.server.command.builder.condition.Conditions;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.utils.entity.EntityFinder;
|
||||
|
||||
public class RemoveCommand extends Command {
|
||||
|
||||
public RemoveCommand() {
|
||||
super("remove");
|
||||
addSubcommand(new RemoveEntities());
|
||||
}
|
||||
|
||||
static class RemoveEntities extends Command {
|
||||
private final ArgumentEntity entity;
|
||||
|
||||
public RemoveEntities() {
|
||||
super("entities");
|
||||
setCondition(Conditions::playerOnly);
|
||||
entity = ArgumentType.Entity("entity");
|
||||
addSyntax(this::remove, entity);
|
||||
}
|
||||
|
||||
private void remove(CommandSender commandSender, CommandContext commandContext) {
|
||||
final EntityFinder entityFinder = commandContext.get(entity);
|
||||
entityFinder.find(commandSender).forEach(Entity::remove);
|
||||
}
|
||||
}
|
||||
}
|
33
src/test/java/demo/commands/SummonCommand.java
Normal file
33
src/test/java/demo/commands/SummonCommand.java
Normal file
@ -0,0 +1,33 @@
|
||||
package demo.commands;
|
||||
|
||||
import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.command.builder.CommandContext;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.command.builder.arguments.minecraft.ArgumentEntity;
|
||||
import net.minestom.server.command.builder.arguments.minecraft.registry.ArgumentEntityType;
|
||||
import net.minestom.server.command.builder.arguments.relative.ArgumentRelativeVec3;
|
||||
import net.minestom.server.command.builder.condition.Conditions;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SummonCommand extends Command {
|
||||
|
||||
private final ArgumentEntityType entity;
|
||||
private final ArgumentRelativeVec3 pos;
|
||||
|
||||
public SummonCommand() {
|
||||
super("summon");
|
||||
setCondition(Conditions::playerOnly);
|
||||
|
||||
entity = ArgumentType.EntityType("entity type");
|
||||
pos = ArgumentType.RelativeVec3("pos");
|
||||
addSyntax(this::execute, entity, pos);
|
||||
}
|
||||
|
||||
private void execute(@NotNull CommandSender commandSender, @NotNull CommandContext commandContext) {
|
||||
final Entity entity = new Entity(commandContext.get(this.entity));
|
||||
//noinspection ConstantConditions - One couldn't possibly execute a command without being in an instance
|
||||
entity.setInstance(commandSender.asPlayer().getInstance(), commandContext.get(pos).from(commandSender.asPlayer()).toPosition());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user