chipmunkbot-archive/util/parse-selector-component.js

20 lines
5.6 KiB
JavaScript
Raw Permalink Normal View History

2022-11-12 20:32:35 -05:00
/* [{"extra":[{"insertion":"§8§5§6§r§b§lHBot","clickEvent":{"action":"suggest_command","value":"/tell §8§5§6§r§b§lHBot "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"4487fe96-58ef-3fa8-ba8e-95e37dc4916d","name":{"text":"§8§5§6§r§b§lHBot"}}},"text":"§8§5§6§r§b§lHBot","color":"reset"},{"color":"gray","text":", "},{"insertion":"cb614801a949a97c","clickEvent":{"action":"suggest_command","value":"/tell cb614801a949a97c "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"b7459561-9a45-383c-9555-409bc50368a8","name":{"text":"cb614801a949a97c"}}},"text":"cb614801a949a97c","color":"reset"},{"color":"gray","text":", "},{"insertion":"BdKjFY","clickEvent":{"action":"suggest_command","value":"/tell BdKjFY "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"a9160e60-1cd7-353b-af29-cc1ed3de8a62","name":{"text":"BdKjFY"}}},"text":"BdKjFY","color":"reset"},{"color":"gray","text":", "},{"insertion":"ggplay","clickEvent":{"action":"suggest_command","value":"/tell ggplay "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"a0cf4faf-68f3-37d4-9554-beb9f5eba02d","name":{"text":"ggplay"}}},"text":"ggplay","color":"reset"},{"color":"gray","text":", "},{"insertion":"ddd","clickEvent":{"action":"suggest_command","value":"/tell ddd "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"3c4cbc2c-9a59-37db-9948-256ec0ec655f","name":{"text":"ddd"}}},"text":"ddd","color":"reset"},{"color":"gray","text":", "},{"insertion":"j0OGou8Wb+nM9rnz","clickEvent":{"action":"suggest_command","value":"/tell j0OGou8Wb+nM9rnz "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"e38f96f1-9480-36cc-bee3-987987d310d0","name":{"text":"j0OGou8Wb+nM9rnz"}}},"text":"j0OGou8Wb+nM9rnz","color":"reset"},{"color":"gray","text":", "},{"insertion":"legend","clickEvent":{"action":"suggest_command","value":"/tell legend "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"9346a80a-4a67-34a6-b3b8-c8d1932e11eb","name":{"text":"legend"}}},"text":"legend","color":"reset"},{"color":"gray","text":", "},{"insertion":"daniel","clickEvent":{"action":"suggest_command","value":"/tell daniel "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"a3e0de76-f567-38f3-9582-25c73f0b0845","name":{"text":"daniel"}}},"text":"daniel","color":"reset"},{"color":"gray","text":", "},{"insertion":"chayapak","clickEvent":{"action":"suggest_command","value":"/tell chayapak "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"b58cac19-066b-307b-97b1-d6e19ed08d7c","name":{"text":"chayapak"}}},"text":"chayapak","color":"reset"},{"color":"gray","text":", "},{"insertion":"ChipmunkBot","clickEvent":{"action":"suggest_command","value":"/tell ChipmunkBot "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"dc78561c-e347-305b-9d65-4bca047c9d0e","name":{"text":"ChipmunkBot"}}},"text":"ChipmunkBot","color":"reset"},{"color":"gray","text":", "},{"insertion":"DarverYee28","clickEvent":{"action":"suggest_command","value":"/tell DarverYee28 "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"6db0f96e-4db1-399b-b654-605b0a48362d","name":{"text":"DarverYee28"}}},"text":"DarverYee28","color":"reset"},{"color":"gray","text":", "},{"insertion":"LazyDaisy","clickEvent":{"action":"suggest_command","value":"/tell LazyDaisy "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"51ea613b-cc5b-3482-b47a-e06d2fae073e","name":{"text":"LazyDaisy"}}},"text":"LazyDaisy","color":"reset"},{"color":"gray","text":", "},{"insertion":"Lil_Lee","clickEvent":{"action":"suggest_command","value":"/tell Lil_Lee "},"hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:player","id":"a042ece4-e5b8-3aed-92f0-953c9bceb4c7","name":{"text":"Lil_Lee"}}},"text":"Lil_Lee","color":"reset"},{"color":"gray","text":", "},{"insertion":"Soda_Baka","clickEvent"
[{"insertion":"93289f74-d58e-4474-80f4-1359810ee61f","hoverEvent":{"action":"show_entity","contents":{"type":"minecraft:sheep","id":"93289f74-d58e-4474-80f4-1359810ee61f","name":{"translate":"entity.minecraft.sheep"}}},"translate":"entity.minecraft.sheep","color":"reset"}] */
function parseSelectorComponent (comp) {
if (comp.extra) comp = comp.extra
else comp = [comp]
const entities = []
for (let i = 0; i < comp.length; i += 2) {
if (comp[i]?.hoverEvent?.action !== 'show_entity') throw new TypeError('Invalid selector component') // TODO: Check comp[i + 1]
const { hoverEvent: { contents } } = comp[i]
entities.push(contents)
}
return entities
}
module.exports = parseSelectorComponent