mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-24 00:26:16 +02:00
custom conflict now work.
This commit is contained in:
parent
baa0c064da
commit
9f35c1a98d
6 changed files with 201 additions and 26 deletions
|
|
@ -1,9 +1,13 @@
|
|||
package io.delilaheve
|
||||
|
||||
import io.delilaheve.util.ConfigOptions
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.configuration.file.YamlConfiguration
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
import xyz.alexcrea.group.EnchantConflictManager
|
||||
import xyz.alexcrea.group.ItemGroupManager
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
|
||||
/**
|
||||
* Bukkit/Spigot/Paper plugin to alter enchantment max
|
||||
|
|
@ -18,11 +22,13 @@ class UnsafeEnchants : JavaPlugin() {
|
|||
const val unsafeBypassPermission = "ue.unsafe_all"
|
||||
// Item Grouping Configuration file name
|
||||
const val itemGroupingConfigName = "item_groups.yml"
|
||||
// Conflict Configuration file name
|
||||
const val enchantConflicConfigName = "enchant_conflict.yml"
|
||||
|
||||
// Current plugin instance
|
||||
lateinit var instance: UnsafeEnchants
|
||||
// Current item grouping configuration instance
|
||||
lateinit var itemGroups: ItemGroupManager
|
||||
lateinit var conflictManager: EnchantConflictManager
|
||||
|
||||
/**
|
||||
* Logging handler
|
||||
|
|
@ -41,24 +47,50 @@ class UnsafeEnchants : JavaPlugin() {
|
|||
instance = this
|
||||
saveDefaultConfig()
|
||||
|
||||
// Save default material grouping config
|
||||
saveResource(itemGroupingConfigName,false)
|
||||
// Load material grouping config
|
||||
val itemGroupConfig = YamlConfiguration()
|
||||
val configReader = this.getTextResource(itemGroupingConfigName)
|
||||
if(configReader == null){
|
||||
logger.severe("could no load item grouping configuration")
|
||||
}else{
|
||||
itemGroupConfig.load(configReader)
|
||||
}
|
||||
val itemGroupConfig = reloadResource(itemGroupingConfigName) ?: return
|
||||
// Read material groups from config
|
||||
itemGroups = ItemGroupManager()
|
||||
itemGroups.prepareGroups(itemGroupConfig)
|
||||
val itemGroupsManager = ItemGroupManager()
|
||||
itemGroupsManager.prepareGroups(itemGroupConfig)
|
||||
|
||||
// Load enchantment conflicts config
|
||||
val conflictConfig = reloadResource(enchantConflicConfigName) ?: return
|
||||
// Read conflicts from config and material group manager
|
||||
conflictManager = EnchantConflictManager()
|
||||
conflictManager.prepareConflicts(conflictConfig,itemGroupsManager)
|
||||
|
||||
server.pluginManager.registerEvents(
|
||||
AnvilEventListener(),
|
||||
this
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
private fun reloadResource(resourceName: String,
|
||||
hardFailSafe:Boolean = true): YamlConfiguration?{
|
||||
// Save default resource
|
||||
val file = File(dataFolder,resourceName)
|
||||
if(!file.exists()){
|
||||
saveResource(resourceName,false)
|
||||
}
|
||||
// Load resource
|
||||
val yamlConfig = YamlConfiguration()
|
||||
try {
|
||||
val configReader = FileReader(file)
|
||||
yamlConfig.load(configReader)
|
||||
} catch (test: Exception){
|
||||
if(hardFailSafe){
|
||||
// This is important and may impact gameplay if it does not load.
|
||||
// Failsafe is to stop the plugin
|
||||
logger.severe("Resource $resourceName Could not be load or reload.")
|
||||
logger.severe("Disabling plugin.")
|
||||
Bukkit.getPluginManager().disablePlugin(this)
|
||||
}else{
|
||||
logger.warning("Resource $resourceName Could not be load or reload.")
|
||||
}
|
||||
return null
|
||||
}
|
||||
return yamlConfig
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue