From 7044860267d9934a5e97f9cdce9940defb369193 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Tue, 3 Mar 2026 03:12:35 +0100 Subject: [PATCH] some fix and add disable error telemetry config --- defaultconfigs/1.18/config.yml | 7 ++++++- defaultconfigs/1.21.11/config.yml | 7 ++++++- defaultconfigs/1.21.9/config.yml | 7 ++++++- defaultconfigs/1.21/config.yml | 7 ++++++- .../io/delilaheve/util/ConfigOptions.kt | 1 + .../cuanvil/command/CustomAnvilCmd.kt | 20 ++++++++++++++----- .../xyz/alexcrea/cuanvil/util/MetricsUtil.kt | 11 +++++++--- src/main/resources/config.yml | 7 ++++++- 8 files changed, 54 insertions(+), 13 deletions(-) diff --git a/defaultconfigs/1.18/config.yml b/defaultconfigs/1.18/config.yml index 69a0e18..47070ba 100644 --- a/defaultconfigs/1.18/config.yml +++ b/defaultconfigs/1.18/config.yml @@ -8,9 +8,14 @@ # It can also collect error information if error is happening (currently faststats only) # It can also be disabled # Please refer to README for public metric link -# possible options: auto, bstat, faststats, disabled +# Possible options: auto, bstat, faststats, disabled (auto by default) metric_type: auto +# Allow to report errors made caused by this plugin (only for faststats) +# This allows me to fix potentials issue that I'm not aware of +# Accept true or false (true by default) +metric_collect_errors: true + # All anvil cost will be capped to limit_repair_value if enabled. # # In other words: diff --git a/defaultconfigs/1.21.11/config.yml b/defaultconfigs/1.21.11/config.yml index c281de8..0d9e089 100644 --- a/defaultconfigs/1.21.11/config.yml +++ b/defaultconfigs/1.21.11/config.yml @@ -8,9 +8,14 @@ # It can also collect error information if error is happening (currently faststats only) # It can also be disabled # Please refer to README for public metric link -# possible options: auto, bstat, faststats, disabled +# Possible options: auto, bstat, faststats, disabled (auto by default) metric_type: auto +# Allow to report errors made caused by this plugin (only for faststats) +# This allows me to fix potentials issue that I'm not aware of +# Accept true or false (true by default) +metric_collect_errors: true + # All anvil cost will be capped to limit_repair_value if enabled. # # In other words: diff --git a/defaultconfigs/1.21.9/config.yml b/defaultconfigs/1.21.9/config.yml index de6f020..d3538b2 100644 --- a/defaultconfigs/1.21.9/config.yml +++ b/defaultconfigs/1.21.9/config.yml @@ -8,9 +8,14 @@ # It can also collect error information if error is happening (currently faststats only) # It can also be disabled # Please refer to README for public metric link -# possible options: auto, bstat, faststats, disabled +# Possible options: auto, bstat, faststats, disabled (auto by default) metric_type: auto +# Allow to report errors made caused by this plugin (only for faststats) +# This allows me to fix potentials issue that I'm not aware of +# Accept true or false (true by default) +metric_collect_errors: true + # All anvil cost will be capped to limit_repair_value if enabled. # # In other words: diff --git a/defaultconfigs/1.21/config.yml b/defaultconfigs/1.21/config.yml index ca4f248..c1677fb 100644 --- a/defaultconfigs/1.21/config.yml +++ b/defaultconfigs/1.21/config.yml @@ -8,9 +8,14 @@ # It can also collect error information if error is happening (currently faststats only) # It can also be disabled # Please refer to README for public metric link -# possible options: auto, bstat, faststats, disabled +# Possible options: auto, bstat, faststats, disabled (auto by default) metric_type: auto +# Allow to report errors made caused by this plugin (only for faststats) +# This allows me to fix potentials issue that I'm not aware of +# Accept true or false (true by default) +metric_collect_errors: true + # All anvil cost will be capped to limit_repair_value if enabled. # # In other words: diff --git a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt index 37ec7c0..8bd76d2 100644 --- a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt +++ b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt @@ -22,6 +22,7 @@ object ConfigOptions { // ---------------------- const val METRIC_TYPE = "metric_type" + const val METRIC_COLLECT_ERROR = "metric_collect_errors" const val CAP_ANVIL_COST = "limit_repair_cost" const val MAX_ANVIL_COST = "limit_repair_value" diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCmd.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCmd.kt index e1c2b34..f1fcb88 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCmd.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCmd.kt @@ -6,6 +6,7 @@ import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender import org.bukkit.command.TabCompleter +import xyz.alexcrea.cuanvil.util.MetricsUtil import java.util.ArrayList class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter { @@ -37,10 +38,14 @@ class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter { args: Array ): Boolean { // Find sub command to execute based on the provided command name - val subcmd: CASubCommand? = if(args.isEmpty()) { - editConfigCommand + val subcmd: CASubCommand? + val newargs: Array + if(args.isEmpty()) { + subcmd = editConfigCommand + newargs = args }else { - commands[args[0].lowercase()] + subcmd = commands[args[0].lowercase()] + newargs = args.copyOfRange(1, args.size) } if(subcmd == null) { @@ -48,8 +53,13 @@ class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter { return true } - val newargs = args.copyOfRange(1, args.size) - return subcmd.executeCommand(sender, cmd, cmdstr, newargs) + try { + return subcmd.executeCommand(sender, cmd, cmdstr, newargs) + } catch (e: Throwable) { + MetricsUtil.trackError(e) + sender.sendMessage("§cError running this command") + return false + } } override fun onTabComplete( diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt index 460ee3f..ad441a5 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt @@ -17,7 +17,8 @@ object MetricsUtil { private var FAST_STATS_METRICS: BukkitMetrics? = null fun loadMetrics(plugin: CustomAnvil) { - val metricString = ConfigHolder.DEFAULT_CONFIG.config.getString(ConfigOptions.METRIC_TYPE, MetricType.AUTO.value)!! + val config = ConfigHolder.DEFAULT_CONFIG.config + val metricString = config.getString(ConfigOptions.METRIC_TYPE, MetricType.AUTO.value)!! val metricType = MetricType.from(metricString) val nmsType = DiagnosticExecutor.fetchNMSType() @@ -31,15 +32,19 @@ object MetricsUtil { } if(metricType.allowFastStats) { - ERROR_TRACKER = ErrorTracker.contextAware(); + val reportErrors = config.getBoolean(ConfigOptions.METRIC_COLLECT_ERROR, true) + if(reportErrors) + ERROR_TRACKER = ErrorTracker.contextAware() + FAST_STATS_METRICS = BukkitMetrics.factory() .addMetric(Metric.string("nms_type") { nmsType }) + .addMetric(Metric.bool("replace_too_expensive") { ConfigOptions.doReplaceTooExpensive }) .addMetric(Metric.bool("using_alpha") { isAlpha }) .errorTracker(ERROR_TRACKER) .token(FASTSTATS_TOKEN) .create(plugin) - FAST_STATS_METRICS!!.ready() + if(reportErrors) FAST_STATS_METRICS!!.ready() } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 88ed56b..7cc1768 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -8,9 +8,14 @@ # It can also collect error information if error is happening (currently faststats only) # It can also be disabled # Please refer to README for public metric link -# possible options: auto, bstat, faststats, disabled +# Possible options: auto, bstat, faststats, disabled (auto by default) metric_type: auto +# Allow to report errors made caused by this plugin (only for faststats) +# This allows me to fix potentials issue that I'm not aware of +# Accept true or false (true by default) +metric_collect_errors: true + # All anvil cost will be capped to limit_repair_value if enabled. # # In other words: