mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 11:38:03 +01:00
Added ArgumentNbtCompoundTag and ArgumentNbtTag
This commit is contained in:
parent
e1093769e5
commit
6217280466
@ -1,3 +1,3 @@
|
|||||||
asmVersion=8.0.1
|
asmVersion=8.0.1
|
||||||
mixinVersion=0.8
|
mixinVersion=0.8
|
||||||
hephaistos_version=v1.1.2
|
hephaistos_version=v1.1.4
|
@ -515,6 +515,12 @@ public final class CommandManager {
|
|||||||
} else if (argument instanceof ArgumentItemStack) {
|
} else if (argument instanceof ArgumentItemStack) {
|
||||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(nodes, argument, executable, false);
|
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(nodes, argument, executable, false);
|
||||||
argumentNode.parser = "minecraft:item_stack";
|
argumentNode.parser = "minecraft:item_stack";
|
||||||
|
} else if (argument instanceof ArgumentNbtCompoundTag) {
|
||||||
|
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(nodes, argument, executable, false);
|
||||||
|
argumentNode.parser = "minecraft:nbt_compound_tag";
|
||||||
|
} else if (argument instanceof ArgumentNbtTag) {
|
||||||
|
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(nodes, argument, executable, false);
|
||||||
|
argumentNode.parser = "minecraft:nbt_tag";
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodes;
|
return nodes;
|
||||||
|
@ -10,6 +10,8 @@ import net.minestom.server.potion.PotionEffect;
|
|||||||
import net.minestom.server.utils.math.FloatRange;
|
import net.minestom.server.utils.math.FloatRange;
|
||||||
import net.minestom.server.utils.math.IntRange;
|
import net.minestom.server.utils.math.IntRange;
|
||||||
import net.minestom.server.utils.time.UpdateOption;
|
import net.minestom.server.utils.time.UpdateOption;
|
||||||
|
import org.jglrxavpok.hephaistos.nbt.NBT;
|
||||||
|
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -94,6 +96,14 @@ public class Arguments {
|
|||||||
return (ItemStack) getObject(id);
|
return (ItemStack) getObject(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NBTCompound getNbtCompound(String id) {
|
||||||
|
return (NBTCompound) getObject(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBT getNBT(String id) {
|
||||||
|
return (NBT) getObject(id);
|
||||||
|
}
|
||||||
|
|
||||||
public Object getObject(String id) {
|
public Object getObject(String id) {
|
||||||
return args.getOrDefault(id, null);
|
return args.getOrDefault(id, null);
|
||||||
}
|
}
|
||||||
|
@ -193,6 +193,7 @@ public class CommandDispatcher {
|
|||||||
if (conditionResult == Argument.SUCCESS) {
|
if (conditionResult == Argument.SUCCESS) {
|
||||||
executorArgs.setArg(argument.getId(), parsedValue);
|
executorArgs.setArg(argument.getId(), parsedValue);
|
||||||
} else {
|
} else {
|
||||||
|
// Condition of an argument not correct, use the argument callback
|
||||||
result.callback = argument.getCallback();
|
result.callback = argument.getCallback();
|
||||||
result.value = argValue;
|
result.value = argValue;
|
||||||
result.error = conditionResult;
|
result.error = conditionResult;
|
||||||
@ -208,6 +209,8 @@ public class CommandDispatcher {
|
|||||||
if (!syntaxesSuggestions.isEmpty()) {
|
if (!syntaxesSuggestions.isEmpty()) {
|
||||||
final int max = syntaxesSuggestions.firstKey(); // number of correct arguments
|
final int max = syntaxesSuggestions.firstKey(); // number of correct arguments
|
||||||
|
|
||||||
|
// Check if at least 1 argument of the syntax is correct
|
||||||
|
if (max > 0) {
|
||||||
// Get the data of the closest syntax
|
// Get the data of the closest syntax
|
||||||
final CommandSuggestionHolder suggestionHolder = syntaxesSuggestions.get(max);
|
final CommandSuggestionHolder suggestionHolder = syntaxesSuggestions.get(max);
|
||||||
final CommandSyntax syntax = suggestionHolder.syntax;
|
final CommandSyntax syntax = suggestionHolder.syntax;
|
||||||
@ -215,7 +218,6 @@ public class CommandDispatcher {
|
|||||||
final int correctionResult = suggestionHolder.correctionResult;
|
final int correctionResult = suggestionHolder.correctionResult;
|
||||||
final int argIndex = suggestionHolder.argIndex;
|
final int argIndex = suggestionHolder.argIndex;
|
||||||
|
|
||||||
if (argValue.length() > 0) {
|
|
||||||
// Found the closest syntax with at least 1 correct argument
|
// Found the closest syntax with at least 1 correct argument
|
||||||
Argument argument = syntax.getArguments()[argIndex];
|
Argument argument = syntax.getArguments()[argIndex];
|
||||||
result.callback = argument.getCallback();
|
result.callback = argument.getCallback();
|
||||||
|
@ -98,4 +98,12 @@ public class ArgumentType {
|
|||||||
return new ArgumentItemStack(id);
|
return new ArgumentItemStack(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ArgumentNbtCompoundTag NbtCompound(String id) {
|
||||||
|
return new ArgumentNbtCompoundTag(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArgumentNbtTag NBT(String id) {
|
||||||
|
return new ArgumentNbtTag(id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import net.minestom.server.registry.Registries;
|
|||||||
import net.minestom.server.utils.NBTUtils;
|
import net.minestom.server.utils.NBTUtils;
|
||||||
import org.jglrxavpok.hephaistos.nbt.NBT;
|
import org.jglrxavpok.hephaistos.nbt.NBT;
|
||||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||||
|
import org.jglrxavpok.hephaistos.nbt.NBTException;
|
||||||
import org.jglrxavpok.hephaistos.nbt.SNBTParser;
|
import org.jglrxavpok.hephaistos.nbt.SNBTParser;
|
||||||
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
@ -37,7 +38,7 @@ public class ArgumentItemStack extends Argument<ItemStack> {
|
|||||||
try {
|
try {
|
||||||
NBT nbt = new SNBTParser(new StringReader(sNBT)).parse();
|
NBT nbt = new SNBTParser(new StringReader(sNBT)).parse();
|
||||||
return nbt instanceof NBTCompound ? SUCCESS : INVALID_NBT;
|
return nbt instanceof NBTCompound ? SUCCESS : INVALID_NBT;
|
||||||
} catch (Exception e) {
|
} catch (NBTException e) {
|
||||||
return INVALID_NBT;
|
return INVALID_NBT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,7 +60,12 @@ public class ArgumentItemStack extends Argument<ItemStack> {
|
|||||||
|
|
||||||
final String sNBT = value.substring(nbtIndex).replace("\\\"", "\"");
|
final String sNBT = value.substring(nbtIndex).replace("\\\"", "\"");
|
||||||
|
|
||||||
final NBTCompound compound = (NBTCompound) new SNBTParser(new StringReader(sNBT)).parse();
|
NBTCompound compound = null;
|
||||||
|
try {
|
||||||
|
compound = (NBTCompound) new SNBTParser(new StringReader(sNBT)).parse();
|
||||||
|
} catch (NBTException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
NBTUtils.loadDataIntoItem(itemStack, compound);
|
NBTUtils.loadDataIntoItem(itemStack, compound);
|
||||||
|
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
package net.minestom.server.command.builder.arguments.minecraft;
|
||||||
|
|
||||||
|
import net.minestom.server.command.builder.arguments.Argument;
|
||||||
|
import org.jglrxavpok.hephaistos.nbt.NBT;
|
||||||
|
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||||
|
import org.jglrxavpok.hephaistos.nbt.NBTException;
|
||||||
|
import org.jglrxavpok.hephaistos.nbt.SNBTParser;
|
||||||
|
|
||||||
|
import java.io.StringReader;
|
||||||
|
|
||||||
|
public class ArgumentNbtCompoundTag extends Argument<NBTCompound> {
|
||||||
|
|
||||||
|
public static final int INVALID_NBT = 1;
|
||||||
|
|
||||||
|
public ArgumentNbtCompoundTag(String id) {
|
||||||
|
super(id, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCorrectionResult(String value) {
|
||||||
|
try {
|
||||||
|
NBT nbt = new SNBTParser(new StringReader(value)).parse();
|
||||||
|
return nbt instanceof NBTCompound ? SUCCESS : INVALID_NBT;
|
||||||
|
} catch (NBTException e) {
|
||||||
|
return INVALID_NBT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NBTCompound parse(String value) {
|
||||||
|
try {
|
||||||
|
NBT nbt = new SNBTParser(new StringReader(value)).parse();
|
||||||
|
return (NBTCompound) nbt;
|
||||||
|
} catch (NBTException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getConditionResult(NBTCompound value) {
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package net.minestom.server.command.builder.arguments.minecraft;
|
||||||
|
|
||||||
|
import net.minestom.server.command.builder.arguments.Argument;
|
||||||
|
import org.jglrxavpok.hephaistos.nbt.NBT;
|
||||||
|
import org.jglrxavpok.hephaistos.nbt.NBTException;
|
||||||
|
import org.jglrxavpok.hephaistos.nbt.SNBTParser;
|
||||||
|
|
||||||
|
import java.io.StringReader;
|
||||||
|
|
||||||
|
public class ArgumentNbtTag extends Argument<NBT> {
|
||||||
|
|
||||||
|
public static final int INVALID_NBT = 1;
|
||||||
|
|
||||||
|
public ArgumentNbtTag(String id) {
|
||||||
|
super(id, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCorrectionResult(String value) {
|
||||||
|
try {
|
||||||
|
NBT nbt = new SNBTParser(new StringReader(value)).parse();
|
||||||
|
return nbt != null ? SUCCESS : INVALID_NBT;
|
||||||
|
} catch (NBTException e) {
|
||||||
|
return INVALID_NBT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NBT parse(String value) {
|
||||||
|
try {
|
||||||
|
NBT nbt = new SNBTParser(new StringReader(value)).parse();
|
||||||
|
return nbt;
|
||||||
|
} catch (NBTException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getConditionResult(NBT value) {
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user