@@ -162,6 +162,9 @@ enum FEATURES {
162162 * - `{ text: '', '#00aced' }` -> `{ text: '', color: '#00aced' }`
163163 */
164164 TEXT_OBJECT_INFERRED_KEYS = 1 << 15 ,
165+
166+ ALLOW_CLICK_EVENTS = 1 << 16 ,
167+ ALLOW_HOVER_EVENTS = 1 << 17 ,
165168}
166169
167170export function compareVersions ( a : string , b : string ) : number {
@@ -288,6 +291,9 @@ export class JsonTextParser {
288291 static maxNestingDepth = 512
289292 static maxArrayLength = 2 ** 31 - 9
290293
294+ // eslint-disable-next-line @typescript-eslint/naming-convention
295+ static FEATURES = FEATURES
296+
291297 static defaultFeatures =
292298 // Minecraft syntax sugar
293299 FEATURES . LITERAL_KEYS |
@@ -298,7 +304,10 @@ export class JsonTextParser {
298304 FEATURES . OPTIONAL_COMMAS |
299305 FEATURES . SHADOW_COLOR_ACCEPTS_STRING |
300306 FEATURES . TEXT_OBJECT_INFERRED_KEYS |
301- FEATURES . IMPLICIT_TEXT_KEY
307+ FEATURES . IMPLICIT_TEXT_KEY |
308+ // Mouse events
309+ FEATURES . ALLOW_CLICK_EVENTS |
310+ FEATURES . ALLOW_HOVER_EVENTS
302311
303312 private s ! : StringStream
304313 private currentNestingDepth = 0
@@ -835,6 +844,9 @@ export class JsonTextParser {
835844 break
836845
837846 case 'clickEvent' : {
847+ if ( ! ( this . enabledFeatures & FEATURES . ALLOW_CLICK_EVENTS ) ) {
848+ this . throwSyntax ( `'clickEvent' field is not allowed` )
849+ }
838850 const event = this . parseLegacyClickEventObject ( )
839851 if ( this . enabledFeatures & FEATURES . MODERN_EVENT_FORMAT ) {
840852 if ( obj . click_event !== undefined ) {
@@ -851,6 +863,9 @@ export class JsonTextParser {
851863 }
852864
853865 case 'click_event' : {
866+ if ( ! ( this . enabledFeatures & FEATURES . ALLOW_CLICK_EVENTS ) ) {
867+ this . throwSyntax ( `'click_event' field is not allowed` )
868+ }
854869 const event = this . parseModernClickEventObject ( )
855870 if ( ! ( this . enabledFeatures & FEATURES . MODERN_EVENT_FORMAT ) ) {
856871 if ( obj . clickEvent !== undefined ) {
@@ -867,6 +882,9 @@ export class JsonTextParser {
867882 }
868883
869884 case 'hoverEvent' : {
885+ if ( ! ( this . enabledFeatures & FEATURES . ALLOW_HOVER_EVENTS ) ) {
886+ this . throwSyntax ( `'hoverEvent' field is not allowed` )
887+ }
870888 const event = this . parseLegacyHoverEventObject ( )
871889 if ( this . enabledFeatures & FEATURES . MODERN_EVENT_FORMAT ) {
872890 if ( obj . hover_event !== undefined ) {
@@ -883,6 +901,9 @@ export class JsonTextParser {
883901 }
884902
885903 case 'hover_event' :
904+ if ( ! ( this . enabledFeatures & FEATURES . ALLOW_HOVER_EVENTS ) ) {
905+ this . throwSyntax ( `'hover_event' field is not allowed` )
906+ }
886907 const event = this . parseModernHoverEventObject ( )
887908 if ( ! ( this . enabledFeatures & FEATURES . MODERN_EVENT_FORMAT ) ) {
888909 if ( obj . hoverEvent !== undefined ) {
0 commit comments