9
0
mirror of https://github.com/Xiao-MoMi/Custom-Nameplates.git synced 2025-12-31 12:46:31 +00:00

1.8.0-SNAPSHOT

This commit is contained in:
Xiao-MoMi
2022-07-27 21:16:20 +08:00
parent 87a4b9c0c9
commit 43dccebb26
51 changed files with 1378 additions and 250 deletions

View File

@@ -1,13 +1,32 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customnameplates;
import com.comphenix.protocol.ProtocolLibrary;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.momirealms.customnameplates.actionbar.Timer;
import net.momirealms.customnameplates.bossbar.QuitAndJoin;
import net.momirealms.customnameplates.commands.Execute;
import net.momirealms.customnameplates.commands.TabComplete;
import net.momirealms.customnameplates.data.DataManager;
import net.momirealms.customnameplates.data.SqlHandler;
import net.momirealms.customnameplates.helper.LibraryLoader;
import net.momirealms.customnameplates.hook.HookManager;
import net.momirealms.customnameplates.hook.Placeholders;
import net.momirealms.customnameplates.listener.PlayerListener;
import net.momirealms.customnameplates.listener.PacketsListener;
import net.momirealms.customnameplates.resource.ResourceManager;
@@ -25,19 +44,17 @@ public final class CustomNameplates extends JavaPlugin {
private ResourceManager resourceManager;
private DataManager dataManager;
private HookManager hookManager;
private ScoreBoardManager scoreBoardManager;
private Timer timer;
public ResourceManager getResourceManager() {
return this.resourceManager;
}
public DataManager getDataManager() { return this.dataManager; }
public HookManager getHookManager() { return this.hookManager; }
public ScoreBoardManager getScoreBoardManager() { return this.scoreBoardManager; }
@Override
public void onLoad(){
instance = this;
LibraryLoader.load("commons-io","commons-io","2.11.0","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("com.zaxxer","HikariCP","5.0.1","https://repo.maven.apache.org/maven2/");
@@ -45,42 +62,55 @@ public final class CustomNameplates extends JavaPlugin {
@Override
public void onEnable() {
adventure = BukkitAudiences.create(this);
AdventureManager.consoleMessage("<gradient:#2E8B57:#48D1CC>[CustomNameplates] </gradient><color:#baffd1>Running on " + Bukkit.getVersion());
//重载插件
ConfigManager.loadModule();
ConfigManager.MainConfig.ReloadConfig();
ConfigManager.Message.ReloadConfig();
ConfigManager.DatabaseConfig.LoadConfig();
//指令注册
if (ConfigManager.bossbar){
ConfigManager.loadBossBar();
Bukkit.getPluginManager().registerEvents(new QuitAndJoin(),this);
}
if (ConfigManager.actionbar){
ConfigManager.ActionbarConfig.LoadConfig();
timer = new Timer();
}
if (ConfigManager.background){
ConfigManager.loadBGConfig();
}
if (ConfigManager.nameplate){
ConfigManager.DatabaseConfig.LoadConfig();
Bukkit.getPluginManager().registerEvents(new PlayerListener(this),this);
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketsListener(this));
}
if (ConfigManager.MainConfig.placeholderAPI){
new Placeholders().register();
AdventureManager.consoleMessage("<gradient:#2E8B57:#48D1CC>[CustomNameplates]</gradient> <color:#baffd1>PlaceholderAPI Hooked!");
}
Objects.requireNonNull(Bukkit.getPluginCommand("customnameplates")).setExecutor(new Execute(this));
Objects.requireNonNull(Bukkit.getPluginCommand("customnameplates")).setTabCompleter(new TabComplete(this));
//事件注册
Bukkit.getPluginManager().registerEvents(new PlayerListener(this),this);
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketsListener(this));
//新建单例
this.resourceManager = new ResourceManager(this);
this.dataManager = new DataManager(this);
this.hookManager = new HookManager(this);
this.scoreBoardManager = new ScoreBoardManager(this);
//生成资源包
resourceManager.generateResourcePack();
if (!DataManager.create()) {
AdventureManager.consoleMessage("<red>[CustomNameplates] Error! Failed to enable Data Manager! Disabling plugin...</red>");
instance.getPluginLoader().disablePlugin(instance);
return;
}
//启动完成
AdventureManager.consoleMessage("<gradient:#2E8B57:#48D1CC>[CustomNameplates]</gradient> <color:#baffd1>Plugin Enabled!");
}
@Override
public void onDisable() {
SqlHandler.saveAll();
SqlHandler.close();
//清除缓存实体
if (ConfigManager.nameplate){
SqlHandler.saveAll();
SqlHandler.close();
}
Execute.pCache.forEach(Entity::remove);
//关闭adventure
if (timer != null){
timer.stopTimer(timer.getTaskID());
}
if(adventure != null) {
adventure.close();
adventure = null;