Added block command argument type

This commit is contained in:
Felix Cravic 2020-11-27 11:24:32 +01:00
parent 80d899a53a
commit cac3c29e41
5 changed files with 34 additions and 10 deletions

View File

@ -7,10 +7,7 @@ import net.minestom.server.command.builder.CommandDispatcher;
import net.minestom.server.command.builder.CommandSyntax;
import net.minestom.server.command.builder.arguments.*;
import net.minestom.server.command.builder.arguments.minecraft.*;
import net.minestom.server.command.builder.arguments.minecraft.registry.ArgumentEnchantment;
import net.minestom.server.command.builder.arguments.minecraft.registry.ArgumentEntityType;
import net.minestom.server.command.builder.arguments.minecraft.registry.ArgumentParticle;
import net.minestom.server.command.builder.arguments.minecraft.registry.ArgumentPotionEffect;
import net.minestom.server.command.builder.arguments.minecraft.registry.*;
import net.minestom.server.command.builder.arguments.number.ArgumentDouble;
import net.minestom.server.command.builder.arguments.number.ArgumentFloat;
import net.minestom.server.command.builder.arguments.number.ArgumentInteger;
@ -502,7 +499,7 @@ public final class CommandManager {
// You can uncomment this to test any brigadier parser on the client
/*DeclareCommandsPacket.Node testNode = simpleArgumentNode(nodes, argument, executable, false);
testNode.parser = "minecraft:vec3";
testNode.parser = "minecraft:block_state";
if (true) {
return nodes;
@ -628,6 +625,9 @@ public final class CommandManager {
} else if (argument instanceof ArgumentEntityType) {
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(nodes, argument, executable, false);
argumentNode.parser = "minecraft:entity_summon";
} else if (argument instanceof ArgumentBlockState) {
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(nodes, argument, executable, false);
argumentNode.parser = "minecraft:block_state";
} else if (argument instanceof ArgumentIntRange) {
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(nodes, argument, executable, false);
argumentNode.parser = "minecraft:int_range";

View File

@ -3,6 +3,7 @@ package net.minestom.server.command.builder;
import net.minestom.server.chat.ChatColor;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.EntityType;
import net.minestom.server.instance.block.Block;
import net.minestom.server.item.Enchantment;
import net.minestom.server.item.ItemStack;
import net.minestom.server.particle.Particle;
@ -98,6 +99,11 @@ public final class Arguments {
return (EntityType) getObject(id);
}
@NotNull
public Block getBlockState(@NotNull String id) {
return (Block) getObject(id);
}
@NotNull
public IntRange getIntRange(@NotNull String id) {
return (IntRange) getObject(id);

View File

@ -1,10 +1,7 @@
package net.minestom.server.command.builder.arguments;
import net.minestom.server.command.builder.arguments.minecraft.*;
import net.minestom.server.command.builder.arguments.minecraft.registry.ArgumentEnchantment;
import net.minestom.server.command.builder.arguments.minecraft.registry.ArgumentEntityType;
import net.minestom.server.command.builder.arguments.minecraft.registry.ArgumentParticle;
import net.minestom.server.command.builder.arguments.minecraft.registry.ArgumentPotionEffect;
import net.minestom.server.command.builder.arguments.minecraft.registry.*;
import net.minestom.server.command.builder.arguments.number.ArgumentDouble;
import net.minestom.server.command.builder.arguments.number.ArgumentFloat;
import net.minestom.server.command.builder.arguments.number.ArgumentInteger;
@ -91,6 +88,10 @@ public class ArgumentType {
return new ArgumentEntityType(id);
}
public static ArgumentBlockState BlockState(@NotNull String id) {
return new ArgumentBlockState(id);
}
public static ArgumentIntRange IntRange(@NotNull String id) {
return new ArgumentIntRange(id);
}

View File

@ -0,0 +1,17 @@
package net.minestom.server.command.builder.arguments.minecraft.registry;
import net.minestom.server.instance.block.Block;
import net.minestom.server.registry.Registries;
import org.jetbrains.annotations.NotNull;
public class ArgumentBlockState extends ArgumentRegistry<Block> {
public ArgumentBlockState(@NotNull String id) {
super(id);
}
@Override
public Block getRegistry(String value) {
return Registries.getBlock(value);
}
}

View File

@ -11,7 +11,7 @@ public abstract class ArgumentRegistry<T> extends Argument<T> {
super(id);
}
public abstract T getRegistry(String value);
public abstract T getRegistry(@NotNull String value);
@Override
public int getCorrectionResult(@NotNull String value) {