mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
translation key for load errors and warnings
This commit is contained in:
parent
1f00a32750
commit
c636767078
2 changed files with 71 additions and 37 deletions
|
|
@ -7,8 +7,6 @@ import org.bukkit.plugin.java.JavaPlugin
|
||||||
import xyz.alexcrea.cuanvil.api.event.CAConfigReadyEvent
|
import xyz.alexcrea.cuanvil.api.event.CAConfigReadyEvent
|
||||||
import xyz.alexcrea.cuanvil.api.event.CAEnchantRegistryReadyEvent
|
import xyz.alexcrea.cuanvil.api.event.CAEnchantRegistryReadyEvent
|
||||||
import xyz.alexcrea.cuanvil.command.CustomAnvilCommand
|
import xyz.alexcrea.cuanvil.command.CustomAnvilCommand
|
||||||
import xyz.alexcrea.cuanvil.command.EditConfigExecutor
|
|
||||||
import xyz.alexcrea.cuanvil.command.ReloadExecutor
|
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||||
import xyz.alexcrea.cuanvil.dependency.MinecraftVersionUtil
|
import xyz.alexcrea.cuanvil.dependency.MinecraftVersionUtil
|
||||||
|
|
@ -18,6 +16,7 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
||||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant
|
||||||
import xyz.alexcrea.cuanvil.lang.Lang
|
import xyz.alexcrea.cuanvil.lang.Lang
|
||||||
|
import xyz.alexcrea.cuanvil.lang.Lang.translate
|
||||||
import xyz.alexcrea.cuanvil.listener.AnvilCloseListener
|
import xyz.alexcrea.cuanvil.listener.AnvilCloseListener
|
||||||
import xyz.alexcrea.cuanvil.listener.AnvilResultListener
|
import xyz.alexcrea.cuanvil.listener.AnvilResultListener
|
||||||
import xyz.alexcrea.cuanvil.listener.ChatEventListener
|
import xyz.alexcrea.cuanvil.listener.ChatEventListener
|
||||||
|
|
@ -109,11 +108,23 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error Logging handler
|
||||||
|
*/
|
||||||
|
@JvmStatic fun logError(message: String, throwable: Throwable? = null, track: Boolean = true) {
|
||||||
|
instance.logger.log(Level.SEVERE, message, throwable)
|
||||||
|
addToLogQueue(message)
|
||||||
|
|
||||||
|
if(track && throwable != null) {
|
||||||
|
MetricsUtil.trackError(throwable)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop plugin if we do not force a dirty start (true by default)
|
// stop plugin if we do not force a dirty start (true by default)
|
||||||
// Return true if start was stopped
|
// Return true if start was stopped
|
||||||
private fun tryDirtyStart(): Boolean {
|
private fun tryDirtyStart(): Boolean {
|
||||||
|
if(ConfigHolder.DEFAULT_CONFIG == null) return false
|
||||||
if(!ConfigHolder.DEFAULT_CONFIG.config.getBoolean("dirty_start", false)) {
|
if(!ConfigHolder.DEFAULT_CONFIG.config.getBoolean("dirty_start", false)) {
|
||||||
Bukkit.getPluginManager().disablePlugin(this)
|
Bukkit.getPluginManager().disablePlugin(this)
|
||||||
return true
|
return true
|
||||||
|
|
@ -124,6 +135,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
// stop plugin if we force a safe start (false by default)
|
// stop plugin if we force a safe start (false by default)
|
||||||
// Return true if start was stopped
|
// Return true if start was stopped
|
||||||
private fun trySafeStart(): Boolean {
|
private fun trySafeStart(): Boolean {
|
||||||
|
if(ConfigHolder.DEFAULT_CONFIG == null) return false
|
||||||
if(ConfigHolder.DEFAULT_CONFIG.config.getBoolean("safe_start", false)) {
|
if(ConfigHolder.DEFAULT_CONFIG.config.getBoolean("safe_start", false)) {
|
||||||
Bukkit.getPluginManager().disablePlugin(this)
|
Bukkit.getPluginManager().disablePlugin(this)
|
||||||
return true
|
return true
|
||||||
|
|
@ -141,8 +153,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
if(!ConfigHolder.loadDefaultConfig())
|
if(!ConfigHolder.loadDefaultConfig())
|
||||||
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)
|
logError("error occurred loading default configuration", e)
|
||||||
MetricsUtil.trackError(e)
|
|
||||||
if(tryDirtyStart()) return
|
if(tryDirtyStart()) return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,16 +161,14 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
try {
|
try {
|
||||||
Lang.reload()
|
Lang.reload()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.log(Level.SEVERE, "error occurred loading language file", e)
|
logError("error occurred loading language file", e)
|
||||||
MetricsUtil.trackError(e)
|
|
||||||
if(tryDirtyStart()) return
|
if(tryDirtyStart()) return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
legacyCheck()
|
legacyCheck()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.log(Level.SEVERE, "error trying to check for legacy system", e)
|
logError("error.load.legacy.failed".translate(), e)
|
||||||
MetricsUtil.trackError(e)
|
|
||||||
if(trySafeStart()) return
|
if(trySafeStart()) return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -168,8 +177,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
try {
|
try {
|
||||||
CustomAnvilCommand(this)
|
CustomAnvilCommand(this)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.log(Level.SEVERE, "error trying to register commands", e)
|
logError("error.load.command-register".translate(), e)
|
||||||
MetricsUtil.trackError(e)
|
|
||||||
if(trySafeStart()) return
|
if(trySafeStart()) return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -178,8 +186,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
try {
|
try {
|
||||||
DependencyManager.loadDependency()
|
DependencyManager.loadDependency()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.log(Level.SEVERE, "error loading dependency compatibility", e)
|
logError("error.load.compatibility".translate(), e)
|
||||||
MetricsUtil.trackError(e)
|
|
||||||
if(tryDirtyStart()) return
|
if(tryDirtyStart()) return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,8 +194,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
try {
|
try {
|
||||||
registerListeners()
|
registerListeners()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.log(Level.SEVERE, "error registering listeners", e)
|
logError("error.load.listeners".translate(), e)
|
||||||
MetricsUtil.trackError(e)
|
|
||||||
if(tryDirtyStart()) return
|
if(tryDirtyStart()) return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,32 +210,22 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
MetricsUtil.shutdownMetrics()
|
MetricsUtil.shutdownMetrics()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadEnchantmentSystemDirty() {
|
|
||||||
try {
|
|
||||||
loadEnchantmentSystem()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
logger.log(Level.SEVERE, "error initializing enchantment system", e)
|
|
||||||
MetricsUtil.trackError(e)
|
|
||||||
tryDirtyStart()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun legacyCheck() {
|
private fun legacyCheck() {
|
||||||
// Disable old plugin name if exist
|
// Disable old plugin name if exist
|
||||||
val potentialPlugin = Bukkit.getPluginManager().getPlugin("UnsafeEnchantsPlus")
|
val potentialPlugin = Bukkit.getPluginManager().getPlugin("UnsafeEnchantsPlus")
|
||||||
if (potentialPlugin != null) {
|
if (potentialPlugin != null) {
|
||||||
Bukkit.getPluginManager().disablePlugin(potentialPlugin)
|
Bukkit.getPluginManager().disablePlugin(potentialPlugin)
|
||||||
logger.warning("An old version of this plugin was detected")
|
logger.warning("warning.load.legacy.old-name.1".translate())
|
||||||
logger.warning("Please note CustomAnvil is a more recent version of UnsafeEnchantsPlus")
|
logger.warning("warning.load.legacy.old-name.2".translate())
|
||||||
}
|
}
|
||||||
|
|
||||||
val isPaper = PlatformUtil.isPaper
|
val isPaper = PlatformUtil.isPaper
|
||||||
if(!isPaper) {
|
if(!isPaper) {
|
||||||
logger.warning("It seems you are using spigot")
|
logger.warning("warning.load.legacy.spigot.1".translate())
|
||||||
logger.warning("Please take notice that spigot is less supported than paper and derivatives")
|
logger.warning("warning.load.legacy.spigot.2".translate())
|
||||||
if(MinecraftVersionUtil.isTooNewForSpigot) {
|
if(MinecraftVersionUtil.isTooNewForSpigot) {
|
||||||
logger.warning("If replace too expensive is not working this is likely because of spigot")
|
logger.warning("warning.load.legacy.spigot-old.1".translate())
|
||||||
logger.warning("As native nms is not supported for spigot starting 26.1")
|
logger.warning("warning.load.legacy.spigot-old.1".translate())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -242,13 +238,13 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
UpdateUtils.currentMinecraftVersion().toString())
|
UpdateUtils.currentMinecraftVersion().toString())
|
||||||
.setFeatured(featured)
|
.setFeatured(featured)
|
||||||
.setOnError {
|
.setOnError {
|
||||||
logger.log(Level.WARNING, "error trying to fetch latest update", it)
|
logger.log(Level.WARNING, "error.load.update.check-fail".translate(), 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
|
||||||
|
|
||||||
logger.warning("An update may be available: $latestVer")
|
logger.warning("warning.load.update.available".translate(Pair("version", latestVer)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -263,6 +259,15 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
server.pluginManager.registerEvents(AnvilCloseListener(DependencyManager.packetManager), this)
|
server.pluginManager.registerEvents(AnvilCloseListener(DependencyManager.packetManager), this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadEnchantmentSystemDirty() {
|
||||||
|
try {
|
||||||
|
loadEnchantmentSystem()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logError("error.load.enchant-system".translate(), e)
|
||||||
|
tryDirtyStart()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadEnchantmentSystem(){
|
private fun loadEnchantmentSystem(){
|
||||||
// Register enchantments
|
// Register enchantments
|
||||||
CAEnchantmentRegistry.getInstance().registerBukkit()
|
CAEnchantmentRegistry.getInstance().registerBukkit()
|
||||||
|
|
@ -273,7 +278,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
|
|
||||||
// Load config
|
// Load config
|
||||||
if (!ConfigHolder.loadNonDefaultConfig()) {
|
if (!ConfigHolder.loadNonDefaultConfig()) {
|
||||||
logger.log(Level.SEVERE,"Plugin has an issue while trying to load non default config... exiting...")
|
logError("error.load.non-default-config".translate())
|
||||||
server.pluginManager.disablePlugin(this)
|
server.pluginManager.disablePlugin(this)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -327,15 +332,15 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
try {
|
try {
|
||||||
val configReader = FileReader(resourceFile)
|
val configReader = FileReader(resourceFile)
|
||||||
yamlConfig.load(configReader)
|
yamlConfig.load(configReader)
|
||||||
} catch (test: Exception) {
|
} catch (_: Exception) {
|
||||||
if (hardFailSafe) {
|
if (hardFailSafe) {
|
||||||
// This is important and may impact gameplay if it does not load.
|
// This is important and may impact gameplay if it does not load.
|
||||||
// Failsafe is to stop the plugin
|
// Failsafe is to stop the plugin
|
||||||
logger.severe("Resource ${resourceFile.path} Could not be load or reload.")
|
logError("error.reload.resource.fail".translate(Pair("path", resourceFile.path)))
|
||||||
logger.severe("Disabling plugin.")
|
logError("error.reload.resource.hard-fail".translate())
|
||||||
Bukkit.getPluginManager().disablePlugin(this)
|
Bukkit.getPluginManager().disablePlugin(this)
|
||||||
} else {
|
} else {
|
||||||
logger.warning("Resource ${resourceFile.path} Could not be load or reload.")
|
logError("error.reload.resource.fail".translate(Pair("path", resourceFile.path)))
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
|
||||||
29
src/main/resources/lang/en.yml
Normal file
29
src/main/resources/lang/en.yml
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
name: English
|
||||||
|
|
||||||
|
warning:
|
||||||
|
load:
|
||||||
|
legacy:
|
||||||
|
old-name:
|
||||||
|
1: "An old version of this plugin was detected"
|
||||||
|
2: "Please note CustomAnvil is a more recent version of UnsafeEnchantsPlus"
|
||||||
|
spigot:
|
||||||
|
1: "It seems you are using spigot"
|
||||||
|
2: "Please take notice that spigot is less supported than paper and derivatives"
|
||||||
|
spigot-old:
|
||||||
|
1: "If replace too expensive is not working this is likely because of spigot"
|
||||||
|
2: "As native nms is not supported for spigot starting 26.1"
|
||||||
|
update.available: "An update may be available: %version"
|
||||||
|
|
||||||
|
error:
|
||||||
|
load:
|
||||||
|
legacy.failed: "error trying to check for legacy system"
|
||||||
|
update.check-fail: "error trying to fetch latest update"
|
||||||
|
command-register: "error trying to register commands"
|
||||||
|
compatibility: "error loading dependency compatibility"
|
||||||
|
listeners: "error registering listeners"
|
||||||
|
enchant-system: "error initializing enchantment system"
|
||||||
|
non-default-config: "Plugin has an issue while trying to load non default config... exiting..."
|
||||||
|
reload:
|
||||||
|
resource:
|
||||||
|
fail: "Resource %path Could not be loaded or reloaded."
|
||||||
|
hard-fail: "Disabling plugin."
|
||||||
Loading…
Add table
Add a link
Reference in a new issue