1.0.1:Fix error:[DirectoryProviderSource] Error loading plugin: name is not defined

This commit is contained in:
xiaobai
2026-02-13 20:56:03 +08:00
parent c7d09c3039
commit 8d8cdcb244
6 changed files with 304 additions and 357 deletions

View File

@@ -1,6 +1,8 @@
package com.playerblocklife;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.logging.Level;
public class PlayerBlockLife extends JavaPlugin {
@@ -10,36 +12,40 @@ public class PlayerBlockLife extends JavaPlugin {
private LifeSystem lifeSystem;
private ConfigManager configManager;
// 在 PlayerBlockLife.java 中添加:
@Override
public void reloadConfig() {
super.reloadConfig();
configManager.reloadConfig();
getLogger().info("配置已重新加载");
}
@Override
public void onEnable() {
instance = this;
// 第一步:保存默认配置
saveDefaultConfig();
// 第二步:初始化管理器(注意顺序!)
this.configManager = new ConfigManager(this);
this.skinManager = new SkinManager(this);
this.blockManager = new PlayerBlockManager(this, skinManager);
this.lifeSystem = new LifeSystem(this);
// 第三步:加载数据(必须在管理器初始化之后)
this.configManager.loadConfig();
// 第四步:注册事件监听器
getServer().getPluginManager().registerEvents(new BlockBreakListener(this), this);
getServer().getPluginManager().registerEvents(new PlayerJoinListener(this), this);
getServer().getPluginManager().registerEvents(new PlayerQuitListener(this), this);
// 第五步:注册命令
getCommand("setlifeblocks").setExecutor(new SetLifeBlocksCommand(this));
getCommand("checklifeblocks").setExecutor(new CheckLifeBlocksCommand(this));
getCommand("pblreload").setExecutor(new AdminCommands(this));
getCommand("pbldelete").setExecutor(new AdminCommands(this));
getCommand("pblrevive").setExecutor(new AdminCommands(this));
getCommand("pblstats").setExecutor(new AdminCommands(this));
// 第六步:加载其他数据
blockManager.loadData();
skinManager.loadAllSkins();
// 第七步:启动定时任务
startScheduler();
getLogger().info("§a========================================");
@@ -50,6 +56,7 @@ public class PlayerBlockLife extends JavaPlugin {
@Override
public void onDisable() {
// 保存数据
if (blockManager != null) {
blockManager.saveData();
}
@@ -59,15 +66,57 @@ public class PlayerBlockLife extends JavaPlugin {
getLogger().info("§cPlayerBlockLife 插件已禁用");
}
/**
* 重写 reloadConfig 方法,避免循环依赖
*/
@Override
public void reloadConfig() {
// 只调用父类的reloadConfig不调用configManager的方法
super.reloadConfig();
getLogger().info("基础配置文件已重新加载");
}
/**
* 插件的完整重载方法(用于命令)
*/
public void reloadPluginConfig() {
if (configManager != null) {
configManager.reloadConfig();
}
if (blockManager != null) {
blockManager.loadData();
}
if (skinManager != null) {
skinManager.loadAllSkins();
}
getLogger().info("插件配置已完全重载");
}
private void startScheduler() {
// 每5分钟自动保存数据
getServer().getScheduler().runTaskTimerAsynchronously(this, () -> {
blockManager.saveData();
skinManager.saveSkinData();
if (blockManager != null) {
blockManager.saveData();
}
if (skinManager != null) {
skinManager.saveSkinData();
}
getLogger().info("数据已自动保存");
}, 6000L, 6000L);
// 每10秒检查玩家生命方块
getServer().getScheduler().runTaskTimer(this, () -> {
lifeSystem.checkAllPlayers();
if (lifeSystem != null) {
lifeSystem.checkAllPlayers();
}
}, 200L, 200L);
// 每分钟清理一次过期缓存
getServer().getScheduler().runTaskTimerAsynchronously(this, () -> {
if (skinManager != null) {
skinManager.cleanupOldCache();
}
}, 1200L, 1200L);
}
public static PlayerBlockLife getInstance() {