mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
add more usefull metrics
This commit is contained in:
parent
b36c1827a4
commit
944e4b025c
3 changed files with 143 additions and 18 deletions
|
|
@ -8,7 +8,7 @@ import xyz.alexcrea.command.ReloadExecutor
|
|||
import xyz.alexcrea.group.EnchantConflictManager
|
||||
import xyz.alexcrea.group.ItemGroupManager
|
||||
import xyz.alexcrea.util.Metrics
|
||||
import xyz.alexcrea.util.Metrics.SimplePie
|
||||
import xyz.alexcrea.util.MetricsUtil
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
|
||||
|
|
@ -64,11 +64,11 @@ class UnsafeEnchants : JavaPlugin() {
|
|||
*/
|
||||
override fun onEnable() {
|
||||
instance = this
|
||||
// Load bstats
|
||||
val metric = Metrics(this, bstatsPluginId)
|
||||
|
||||
reloadAllConfigs()
|
||||
addCustomMetric(metric)
|
||||
// Load metrics
|
||||
val metric = Metrics(this, bstatsPluginId)
|
||||
MetricsUtil.addCustomMetric(metric)
|
||||
|
||||
// Add command to reload the plugin
|
||||
val command = getCommand(commandReloadName)
|
||||
|
|
@ -102,19 +102,9 @@ class UnsafeEnchants : JavaPlugin() {
|
|||
// Set the global variable
|
||||
UnsafeEnchants.conflictManager = conflictManager
|
||||
UnsafeEnchants.unitRepairConfig = unitRepairConfig
|
||||
}
|
||||
|
||||
private fun addCustomMetric(metric: Metrics) {
|
||||
metric.addCustomChart(SimplePie("item_rename_cost") {
|
||||
ConfigOptions.itemRenameCost.toString()
|
||||
})
|
||||
metric.addCustomChart(SimplePie("item_repair_cost") {
|
||||
ConfigOptions.itemRepairCost.toString()
|
||||
})
|
||||
metric.addCustomChart(SimplePie("sacrifice_illegal_enchant_cost") {
|
||||
ConfigOptions.sacrificeIllegalCost.toString()
|
||||
})
|
||||
|
||||
// Test if default config
|
||||
MetricsUtil.testIfConfigIsDefault(config, itemGroupConfig, conflictConfig, unitRepairConfig)
|
||||
}
|
||||
|
||||
private fun reloadResource(resourceName: String,
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ object ConfigOptions {
|
|||
// Path for removing repair cost limits
|
||||
private const val REMOVE_REPAIR_LIMIT = "remove_repair_limit"
|
||||
// Root path for enchantment limits
|
||||
private const val ENCHANT_LIMIT_ROOT = "enchant_limits"
|
||||
const val ENCHANT_LIMIT_ROOT = "enchant_limits"
|
||||
// Root path for enchantment values
|
||||
private const val ENCHANT_VALUES_ROOT = "enchant_values"
|
||||
const val ENCHANT_VALUES_ROOT = "enchant_values"
|
||||
// Keys for specific enchantment values
|
||||
private const val KEY_BOOK = "book"
|
||||
private const val KEY_ITEM = "item"
|
||||
|
|
@ -194,4 +194,20 @@ object ConfigOptions {
|
|||
?: DEFAULT_ENCHANT_VALUE
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of key of basic config options
|
||||
*/
|
||||
fun getBasicConfigKeys(): Array<String>{
|
||||
return arrayOf(DEFAULT_LIMIT_PATH,
|
||||
LIMIT_REPAIR_COST,
|
||||
LIMIT_REPAIR_VALUE,
|
||||
ITEM_REPAIR_COST,
|
||||
UNIT_REPAIR_COST,
|
||||
ITEM_RENAME_COST,
|
||||
SACRIFICE_ILLEGAL_COST,
|
||||
REMOVE_REPAIR_LIMIT
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
119
src/main/kotlin/xyz/alexcrea/util/MetricsUtil.kt
Normal file
119
src/main/kotlin/xyz/alexcrea/util/MetricsUtil.kt
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
package xyz.alexcrea.util
|
||||
|
||||
import io.delilaheve.UnsafeEnchants
|
||||
import io.delilaheve.util.ConfigOptions
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
|
||||
object MetricsUtil {
|
||||
|
||||
private const val baseConfigHash = -1527723485
|
||||
private const val enchantLimitsConfigHash = 781312397
|
||||
private const val enchantValuesConfigHash = 1072574774
|
||||
private const val enchantConflictConfigHash = 1406650190
|
||||
private const val itemGroupsConfigHash = -1014133828
|
||||
private const val unitRepairItemConfigHash = 536871958
|
||||
private const val baseConfigPieName = "isDefaultBaseConfig"
|
||||
private const val enchantLimitsConfigPieName = "isDefaultEnchantLimitsConfig"
|
||||
private const val enchantValuesConfigPieName = "isDefaultEnchantValuesConfig"
|
||||
private const val enchantConflictConfigPieName = "isDefaultEnchantConflictConfig"
|
||||
private const val itemGroupsConfigPieName = "isDefaultItemGroupsConfig"
|
||||
private const val unitRepairItemConfigPieName = "isDefaultUnitRepairItemConfig"
|
||||
private var isDefaultBaseConfig = true
|
||||
private var isDefaultEnchantLimitsConfig = true
|
||||
private var isDefaultEnchantValuesConfig = true
|
||||
private var isDefaultEnchantConflictConfig = true
|
||||
private var isDefaultItemGroupsConfig = true
|
||||
private var isDefaultUnitRepairItemConfig = true
|
||||
|
||||
/**
|
||||
* Get hash of a key, value a pair of a configuration section
|
||||
*/
|
||||
private fun getHashFromKey(section: ConfigurationSection, key: String): Int {
|
||||
// Key is assumend to exist
|
||||
val resultHash: Int
|
||||
if(section.isConfigurationSection(key)){
|
||||
val sectionResult = getConfigurationHash(section.getConfigurationSection(key)!!)
|
||||
resultHash = key.hashCode() xor sectionResult
|
||||
}else{
|
||||
resultHash = key.hashCode() xor section.getString(key).hashCode()
|
||||
}
|
||||
return resultHash.hashCode()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hash of a configuration section
|
||||
*/
|
||||
private fun getConfigurationHash(section: ConfigurationSection): Int {
|
||||
var resultHash = 0
|
||||
for (key in section.getKeys(false)) {
|
||||
resultHash = resultHash xor getHashFromKey(section,key)
|
||||
}
|
||||
return resultHash
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hash value of the default config
|
||||
*/
|
||||
private fun testBaseConfig(defaultConfig: ConfigurationSection): Int{
|
||||
var result = 0
|
||||
for (key in ConfigOptions.getBasicConfigKeys()) {
|
||||
result = result xor getHashFromKey(defaultConfig,key)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the used configuration is the default config
|
||||
*/
|
||||
fun testIfConfigIsDefault(defaultConfig: ConfigurationSection,
|
||||
enchantConflictConfig: ConfigurationSection,
|
||||
itemGroupsConfig: ConfigurationSection,
|
||||
unitRepairItemConfig: ConfigurationSection){
|
||||
// Calculate hash of config
|
||||
val baseConfig = testBaseConfig(defaultConfig)
|
||||
val limitEnchantConfig = getHashFromKey(defaultConfig, ConfigOptions.ENCHANT_LIMIT_ROOT)
|
||||
val enchantValueConfig =getHashFromKey(defaultConfig, ConfigOptions.ENCHANT_VALUES_ROOT)
|
||||
val enchantConflictConfig2 = getConfigurationHash(enchantConflictConfig)
|
||||
val itemGroupConfig = getConfigurationHash(itemGroupsConfig)
|
||||
val unitRepairConfig = getConfigurationHash(unitRepairItemConfig)
|
||||
// Test if default
|
||||
isDefaultBaseConfig = baseConfigHash == baseConfig
|
||||
isDefaultEnchantLimitsConfig = enchantLimitsConfigHash == limitEnchantConfig
|
||||
isDefaultEnchantValuesConfig = enchantValuesConfigHash == enchantValueConfig
|
||||
isDefaultEnchantConflictConfig = enchantConflictConfigHash == enchantConflictConfig2
|
||||
isDefaultItemGroupsConfig = itemGroupsConfigHash == itemGroupConfig
|
||||
isDefaultUnitRepairItemConfig = unitRepairItemConfigHash == unitRepairConfig
|
||||
// If not default and debug flag active, print the hash.
|
||||
if(ConfigOptions.debugLog){
|
||||
if(!isDefaultBaseConfig){UnsafeEnchants.log("baseConfig: $baseConfig")}
|
||||
if(!isDefaultEnchantLimitsConfig){UnsafeEnchants.log("limitEnchantConfig: $limitEnchantConfig")}
|
||||
if(!isDefaultEnchantValuesConfig){UnsafeEnchants.log("enchantValueConfig: $enchantValueConfig")}
|
||||
if(!isDefaultEnchantConflictConfig){UnsafeEnchants.log("enchantConflictConfig: $enchantConflictConfig")}
|
||||
if(!isDefaultItemGroupsConfig){UnsafeEnchants.log("itemGroupConfig: $itemGroupConfig")}
|
||||
if(!isDefaultUnitRepairItemConfig){UnsafeEnchants.log("unitRepairConfig: $unitRepairConfig")}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun addCustomMetric(metric: Metrics) {
|
||||
metric.addCustomChart(Metrics.SimplePie(baseConfigPieName) {
|
||||
isDefaultBaseConfig.toString()
|
||||
})
|
||||
metric.addCustomChart(Metrics.SimplePie(enchantLimitsConfigPieName) {
|
||||
isDefaultEnchantLimitsConfig.toString()
|
||||
})
|
||||
metric.addCustomChart(Metrics.SimplePie(enchantValuesConfigPieName) {
|
||||
isDefaultEnchantValuesConfig.toString()
|
||||
})
|
||||
metric.addCustomChart(Metrics.SimplePie(enchantConflictConfigPieName) {
|
||||
isDefaultEnchantConflictConfig.toString()
|
||||
})
|
||||
metric.addCustomChart(Metrics.SimplePie(itemGroupsConfigPieName) {
|
||||
isDefaultItemGroupsConfig.toString()
|
||||
})
|
||||
metric.addCustomChart(Metrics.SimplePie(unitRepairItemConfigPieName) {
|
||||
isDefaultUnitRepairItemConfig.toString()
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue