mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Fix item stack argument
This commit is contained in:
parent
13b7039721
commit
de944edf42
@ -24,6 +24,7 @@ public class ArgumentItemStack extends Argument<ItemStack> {
|
|||||||
|
|
||||||
public static final int NO_MATERIAL = 1;
|
public static final int NO_MATERIAL = 1;
|
||||||
public static final int INVALID_NBT = 2;
|
public static final int INVALID_NBT = 2;
|
||||||
|
public static final int INVALID_MATERIAL = 3;
|
||||||
|
|
||||||
public ArgumentItemStack(String id) {
|
public ArgumentItemStack(String id) {
|
||||||
super(id, true);
|
super(id, true);
|
||||||
@ -56,11 +57,15 @@ public class ArgumentItemStack extends Argument<ItemStack> {
|
|||||||
if (nbtIndex == -1) {
|
if (nbtIndex == -1) {
|
||||||
// Only material name
|
// Only material name
|
||||||
final Material material = Material.fromNamespaceId(input);
|
final Material material = Material.fromNamespaceId(input);
|
||||||
|
if (material == null)
|
||||||
|
throw new ArgumentSyntaxException("Material is invalid", input, INVALID_MATERIAL);
|
||||||
return ItemStack.of(material);
|
return ItemStack.of(material);
|
||||||
} else {
|
} else {
|
||||||
// Material plus additional NBT
|
// Material plus additional NBT
|
||||||
final String materialName = input.substring(0, nbtIndex);
|
final String materialName = input.substring(0, nbtIndex);
|
||||||
final Material material = Material.fromNamespaceId(materialName);
|
final Material material = Material.fromNamespaceId(materialName);
|
||||||
|
if (material == null)
|
||||||
|
throw new ArgumentSyntaxException("Material is invalid", input, INVALID_MATERIAL);
|
||||||
|
|
||||||
final String sNBT = input.substring(nbtIndex).replace("\\\"", "\"");
|
final String sNBT = input.substring(nbtIndex).replace("\\\"", "\"");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user