mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Remove custom metric
This commit is contained in:
parent
a9c65dfddc
commit
97bf57b8aa
10 changed files with 2 additions and 185 deletions
|
|
@ -15,7 +15,6 @@ import xyz.alexcrea.cuanvil.packet.PacketManager
|
|||
import xyz.alexcrea.cuanvil.packet.ProtocoLibWrapper
|
||||
import xyz.alexcrea.cuanvil.update.Update_1_21
|
||||
import xyz.alexcrea.cuanvil.util.Metrics
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
|
||||
|
|
@ -116,8 +115,7 @@ class CustomAnvil : JavaPlugin() {
|
|||
GuiSharedConstant.loadConstants()
|
||||
|
||||
// Load metrics
|
||||
val metric = Metrics(this, bstatsPluginId)
|
||||
MetricsUtil.addCustomMetric(metric)
|
||||
Metrics(this, bstatsPluginId)
|
||||
|
||||
// Add commands to reload the plugin
|
||||
prepareCommand()
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import org.bukkit.command.CommandExecutor
|
|||
import org.bukkit.command.CommandSender
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.*
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||
|
||||
class ReloadExecutor : CommandExecutor {
|
||||
override fun onCommand(sender: CommandSender, cmd: Command, cmdstr: String, args: Array<out String>): Boolean {
|
||||
|
|
@ -45,9 +44,6 @@ class ReloadExecutor : CommandExecutor {
|
|||
UnitRepairConfigGui.INSTANCE.reloadValues()
|
||||
CustomRecipeConfigGui.INSTANCE.reloadValues()
|
||||
|
||||
// & update metric
|
||||
MetricsUtil.testIfConfigIsDefault()
|
||||
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
|
|
|
|||
|
|
@ -1,160 +0,0 @@
|
|||
package xyz.alexcrea.cuanvil.util
|
||||
|
||||
import io.delilaheve.CustomAnvil
|
||||
import io.delilaheve.util.ConfigOptions
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
|
||||
object MetricsUtil {
|
||||
|
||||
private const val baseConfigHash = 1000387384
|
||||
private const val enchantLimitsConfigHash = -275034280
|
||||
private const val enchantValuesConfigHash = -17048020
|
||||
private const val enchantConflictConfigHash = 546475833
|
||||
private const val itemGroupsConfigHash = 1406650190
|
||||
private const val unitRepairItemConfigHash = 536871958
|
||||
private const val customAnvilCraftConfigHash = 0
|
||||
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 const val customAnvilCraftConfigPieName = "isDefaultCustomAnvilCraftConfig"
|
||||
private var isDefaultBaseConfig = true
|
||||
private var isDefaultEnchantLimitsConfig = true
|
||||
private var isDefaultEnchantValuesConfig = true
|
||||
private var isDefaultEnchantConflictConfig = true
|
||||
private var isDefaultItemGroupsConfig = true
|
||||
private var isDefaultUnitRepairItemConfig = true
|
||||
private var isDefaultCustomAnvilCraftConfig = 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 = if (section.isConfigurationSection(key)) {
|
||||
val sectionResult = getConfigurationHash(section.getConfigurationSection(key)!!)
|
||||
key.hashCode() xor sectionResult
|
||||
} else {
|
||||
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() {
|
||||
// Calculate hash of config
|
||||
val baseConfig = testBaseConfig(ConfigHolder.DEFAULT_CONFIG.config)
|
||||
val limitEnchantConfig = getHashFromKey(ConfigHolder.DEFAULT_CONFIG.config, ConfigOptions.ENCHANT_LIMIT_ROOT)
|
||||
val enchantValueConfig = getHashFromKey(ConfigHolder.DEFAULT_CONFIG.config, ConfigOptions.ENCHANT_VALUES_ROOT)
|
||||
val enchantConflictConfig = getConfigurationHash(ConfigHolder.CONFLICT_HOLDER.config)
|
||||
val itemGroupConfig = getConfigurationHash(ConfigHolder.ITEM_GROUP_HOLDER.config)
|
||||
val unitRepairConfig = getConfigurationHash(ConfigHolder.UNIT_REPAIR_HOLDER.config)
|
||||
val customRecipeConfig = getConfigurationHash(ConfigHolder.CUSTOM_RECIPE_HOLDER.config)
|
||||
// Test if default
|
||||
isDefaultBaseConfig = baseConfigHash == baseConfig
|
||||
isDefaultEnchantLimitsConfig = enchantLimitsConfigHash == limitEnchantConfig
|
||||
isDefaultEnchantValuesConfig = enchantValuesConfigHash == enchantValueConfig
|
||||
isDefaultEnchantConflictConfig = enchantConflictConfigHash == enchantConflictConfig
|
||||
isDefaultItemGroupsConfig = itemGroupsConfigHash == itemGroupConfig
|
||||
isDefaultUnitRepairItemConfig = unitRepairItemConfigHash == unitRepairConfig
|
||||
isDefaultCustomAnvilCraftConfig = customAnvilCraftConfigHash == customRecipeConfig
|
||||
// If not default and debug flag active, print the hash.
|
||||
if (ConfigOptions.debugLog) {
|
||||
if (!isDefaultBaseConfig) {
|
||||
CustomAnvil.log("baseConfig: $baseConfig")
|
||||
}
|
||||
if (!isDefaultEnchantLimitsConfig) {
|
||||
CustomAnvil.log("limitEnchantConfig: $limitEnchantConfig")
|
||||
}
|
||||
if (!isDefaultEnchantValuesConfig) {
|
||||
CustomAnvil.log("enchantValueConfig: $enchantValueConfig")
|
||||
}
|
||||
if (!isDefaultEnchantConflictConfig) {
|
||||
CustomAnvil.log("enchantConflictConfig: $enchantConflictConfig")
|
||||
}
|
||||
if (!isDefaultItemGroupsConfig) {
|
||||
CustomAnvil.log("itemGroupConfig: $itemGroupConfig")
|
||||
}
|
||||
if (!isDefaultUnitRepairItemConfig) {
|
||||
CustomAnvil.log("unitRepairConfig: $unitRepairConfig")
|
||||
}
|
||||
if (!isDefaultCustomAnvilCraftConfig) {
|
||||
CustomAnvil.log("customRecipeConfig: $customRecipeConfig")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun notifyChange(holder: ConfigHolder, path: String) {
|
||||
if (ConfigHolder.DEFAULT_CONFIG.equals(holder)) {
|
||||
if (path.startsWith(ConfigOptions.ENCHANT_LIMIT_ROOT + ".")) {
|
||||
isDefaultEnchantLimitsConfig = false
|
||||
} else if (path.startsWith(ConfigOptions.ENCHANT_VALUES_ROOT + ".")) {
|
||||
isDefaultEnchantValuesConfig = false
|
||||
} else {
|
||||
isDefaultBaseConfig = false
|
||||
}
|
||||
} else if (ConfigHolder.CONFLICT_HOLDER.equals(holder)) {
|
||||
isDefaultEnchantConflictConfig = false
|
||||
} else if (ConfigHolder.ITEM_GROUP_HOLDER.equals(holder)) {
|
||||
isDefaultItemGroupsConfig = false
|
||||
} else if (ConfigHolder.UNIT_REPAIR_HOLDER.equals(holder)) {
|
||||
isDefaultUnitRepairItemConfig = false
|
||||
} else if (ConfigHolder.CUSTOM_RECIPE_HOLDER.equals(holder)) {
|
||||
isDefaultCustomAnvilCraftConfig = false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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()
|
||||
})
|
||||
metric.addCustomChart(Metrics.SimplePie(customAnvilCraftConfigPieName) {
|
||||
isDefaultCustomAnvilCraftConfig.toString()
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue