mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-12-22 20:58:47 +00:00
feat: 调整注册逻辑 修改分离配置类
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
c4a9d9184a
commit
1be30bf249
@ -42,7 +42,7 @@ public class Yum extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
new YumAPI(this);
|
||||
new YumAPI();
|
||||
initCommands();
|
||||
initListeners();
|
||||
initRunnable();
|
||||
@ -92,15 +92,21 @@ public class Yum extends JavaPlugin {
|
||||
new PluginNetworkListener(this);
|
||||
PluginKit.scp("§a网络管理系统已启用...");
|
||||
}
|
||||
new ThreadSafetyListener(this);
|
||||
if (ConfigManager.i().isThreadSafe()) {
|
||||
new ThreadSafetyListener(this);
|
||||
PluginKit.scp("§a线程管理系统已启用...");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化任务
|
||||
*/
|
||||
private void initRunnable() {
|
||||
final Timer task = new Timer();
|
||||
PluginKit.scp("§a线程管理系统已启用...");
|
||||
task.scheduleAtFixedRate(new MainThreadCheckTask(Thread.currentThread()), 0, 3000);
|
||||
// 需要在主线程注册任务
|
||||
if (ConfigManager.i().isMainThreadCheck() && Bukkit.isPrimaryThread()) {
|
||||
final Timer task = new Timer();
|
||||
PluginKit.scp("§aIO管理系统已启用...");
|
||||
task.scheduleAtFixedRate(new MainThreadCheckTask(Thread.currentThread()), 0, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import cn.citycraft.CommonData.UpdatePlugin;
|
||||
import cn.citycraft.PluginHelper.kit.PKit;
|
||||
import pw.yumc.Yum.managers.ConfigManager;
|
||||
import pw.yumc.Yum.managers.DownloadManager;
|
||||
import pw.yumc.Yum.managers.PluginsManager;
|
||||
@ -360,8 +361,8 @@ public class YumAPI {
|
||||
* @param plugin
|
||||
* 插件实体
|
||||
*/
|
||||
public YumAPI(final Plugin plugin) {
|
||||
YumAPI.main = plugin;
|
||||
public YumAPI() {
|
||||
YumAPI.main = PKit.instance;
|
||||
plugman = new PluginsManager(main);
|
||||
download = new DownloadManager(main);
|
||||
repo = new RepositoryManager(main);
|
||||
|
@ -14,16 +14,18 @@ public class PluginNetworkListener implements Listener {
|
||||
public String prefix = "§6[§bYum §a网络管理§6] ";
|
||||
public String warnMain = "§c插件 §6%s §c尝试在主线程访问网络 §4可能会导致服务器卡顿或无响应!";
|
||||
public String warn = "§c插件 §6%s §c尝试访问网络 §4请注意服务器网络安全!";
|
||||
public String breaked = "§4已阻止黑名单插件 §b%s §4访问网络!";
|
||||
public String url = "§4地址: %s";
|
||||
public String breaked = "§c已阻止插件 §6%s §c访问网络!";
|
||||
public String url = "§c地址: %s";
|
||||
|
||||
public PluginNetworkListener(final Yum yum) {
|
||||
Bukkit.getPluginManager().registerEvents(this, yum);
|
||||
}
|
||||
|
||||
public void breakNetwork(final PluginNetworkEvent e) {
|
||||
PluginKit.sc(String.format(prefix + breaked, e.getPlugin().getName()));
|
||||
PluginKit.sc(String.format(url, e.getUrl().toString()));
|
||||
if (ConfigManager.i().isNetworkShowInfo()) {
|
||||
PluginKit.sc(String.format(prefix + breaked, e.getPlugin().getName()));
|
||||
PluginKit.sc(String.format(prefix + url, e.getUrl().toString()));
|
||||
}
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -39,7 +41,6 @@ public class PluginNetworkListener implements Listener {
|
||||
大神你好.isEmpty();
|
||||
return;
|
||||
}
|
||||
final boolean isPrimaryThread = e.isPrimaryThread();
|
||||
if (plugin != null) {
|
||||
if (ConfigManager.i().getNetworkBlackList().contains(plugin.getName())) {
|
||||
breakNetwork(e);
|
||||
@ -48,9 +49,14 @@ public class PluginNetworkListener implements Listener {
|
||||
if (ConfigManager.i().getNetworkIgnoreList().contains(plugin.getName())) {
|
||||
return;
|
||||
}
|
||||
PluginKit.sc(String.format(prefix + (isPrimaryThread ? warnMain : warn), plugin.getName(), urlinfo));
|
||||
if (!ConfigManager.i().isAllowPrimaryThread() && isPrimaryThread) {
|
||||
breakNetwork(e);
|
||||
if (e.isPrimaryThread()) {
|
||||
PluginKit.sc(String.format(prefix + warnMain, plugin.getName()));
|
||||
if (!ConfigManager.i().isAllowPrimaryThread()) {
|
||||
breakNetwork(e);
|
||||
}
|
||||
} else {
|
||||
PluginKit.sc(String.format(prefix + warn, plugin.getName()));
|
||||
PluginKit.sc(String.format(prefix + url, urlinfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,12 +73,10 @@ public class ThreadSafetyListener implements Listener {
|
||||
checkSafety(teleportEvent);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPluginDisable(final PluginDisableEvent pluginDisableEvent) {
|
||||
checkSafety(pluginDisableEvent);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPluginEnable(final PluginEnableEvent pluginEnableEvent) {
|
||||
checkSafety(pluginEnableEvent);
|
||||
}
|
||||
@ -88,7 +86,6 @@ public class ThreadSafetyListener implements Listener {
|
||||
checkSafety(worldLoadEvent);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldSave(final WorldSaveEvent worldSaveEvent) {
|
||||
checkSafety(worldSaveEvent);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ public class ConfigManager {
|
||||
public final FileConfig config;
|
||||
public final FileConfig setop;
|
||||
public final FileConfig network;
|
||||
public final FileConfig thread;
|
||||
|
||||
public static ConfigManager i() {
|
||||
return i;
|
||||
@ -26,6 +27,7 @@ public class ConfigManager {
|
||||
config = new FileConfig(plugin);
|
||||
setop = new FileConfig(plugin, "setop.yml");
|
||||
network = new FileConfig(plugin, "network.yml");
|
||||
thread = new FileConfig(plugin, "thread.yml");
|
||||
}
|
||||
|
||||
public List<String> getBlackList() {
|
||||
@ -56,6 +58,10 @@ public class ConfigManager {
|
||||
return network.getBoolean("AllowPrimaryThread", false);
|
||||
}
|
||||
|
||||
public boolean isMainThreadCheck() {
|
||||
return thread.getBoolean("MainThreadCheck", true);
|
||||
}
|
||||
|
||||
public boolean isNetworkDebug() {
|
||||
return network.getBoolean("NetworkDebug", false);
|
||||
}
|
||||
@ -64,12 +70,21 @@ public class ConfigManager {
|
||||
return network.getBoolean(ENABLE, true);
|
||||
}
|
||||
|
||||
public boolean isNetworkShowInfo() {
|
||||
return network.getBoolean("ShowInfo", true);
|
||||
}
|
||||
|
||||
public boolean isSetOpEnable() {
|
||||
return setop.getBoolean(ENABLE, true);
|
||||
}
|
||||
|
||||
public boolean isThreadSafe() {
|
||||
return thread.getBoolean("ThreadSafe", true);
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
setop.reload();
|
||||
network.reload();
|
||||
thread.reload();
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ import java.util.logging.Level;
|
||||
import cn.citycraft.PluginHelper.kit.PKit;
|
||||
|
||||
/**
|
||||
*
|
||||
* 线程安全检查任务
|
||||
*
|
||||
* @since 2016年6月22日 下午4:57:32
|
||||
* @author 喵♂呜
|
||||
*/
|
||||
|
@ -1,15 +1,18 @@
|
||||
#配置版本号 请勿修改!!!
|
||||
Version: 1.0
|
||||
Version: 1.1
|
||||
|
||||
#是否开启
|
||||
Enable: true
|
||||
#是否显示详细信息
|
||||
ShowInfo: true
|
||||
#网络调试模式
|
||||
NetworkDebug: false
|
||||
#是否允许插件主线程访问网络
|
||||
AllowPrimaryThread: false
|
||||
#黑名单列表
|
||||
Black:
|
||||
- BukkitInjectedTools
|
||||
- FeatherBoard
|
||||
#忽略检测列表
|
||||
Ignore:
|
||||
- Essentials
|
||||
#URL白名单网址
|
||||
WhiteKeyList:
|
||||
- yum
|
||||
- Essentials
|
7
src/main/resources/thread.yml
Normal file
7
src/main/resources/thread.yml
Normal file
@ -0,0 +1,7 @@
|
||||
#配置版本号 请勿修改!!!
|
||||
Version: 1.0
|
||||
|
||||
#是否开启线程安全检测
|
||||
ThreadSafe: true
|
||||
#是否开启主线程IO检测
|
||||
MainThreadCheck: true
|
Loading…
Reference in New Issue
Block a user