feat: 添加新配置文件 更新配置管理类

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-06-16 21:02:27 +08:00
parent bd273fcc31
commit acef319e0d
7 changed files with 100 additions and 24 deletions

View File

@ -94,5 +94,11 @@
<type>jar</type> <type>jar</type>
<version>1.0</version> <version>1.0</version>
</dependency> </dependency>
<dependency>
<groupId>pw.yumc</groupId>
<artifactId>BukkitInjectedTools</artifactId>
<type>jar</type>
<version>1.0</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -7,7 +7,7 @@ import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.CommonData.UpdatePlugin; import cn.citycraft.CommonData.UpdatePlugin;
import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.kit.PluginKit;
import cn.citycraft.PluginHelper.utils.VersionChecker; import cn.citycraft.PluginHelper.utils.VersionChecker;
import pw.yumc.Yum.api.YumAPI; import pw.yumc.Yum.api.YumAPI;
import pw.yumc.Yum.commands.FileCommand; import pw.yumc.Yum.commands.FileCommand;
@ -25,14 +25,8 @@ import pw.yumc.Yum.managers.NetworkManager;
* @since 2015年8月21日下午5:14:39 * @since 2015年8月21日下午5:14:39
*/ */
public class Yum extends JavaPlugin { public class Yum extends JavaPlugin {
FileConfig config;
NetworkManager netmgr; NetworkManager netmgr;
@Override
public FileConfig getConfig() {
return config;
}
public void initCommands() { public void initCommands() {
new YumCommand(this); new YumCommand(this);
new NetCommand(this); new NetCommand(this);
@ -40,8 +34,24 @@ public class Yum extends JavaPlugin {
} }
public void initListeners() { public void initListeners() {
new SecurityListener(this); if (ConfigManager.i().isSetOpEnable()) {
new PluginNetworkListener(this); 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 @Override
@ -61,9 +71,8 @@ public class Yum extends JavaPlugin {
@Override @Override
public void onLoad() { public void onLoad() {
config = new FileConfig(this);
// 初始化配置 // 初始化配置
ConfigManager.init(getConfig()); ConfigManager.i();
// 初始化更新列 // 初始化更新列
UpdatePlugin.getUpdateList(); UpdatePlugin.getUpdateList();
// 启用网络注入 // 启用网络注入

View File

@ -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请注意服务器网络安全!"; 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) { if (plugin != null) {
Bukkit.getConsoleSender().sendMessage(String.format(str, plugin.getName(), urlinfo)); 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在主线程访问网络!"); Bukkit.getConsoleSender().sendMessage("§6[§bYum §a网络管理§6] §4已阻止插件 §b" + plugin.getName() + " §4在主线程访问网络!");
ExceptionKit.throwException(new IOException("[Yum 网络防护] 已开启网络防护 不允许在主线程访问网络!")); ExceptionKit.throwException(new IOException("[Yum 网络防护] 已开启网络防护 不允许在主线程访问网络!"));
} }

View File

@ -2,32 +2,77 @@ package pw.yumc.Yum.managers;
import java.util.List; import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.PluginHelper.kit.PKit;
public class ConfigManager { public class ConfigManager {
private static boolean allowPrimaryThread;
private static boolean networkDebug;
private static List<String> blackList; private static List<String> blackList;
private static List<String> ignoreList; 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; return blackList;
} }
public static List<String> getIgnoreList() { public List<String> getIgnoreList() {
return ignoreList; return ignoreList;
} }
public static void init(final FileConfig config) { public List<String> getNetworkBlackList() {
allowPrimaryThread = config.getBoolean("AllowPrimaryThread", false); return network.getStringList(BLACK);
networkDebug = config.getBoolean("NetworkDebug", false);
} }
public static boolean isAllowPrimaryThread() { public List<String> getNetworkIgnoreList() {
return allowPrimaryThread; return network.getStringList(IGNORE);
} }
public static boolean isNetworkDebug() { public List<String> getSetOpBlackList() {
return networkDebug; 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();
} }
} }

View File

@ -186,7 +186,7 @@ public class RepositoryManager {
public boolean updateRepositories(final CommandSender sender) { public boolean updateRepositories(final CommandSender sender) {
repocache.getPlugins().clear(); repocache.getPlugins().clear();
if (repocache.getRepos().isEmpty()) { 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(); final Iterator<Entry<String, Repositories>> keys = repocache.getRepos().entrySet().iterator();
while (keys.hasNext()) { while (keys.hasNext()) {

View File

@ -0,0 +1,8 @@
#是否开启
Enable: true
#黑名单列表
Black:
- BukkitInjectedTools
#忽略检测列表
Ignore:
- Essentials

View File

@ -0,0 +1,8 @@
#是否开启
Enable: true
#黑名单列表
Black:
- BukkitInjectedTools
#忽略检测列表
Ignore:
- Essentials