1
mirror of https://github.com/CarmJos/UltraDepository.git synced 2024-09-19 19:55:45 +00:00

更换插件的加载入口

This commit is contained in:
Carm Jos 2022-03-04 16:45:08 +08:00
parent 717e313f25
commit c6c6b3bc37
4 changed files with 182 additions and 163 deletions

View File

@ -30,6 +30,8 @@ public class Main extends EasyPlugin {
private DataStorage storage; private DataStorage storage;
private ConfigManager configManager;
private UserManager userManager; private UserManager userManager;
private EconomyManager economyManager; private EconomyManager economyManager;
private DepositoryManager depositoryManager; private DepositoryManager depositoryManager;
@ -47,7 +49,8 @@ public class Main extends EasyPlugin {
protected boolean initialize() { protected boolean initialize() {
log("加载配置文件..."); log("加载配置文件...");
if (!ConfigManager.initialize()) { this.configManager = new ConfigManager(this);
if (!configManager.initialize()) {
log("初始化配置文件失败,放弃加载。"); log("初始化配置文件失败,放弃加载。");
return false; return false;
} }
@ -160,6 +163,10 @@ public class Main extends EasyPlugin {
return depositoryManager; return depositoryManager;
} }
protected ConfigManager getConfigManager() {
return configManager;
}
@Override @Override
public boolean isDebugging() { public boolean isDebugging() {
return PluginConfig.DEBUG.get(); return PluginConfig.DEBUG.get();

View File

@ -1,5 +1,6 @@
package cc.carm.plugin.ultradepository; package cc.carm.plugin.ultradepository;
import cc.carm.plugin.ultradepository.manager.ConfigManager;
import cc.carm.plugin.ultradepository.manager.DepositoryManager; import cc.carm.plugin.ultradepository.manager.DepositoryManager;
import cc.carm.plugin.ultradepository.manager.EconomyManager; import cc.carm.plugin.ultradepository.manager.EconomyManager;
import cc.carm.plugin.ultradepository.manager.UserManager; import cc.carm.plugin.ultradepository.manager.UserManager;
@ -27,4 +28,8 @@ public class UltraDepository {
return Main.getInstance().getDepositoryManager(); return Main.getInstance().getDepositoryManager();
} }
public static ConfigManager getConfigManager() {
return Main.getInstance().getConfigManager();
}
} }

View File

@ -6,7 +6,7 @@ import cc.carm.lib.easyplugin.configuration.impl.ConfigSound;
import cc.carm.lib.easyplugin.configuration.message.ConfigMessage; import cc.carm.lib.easyplugin.configuration.message.ConfigMessage;
import cc.carm.lib.easyplugin.configuration.message.ConfigMessageList; import cc.carm.lib.easyplugin.configuration.message.ConfigMessageList;
import cc.carm.lib.easyplugin.configuration.values.ConfigValue; import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
import cc.carm.plugin.ultradepository.manager.ConfigManager; import cc.carm.plugin.ultradepository.UltraDepository;
import cc.carm.plugin.ultradepository.storage.StorageMethod; import cc.carm.plugin.ultradepository.storage.StorageMethod;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -69,14 +69,16 @@ public class PluginConfig {
public static class AdditionalLore { public static class AdditionalLore {
public static final ConfigMessageList AVAILABLE_FOR_SALE = new ConfigMessageList( public static final ConfigMessageList AVAILABLE_FOR_SALE = new ConfigMessageList(
ConfigManager::getPluginConfig, "general.additional-lore.available-for-sale", () -> UltraDepository.getConfigManager().getPluginConfig(),
"general.additional-lore.available-for-sale",
new String[]{}, new String[]{},
new String[]{ new String[]{
"%(item_name)", "%(amount)", "%(price)", "%(sold)", "%(remain)", "%(limit)" "%(item_name)", "%(amount)", "%(price)", "%(sold)", "%(remain)", "%(limit)"
}); });
public static final ConfigMessageList NOT_FOR_SALE = new ConfigMessageList( public static final ConfigMessageList NOT_FOR_SALE = new ConfigMessageList(
ConfigManager::getPluginConfig, "general.additional-lore.not-for-sale", () -> UltraDepository.getConfigManager().getPluginConfig(),
"general.additional-lore.not-for-sale",
new String[]{}, new String[]{ new String[]{}, new String[]{
"%(item_name)", "%(amount)" "%(item_name)", "%(amount)"
}); });
@ -89,14 +91,15 @@ public class PluginConfig {
*/ */
public static class ClickLore { public static class ClickLore {
public static final ConfigMessageList AVAILABLE_FOR_SALE = new ConfigMessageList( public static final ConfigMessageList AVAILABLE_FOR_SALE = new ConfigMessageList(
ConfigManager::getPluginConfig, () -> UltraDepository.getConfigManager().getPluginConfig(),
"general.click-lore.available-for-sale", "general.click-lore.available-for-sale",
new String[]{}, new String[]{ new String[]{}, new String[]{
"%(item_name)", "%(amount)", "%(price)" "%(item_name)", "%(amount)", "%(price)"
}); });
public static final ConfigMessageList NOT_FOR_SALE = new ConfigMessageList( public static final ConfigMessageList NOT_FOR_SALE = new ConfigMessageList(
ConfigManager::getPluginConfig, "general.click-lore.not-for-sale", () -> UltraDepository.getConfigManager().getPluginConfig(),
"general.click-lore.not-for-sale",
new String[]{}, new String[]{},
new String[]{ new String[]{
"%(item_name)", "%(amount)" "%(item_name)", "%(amount)"
@ -105,7 +108,7 @@ public class PluginConfig {
public static final ConfigMessageList CLICK_LORE = new ConfigMessageList( public static final ConfigMessageList CLICK_LORE = new ConfigMessageList(
ConfigManager::getPluginConfig, () -> UltraDepository.getConfigManager().getPluginConfig(),
"general.click-lore", "general.click-lore",
new String[]{}, new String[]{ new String[]{}, new String[]{
"%(item_name)", "%(amount)", "%(price)" "%(item_name)", "%(amount)", "%(price)"
@ -118,7 +121,7 @@ public class PluginConfig {
public static final ConfigMessage TITLE = new ConfigMessage( public static final ConfigMessage TITLE = new ConfigMessage(
ConfigManager::getPluginConfig, () -> UltraDepository.getConfigManager().getPluginConfig(),
"general.sell-gui.title", "general.sell-gui.title",
"&a&l出售", new String[]{ "&a&l出售", new String[]{
"%(item_name)", "%(backpack_name)" "%(item_name)", "%(backpack_name)"

View File

@ -7,33 +7,37 @@ import cc.carm.lib.easyplugin.configuration.language.MessagesInitializer;
import cc.carm.plugin.ultradepository.UltraDepository; import cc.carm.plugin.ultradepository.UltraDepository;
import cc.carm.plugin.ultradepository.configuration.PluginMessages; import cc.carm.plugin.ultradepository.configuration.PluginMessages;
import cc.carm.plugin.ultradepository.util.JarUtil; import cc.carm.plugin.ultradepository.util.JarUtil;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
public class ConfigManager { public class ConfigManager {
private static FileConfig pluginConfiguration; private final JavaPlugin plugin;
private static MessagesConfig messageConfiguration; private FileConfig pluginConfiguration;
private MessagesConfig messageConfiguration;
public static boolean initialize() { public ConfigManager(JavaPlugin plugin) {
UltraDepository udPlugin = UltraDepository.getInstance(); this.plugin = plugin;
}
public boolean initialize() {
try { try {
File configFile = new File(udPlugin.getDataFolder(), "config.yml"); File configFile = new File(plugin.getDataFolder(), "config.yml");
if (!configFile.exists()) { if (!configFile.exists()) {
//没找到配置文件可能是第一次加载此插件 //没找到配置文件可能是第一次加载此插件
//把一些英文版的东西复制出来方便英文用户使用 //把一些英文版的东西复制出来方便英文用户使用
UltraDepository.getInstance().log(" 未找到配置文件,生成默认配置..."); UltraDepository.getInstance().log(" 未找到配置文件,生成默认配置...");
JarUtil.copyFolderFromJar( JarUtil.copyFolderFromJar(
"i18n", udPlugin.getDataFolder(), "i18n", plugin.getDataFolder(),
JarUtil.CopyOption.COPY_IF_NOT_EXIST JarUtil.CopyOption.COPY_IF_NOT_EXIST
); );
} }
pluginConfiguration = new FileConfig(udPlugin, "config.yml"); pluginConfiguration = new FileConfig(plugin, "config.yml");
messageConfiguration = new MessagesConfig(udPlugin, "messages.yml"); messageConfiguration = new MessagesConfig(plugin, "messages.yml");
FileConfig.pluginConfiguration = () -> pluginConfiguration; FileConfig.pluginConfiguration = () -> pluginConfiguration;
FileConfig.messageConfiguration = () -> messageConfiguration; FileConfig.messageConfiguration = () -> messageConfiguration;
@ -47,15 +51,15 @@ public class ConfigManager {
} }
} }
public static FileConfig getPluginConfig() { public FileConfig getPluginConfig() {
return pluginConfiguration; return pluginConfiguration;
} }
public static MessagesConfig getMessageConfig() { public MessagesConfig getMessageConfig() {
return messageConfiguration; return messageConfiguration;
} }
public static void reload() { public void reload() {
try { try {
getPluginConfig().reload(); getPluginConfig().reload();
getMessageConfig().reload(); getMessageConfig().reload();
@ -64,7 +68,7 @@ public class ConfigManager {
} }
} }
public static void saveConfig() { public void saveConfig() {
try { try {
getPluginConfig().save(); getPluginConfig().save();
getMessageConfig().save(); getMessageConfig().save();