mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
commit
2dd48a8041
20 changed files with 243 additions and 62 deletions
|
|
@ -13,6 +13,7 @@ Here dependencies are used by custom anvil
|
||||||
- [modrinth-publish](https://github.com/cloudnode-pro/modrinth-publish) by Zefir
|
- [modrinth-publish](https://github.com/cloudnode-pro/modrinth-publish) by Zefir
|
||||||
- [discord-webhook](https://github.com/tsickert/discord-webhook) by tsickert
|
- [discord-webhook](https://github.com/tsickert/discord-webhook) by tsickert
|
||||||
- Thanks [bstats](https://bstats.org/) for keeping me motivated
|
- Thanks [bstats](https://bstats.org/) for keeping me motivated
|
||||||
|
- And [FastStats](https://faststats.dev/) alternative to bstats in beta test
|
||||||
- [ModrinthUpdateChecker](https://github.com/Clickism/ModrinthUpdateChecker) by Clickism and thanks to the modrinth team
|
- [ModrinthUpdateChecker](https://github.com/Clickism/ModrinthUpdateChecker) by Clickism and thanks to the modrinth team
|
||||||
|
|
||||||
### Compatibility
|
### Compatibility
|
||||||
|
|
|
||||||
11
README.md
11
README.md
|
|
@ -68,7 +68,7 @@ Please note that 1.16.5 to 1.17.1 are not officially supported. Run at your own
|
||||||
|
|
||||||
### For custom enchantment plugin developers
|
### For custom enchantment plugin developers
|
||||||
For information about the API, please refer to [the Wiki](https://github.com/alexcrea/CustomAnvil/wiki) \
|
For information about the API, please refer to [the Wiki](https://github.com/alexcrea/CustomAnvil/wiki) \
|
||||||
(Please note that the wiki is currently incomplete)
|
(Please note that the wiki is currently incomplete)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
@ -76,7 +76,14 @@ For information about the API, please refer to [the Wiki](https://github.com/ale
|
||||||
see [Here](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs)
|
see [Here](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs)
|
||||||
|
|
||||||
---
|
---
|
||||||
Custom anvil [use bstat](https://bstats.org/plugin/bukkit/Unsafe%20Enchants%20Plus/20923) for metric. You can [disable it](https://bstats.org/getting-started) if you like.
|
### Metric And Telemetry
|
||||||
|
Custom anvil [use bstat](https://bstats.org/plugin/bukkit/Unsafe%20Enchants%20Plus/20923)
|
||||||
|
and [faststats](https://faststats.dev/project/customanvil/minecraft-plugin) for metric and error reporting.
|
||||||
|
|
||||||
|
You can select specific telemetry or disable all in config.yml. \
|
||||||
|
You can also [disable bstat](https://bstats.org/getting-started) and [faststats](https://faststats.dev/info) in their /plugin folder if you like too.
|
||||||
|
|
||||||
|
faststats is in beta testing please report me or them any error you encounter
|
||||||
|
|
||||||
### Credits and Thanks
|
### Credits and Thanks
|
||||||
Credits and thanks can be seen [here](https://github.com/alexcrea/CustomAnvil/blob/v1.x.x/CREDITS.md)
|
Credits and thanks can be seen [here](https://github.com/alexcrea/CustomAnvil/blob/v1.x.x/CREDITS.md)
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,12 @@ repositories {
|
||||||
|
|
||||||
// ExcellentEnchants
|
// ExcellentEnchants
|
||||||
maven(url = "https://repo.nightexpressdev.com/releases")
|
maven(url = "https://repo.nightexpressdev.com/releases")
|
||||||
|
|
||||||
|
// for fast stats
|
||||||
|
maven {
|
||||||
|
name = "thenextlvlReleases"
|
||||||
|
url = uri("https://repo.thenextlvl.net/releases")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val reobfNMS = providers.gradleProperty("subprojects.reobfnms")
|
val reobfNMS = providers.gradleProperty("subprojects.reobfnms")
|
||||||
|
|
@ -45,6 +51,9 @@ dependencies {
|
||||||
// Spigot api
|
// Spigot api
|
||||||
compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT")
|
compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT")
|
||||||
|
|
||||||
|
// fast stats
|
||||||
|
implementation("dev.faststats.metrics:bukkit:0.16.0")
|
||||||
|
|
||||||
// minimessage
|
// minimessage
|
||||||
implementation("net.kyori:adventure-text-minimessage:4.25.0")
|
implementation("net.kyori:adventure-text-minimessage:4.25.0")
|
||||||
|
|
||||||
|
|
@ -132,7 +141,7 @@ allprojects {
|
||||||
// Set target version
|
// Set target version
|
||||||
tasks.withType<JavaCompile>().configureEach {
|
tasks.withType<JavaCompile>().configureEach {
|
||||||
sourceCompatibility =
|
sourceCompatibility =
|
||||||
"16" // We aim for java 16 for minecraft 1.16.5. even if it not really suported by custom anvil.
|
"16" // We aim for java 16 for minecraft 1.16.5. even if it not really supported by custom anvil.
|
||||||
targetCompatibility = "16"
|
targetCompatibility = "16"
|
||||||
|
|
||||||
options.encoding = "UTF-8"
|
options.encoding = "UTF-8"
|
||||||
|
|
@ -156,7 +165,8 @@ tasks {
|
||||||
archiveFileName.set(name)
|
archiveFileName.set(name)
|
||||||
|
|
||||||
// Shadow necessary dependency
|
// Shadow necessary dependency
|
||||||
relocate("com.github.stefvanschie.inventoryframework", "xyz.alexcrea.inventoryframework")
|
relocate("com.github.stefvanschie.inventoryframework", "xyz.alexcrea.cuanvil.inventoryframework")
|
||||||
|
relocate("dev.faststats", "xyz.alexcrea.cuanvil.faststats")
|
||||||
|
|
||||||
filesMatching("plugin.yml") {
|
filesMatching("plugin.yml") {
|
||||||
expand(
|
expand(
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,19 @@
|
||||||
# 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 (auto by default)
|
||||||
|
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:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,19 @@
|
||||||
# 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 (auto by default)
|
||||||
|
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:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,19 @@
|
||||||
# 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 (auto by default)
|
||||||
|
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:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,19 @@
|
||||||
# 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 (auto by default)
|
||||||
|
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:
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import xyz.alexcrea.cuanvil.group.EnchantConflictManager;
|
import xyz.alexcrea.cuanvil.group.EnchantConflictManager;
|
||||||
import xyz.alexcrea.cuanvil.group.ItemGroupManager;
|
import xyz.alexcrea.cuanvil.group.ItemGroupManager;
|
||||||
import xyz.alexcrea.cuanvil.recipe.CustomAnvilRecipeManager;
|
import xyz.alexcrea.cuanvil.recipe.CustomAnvilRecipeManager;
|
||||||
|
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -145,6 +146,7 @@ public abstract class ConfigHolder {
|
||||||
sufficientSuccess = true;
|
sufficientSuccess = true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not copy backup saving config " + base.getName(), e);
|
CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not copy backup saving config " + base.getName(), e);
|
||||||
|
MetricsUtil.INSTANCE.trackError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// save last backup
|
// save last backup
|
||||||
|
|
@ -275,6 +277,7 @@ public abstract class ConfigHolder {
|
||||||
this.deletedConfigFile.createNewFile();
|
this.deletedConfigFile.createNewFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not create " + this.deletedConfigFile.getPath(), e);
|
CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not create " + this.deletedConfigFile.getPath(), e);
|
||||||
|
MetricsUtil.INSTANCE.trackError(e);
|
||||||
}
|
}
|
||||||
loadDeletedListFile(false);
|
loadDeletedListFile(false);
|
||||||
|
|
||||||
|
|
@ -312,6 +315,7 @@ public abstract class ConfigHolder {
|
||||||
this.deletedListConfig.save(this.deletedConfigFile);
|
this.deletedListConfig.save(this.deletedConfigFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not save " + this.deletedConfigFile.getPath(), e);
|
CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not save " + this.deletedConfigFile.getPath(), e);
|
||||||
|
MetricsUtil.INSTANCE.trackError(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import xyz.alexcrea.cuanvil.enchant.bulk.BukkitEnchantBulkOperation;
|
||||||
import xyz.alexcrea.cuanvil.enchant.bulk.BulkCleanEnchantOperation;
|
import xyz.alexcrea.cuanvil.enchant.bulk.BulkCleanEnchantOperation;
|
||||||
import xyz.alexcrea.cuanvil.enchant.bulk.BulkGetEnchantOperation;
|
import xyz.alexcrea.cuanvil.enchant.bulk.BulkGetEnchantOperation;
|
||||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CABukkitEnchantment;
|
import xyz.alexcrea.cuanvil.enchant.wrapped.CABukkitEnchantment;
|
||||||
|
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
@ -85,11 +86,13 @@ public class CAEnchantmentRegistry {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var error = new IllegalStateException("enchantment " + enchantment.getKey() + " was already registered");
|
||||||
CustomAnvil.instance.getLogger().log(Level.WARNING,
|
CustomAnvil.instance.getLogger().log(Level.WARNING,
|
||||||
"Duplicate distinct registered enchantment. This should NOT happen any time.\n" +
|
"Duplicate distinct registered enchantment. This should NOT happen any time.\n" +
|
||||||
"If you are a custom anvil developer: Maybe custom anvil detected your enchantment as a bukkit enchantment. " +
|
"If you are a custom anvil developer: Maybe custom anvil detected your enchantment as a bukkit enchantment. " +
|
||||||
"you should maybe remove enchantment with the same key before registering yours",
|
"you should maybe remove enchantment with the same key before registering yours",
|
||||||
new IllegalStateException("enchantment " + enchantment.getKey() + " was already registered"));
|
error);
|
||||||
|
MetricsUtil.INSTANCE.trackError(error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
|
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
@ -41,6 +42,7 @@ public class ConfirmActionGui extends AbstractAskGui {
|
||||||
success = onConfirm.get();
|
success = onConfirm.get();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not process confirmation supplier.", e);
|
CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not process confirmation supplier.", e);
|
||||||
|
MetricsUtil.INSTANCE.trackError(e);
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
@ -264,6 +265,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
updateGuiValues();
|
updateGuiValues();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating enchants for " + this.enchantConflict, e);
|
CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating enchants for " + this.enchantConflict, e);
|
||||||
|
MetricsUtil.INSTANCE.trackError(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save file configuration to disk
|
// Save file configuration to disk
|
||||||
|
|
@ -308,6 +310,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
updateGuiValues();
|
updateGuiValues();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating group for " + this.enchantConflict, e);
|
CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating group for " + this.enchantConflict, e);
|
||||||
|
MetricsUtil.INSTANCE.trackError(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save file configuration to disk
|
// Save file configuration to disk
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener
|
||||||
import xyz.alexcrea.cuanvil.update.ModrinthUpdateChecker
|
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.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 +34,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
|
||||||
|
|
@ -118,7 +117,8 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
try {
|
try {
|
||||||
legacyCheck()
|
legacyCheck()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.log(Level.SEVERE, "error trying to check for legacy system" , e)
|
logger.log(Level.SEVERE, "error trying to check for legacy system", e)
|
||||||
|
MetricsUtil.trackError(e)
|
||||||
if(trySafeStart()) return
|
if(trySafeStart()) return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -126,7 +126,8 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
try {
|
try {
|
||||||
prepareCommand()
|
prepareCommand()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.log(Level.SEVERE, "error trying to register commands" , e)
|
logger.log(Level.SEVERE, "error trying to register commands", e)
|
||||||
|
MetricsUtil.trackError(e)
|
||||||
if(trySafeStart()) return
|
if(trySafeStart()) return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,6 +137,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
throw RuntimeException("Error loading configuration file")
|
throw RuntimeException("Error loading configuration file")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.log(Level.SEVERE, "error occurred loading default configuration", e)
|
logger.log(Level.SEVERE, "error occurred loading default configuration", e)
|
||||||
|
MetricsUtil.trackError(e)
|
||||||
if(tryDirtyStart()) return
|
if(tryDirtyStart()) return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,6 +146,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
DependencyManager.loadDependency()
|
DependencyManager.loadDependency()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.log(Level.SEVERE, "error loading dependency compatibility", e)
|
logger.log(Level.SEVERE, "error loading dependency compatibility", e)
|
||||||
|
MetricsUtil.trackError(e)
|
||||||
if(tryDirtyStart()) return
|
if(tryDirtyStart()) return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,24 +155,28 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
registerListeners()
|
registerListeners()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.log(Level.SEVERE, "error registering listeners", e)
|
logger.log(Level.SEVERE, "error registering listeners", e)
|
||||||
|
MetricsUtil.trackError(e)
|
||||||
if(tryDirtyStart()) return
|
if(tryDirtyStart()) return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.log(Level.SEVERE, "error initializing enchantment ssytem", e)
|
logger.log(Level.SEVERE, "error initializing enchantment system", e)
|
||||||
|
MetricsUtil.trackError(e)
|
||||||
tryDirtyStart()
|
tryDirtyStart()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -196,7 +203,10 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
|
|
||||||
ModrinthUpdateChecker(modrinthPluginID, loader, null)
|
ModrinthUpdateChecker(modrinthPluginID, loader, null)
|
||||||
.setFeatured(featured)
|
.setFeatured(featured)
|
||||||
.setOnError { logger.log(Level.WARNING, "error trying to fetch latest update", it) }
|
.setOnError {
|
||||||
|
logger.log(Level.WARNING, "error trying to fetch latest update", it)
|
||||||
|
MetricsUtil.trackError(it)
|
||||||
|
}
|
||||||
.checkVersion { latestVer: String? ->
|
.checkVersion { latestVer: String? ->
|
||||||
CustomAnvil.latestVer = latestVer
|
CustomAnvil.latestVer = latestVer
|
||||||
if(latestVer == null || version.contains(latestVer)) return@checkVersion
|
if(latestVer == null || version.contains(latestVer)) return@checkVersion
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ object ConfigOptions {
|
||||||
// Path for config values
|
// Path for config values
|
||||||
// ----------------------
|
// ----------------------
|
||||||
|
|
||||||
|
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"
|
||||||
const val REMOVE_ANVIL_COST_LIMIT = "remove_repair_limit"
|
const val REMOVE_ANVIL_COST_LIMIT = "remove_repair_limit"
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
@ -20,7 +21,6 @@ class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
||||||
"gui", editConfigCommand,
|
"gui", editConfigCommand,
|
||||||
"reload", ReloadExecutor(),
|
"reload", ReloadExecutor(),
|
||||||
"diagnostic", DiagnosticExecutor(),
|
"diagnostic", DiagnosticExecutor(),
|
||||||
//"debug", DebugExecutor(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
@ -38,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) {
|
||||||
|
|
@ -49,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(
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
|
||||||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.componentLore
|
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.componentLore
|
||||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
|
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
|
||||||
import xyz.alexcrea.cuanvil.util.AnvilUseType
|
import xyz.alexcrea.cuanvil.util.AnvilUseType
|
||||||
|
import xyz.alexcrea.cuanvil.util.MetricsUtil.trackError
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
|
|
||||||
object DependencyManager {
|
object DependencyManager {
|
||||||
|
|
@ -141,6 +142,7 @@ object DependencyManager {
|
||||||
"Error while trying to handle custom anvil supported plugin: ",
|
"Error while trying to handle custom anvil supported plugin: ",
|
||||||
e
|
e
|
||||||
)
|
)
|
||||||
|
trackError(e)
|
||||||
|
|
||||||
// Just in case to avoid illegal items
|
// Just in case to avoid illegal items
|
||||||
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
||||||
|
|
@ -180,6 +182,7 @@ object DependencyManager {
|
||||||
"Error while trying to handle custom anvil supported plugin: ",
|
"Error while trying to handle custom anvil supported plugin: ",
|
||||||
e
|
e
|
||||||
)
|
)
|
||||||
|
trackError(e)
|
||||||
|
|
||||||
// Just in case to avoid illegal items
|
// Just in case to avoid illegal items
|
||||||
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
||||||
|
|
@ -233,6 +236,7 @@ object DependencyManager {
|
||||||
"Error while trying to handle custom anvil supported plugin: ",
|
"Error while trying to handle custom anvil supported plugin: ",
|
||||||
e
|
e
|
||||||
)
|
)
|
||||||
|
trackError(e)
|
||||||
|
|
||||||
// Just in case to avoid illegal items
|
// Just in case to avoid illegal items
|
||||||
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
||||||
|
|
@ -262,6 +266,7 @@ object DependencyManager {
|
||||||
"Error while trying to handle custom anvil supported plugin: ",
|
"Error while trying to handle custom anvil supported plugin: ",
|
||||||
e
|
e
|
||||||
)
|
)
|
||||||
|
trackError(e)
|
||||||
|
|
||||||
// Just in case to avoid illegal items
|
// Just in case to avoid illegal items
|
||||||
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import org.bukkit.inventory.AnvilInventory
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener
|
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener
|
||||||
import xyz.alexcrea.cuanvil.util.AnvilXpUtil
|
import xyz.alexcrea.cuanvil.util.AnvilXpUtil
|
||||||
|
import xyz.alexcrea.cuanvil.util.MetricsUtil.trackError
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
|
@ -38,6 +39,7 @@ class DisenchantmentDependency {
|
||||||
Level.SEVERE, "Could not initialize disenchantment support" +
|
Level.SEVERE, "Could not initialize disenchantment support" +
|
||||||
"please report this bug to the developer", e
|
"please report this bug to the developer", e
|
||||||
)
|
)
|
||||||
|
trackError(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
79
src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt
Normal file
79
src/main/kotlin/xyz/alexcrea/cuanvil/util/MetricsUtil.kt
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
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 config = ConfigHolder.DEFAULT_CONFIG.config
|
||||||
|
val metricString = 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)
|
||||||
|
metric.addCustomChart(Metrics.SimplePie("nms_type") { nmsType })
|
||||||
|
metric.addCustomChart(Metrics.SimplePie("using_alpha") { isAlpha.toString() })
|
||||||
|
} catch (_: Exception) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(metricType.allowFastStats) {
|
||||||
|
val reportErrors = config.getBoolean(ConfigOptions.METRIC_COLLECT_ERROR, true)
|
||||||
|
if(reportErrors)
|
||||||
|
ERROR_TRACKER = ErrorTracker.contextAware()
|
||||||
|
|
||||||
|
FAST_STATS_METRICS = BukkitMetrics.factory()
|
||||||
|
.addMetric(Metric.string("nms_type") { nmsType })
|
||||||
|
.addMetric(Metric.bool("replace_too_expensive") { ConfigOptions.doReplaceTooExpensive })
|
||||||
|
.addMetric(Metric.bool("using_alpha") { isAlpha })
|
||||||
|
.errorTracker(ERROR_TRACKER)
|
||||||
|
.token(FASTSTATS_TOKEN)
|
||||||
|
.create(plugin)
|
||||||
|
|
||||||
|
if(reportErrors) 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,21 @@
|
||||||
#
|
#
|
||||||
# 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 (auto by default)
|
||||||
|
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:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue