Dependency enchantment registering now use the api.

This commit is contained in:
alexcrea 2024-07-09 21:21:10 +02:00
parent 6f1e53f68e
commit 365d0ea847
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
6 changed files with 25 additions and 33 deletions

View file

@ -5,7 +5,6 @@ import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.dependency.DependencyManager;
import xyz.alexcrea.cuanvil.enchant.wrapped.CAVanillaEnchantment; import xyz.alexcrea.cuanvil.enchant.wrapped.CAVanillaEnchantment;
import java.util.*; import java.util.*;
@ -38,13 +37,6 @@ public class CAEnchantmentRegistry {
register(new CAVanillaEnchantment(enchantment)); register(new CAVanillaEnchantment(enchantment));
} }
if(DependencyManager.INSTANCE.getEnchantmentSquaredCompatibility() != null){
DependencyManager.INSTANCE.getEnchantmentSquaredCompatibility().registerEnchantments();
}
if(DependencyManager.INSTANCE.getEcoEnchantCompatibility() != null){
DependencyManager.INSTANCE.getEcoEnchantCompatibility().registerEnchantments();
}
} }
/** /**

View file

@ -36,7 +36,7 @@ public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGr
new IncludeGroup("new_group"), new IncludeGroup("new_group"),
0); 0);
ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList().add(conflict); ConfigHolder.CONFLICT_HOLDER.getConflictManager().addConflict(conflict);
// save empty conflict in config // save empty conflict in config
String[] emptyStringArray = new String[0]; String[] emptyStringArray = new String[0];

View file

@ -80,8 +80,6 @@ class CustomAnvil : JavaPlugin() {
override fun onEnable() { override fun onEnable() {
instance = this instance = this
val pluginManager = Bukkit.getPluginManager();
// 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) {
@ -93,13 +91,9 @@ class CustomAnvil : JavaPlugin() {
// Load dependency // Load dependency
DependencyManager.loadDependency() DependencyManager.loadDependency()
// Register enchantments // Register vanilla enchantments
CAEnchantmentRegistry.getInstance().registerStartupEnchantments() CAEnchantmentRegistry.getInstance().registerStartupEnchantments()
// Load chat listener
chatListener = ChatEventListener()
pluginManager.registerEvents(chatListener, this)
// Load config // Load config
val success = ConfigHolder.loadConfig() val success = ConfigHolder.loadConfig()
if (!success) return if (!success) return
@ -107,23 +101,26 @@ class CustomAnvil : JavaPlugin() {
// temporary: handle 1.21 update // temporary: handle 1.21 update
Update_1_21.handleUpdate() Update_1_21.handleUpdate()
// Handle custom enchant config
DependencyManager.handleConfigChanges(this)
// Load gui constants //TODO maybe something better later // Load gui constants //TODO maybe something better later
MainConfigGui.getInstance().init(DependencyManager.packetManager) MainConfigGui.getInstance().init(DependencyManager.packetManager)
GuiSharedConstant.loadConstants() GuiSharedConstant.loadConstants()
// Load metrics // Register enchantment of compatible plugin and load configuration change.
Metrics(this, bstatsPluginId) DependencyManager.registerEnchantments()
DependencyManager.handleCompatibilityConfig(this)
// Add commands to reload the plugin // Add commands to reload the plugin
prepareCommand() prepareCommand()
server.pluginManager.registerEvents( // Load chat listener
AnvilEventListener(DependencyManager.packetManager), chatListener = ChatEventListener()
this server.pluginManager.registerEvents(chatListener, this)
)
// Register anvil events
server.pluginManager.registerEvents(AnvilEventListener(DependencyManager.packetManager), this)
// Load metrics
Metrics(this, bstatsPluginId)
} }
fun reloadResource( fun reloadResource(

View file

@ -37,7 +37,7 @@ object DependencyManager {
} }
fun handleConfigChanges(plugin: Plugin) { fun handleCompatibilityConfig(plugin: Plugin) {
val folder = File(plugin.dataFolder, "compatibility") val folder = File(plugin.dataFolder, "compatibility")
enchantmentSquaredCompatibility?.registerPluginConfiguration() enchantmentSquaredCompatibility?.registerPluginConfiguration()
@ -53,4 +53,10 @@ object DependencyManager {
defaultConfig["enchant_values.${enchantment.key.key}.book"] = rarity.bookValue defaultConfig["enchant_values.${enchantment.key.key}.book"] = rarity.bookValue
} }
fun registerEnchantments() {
enchantmentSquaredCompatibility?.registerEnchantments()
ecoEnchantCompatibility?.registerEnchantments()
}
} }

View file

@ -53,7 +53,7 @@ class EcoEnchantDependency(private val ecoEnchantPlugin: Plugin) {
doSave = true doSave = true
config[testPath] = true config[testPath] = true
DependencyManager.writeDefaultConfig(defaultConfig, enchantment) DependencyManager.writeDefaultConfig(defaultConfig, enchantment) //TODO move to api register
} }
} }

View file

@ -9,6 +9,7 @@ import org.bukkit.event.inventory.PrepareAnvilEvent
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
import org.bukkit.plugin.Plugin import org.bukkit.plugin.Plugin
import xyz.alexcrea.cuanvil.api.ConflictBuilder import xyz.alexcrea.cuanvil.api.ConflictBuilder
import xyz.alexcrea.cuanvil.api.EnchantmentApi
import xyz.alexcrea.cuanvil.api.MaterialGroupApi import xyz.alexcrea.cuanvil.api.MaterialGroupApi
import xyz.alexcrea.cuanvil.config.ConfigHolder import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.enchant.CAEnchantment import xyz.alexcrea.cuanvil.enchant.CAEnchantment
@ -36,11 +37,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
fun registerEnchantments(){ fun registerEnchantments(){
for (enchant in CustomEnchantManager.getInstance().allEnchants.values) { for (enchant in CustomEnchantManager.getInstance().allEnchants.values) {
CAEnchantmentRegistry.getInstance().register( EnchantmentApi.registerEnchantment(CAEnchantSquaredEnchantment(enchant))
CAEnchantSquaredEnchantment(
enchant
)
)
} }
} }
@ -81,7 +78,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
} }
// Write default level limit and xp cost // Write default level limit and xp cost
for (enchantment in esEnchantments) { for (enchantment in esEnchantments) { //TODO move to api register
DependencyManager.writeDefaultConfig(defaultConfig, enchantment) DependencyManager.writeDefaultConfig(defaultConfig, enchantment)
} }