handle invalid identifiers, fixes #980
This commit is contained in:
1 parent
8dc1556790
commit
d07fe18bb5
6 files changed
+47
-49
No files matched your search
@@ -17,6 +17,7 @@ import carpet.script.CarpetScriptServer;
|
||||
import carpet.script.EntityEventsGroup;
|
||||
import carpet.script.argument.Vector3Argument;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.utils.InputValidator;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
@@ -249,7 +250,7 @@ public class EntityValue extends Value
|
||||
positive = false;
|
||||
who = who.substring(1);
|
||||
}
|
||||
net.minecraft.tag.Tag<EntityType<?>> eTag = server.getTagManager().getEntityTypes().getTag(new Identifier(who));
|
||||
net.minecraft.tag.Tag<EntityType<?>> eTag = server.getTagManager().getEntityTypes().getTag(InputValidator.identifierOf(who));
|
||||
if (eTag == null) throw new InternalExpressionException(who+" is not a valid entity descriptor");
|
||||
if (positive)
|
||||
{
|
||||
@@ -444,7 +445,7 @@ public class EntityValue extends Value
|
||||
|
||||
put("has_scoreboard_tag", (e, a) -> BooleanValue.of(e.getScoreboardTags().contains(a.getString())));
|
||||
put("has_entity_tag", (e, a) -> {
|
||||
net.minecraft.tag.Tag<EntityType<?>> tag = e.getServer().getTagManager().getEntityTypes().getTag(new Identifier(a.getString()));
|
||||
net.minecraft.tag.Tag<EntityType<?>> tag = e.getServer().getTagManager().getEntityTypes().getTag(InputValidator.identifierOf(a.getString()));
|
||||
if (tag == null) return Value.NULL;
|
||||
return BooleanValue.of(e.getType().isIn(tag));
|
||||
});
|
||||
@@ -609,7 +610,7 @@ public class EntityValue extends Value
|
||||
|
||||
put("brain", (e, a) -> {
|
||||
String module = a.getString();
|
||||
MemoryModuleType<?> moduleType = Registry.MEMORY_MODULE_TYPE.get(new Identifier(module));
|
||||
MemoryModuleType<?> moduleType = Registry.MEMORY_MODULE_TYPE.get(InputValidator.identifierOf(module));
|
||||
if (moduleType == MemoryModuleType.DUMMY) return Value.NULL;
|
||||
if (e instanceof LivingEntity)
|
||||
{
|
||||
@@ -704,7 +705,7 @@ public class EntityValue extends Value
|
||||
return ListValue.wrap(effects);
|
||||
}
|
||||
String effectName = a.getString();
|
||||
StatusEffect potion = Registry.STATUS_EFFECT.get(new Identifier(effectName));
|
||||
StatusEffect potion = Registry.STATUS_EFFECT.get(InputValidator.identifierOf(effectName));
|
||||
if (potion == null)
|
||||
throw new InternalExpressionException("No such an effect: "+effectName);
|
||||
if (!((LivingEntity) e).hasStatusEffect(potion))
|
||||
@@ -848,7 +849,7 @@ public class EntityValue extends Value
|
||||
AttributeContainer container = el.getAttributes();
|
||||
return MapValue.wrap(Registry.ATTRIBUTE.stream().filter(container::hasAttribute).collect(Collectors.toMap(aa -> ValueConversions.of(Registry.ATTRIBUTE.getId(aa)), aa -> NumericValue.of(container.getValue(aa)))));
|
||||
}
|
||||
Identifier id = new Identifier(a.getString());
|
||||
Identifier id = InputValidator.identifierOf(a.getString());
|
||||
EntityAttribute attrib = Registry.ATTRIBUTE.getOrEmpty(id).orElseThrow(
|
||||
() -> new InternalExpressionException("Unknown attribute: "+a.getString())
|
||||
);
|
||||
@@ -1360,7 +1361,7 @@ public class EntityValue extends Value
|
||||
if (lv.size() >= 1 && lv.size() <= 6)
|
||||
{
|
||||
String effectName = lv.get(0).getString();
|
||||
StatusEffect effect = Registry.STATUS_EFFECT.get(new Identifier(effectName));
|
||||
StatusEffect effect = Registry.STATUS_EFFECT.get(InputValidator.identifierOf(effectName));
|
||||
if (effect == null)
|
||||
throw new InternalExpressionException("Wrong effect name: "+effectName);
|
||||
if (lv.size() == 1)
|
||||
@@ -1393,7 +1394,7 @@ public class EntityValue extends Value
|
||||
else
|
||||
{
|
||||
String effectName = v.getString();
|
||||
StatusEffect effect = Registry.STATUS_EFFECT.get(new Identifier(effectName));
|
||||
StatusEffect effect = Registry.STATUS_EFFECT.get(InputValidator.identifierOf(effectName));
|
||||
if (effect == null)
|
||||
throw new InternalExpressionException("Wrong effect name: "+effectName);
|
||||
le.removeStatusEffect(effect);
|
||||
|
||||
Reference in new issue
Block a user