From 6f54d3d23d4dc3dc37ab84ed7f2cd7dd825b7a12 Mon Sep 17 00:00:00 2001 From: Frej Alexander Nielsen Date: Sat, 9 Sep 2023 17:31:47 +0200 Subject: [PATCH 1/4] Handle unknown scoreboard objectives --- lib/plugins/scoreboard.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/plugins/scoreboard.js b/lib/plugins/scoreboard.js index fa071f09f..916b4ff12 100644 --- a/lib/plugins/scoreboard.js +++ b/lib/plugins/scoreboard.js @@ -19,6 +19,10 @@ function inject (bot) { } if (packet.action === 2) { + if(!(packet.name in scoreboards)) { + bot.emit('error', `Received update for unknown objective ${packet.name}`) + return + } scoreboards[packet.name].setTitle(packet.displayText) bot.emit('scoreboardTitleChanged', scoreboards[packet.name]) } From 955d4bb901775e21a239e19a39b1fd82e89e6903 Mon Sep 17 00:00:00 2001 From: Frej Alexander Nielsen Date: Sat, 9 Sep 2023 17:36:02 +0200 Subject: [PATCH 2/4] Fix lint --- lib/plugins/scoreboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/scoreboard.js b/lib/plugins/scoreboard.js index 916b4ff12..c6dd0814e 100644 --- a/lib/plugins/scoreboard.js +++ b/lib/plugins/scoreboard.js @@ -19,7 +19,7 @@ function inject (bot) { } if (packet.action === 2) { - if(!(packet.name in scoreboards)) { + if (!(packet.name in scoreboards)) { bot.emit('error', `Received update for unknown objective ${packet.name}`) return } From e9e81ace891c3e42a8e1a3687e29a8b8bafc02d3 Mon Sep 17 00:00:00 2001 From: Frej Alexander Nielsen Date: Sat, 9 Sep 2023 17:41:31 +0200 Subject: [PATCH 3/4] Throw as error instead of string --- lib/plugins/scoreboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/scoreboard.js b/lib/plugins/scoreboard.js index c6dd0814e..cc7e204b3 100644 --- a/lib/plugins/scoreboard.js +++ b/lib/plugins/scoreboard.js @@ -20,7 +20,7 @@ function inject (bot) { if (packet.action === 2) { if (!(packet.name in scoreboards)) { - bot.emit('error', `Received update for unknown objective ${packet.name}`) + bot.emit('error', new Error(`Received update for unknown objective ${packet.name}`)) return } scoreboards[packet.name].setTitle(packet.displayText) From a97e8ed5737249663b0bea1ec9dfef06d21bb86c Mon Sep 17 00:00:00 2001 From: Frej Alexander Nielsen Date: Sat, 9 Sep 2023 20:00:22 +0200 Subject: [PATCH 4/4] Use Object.hasOwn instead of in operator --- lib/plugins/scoreboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/scoreboard.js b/lib/plugins/scoreboard.js index cc7e204b3..f29d669f2 100644 --- a/lib/plugins/scoreboard.js +++ b/lib/plugins/scoreboard.js @@ -19,7 +19,7 @@ function inject (bot) { } if (packet.action === 2) { - if (!(packet.name in scoreboards)) { + if (!Object.hasOwn(scoreboards, packet.name)) { bot.emit('error', new Error(`Received update for unknown objective ${packet.name}`)) return }