Permalink
Browse files

Fixed issues with entity highlighting and scores= for entitity selctors

  • Loading branch information...
42iscool42 committed Apr 4, 2018
1 parent b9307ec commit 1c07c335bc75183654a5087dda02e193c3b6a958
Showing with 29 additions and 13 deletions.
  1. +1 −1 CommandTree.py
  2. +2 −1 Data.py
  3. +24 −9 Parser.py
  4. +2 −2 commands.json

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -9,7 +9,8 @@
NBT_COMPOUND_TAGS = ["recipeBook","Leash","pages","abilities","Entity","RootVehicle","Passengers","Tags","CommandStats","SelectedItem","EnderItems","DecorItem","Item","ArmorItem","SaddleItem","Offers","Recipes","buy","buyB","sell","tag","Potion","SpawnPotentials","Properties","SpawnData","TileEntityData","Effects","0","1","2","3","4","Pose","BeamTarget","FireworksItem","Explosion","Explosions","Fireworks","Colors","FadeColors","Owner","Target","Patterns","ExitPortal","RecordItem","Textures","CanDestroy","CanPlaceOn","ench","BlockEntityTag","display","SkullOwner","textures","Value","SKIN","CAPE","EntityTag","Decorations","ShoulderEntityLeft","ShoulderEntityRight"]
NBT_STRING_LIST_TAGS = ["Lore", "Tags"]
NBT_INTEGER_LIST_TAGS = ["Colors", "FadeColors"]
NBT_FLOAT_LIST_TAGS = ["Pos","Motion","direction","power","Body","LeftArm","RightArm","LeftLeg","RightLeg","Head","Rotation"]
NBT_FLOAT_LIST_TAGS = ["Pos","power","Body","LeftArm","RightArm","LeftLeg","RightLeg","Head","Rotation"]
NBT_DOUBLE_LIST_TAGS = ["Motion","direction","Power"]
NBT_COMPOUNT_LIST_TAGS = ["Attributes", "ActiveEffects", "HandItems","ArmorItems","Inventory","Items","CustomPotionEffects","AttributeModifiers","StoredEnchantments","textures","Passengers"]
PARTICLES = ["ambient_entity_effect","angry_villager","block","damage_indicator","dragon_breath","dripping_lava","dripping_water","dust","effect","elder_guardian","enchant","enchanted_hit","end_rod","entity_effect","explosion","explosion_emitter","falling_dust","firework","fishing","happy_villager","instant_effect","item","item_slime","item_snowball","large_smoke","mycelium","poof","rain","sweep_attack","totem_of_undying","underwater","witch", "smoke"]
JSON_STRING_KEYS = ["text","insertion","title","author","translate","command","keybind"]
@@ -15,7 +15,7 @@ class Parser:
"axes" : re.compile("[xyz]+"),
"entity_tag" : re.compile("\w+"),
"entity_tag_key" : re.compile("(\w+)[\t ]*(=)"),
"entity_tag_advancement_key" : re.compile("([a-z_\-1-9]+:)?([a-z_]+)[\t ]*(=)"),
"entity_tag_advancement_key" : re.compile("([a-z_\-1-9]+:)?(\w+)[\t ]*(=)"),
"nbt_key" : re.compile("(\w+)[\t ]*:"),
"nbt_boolean" : re.compile("[01]"),
"color" : re.compile("none|black|dark_blue|dark_green|dark_aqua|dark_red|dark_purple|gold|gray|dark_gray|blue|green|aqua|red|light_purple|yellow|white"),
@@ -35,7 +35,8 @@ class Parser:
"operation" : re.compile("[+\-\*\%\/]?=|>?<|>"),
"entity_anchor" : re.compile("feet|eyes"),
"resource_location" : re.compile("([\w]+:)?([\w\.]+)"),
"potions" : re.compile("(minecraft:)?(water|mundane|thick|awkward|night_vision|long_night_vision|invisibility|long_invisibility|leaping|strong_leaping|long_leaping|fire_resistance|long_fire_resistance|swiftness|strong_swiftness|long_swiftness|slowness|long_slowness|water_breathing|long_water_breathing|healing|strong_healing|strong_harming|poison|strong_poison|long_poison|regeneration|strong_regeneration|long_regeneration|strength|strong_strength|long_strength|weakness|long_weakness|luck|turtle_master|strong_turtle_master|long_turtle_master)")
"potions" : re.compile("(minecraft:)?(water|mundane|thick|awkward|night_vision|long_night_vision|invisibility|long_invisibility|leaping|strong_leaping|long_leaping|fire_resistance|long_fire_resistance|swiftness|strong_swiftness|long_swiftness|slowness|long_slowness|water_breathing|long_water_breathing|healing|strong_healing|strong_harming|poison|strong_poison|long_poison|regeneration|strong_regeneration|long_regeneration|strength|strong_strength|long_strength|weakness|long_weakness|luck|turtle_master|strong_turtle_master|long_turtle_master)"),
"sound" : re.compile("(\w+\.)+\w+")
}
def __init__(self, view):
@@ -52,6 +53,7 @@ def __init__(self, view):
self.nbt_value_parsers = [
(self.nbt_list_parser, self.string_parser, None, ""),
(self.nbt_list_parser, self.float_parser, self.mccconstant, "d"),
(self.nbt_list_parser, self.integer_parser, None, ""),
(self.nbt_value_parser, self.float_parser, self.mccconstant, "d"),
(self.nbt_list_parser, self.nbt_parser, None, ""),
@@ -655,7 +657,9 @@ def integer_parser(self, properties={}):
def block_parser(self, properties={}):
start = self.current
lenient = False
if self.current < len(self.string) and self.string[self.current] == "#":
lenient=True
self.current += 1
block_match = self.regex["item_block_id"].match(self.string, self.current)
@@ -673,9 +677,9 @@ def block_parser(self, properties={}):
block_name = block_match.group(0)
if block_name in BLOCKS:
states = BLOCKS[block_name]
properties = BLOCKS[block_name]["properties"]
else:
states = {}
properties = {}
if self.current >= len(self.string) or self.string[self.current] != "[":
return self.nbt_parser(properties)
@@ -694,11 +698,12 @@ def block_parser(self, properties={}):
return self.current + 1
key = key_match.group(1)
if key in states:
if lenient or key in properties:
self.mccstring.append(sublime.Region(self.region_begin + key_match.start(1), self.region_begin + key_match.end(1)))
else:
self.invalid.append(sublime.Region(self.region_begin + key_match.start(1), self.region_begin + key_match.end(1)))
self.mcccommand.append(sublime.Region(self.region_begin + key_match.start(2), self.region_begin + key_match.end(2)))
self.current = key_match.end()
reached_end = self.skip_whitespace(start_of_key)
if reached_end:
@@ -709,10 +714,11 @@ def block_parser(self, properties={}):
self.invalid.append(sublime.Region(self.region_begin + self.current, self.region_begin + self.current + 1))
return self.current + 1
if key in states and value_match.group(0) in states[key]:
self.mccstring.append(self.region_begin + value_match.start(), self.region_begin + value_match.end())
print("Key: " + key +" value: " + value_match.group())
if lenient or (key in properties and value_match.group() in properties[key]):
self.mccstring.append(sublime.Region(self.region_begin + value_match.start(), self.region_begin + value_match.end()))
else:
self.invalid.append(self.region_begin + value_match.start(), self.region_begin + value_match.end())
self.invalid.append(sublime.Region(self.region_begin + value_match.start(), self.region_begin + value_match.end()))
self.current = value_match.end()
reached_end = self.skip_whitespace(start_of_key)
@@ -1134,6 +1140,9 @@ def json_score_parser(self, properties={}):
def objective_criteria_parser(self, properties={}):
return self.string_parser({"type":"word"})
def entity_location_parser(self, properties={}):
return self.regex_parser(self.regex["entity"], [self.mccliteral, self.mccstring])
def resource_location_parser(self, properties={}):
return self.regex_parser(self.regex["resource_location"], [self.mccliteral, self.mccstring])
@@ -1167,6 +1176,9 @@ def scoreboard_operation_parser(self, properties={}):
def mob_effect_parser(self, proeprties={}):
return self.regex_parser(self.regex["potions"], [self.mccliteral, self.mccstring])
def sound_parser(self, properties={}):
return self.regex_parser(self.regex["sound"], [self.mccstring])
def regex_parser(self, pattern, scopes, properties={}):
pattern_match = pattern.match(self.string, self.current)
if pattern_match:
@@ -1247,12 +1259,15 @@ def generate_quote(self, escape_depth):
"minecraft:entity_anchor" : entity_anchor_parser,
"minecraft:operation" : scoreboard_operation_parser, # +=, = , <>, etc
"minecraft:range" : brigadier_range_parser,
"minecraft:mob_effect" : mob_effect_parser,
"minecraft:sound" : sound_parser,
"minecraft:objective_criteria":objective_criteria_parser,
"minecraft:mob_effect" : mob_effect_parser
"minecraft:entity_location": entity_location_parser
}
nbt_key_lists = [
NBT_STRING_LIST_TAGS,
NBT_DOUBLE_LIST_TAGS,
NBT_INTEGER_LIST_TAGS,
NBT_DOUBLE_TAGS,
NBT_COMPOUNT_LIST_TAGS,
@@ -2758,7 +2758,7 @@
"children": {
"sound": {
"type": "argument",
"parser": "minecraft:resource_location",
"parser": "minecraft:sound",
"children": {
"ambient": {
"type": "literal",
@@ -4006,7 +4006,7 @@
"children": {
"entity": {
"type": "argument",
"parser": "minecraft:resource_location",
"parser": "minecraft:entity_location",
"children": {
"pos": {
"type": "argument",

0 comments on commit 1c07c33

Please sign in to comment.