some fix and add disable error telemetry config

This commit is contained in:
alexcrea 2026-03-03 03:12:35 +01:00
parent 48f0cab15d
commit 7044860267
Signed by: alexcrea
GPG key ID: E346CD16413450E3
8 changed files with 54 additions and 13 deletions

View file

@ -8,9 +8,14 @@
# It can also collect error information if error is happening (currently faststats only) # It can also collect error information if error is happening (currently faststats only)
# It can also be disabled # It can also be disabled
# Please refer to README for public metric link # 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 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. # All anvil cost will be capped to limit_repair_value if enabled.
# #
# In other words: # In other words:

View file

@ -8,9 +8,14 @@
# It can also collect error information if error is happening (currently faststats only) # It can also collect error information if error is happening (currently faststats only)
# It can also be disabled # It can also be disabled
# Please refer to README for public metric link # 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 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. # All anvil cost will be capped to limit_repair_value if enabled.
# #
# In other words: # In other words:

View file

@ -8,9 +8,14 @@
# It can also collect error information if error is happening (currently faststats only) # It can also collect error information if error is happening (currently faststats only)
# It can also be disabled # It can also be disabled
# Please refer to README for public metric link # 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 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. # All anvil cost will be capped to limit_repair_value if enabled.
# #
# In other words: # In other words:

View file

@ -8,9 +8,14 @@
# It can also collect error information if error is happening (currently faststats only) # It can also collect error information if error is happening (currently faststats only)
# It can also be disabled # It can also be disabled
# Please refer to README for public metric link # 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 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. # All anvil cost will be capped to limit_repair_value if enabled.
# #
# In other words: # In other words:

View file

@ -22,6 +22,7 @@ object ConfigOptions {
// ---------------------- // ----------------------
const val METRIC_TYPE = "metric_type" const val METRIC_TYPE = "metric_type"
const val METRIC_COLLECT_ERROR = "metric_collect_errors"
const val CAP_ANVIL_COST = "limit_repair_cost" const val CAP_ANVIL_COST = "limit_repair_cost"
const val MAX_ANVIL_COST = "limit_repair_value" const val MAX_ANVIL_COST = "limit_repair_value"

View file

@ -6,6 +6,7 @@ import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter import org.bukkit.command.TabCompleter
import xyz.alexcrea.cuanvil.util.MetricsUtil
import java.util.ArrayList import java.util.ArrayList
class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter { class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
@ -37,10 +38,14 @@ class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
args: Array<out String> args: Array<out String>
): Boolean { ): Boolean {
// Find sub command to execute based on the provided command name // Find sub command to execute based on the provided command name
val subcmd: CASubCommand? = if(args.isEmpty()) { val subcmd: CASubCommand?
editConfigCommand val newargs: Array<out String>
if(args.isEmpty()) {
subcmd = editConfigCommand
newargs = args
}else { }else {
commands[args[0].lowercase()] subcmd = commands[args[0].lowercase()]
newargs = args.copyOfRange(1, args.size)
} }
if(subcmd == null) { if(subcmd == null) {
@ -48,8 +53,13 @@ class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
return true return true
} }
val newargs = args.copyOfRange(1, args.size) try {
return subcmd.executeCommand(sender, cmd, cmdstr, newargs) return subcmd.executeCommand(sender, cmd, cmdstr, newargs)
} catch (e: Throwable) {
MetricsUtil.trackError(e)
sender.sendMessage("§cError running this command")
return false
}
} }
override fun onTabComplete( override fun onTabComplete(

View file

@ -17,7 +17,8 @@ object MetricsUtil {
private var FAST_STATS_METRICS: BukkitMetrics? = null private var FAST_STATS_METRICS: BukkitMetrics? = null
fun loadMetrics(plugin: CustomAnvil) { 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 metricType = MetricType.from(metricString)
val nmsType = DiagnosticExecutor.fetchNMSType() val nmsType = DiagnosticExecutor.fetchNMSType()
@ -31,15 +32,19 @@ object MetricsUtil {
} }
if(metricType.allowFastStats) { 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() FAST_STATS_METRICS = BukkitMetrics.factory()
.addMetric(Metric.string("nms_type") { nmsType }) .addMetric(Metric.string("nms_type") { nmsType })
.addMetric(Metric.bool("replace_too_expensive") { ConfigOptions.doReplaceTooExpensive })
.addMetric(Metric.bool("using_alpha") { isAlpha }) .addMetric(Metric.bool("using_alpha") { isAlpha })
.errorTracker(ERROR_TRACKER) .errorTracker(ERROR_TRACKER)
.token(FASTSTATS_TOKEN) .token(FASTSTATS_TOKEN)
.create(plugin) .create(plugin)
FAST_STATS_METRICS!!.ready() if(reportErrors) FAST_STATS_METRICS!!.ready()
} }
} }

View file

@ -8,9 +8,14 @@
# It can also collect error information if error is happening (currently faststats only) # It can also collect error information if error is happening (currently faststats only)
# It can also be disabled # It can also be disabled
# Please refer to README for public metric link # 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 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. # All anvil cost will be capped to limit_repair_value if enabled.
# #
# In other words: # In other words: