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
bd273fcc31
commit
acef319e0d
6
pom.xml
6
pom.xml
@ -94,5 +94,11 @@
|
||||
<type>jar</type>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>BukkitInjectedTools</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -7,7 +7,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.CommonData.UpdatePlugin;
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
import cn.citycraft.PluginHelper.kit.PluginKit;
|
||||
import cn.citycraft.PluginHelper.utils.VersionChecker;
|
||||
import pw.yumc.Yum.api.YumAPI;
|
||||
import pw.yumc.Yum.commands.FileCommand;
|
||||
@ -25,14 +25,8 @@ import pw.yumc.Yum.managers.NetworkManager;
|
||||
* @since 2015年8月21日下午5:14:39
|
||||
*/
|
||||
public class Yum extends JavaPlugin {
|
||||
FileConfig config;
|
||||
NetworkManager netmgr;
|
||||
|
||||
@Override
|
||||
public FileConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void initCommands() {
|
||||
new YumCommand(this);
|
||||
new NetCommand(this);
|
||||
@ -40,8 +34,24 @@ public class Yum extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void initListeners() {
|
||||
new SecurityListener(this);
|
||||
new PluginNetworkListener(this);
|
||||
if (ConfigManager.i().isSetOpEnable()) {
|
||||
try {
|
||||
final ClassLoader cl = Class.forName("pw.yumc.injected.event.SetOpEvent").getClassLoader();
|
||||
try {
|
||||
cl.getClass().getDeclaredField("plugin");
|
||||
throw new ClassNotFoundException();
|
||||
} catch (final NoSuchFieldException | SecurityException e) {
|
||||
new SecurityListener(this);
|
||||
PluginKit.scp("§a安全管理系统已启用...");
|
||||
}
|
||||
} catch (final ClassNotFoundException e) {
|
||||
PluginKit.scp("§c服务端未注入安全拦截器 关闭功能...");
|
||||
}
|
||||
}
|
||||
if (ConfigManager.i().isNetworkEnable()) {
|
||||
new PluginNetworkListener(this);
|
||||
PluginKit.scp("§a网络管理系统已启用...");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -61,9 +71,8 @@ public class Yum extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
config = new FileConfig(this);
|
||||
// 初始化配置
|
||||
ConfigManager.init(getConfig());
|
||||
ConfigManager.i();
|
||||
// 初始化更新列
|
||||
UpdatePlugin.getUpdateList();
|
||||
// 启用网络注入
|
||||
|
@ -24,7 +24,7 @@ public class PluginNetworkListener implements Listener {
|
||||
final String str = isPrimaryThread ? "§6[§bYum §a网络管理§6] §c插件 §6%s §c尝试在主线程访问 §e%s §4可能会导致服务器卡顿或无响应!" : "§6[§bYum §a网络监控§6] §c插件 §6%s §c尝试访问 §e%s §c请注意服务器网络安全!";
|
||||
if (plugin != null) {
|
||||
Bukkit.getConsoleSender().sendMessage(String.format(str, plugin.getName(), urlinfo));
|
||||
if (!ConfigManager.isAllowPrimaryThread() && isPrimaryThread) {
|
||||
if (!ConfigManager.i().isAllowPrimaryThread() && isPrimaryThread) {
|
||||
Bukkit.getConsoleSender().sendMessage("§6[§bYum §a网络管理§6] §4已阻止插件 §b" + plugin.getName() + " §4在主线程访问网络!");
|
||||
ExceptionKit.throwException(new IOException("[Yum 网络防护] 已开启网络防护 不允许在主线程访问网络!"));
|
||||
}
|
||||
|
@ -2,32 +2,77 @@ package pw.yumc.Yum.managers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
import cn.citycraft.PluginHelper.kit.PKit;
|
||||
|
||||
public class ConfigManager {
|
||||
private static boolean allowPrimaryThread;
|
||||
private static boolean networkDebug;
|
||||
private static List<String> blackList;
|
||||
private static List<String> ignoreList;
|
||||
|
||||
public static List<String> getBlackList() {
|
||||
private final static String ENABLE = "Enable";
|
||||
private final static String BLACK = "Black";
|
||||
private final static String IGNORE = "Ignore";
|
||||
|
||||
private final static ConfigManager i = new ConfigManager(PKit.i());
|
||||
|
||||
private final FileConfig config;
|
||||
private final FileConfig setop;
|
||||
private final FileConfig network;
|
||||
|
||||
public static ConfigManager i() {
|
||||
return i;
|
||||
}
|
||||
|
||||
public ConfigManager(final JavaPlugin plugin) {
|
||||
config = new FileConfig(plugin);
|
||||
setop = new FileConfig(plugin, "setop.yml");
|
||||
network = new FileConfig(plugin, "network.yml");
|
||||
}
|
||||
|
||||
public List<String> getBlackList() {
|
||||
return blackList;
|
||||
}
|
||||
|
||||
public static List<String> getIgnoreList() {
|
||||
public List<String> getIgnoreList() {
|
||||
return ignoreList;
|
||||
}
|
||||
|
||||
public static void init(final FileConfig config) {
|
||||
allowPrimaryThread = config.getBoolean("AllowPrimaryThread", false);
|
||||
networkDebug = config.getBoolean("NetworkDebug", false);
|
||||
public List<String> getNetworkBlackList() {
|
||||
return network.getStringList(BLACK);
|
||||
}
|
||||
|
||||
public static boolean isAllowPrimaryThread() {
|
||||
return allowPrimaryThread;
|
||||
public List<String> getNetworkIgnoreList() {
|
||||
return network.getStringList(IGNORE);
|
||||
}
|
||||
|
||||
public static boolean isNetworkDebug() {
|
||||
return networkDebug;
|
||||
public List<String> getSetOpBlackList() {
|
||||
return setop.getStringList(BLACK);
|
||||
}
|
||||
|
||||
public List<String> getSetOpIgnoreList() {
|
||||
return setop.getStringList(IGNORE);
|
||||
}
|
||||
|
||||
public boolean isAllowPrimaryThread() {
|
||||
return config.getBoolean("AllowPrimaryThread", false);
|
||||
}
|
||||
|
||||
public boolean isNetworkDebug() {
|
||||
return config.getBoolean("NetworkDebug", false);
|
||||
}
|
||||
|
||||
public boolean isNetworkEnable() {
|
||||
return network.getBoolean(ENABLE, true);
|
||||
}
|
||||
|
||||
public boolean isSetOpEnable() {
|
||||
return setop.getBoolean(ENABLE, true);
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
setop.reload();
|
||||
network.reload();
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ public class RepositoryManager {
|
||||
public boolean updateRepositories(final CommandSender sender) {
|
||||
repocache.getPlugins().clear();
|
||||
if (repocache.getRepos().isEmpty()) {
|
||||
repocache.addRepo("https://coding.net/u/502647092/p/YumData/git/raw/master/yumcenter/repo.info");
|
||||
repocache.addRepo("http://data.yumc.pw/yumcenter/repo.info");
|
||||
}
|
||||
final Iterator<Entry<String, Repositories>> keys = repocache.getRepos().entrySet().iterator();
|
||||
while (keys.hasNext()) {
|
||||
|
8
src/main/resources/network.yml
Normal file
8
src/main/resources/network.yml
Normal file
@ -0,0 +1,8 @@
|
||||
#是否开启
|
||||
Enable: true
|
||||
#黑名单列表
|
||||
Black:
|
||||
- BukkitInjectedTools
|
||||
#忽略检测列表
|
||||
Ignore:
|
||||
- Essentials
|
8
src/main/resources/setop.yml
Normal file
8
src/main/resources/setop.yml
Normal file
@ -0,0 +1,8 @@
|
||||
#是否开启
|
||||
Enable: true
|
||||
#黑名单列表
|
||||
Black:
|
||||
- BukkitInjectedTools
|
||||
#忽略检测列表
|
||||
Ignore:
|
||||
- Essentials
|
Loading…
Reference in New Issue
Block a user