mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
fix metrics
This commit is contained in:
parent
af892aabe0
commit
180459a7b9
6 changed files with 56 additions and 17 deletions
|
|
@ -6,6 +6,7 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import xyz.alexcrea.cuanvil.group.EnchantConflictManager;
|
||||
import xyz.alexcrea.cuanvil.group.ItemGroupManager;
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
|
@ -24,7 +25,11 @@ public abstract class ConfigHolder {
|
|||
CONFLICT_HOLDER = new ConflictConfigHolder();
|
||||
UNIT_REPAIR_HOLDER = new UnitRepairHolder();
|
||||
|
||||
return reloadAllFromDisk(true);
|
||||
boolean result = reloadAllFromDisk(true);
|
||||
if(result){
|
||||
MetricsUtil.INSTANCE.testIfConfigIsDefault();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean reloadAllFromDisk(boolean hardfail){
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.function.Consumer;
|
||||
|
|
@ -104,6 +105,8 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
|||
@Override
|
||||
public boolean onSave() {
|
||||
holder.config.getConfig().set(holder.configPath, now);
|
||||
|
||||
MetricsUtil.INSTANCE.notifyChange(this.holder.config, this.holder.configPath);
|
||||
if(TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
|
||||
return holder.config.saveToDisk(TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
|||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
|
|
@ -181,9 +182,11 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
|
||||
@Override
|
||||
public boolean onSave() {
|
||||
holder.config.getConfig().set(holder.configPath+ITEM_PATH, now);
|
||||
holder.config.getConfig().set(holder.configPath+BOOK_PATH, nowBook);
|
||||
|
||||
MetricsUtil.INSTANCE.notifyChange(this.holder.config, this.holder.configPath);
|
||||
if(TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
|
||||
holder.config.getConfig().set(holder.configPath+ITEM_PATH, now);
|
||||
holder.config.getConfig().set(holder.configPath+BOOK_PATH, nowBook);
|
||||
return holder.config.saveToDisk(TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
|||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
|
@ -205,8 +206,10 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
|
||||
@Override
|
||||
public boolean onSave() {
|
||||
holder.config.getConfig().set(holder.configPath, now);
|
||||
|
||||
MetricsUtil.INSTANCE.notifyChange(this.holder.config, this.holder.configPath);
|
||||
if(TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
|
||||
holder.config.getConfig().set(holder.configPath, now);
|
||||
return holder.config.saveToDisk(TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ import org.bukkit.command.CommandExecutor
|
|||
import org.bukkit.command.CommandSender
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.gui.config.BasicConfigGui
|
||||
import xyz.alexcrea.cuanvil.gui.config.EnchantCostConfigGui
|
||||
import xyz.alexcrea.cuanvil.gui.config.EnchantLimitConfigGui
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||
|
||||
class ReloadExecutor : CommandExecutor {
|
||||
override fun onCommand(sender: CommandSender, cmd: Command, cmdstr: String, args: Array<out String>): Boolean {
|
||||
|
|
@ -36,6 +39,12 @@ class ReloadExecutor : CommandExecutor {
|
|||
|
||||
// Then update all global gui containing value from config
|
||||
BasicConfigGui.INSTANCE.updateGuiValues()
|
||||
EnchantCostConfigGui.INSTANCE.updateGuiValues()
|
||||
EnchantLimitConfigGui.INSTANCE.updateGuiValues()
|
||||
|
||||
// & update metric
|
||||
MetricsUtil.testIfConfigIsDefault()
|
||||
|
||||
return true
|
||||
}catch (e: Exception){
|
||||
e.printStackTrace()
|
||||
|
|
|
|||
|
|
@ -3,14 +3,15 @@ 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 = -1592940914
|
||||
private const val enchantLimitsConfigHash = 781312397
|
||||
private const val enchantLimitsConfigHash = -1014133828
|
||||
private const val enchantValuesConfigHash = 1072574774
|
||||
private const val enchantConflictConfigHash = 1406650190
|
||||
private const val itemGroupsConfigHash = -1014133828
|
||||
private const val itemGroupsConfigHash = 1406650190
|
||||
private const val unitRepairItemConfigHash = 536871958
|
||||
private const val baseConfigPieName = "isDefaultBaseConfig"
|
||||
private const val enchantLimitsConfigPieName = "isDefaultEnchantLimitsConfig"
|
||||
|
|
@ -65,22 +66,19 @@ object MetricsUtil {
|
|||
/**
|
||||
* Test if the used configuration is the default config
|
||||
*/
|
||||
fun testIfConfigIsDefault(defaultConfig: ConfigurationSection,
|
||||
enchantConflictConfig: ConfigurationSection,
|
||||
itemGroupsConfig: ConfigurationSection,
|
||||
unitRepairItemConfig: ConfigurationSection){
|
||||
fun testIfConfigIsDefault(){
|
||||
// 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)
|
||||
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)
|
||||
// Test if default
|
||||
isDefaultBaseConfig = baseConfigHash == baseConfig
|
||||
isDefaultEnchantLimitsConfig = enchantLimitsConfigHash == limitEnchantConfig
|
||||
isDefaultEnchantValuesConfig = enchantValuesConfigHash == enchantValueConfig
|
||||
isDefaultEnchantConflictConfig = enchantConflictConfigHash == enchantConflictConfig2
|
||||
isDefaultEnchantConflictConfig = enchantConflictConfigHash == enchantConflictConfig
|
||||
isDefaultItemGroupsConfig = itemGroupsConfigHash == itemGroupConfig
|
||||
isDefaultUnitRepairItemConfig = unitRepairItemConfigHash == unitRepairConfig
|
||||
// If not default and debug flag active, print the hash.
|
||||
|
|
@ -95,6 +93,24 @@ object MetricsUtil {
|
|||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
fun addCustomMetric(metric: Metrics) {
|
||||
metric.addCustomChart(Metrics.SimplePie(baseConfigPieName) {
|
||||
isDefaultBaseConfig.toString()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue