mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
progress on new metrics
This commit is contained in:
parent
d037263e3f
commit
3e68af06ea
11 changed files with 141 additions and 47 deletions
|
|
@ -3,6 +3,14 @@
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# What service of metric should custom anvil use
|
||||||
|
# Custom anvil collect generic information like server minecraft version, type, etc...
|
||||||
|
# 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
|
||||||
|
metric_type: auto
|
||||||
|
|
||||||
# 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:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,14 @@
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# What service of metric should custom anvil use
|
||||||
|
# Custom anvil collect generic information like server minecraft version, type, etc...
|
||||||
|
# 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
|
||||||
|
metric_type: auto
|
||||||
|
|
||||||
# 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:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,14 @@
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# What service of metric should custom anvil use
|
||||||
|
# Custom anvil collect generic information like server minecraft version, type, etc...
|
||||||
|
# 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
|
||||||
|
metric_type: auto
|
||||||
|
|
||||||
# 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:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,14 @@
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# What service of metric should custom anvil use
|
||||||
|
# Custom anvil collect generic information like server minecraft version, type, etc...
|
||||||
|
# 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
|
||||||
|
metric_type: auto
|
||||||
|
|
||||||
# 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:
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import xyz.alexcrea.cuanvil.update.ModrinthUpdateChecker
|
||||||
import xyz.alexcrea.cuanvil.update.PluginSetDefault
|
import xyz.alexcrea.cuanvil.update.PluginSetDefault
|
||||||
import xyz.alexcrea.cuanvil.update.UpdateHandler
|
import xyz.alexcrea.cuanvil.update.UpdateHandler
|
||||||
import xyz.alexcrea.cuanvil.util.Metrics
|
import xyz.alexcrea.cuanvil.util.Metrics
|
||||||
|
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileReader
|
import java.io.FileReader
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
|
|
@ -34,7 +35,6 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// pluginIDS
|
// pluginIDS
|
||||||
private const val bstatsPluginId = 20923
|
|
||||||
private const val modrinthPluginID = "S75Ueiq9"
|
private const val modrinthPluginID = "S75Ueiq9"
|
||||||
|
|
||||||
// Permission string required to use the plugin's features
|
// Permission string required to use the plugin's features
|
||||||
|
|
@ -156,15 +156,17 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load metrics
|
// Load metrics
|
||||||
try {
|
MetricsUtil.loadMetrics(this)
|
||||||
Metrics(this, bstatsPluginId)
|
|
||||||
} catch (_: Exception) {}
|
|
||||||
|
|
||||||
// Load other thing later.
|
// Load other thing later.
|
||||||
// It is so other dependent plugins can implement there event listener before we fire them.
|
// It is so other dependent plugins can implement there event listener before we fire them.
|
||||||
DependencyManager.scheduler.scheduleGlobally(this) { loadEnchantmentSystemDirty() }
|
DependencyManager.scheduler.scheduleGlobally(this) { loadEnchantmentSystemDirty() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDisable() {
|
||||||
|
MetricsUtil.shutdownMetrics()
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadEnchantmentSystemDirty() {
|
private fun loadEnchantmentSystemDirty() {
|
||||||
try {
|
try {
|
||||||
loadEnchantmentSystem()
|
loadEnchantmentSystem()
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ object ConfigOptions {
|
||||||
// Path for config values
|
// Path for config values
|
||||||
// ----------------------
|
// ----------------------
|
||||||
|
|
||||||
|
const val METRIC_TYPE = "metric_type"
|
||||||
|
|
||||||
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"
|
||||||
const val REMOVE_ANVIL_COST_LIMIT = "remove_repair_limit"
|
const val REMOVE_ANVIL_COST_LIMIT = "remove_repair_limit"
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
||||||
"gui", editConfigCommand,
|
"gui", editConfigCommand,
|
||||||
"reload", ReloadExecutor(),
|
"reload", ReloadExecutor(),
|
||||||
"diagnostic", DiagnosticExecutor(),
|
"diagnostic", DiagnosticExecutor(),
|
||||||
//"debug", DebugExecutor(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
package xyz.alexcrea.cuanvil.command
|
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil
|
|
||||||
import org.bukkit.command.Command
|
|
||||||
import org.bukkit.command.CommandSender
|
|
||||||
import java.util.logging.Level
|
|
||||||
|
|
||||||
class DebugExecutor : CASubCommand() {
|
|
||||||
|
|
||||||
override fun executeCommand(
|
|
||||||
sender: CommandSender,
|
|
||||||
cmd: Command,
|
|
||||||
cmdstr: String,
|
|
||||||
args: Array<out String>
|
|
||||||
): Boolean {
|
|
||||||
CustomAnvil.instance.logger.log(Level.SEVERE, "aaaaaaaaaaaaaaaaaaa");
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
|
|
||||||
//TODO
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -37,6 +37,21 @@ class DiagnosticExecutor: CASubCommand() {
|
||||||
|
|
||||||
companion object{
|
companion object{
|
||||||
private const val NO_DIAG_PERM = "You do not have permission to diagnostic this server"
|
private const val NO_DIAG_PERM = "You do not have permission to diagnostic this server"
|
||||||
|
|
||||||
|
fun fetchNMSType(): String {
|
||||||
|
val packetManager = DependencyManager.packetManager
|
||||||
|
val packetManagerClass = packetManager.javaClass
|
||||||
|
|
||||||
|
val result = when (packetManagerClass) {
|
||||||
|
PaperPacketManager::class.java -> "Paper NMS"
|
||||||
|
ProtocoLibWrapper::class.java -> "Protocolib"
|
||||||
|
NoPacketManager::class.java -> "None"
|
||||||
|
else -> "Version Specific"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return "$result ${if(packetManager.canSetInstantBuild) '✅' else '❌'}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class DiagParams(val value: String) {
|
enum class DiagParams(val value: String) {
|
||||||
|
|
@ -124,7 +139,10 @@ class DiagnosticExecutor: CASubCommand() {
|
||||||
|
|
||||||
fun diagnostic(sender: CommandSender, stb: StringBuilder, params: Set<DiagParams>){
|
fun diagnostic(sender: CommandSender, stb: StringBuilder, params: Set<DiagParams>){
|
||||||
stb.append("Server Info\n")
|
stb.append("Server Info\n")
|
||||||
stb.append("\nPlugin Version: ").append(CustomAnvil.instance.description.version)
|
val version = CustomAnvil.instance.description.version
|
||||||
|
stb.append("\nPlugin Version: ").append(version)
|
||||||
|
if(version.contains("dev")) stb.append(" (alpha)")
|
||||||
|
|
||||||
stb.append("\nLatest Update: ").append(CustomAnvil.latestVer)
|
stb.append("\nLatest Update: ").append(CustomAnvil.latestVer)
|
||||||
stb.append("\nServer Version: ").append(Bukkit.getVersion()).append(" (").append(Bukkit.getName()).append(')')
|
stb.append("\nServer Version: ").append(Bukkit.getVersion()).append(" (").append(Bukkit.getName()).append(')')
|
||||||
stb.append("\nPlugin Enabled: ").append(if(CustomAnvil.instance.isEnabled) "Yes" else "No")
|
stb.append("\nPlugin Enabled: ").append(if(CustomAnvil.instance.isEnabled) "Yes" else "No")
|
||||||
|
|
@ -181,21 +199,6 @@ class DiagnosticExecutor: CASubCommand() {
|
||||||
simulateAnvil(player, stb, sword, enchantedBook, enchantedSword)
|
simulateAnvil(player, stb, sword, enchantedBook, enchantedSword)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchNMSType(): String {
|
|
||||||
val packetManager = DependencyManager.packetManager
|
|
||||||
val packetManagerClass = packetManager.javaClass
|
|
||||||
|
|
||||||
val result = when (packetManagerClass) {
|
|
||||||
PaperPacketManager::class.java -> "Paper NMS"
|
|
||||||
ProtocoLibWrapper::class.java -> "Protocolib"
|
|
||||||
NoPacketManager::class.java -> "None"
|
|
||||||
else -> "Version Specific"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return "$result ${if(packetManager.canSetInstantBuild) '✅' else '❌'}"
|
|
||||||
}
|
|
||||||
|
|
||||||
private val Plugin.pluginNameDisplay: String
|
private val Plugin.pluginNameDisplay: String
|
||||||
get() {
|
get() {
|
||||||
return this.name + " v" + this.description.version
|
return this.name + " v" + this.description.version
|
||||||
|
|
|
||||||
73
src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt
Normal file
73
src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
package xyz.alexcrea.cuanvil.util
|
||||||
|
|
||||||
|
import dev.faststats.bukkit.BukkitMetrics
|
||||||
|
import dev.faststats.core.ErrorTracker
|
||||||
|
import dev.faststats.core.data.Metric
|
||||||
|
import io.delilaheve.CustomAnvil
|
||||||
|
import io.delilaheve.util.ConfigOptions
|
||||||
|
import xyz.alexcrea.cuanvil.command.DiagnosticExecutor
|
||||||
|
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
|
|
||||||
|
object MetricsUtil {
|
||||||
|
|
||||||
|
private const val BSTATS_PLUGIN_ID = 20923
|
||||||
|
private const val FASTSTATS_TOKEN = "fc282b048adcc71a77bc00ace49e8a81"
|
||||||
|
|
||||||
|
private var ERROR_TRACKER: ErrorTracker? = null
|
||||||
|
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 metricType = MetricType.from(metricString)
|
||||||
|
|
||||||
|
val nmsType = DiagnosticExecutor.fetchNMSType()
|
||||||
|
val isAlpha = CustomAnvil.instance.description.version.contains("dev")
|
||||||
|
if(metricType.allowBStats) {
|
||||||
|
try {
|
||||||
|
val metric = Metrics(plugin, BSTATS_PLUGIN_ID)
|
||||||
|
//TODO nms type custom chart
|
||||||
|
} catch (_: Exception) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(metricType.allowFastStats) {
|
||||||
|
ERROR_TRACKER = ErrorTracker.contextAware();
|
||||||
|
FAST_STATS_METRICS = BukkitMetrics.factory()
|
||||||
|
.addMetric(Metric.string("nms_type") { nmsType })
|
||||||
|
.addMetric(Metric.bool("using_alpha") { isAlpha })
|
||||||
|
.errorTracker(ERROR_TRACKER)
|
||||||
|
.token(FASTSTATS_TOKEN)
|
||||||
|
.create(plugin)
|
||||||
|
|
||||||
|
FAST_STATS_METRICS!!.ready()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun shutdownMetrics() {
|
||||||
|
FAST_STATS_METRICS?.shutdown()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun trackError(e: Throwable) {
|
||||||
|
ERROR_TRACKER?.trackError(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun trackError(message: String) {
|
||||||
|
ERROR_TRACKER?.trackError(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class MetricType(
|
||||||
|
val value: String,
|
||||||
|
val allowBStats: Boolean,
|
||||||
|
val allowFastStats: Boolean,
|
||||||
|
) {
|
||||||
|
AUTO("auto", true, true),
|
||||||
|
BSTATS("bstat", true, false),
|
||||||
|
FAST_STATS("faststats", false, true),
|
||||||
|
DISABLED("disabled", false, false),
|
||||||
|
;
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun from(value: String): MetricType = entries.find { it.value == value } ?: AUTO
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,16 @@
|
||||||
#
|
#
|
||||||
# It is recommended that you use /configanvil to edit theses config.
|
# It is recommended that you use /configanvil to edit most of these config.
|
||||||
# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes !
|
# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes !
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# What service of metric should custom anvil use
|
||||||
|
# Custom anvil collect generic information like server minecraft version, type, etc...
|
||||||
|
# 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
|
||||||
|
metric_type: auto
|
||||||
|
|
||||||
# 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:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue