feat: 使用新版本API

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-09-27 17:02:20 +08:00
parent 340d457e41
commit 277f42bd2e
20 changed files with 84 additions and 78 deletions

View File

@ -12,7 +12,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.CommonData.UpdatePlugin; import cn.citycraft.CommonData.UpdatePlugin;
import cn.citycraft.PluginHelper.ext.kit.Reflect; import cn.citycraft.PluginHelper.ext.kit.Reflect;
import cn.citycraft.PluginHelper.kit.PluginKit;
import pw.yumc.Yum.api.YumAPI; import pw.yumc.Yum.api.YumAPI;
import pw.yumc.Yum.commands.FileCommand; import pw.yumc.Yum.commands.FileCommand;
import pw.yumc.Yum.commands.MonitorCommand; import pw.yumc.Yum.commands.MonitorCommand;
@ -26,6 +25,7 @@ import pw.yumc.Yum.managers.ConfigManager;
import pw.yumc.Yum.managers.MonitorManager; import pw.yumc.Yum.managers.MonitorManager;
import pw.yumc.Yum.managers.NetworkManager; import pw.yumc.Yum.managers.NetworkManager;
import pw.yumc.Yum.runnables.MainThreadCheckTask; import pw.yumc.Yum.runnables.MainThreadCheckTask;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.statistic.Statistics; import pw.yumc.YumCore.statistic.Statistics;
import pw.yumc.YumCore.update.SubscribeTask; import pw.yumc.YumCore.update.SubscribeTask;
@ -108,19 +108,19 @@ public class Yum extends JavaPlugin {
throw new ClassNotFoundException(); throw new ClassNotFoundException();
} catch (final NoSuchFieldException | SecurityException e) { } catch (final NoSuchFieldException | SecurityException e) {
new SecurityListener(this); new SecurityListener(this);
PluginKit.scp("§a安全管理系统已启用..."); Log.console("§a安全管理系统已启用...");
} }
} catch (final ClassNotFoundException e) { } catch (final ClassNotFoundException e) {
PluginKit.scp("§c服务端未注入安全拦截器 关闭功能..."); Log.console("§c服务端未注入安全拦截器 关闭功能...");
} }
} }
if (ConfigManager.i().isNetworkEnable()) { if (ConfigManager.i().isNetworkEnable()) {
new PluginNetworkListener(this); new PluginNetworkListener(this);
PluginKit.scp("§a网络管理系统已启用..."); Log.console("§a网络管理系统已启用...");
} }
if (ConfigManager.i().isThreadSafe()) { if (ConfigManager.i().isThreadSafe()) {
new ThreadSafetyListener(this); new ThreadSafetyListener(this);
PluginKit.scp("§a线程管理系统已启用..."); Log.console("§a线程管理系统已启用...");
} }
if (ConfigManager.i().isMonitorEnable()) { if (ConfigManager.i().isMonitorEnable()) {
new PluginListener(); new PluginListener();
@ -133,7 +133,7 @@ public class Yum extends JavaPlugin {
private void initRunnable() { private void initRunnable() {
// 需要在主线程注册任务 // 需要在主线程注册任务
if (ConfigManager.i().isMainThreadCheck() && mainThread != null) { if (ConfigManager.i().isMainThreadCheck() && mainThread != null) {
PluginKit.scp("§aI O 管理系统已启用..."); Log.console("§aI O 管理系统已启用...");
if (tt != null) { if (tt != null) {
tt.cancel(); tt.cancel();
} }

View File

@ -11,8 +11,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import cn.citycraft.CommonData.UpdatePlugin; import cn.citycraft.CommonData.UpdatePlugin;
import cn.citycraft.PluginHelper.kit.PKit;
import cn.citycraft.PluginHelper.kit.PluginKit;
import pw.yumc.Yum.inject.CommandInjector; import pw.yumc.Yum.inject.CommandInjector;
import pw.yumc.Yum.inject.ListenerInjector; import pw.yumc.Yum.inject.ListenerInjector;
import pw.yumc.Yum.inject.TaskInjector; import pw.yumc.Yum.inject.TaskInjector;
@ -21,6 +19,8 @@ import pw.yumc.Yum.managers.DownloadManager;
import pw.yumc.Yum.managers.PluginsManager; import pw.yumc.Yum.managers.PluginsManager;
import pw.yumc.Yum.managers.RepositoryManager; import pw.yumc.Yum.managers.RepositoryManager;
import pw.yumc.Yum.models.PluginInfo; import pw.yumc.Yum.models.PluginInfo;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.kit.PKit;
/** /**
* Yum管理中心 * Yum管理中心
@ -42,7 +42,7 @@ public class YumAPI {
* 插件实体 * 插件实体
*/ */
public YumAPI() { public YumAPI() {
YumAPI.main = PKit.instance; YumAPI.main = P.instance;
plugman = new PluginsManager(main); plugman = new PluginsManager(main);
download = new DownloadManager(main); download = new DownloadManager(main);
repo = new RepositoryManager(main); repo = new RepositoryManager(main);
@ -321,7 +321,7 @@ public class YumAPI {
* 命令发送者 * 命令发送者
*/ */
public static void updateCheck(final CommandSender sender) { public static void updateCheck(final CommandSender sender) {
PluginKit.runTaskLaterAsync(new Runnable() { PKit.runTaskLaterAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
final List<Plugin> ulist = getUpdateList(sender); final List<Plugin> ulist = getUpdateList(sender);
@ -395,7 +395,7 @@ public class YumAPI {
* 更新注入 * 更新注入
*/ */
public static void updateInject() { public static void updateInject() {
PluginKit.runTaskLater(new Runnable() { PKit.runTaskLater(new Runnable() {
@Override @Override
public void run() { public void run() {
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) { for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
@ -409,7 +409,7 @@ public class YumAPI {
* 更新Yum源数据 * 更新Yum源数据
*/ */
public static void updateRepo(final CommandSender sender) { public static void updateRepo(final CommandSender sender) {
PluginKit.runTaskAsync(new Runnable() { PKit.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
repo.updateRepositories(sender); repo.updateRepositories(sender);

View File

@ -2,7 +2,12 @@ package pw.yumc.Yum.commands;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -52,7 +57,7 @@ public class FileCommand implements CommandExecutor {
@Cmd(aliases = "cp", minimumArguments = 2) @Cmd(aliases = "cp", minimumArguments = 2)
@Help(value = "复制文件", possibleArguments = "<源文件> <目标目录>") @Help(value = "复制文件", possibleArguments = "<源文件> <目标目录>")
@Async @Async
public void copy(final CommandArgument e) { public void copy(final CommandArgument e) throws FileNotFoundException, IOException {
final String[] args = e.getArgs(); final String[] args = e.getArgs();
final CommandSender sender = e.getSender(); final CommandSender sender = e.getSender();
final File src = new File(args[0]); final File src = new File(args[0]);
@ -65,7 +70,7 @@ public class FileCommand implements CommandExecutor {
sender.sendMessage(String.format(file_is_dir, args[0])); sender.sendMessage(String.format(file_is_dir, args[0]));
return; return;
} }
if (FileUtil.copyFile(src, des)) { if (Files.copy(new FileInputStream(src), des.toPath(), StandardCopyOption.REPLACE_EXISTING) != 0) {
sender.sendMessage(String.format(copySuccess, args[0])); sender.sendMessage(String.format(copySuccess, args[0]));
} else { } else {
sender.sendMessage(String.format(copyFailed, args[0])); sender.sendMessage(String.format(copyFailed, args[0]));

View File

@ -21,7 +21,6 @@ import org.bukkit.plugin.TimedRegisteredListener;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import cn.citycraft.PluginHelper.ext.kit.Reflect; import cn.citycraft.PluginHelper.ext.kit.Reflect;
import cn.citycraft.PluginHelper.kit.PluginKit;
import cn.citycraft.PluginHelper.kit.StrKit; import cn.citycraft.PluginHelper.kit.StrKit;
import pw.yumc.Yum.Yum; import pw.yumc.Yum.Yum;
import pw.yumc.Yum.api.YumAPI; import pw.yumc.Yum.api.YumAPI;
@ -36,6 +35,7 @@ import pw.yumc.YumCore.commands.CommandManager;
import pw.yumc.YumCore.commands.annotation.Async; import pw.yumc.YumCore.commands.annotation.Async;
import pw.yumc.YumCore.commands.annotation.Cmd; import pw.yumc.YumCore.commands.annotation.Cmd;
import pw.yumc.YumCore.commands.annotation.Help; import pw.yumc.YumCore.commands.annotation.Help;
import pw.yumc.YumCore.kit.PKit;
/** /**
* *
@ -218,7 +218,7 @@ public class MonitorCommand implements CommandExecutor {
sender.sendMessage(no_error); sender.sendMessage(no_error);
return; return;
} }
final Plugin plugin = PluginKit.getOperatePlugin(lastError.getStackTrace()); final Plugin plugin = PKit.getOperatePlugin(lastError.getStackTrace());
sender.sendMessage(String.format(last_error, plugin != null ? plugin.getName() : "未知")); sender.sendMessage(String.format(last_error, plugin != null ? plugin.getName() : "未知"));
lastError.printStackTrace(); lastError.printStackTrace();
} }

View File

@ -19,7 +19,6 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.PluginHelper.callback.CallBack.One; import cn.citycraft.PluginHelper.callback.CallBack.One;
import cn.citycraft.PluginHelper.kit.PluginKit;
import cn.citycraft.PluginHelper.kit.ZipKit; import cn.citycraft.PluginHelper.kit.ZipKit;
import cn.citycraft.PluginHelper.utils.FileUtil; import cn.citycraft.PluginHelper.utils.FileUtil;
import cn.citycraft.PluginHelper.utils.IOUtil; import cn.citycraft.PluginHelper.utils.IOUtil;
@ -38,6 +37,7 @@ import pw.yumc.YumCore.commands.annotation.Async;
import pw.yumc.YumCore.commands.annotation.Cmd; import pw.yumc.YumCore.commands.annotation.Cmd;
import pw.yumc.YumCore.commands.annotation.Help; import pw.yumc.YumCore.commands.annotation.Help;
import pw.yumc.YumCore.commands.annotation.Sort; import pw.yumc.YumCore.commands.annotation.Sort;
import pw.yumc.YumCore.kit.PKit;
import pw.yumc.YumCore.tellraw.Tellraw; import pw.yumc.YumCore.tellraw.Tellraw;
/** /**
@ -87,7 +87,7 @@ public class YumCommand implements Listener, CommandExecutor {
public void bukkitrepo(final CommandArgument e) { public void bukkitrepo(final CommandArgument e) {
final String[] args = e.getArgs(); final String[] args = e.getArgs();
final CommandSender sender = e.getSender(); final CommandSender sender = e.getSender();
PluginKit.runTaskAsync(new Runnable() { PKit.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
final String id = args[1]; final String id = args[1];

View File

@ -16,7 +16,6 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import cn.citycraft.PluginHelper.ext.kit.Reflect; import cn.citycraft.PluginHelper.ext.kit.Reflect;
import cn.citycraft.PluginHelper.kit.PluginKit;
import cn.citycraft.PluginHelper.kit.StrKit; import cn.citycraft.PluginHelper.kit.StrKit;
import pw.yumc.Yum.commands.MonitorCommand; import pw.yumc.Yum.commands.MonitorCommand;
import pw.yumc.Yum.managers.MonitorManager; import pw.yumc.Yum.managers.MonitorManager;
@ -63,7 +62,7 @@ public class CommandInjector implements TabExecutor {
} }
} }
} catch (final Throwable e) { } catch (final Throwable e) {
PluginKit.sc(String.format(inject_error, plugin.getName())); MonitorManager.log(String.format(inject_error, plugin.getName()));
} }
} }

View File

@ -6,11 +6,12 @@ import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.PluginEnableEvent;
import cn.citycraft.PluginHelper.kit.PluginKit;
import pw.yumc.Yum.api.YumAPI; import pw.yumc.Yum.api.YumAPI;
import pw.yumc.Yum.managers.ConfigManager; import pw.yumc.Yum.managers.ConfigManager;
import pw.yumc.Yum.managers.MonitorManager; import pw.yumc.Yum.managers.MonitorManager;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.P; import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.kit.PKit;
/** /**
* *
@ -21,7 +22,7 @@ public class PluginListener implements Listener {
public PluginListener() { public PluginListener() {
Bukkit.getPluginManager().registerEvents(this, P.instance); Bukkit.getPluginManager().registerEvents(this, P.instance);
PluginKit.scp("§a性能监控系统已启用..."); Log.console("§a性能监控系统已启用...");
} }
@EventHandler @EventHandler
@ -35,7 +36,7 @@ public class PluginListener implements Listener {
return; return;
} }
MonitorManager.reset(e.getPlugin().getName()); MonitorManager.reset(e.getPlugin().getName());
PluginKit.runTaskLater(new Runnable() { PKit.runTaskLater(new Runnable() {
@Override @Override
public void run() { public void run() {
YumAPI.inject(e.getPlugin()); YumAPI.inject(e.getPlugin());

View File

@ -5,11 +5,11 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.kit.PluginKit;
import pw.yumc.Yum.Yum; import pw.yumc.Yum.Yum;
import pw.yumc.Yum.commands.NetCommand; import pw.yumc.Yum.commands.NetCommand;
import pw.yumc.Yum.events.PluginNetworkEvent; import pw.yumc.Yum.events.PluginNetworkEvent;
import pw.yumc.Yum.managers.ConfigManager; import pw.yumc.Yum.managers.ConfigManager;
import pw.yumc.YumCore.bukkit.Log;
public class PluginNetworkListener implements Listener { public class PluginNetworkListener implements Listener {
public String prefix = "§6[§bYum §a网络管理§6] "; public String prefix = "§6[§bYum §a网络管理§6] ";
@ -24,8 +24,8 @@ public class PluginNetworkListener implements Listener {
public void breakNetwork(final PluginNetworkEvent e) { public void breakNetwork(final PluginNetworkEvent e) {
if (ConfigManager.i().isNetworkShowInfo()) { if (ConfigManager.i().isNetworkShowInfo()) {
PluginKit.sc(String.format(prefix + breaked, e.getPlugin().getName())); Log.console(prefix + breaked, e.getPlugin().getName());
PluginKit.sc(String.format(prefix + url, e.getUrl().toString())); Log.console(prefix + url, e.getUrl().toString());
} }
e.setCancelled(true); e.setCancelled(true);
} }
@ -55,13 +55,13 @@ public class PluginNetworkListener implements Listener {
return; return;
} }
if (e.isPrimaryThread()) { if (e.isPrimaryThread()) {
PluginKit.sc(String.format(prefix + warnMain, plugin.getName())); Log.console(prefix + warnMain, plugin.getName());
if (!ConfigManager.i().isAllowPrimaryThread()) { if (!ConfigManager.i().isAllowPrimaryThread()) {
breakNetwork(e); breakNetwork(e);
} }
} else { } else {
PluginKit.sc(String.format(prefix + warn, plugin.getName())); Log.console(prefix + warn, plugin.getName());
PluginKit.sc(String.format(prefix + url, urlinfo)); Log.console(prefix + url, urlinfo);
} }
} }
} }

View File

@ -5,9 +5,10 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.kit.PluginKit;
import pw.yumc.Yum.Yum; import pw.yumc.Yum.Yum;
import pw.yumc.Yum.managers.ConfigManager; import pw.yumc.Yum.managers.ConfigManager;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.kit.PKit;
import pw.yumc.injected.event.SetOpEvent; import pw.yumc.injected.event.SetOpEvent;
/** /**
@ -26,10 +27,10 @@ public class SecurityListener implements Listener {
@EventHandler @EventHandler
public void setop(final SetOpEvent e) { public void setop(final SetOpEvent e) {
final Plugin plugin = PluginKit.getOperatePlugin(); final Plugin plugin = PKit.getOperatePlugin();
if (plugin != null) { if (plugin != null) {
if (ConfigManager.i().getSetOpBlackList().contains(plugin.getName())) { if (ConfigManager.i().getSetOpBlackList().contains(plugin.getName())) {
PluginKit.sc(String.format(prefix + prevent, plugin, e.getOfflinePlayer().getName())); Log.console(prefix + prevent, plugin, e.getOfflinePlayer().getName());
e.setCancelled(true); e.setCancelled(true);
return; return;
} }

View File

@ -17,8 +17,8 @@ import org.bukkit.event.world.WorldSaveEvent;
import org.bukkit.event.world.WorldUnloadEvent; import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.kit.PluginKit;
import pw.yumc.Yum.Yum; import pw.yumc.Yum.Yum;
import pw.yumc.YumCore.kit.PKit;
/** /**
* Fork From LagMonitor: https://github.com/games647/LagMonitor.git * Fork From LagMonitor: https://github.com/games647/LagMonitor.git
@ -86,7 +86,7 @@ public class ThreadSafetyListener implements Listener {
private void checkSafety(final Event eventType) { private void checkSafety(final Event eventType) {
if (Yum.mainThread != null && Thread.currentThread() != Yum.mainThread && !eventType.isAsynchronous()) { if (Yum.mainThread != null && Thread.currentThread() != Yum.mainThread && !eventType.isAsynchronous()) {
final String eventName = eventType.getEventName(); final String eventName = eventType.getEventName();
final Plugin plugin = PluginKit.getOperatePlugin(); final Plugin plugin = PKit.getOperatePlugin();
if (plugin != null) { if (plugin != null) {
throw new IllegalAccessError("[Yum 线程安全]: 请勿异步调用一个同步事件 " + eventName + " 操作插件: " + plugin.getName()); throw new IllegalAccessError("[Yum 线程安全]: 请勿异步调用一个同步事件 " + eventName + " 操作插件: " + plugin.getName());
} }

View File

@ -4,9 +4,9 @@ import java.util.List;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.PluginHelper.sql.DataBase;
import pw.yumc.YumCore.bukkit.P; import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.config.FileConfig;
import pw.yumc.YumCore.sql.DataBase;
public class ConfigManager { public class ConfigManager {
public final static String ENABLE = "Enable"; public final static String ENABLE = "Enable";
@ -22,11 +22,11 @@ public class ConfigManager {
public final FileConfig monitor; public final FileConfig monitor;
public ConfigManager(final JavaPlugin plugin) { public ConfigManager(final JavaPlugin plugin) {
config = new FileConfig(plugin); config = new FileConfig();
setop = new FileConfig(plugin, "setop.yml"); setop = new FileConfig("setop.yml");
network = new FileConfig(plugin, "network.yml"); network = new FileConfig("network.yml");
thread = new FileConfig(plugin, "thread.yml"); thread = new FileConfig("thread.yml");
monitor = new FileConfig(plugin, "monitor.yml"); monitor = new FileConfig("monitor.yml");
} }
public static ConfigManager i() { public static ConfigManager i() {

View File

@ -1,8 +1,8 @@
package pw.yumc.Yum.managers; package pw.yumc.Yum.managers;
import cn.citycraft.PluginHelper.sql.DataBase;
import cn.citycraft.PluginHelper.sql.KeyValue;
import cn.citycraft.PluginHelper.sql.Type; import cn.citycraft.PluginHelper.sql.Type;
import pw.yumc.YumCore.sql.DataBase;
import pw.yumc.YumCore.sql.core.KeyValue;
public class DataManager { public class DataManager {
private static DataBase db = ConfigManager.i().getDataBase(); private static DataBase db = ConfigManager.i().getDataBase();

View File

@ -16,7 +16,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.kit.LogKit; import cn.citycraft.PluginHelper.kit.LogKit;
import cn.citycraft.PluginHelper.kit.PluginKit; import pw.yumc.YumCore.bukkit.Log;
/** /**
* 能耗监控管理 * 能耗监控管理
@ -65,7 +65,7 @@ public class MonitorManager {
if (log_to_file) { if (log_to_file) {
elog.logSender(message); elog.logSender(message);
} else { } else {
PluginKit.sc(message); Log.console(message);
} }
} }
@ -92,7 +92,7 @@ public class MonitorManager {
if (log_to_file) { if (log_to_file) {
mlog.logSender(message); mlog.logSender(message);
} else { } else {
PluginKit.sc(message); Log.console(message);
} }
} }
@ -107,7 +107,7 @@ public class MonitorManager {
elog(String.format(errStackTrace, ste.getClassName(), ste.getMethodName(), ste.getFileName(), ste.getLineNumber())); elog(String.format(errStackTrace, ste.getClassName(), ste.getMethodName(), ste.getFileName(), ste.getLineNumber()));
} }
if (debug) { if (debug) {
PluginKit.sc(devInfo); Log.console(devInfo);
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -140,8 +140,8 @@ public class MonitorManager {
if (oriMap == null || oriMap.isEmpty()) { if (oriMap == null || oriMap.isEmpty()) {
return oriMap; return oriMap;
} }
final Map<String, Long> sortedMap = new LinkedHashMap<String, Long>(); final Map<String, Long> sortedMap = new LinkedHashMap<>();
final List<Map.Entry<String, Long>> entryList = new ArrayList<Map.Entry<String, Long>>(oriMap.entrySet()); final List<Map.Entry<String, Long>> entryList = new ArrayList<>(oriMap.entrySet());
Collections.sort(entryList, new MonitorComparator()); Collections.sort(entryList, new MonitorComparator());
final Iterator<Map.Entry<String, Long>> iter = entryList.iterator(); final Iterator<Map.Entry<String, Long>> iter = entryList.iterator();
Entry<String, Long> tmpEntry = null; Entry<String, Long> tmpEntry = null;

View File

@ -10,9 +10,9 @@ import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import cn.citycraft.PluginHelper.kit.ExceptionKit; import cn.citycraft.PluginHelper.kit.ExceptionKit;
import cn.citycraft.PluginHelper.kit.PluginKit;
import pw.yumc.Yum.Yum; import pw.yumc.Yum.Yum;
import pw.yumc.Yum.events.PluginNetworkEvent; import pw.yumc.Yum.events.PluginNetworkEvent;
import pw.yumc.YumCore.kit.PKit;
/** /**
* 网络代理处理类 * 网络代理处理类
@ -52,7 +52,7 @@ public class NetworkManager {
@Override @Override
public List<Proxy> select(final URI uri) { public List<Proxy> select(final URI uri) {
final PluginNetworkEvent pne = new PluginNetworkEvent(PluginKit.getOperatePlugin(), uri, Bukkit.isPrimaryThread()); final PluginNetworkEvent pne = new PluginNetworkEvent(PKit.getOperatePlugin(), uri, Bukkit.isPrimaryThread());
Bukkit.getPluginManager().callEvent(pne); Bukkit.getPluginManager().callEvent(pne);
if (pne.isCancelled()) { if (pne.isCancelled()) {
ExceptionKit.throwException(new IOException("[Yum 网络防护] 已开启网络防护 并被联网规则拦截!")); ExceptionKit.throwException(new IOException("[Yum 网络防护] 已开启网络防护 并被联网规则拦截!"));

View File

@ -33,8 +33,8 @@ import org.bukkit.plugin.UnknownDependencyException;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import cn.citycraft.PluginHelper.kit.StrKit;
import cn.citycraft.PluginHelper.utils.FileUtil; import cn.citycraft.PluginHelper.utils.FileUtil;
import cn.citycraft.PluginHelper.utils.StringUtil;
/** /**
* 插件管理类 * 插件管理类
@ -207,7 +207,7 @@ public class PluginsManager {
* @return 插件 * @return 插件
*/ */
public Plugin getPluginByName(final String[] args, final int start) { public Plugin getPluginByName(final String[] args, final int start) {
return getPluginByName(StringUtil.consolidateStrings(args, start)); return getPluginByName(StrKit.consolidateStrings(args, start));
} }
/** /**
@ -233,7 +233,7 @@ public class PluginsManager {
} }
public List<String> getPluginNames(final boolean fullName) { public List<String> getPluginNames(final boolean fullName) {
final List<String> plugins = new ArrayList<String>(); final List<String> plugins = new ArrayList<>();
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) { for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
plugins.add(fullName ? plugin.getDescription().getFullName() : plugin.getName()); plugins.add(fullName ? plugin.getDescription().getFullName() : plugin.getName());
} }
@ -263,7 +263,7 @@ public class PluginsManager {
* @return 插件命令 * @return 插件命令
*/ */
public String getUsages(final Plugin plugin) { public String getUsages(final Plugin plugin) {
final List<String> parsedCommands = new ArrayList<String>(); final List<String> parsedCommands = new ArrayList<>();
final Map<String, Map<String, Object>> commands = plugin.getDescription().getCommands(); final Map<String, Map<String, Object>> commands = plugin.getDescription().getCommands();

View File

@ -14,7 +14,6 @@ import org.bukkit.command.CommandSender;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
import cn.citycraft.PluginHelper.kit.HttpKit;
import cn.citycraft.PluginHelper.kit.StrKit; import cn.citycraft.PluginHelper.kit.StrKit;
import pw.yumc.Yum.models.PluginInfo; import pw.yumc.Yum.models.PluginInfo;
import pw.yumc.Yum.models.RepoCache; import pw.yumc.Yum.models.RepoCache;
@ -24,6 +23,7 @@ import pw.yumc.Yum.models.RepoSerialization.Repositories;
import pw.yumc.Yum.models.RepoSerialization.Repository; import pw.yumc.Yum.models.RepoSerialization.Repository;
import pw.yumc.Yum.models.RepoSerialization.TagInfo; import pw.yumc.Yum.models.RepoSerialization.TagInfo;
import pw.yumc.Yum.models.RepoSerialization.URLType; import pw.yumc.Yum.models.RepoSerialization.URLType;
import pw.yumc.YumCore.kit.HttpKit;
/** /**
* 仓库管理类 * 仓库管理类
@ -71,7 +71,7 @@ public class RepositoryManager {
} }
public List<PluginInfo> getAllPlugin() { public List<PluginInfo> getAllPlugin() {
final List<PluginInfo> li = new ArrayList<PluginInfo>(); final List<PluginInfo> li = new ArrayList<>();
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) { for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
li.add(plugin.getValue()); li.add(plugin.getValue());
} }
@ -79,7 +79,7 @@ public class RepositoryManager {
} }
public List<String> getAllPluginName() { public List<String> getAllPluginName() {
final List<String> li = new ArrayList<String>(); final List<String> li = new ArrayList<>();
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) { for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
li.add(plugin.getValue().name); li.add(plugin.getValue().name);
} }
@ -87,7 +87,7 @@ public class RepositoryManager {
} }
public List<String> getAllPluginsInfo() { public List<String> getAllPluginsInfo() {
final List<String> li = new ArrayList<String>(); final List<String> li = new ArrayList<>();
li.add("§d仓库名称 §a插件名称 §e插件描述"); li.add("§d仓库名称 §a插件名称 §e插件描述");
for (final Entry<String, PluginInfo> pi : repocache.getPlugins().entrySet()) { for (final Entry<String, PluginInfo> pi : repocache.getPlugins().entrySet()) {
final Plugin plugin = pi.getValue().plugin; final Plugin plugin = pi.getValue().plugin;
@ -114,7 +114,7 @@ public class RepositoryManager {
} }
public List<PluginInfo> getPluginInfo(final String name) { public List<PluginInfo> getPluginInfo(final String name) {
final List<PluginInfo> li = new ArrayList<PluginInfo>(); final List<PluginInfo> li = new ArrayList<>();
for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) { for (final Entry<String, PluginInfo> plugin : repocache.getPlugins().entrySet()) {
if (plugin.getValue().name.equalsIgnoreCase(name)) { if (plugin.getValue().name.equalsIgnoreCase(name)) {
li.add(plugin.getValue()); li.add(plugin.getValue());

View File

@ -9,7 +9,7 @@ import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
import cn.citycraft.PluginHelper.kit.StrKit; import pw.yumc.YumCore.kit.StrKit;
public class BukkitDev implements Serializable { public class BukkitDev implements Serializable {
public static String HOST = "https://api.curseforge.com"; public static String HOST = "https://api.curseforge.com";

View File

@ -5,7 +5,6 @@ import java.io.Serializable;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import cn.citycraft.PluginHelper.PluginHelperLogger;
import cn.citycraft.PluginHelper.utils.IOUtil; import cn.citycraft.PluginHelper.utils.IOUtil;
import pw.yumc.Yum.models.RepoSerialization.Plugin; import pw.yumc.Yum.models.RepoSerialization.Plugin;
import pw.yumc.Yum.models.RepoSerialization.TagInfo; import pw.yumc.Yum.models.RepoSerialization.TagInfo;
@ -95,7 +94,7 @@ public class PluginInfo implements Serializable {
String ver = version; String ver = version;
if (ver == null) { if (ver == null) {
if (plugin.tags != null) { if (plugin.tags != null) {
PluginHelperLogger.getLogger().debug("发现存在TAG标签 开始检索: " + NMSVersion); Log.debug("发现存在TAG标签 开始检索: " + NMSVersion);
for (final TagInfo tagInfo : plugin.tags) { for (final TagInfo tagInfo : plugin.tags) {
if (tagInfo.tag.equalsIgnoreCase(NMSVersion)) { if (tagInfo.tag.equalsIgnoreCase(NMSVersion)) {
sender.sendMessage("§6版本: §b从Tag标签中获取 §e" + NMSVersion + " §b的最新版本..."); sender.sendMessage("§6版本: §b从Tag标签中获取 §e" + NMSVersion + " §b的最新版本...");

View File

@ -10,13 +10,13 @@ import java.util.Map.Entry;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
import cn.citycraft.PluginHelper.kit.PluginKit;
import cn.citycraft.PluginHelper.utils.IOUtil; import cn.citycraft.PluginHelper.utils.IOUtil;
import pw.yumc.Yum.models.RepoSerialization.Repositories; import pw.yumc.Yum.models.RepoSerialization.Repositories;
import pw.yumc.YumCore.bukkit.Log;
public class RepoCache implements Serializable { public class RepoCache implements Serializable {
Map<String, PluginInfo> plugins = new HashMap<String, PluginInfo>(); Map<String, PluginInfo> plugins = new HashMap<>();
Map<String, Repositories> repos = new HashMap<String, Repositories>(); Map<String, Repositories> repos = new HashMap<>();
public void addPlugins(final String name, final PluginInfo info) { public void addPlugins(final String name, final PluginInfo info) {
plugins.put(name, info); plugins.put(name, info);
@ -35,7 +35,7 @@ public class RepoCache implements Serializable {
} }
public List<String> getAllRepoInfo() { public List<String> getAllRepoInfo() {
final List<String> repoinfo = new ArrayList<String>(); final List<String> repoinfo = new ArrayList<>();
for (final Entry<String, Repositories> repo : repos.entrySet()) { for (final Entry<String, Repositories> repo : repos.entrySet()) {
repoinfo.add(String.format("§d仓库: §e%s §6- §3%s", repo.getValue().name, repo.getKey())); repoinfo.add(String.format("§d仓库: §e%s §6- §3%s", repo.getValue().name, repo.getKey()));
} }
@ -49,12 +49,12 @@ public class RepoCache implements Serializable {
public Repositories getRepo(final String repo) { public Repositories getRepo(final String repo) {
final String json = IOUtil.getData(repo); final String json = IOUtil.getData(repo);
if (json == null || json.isEmpty()) { if (json == null || json.isEmpty()) {
PluginKit.sc("§6[§bYum§6] §c源地址获取数据为空 §b" + repo); Log.console("§c源地址获取数据为空 §b" + repo);
return null; return null;
} }
final Repositories reposes = new Repositories((JSONObject) JSONValue.parse(json)); final Repositories reposes = new Repositories((JSONObject) JSONValue.parse(json));
if (reposes.repos.isEmpty()) { if (reposes.repos.isEmpty()) {
PluginKit.sc("§6[§bYum§6] §c源地址解析Json为空 §b" + repo); Log.console("§c源地址解析Json为空 §b" + repo);
return null; return null;
} }
return reposes; return reposes;

View File

@ -5,8 +5,9 @@ import java.util.TimerTask;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.kit.PluginKit;
import cn.citycraft.PluginHelper.kit.ServerKit; import cn.citycraft.PluginHelper.kit.ServerKit;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.kit.PKit;
/** /**
* 线程安全检查任务 * 线程安全检查任务
@ -45,22 +46,22 @@ public class MainThreadCheckTask extends TimerTask {
if (isElementEqual(topElement, "java.net.DualStackPlainSocketImpl", "connect0") if (isElementEqual(topElement, "java.net.DualStackPlainSocketImpl", "connect0")
|| isElementEqual(topElement, "java.net.SocketInputStream", "socketRead0") || isElementEqual(topElement, "java.net.SocketInputStream", "socketRead0")
|| isElementEqual(topElement, "java.net.SocketOutputStream", "socketWrite0")) { || isElementEqual(topElement, "java.net.SocketOutputStream", "socketWrite0")) {
final Plugin plugin = PluginKit.getOperatePlugin(stackTrace); final Plugin plugin = PKit.getOperatePlugin(stackTrace);
if (plugin != null) { if (plugin != null) {
PluginKit.sc(String.format(prefix + warnPNet, plugin.getName())); Log.console(prefix + warnPNet, plugin.getName());
} else { } else {
PluginKit.sc(prefix + warnNet); Log.console(prefix + warnNet);
} }
tick(); tick();
} }
// File (in) - java.io.FileInputStream.readBytes // File (in) - java.io.FileInputStream.readBytes
// File (out) - java.io.FileOutputStream.writeBytes // File (out) - java.io.FileOutputStream.writeBytes
else if (isElementEqual(topElement, "java.io.FileInputStream", "readBytes") || isElementEqual(topElement, "java.io.FileOutputStream", "writeBytes")) { else if (isElementEqual(topElement, "java.io.FileInputStream", "readBytes") || isElementEqual(topElement, "java.io.FileOutputStream", "writeBytes")) {
final Plugin plugin = PluginKit.getOperatePlugin(stackTrace); final Plugin plugin = PKit.getOperatePlugin(stackTrace);
if (plugin != null) { if (plugin != null) {
PluginKit.sc(String.format(prefix + warnPIO, plugin.getName())); Log.console(prefix + warnPIO, plugin.getName());
} else { } else {
PluginKit.sc(prefix + warnIO); Log.console(prefix + warnIO);
} }
tick(); tick();
} else { } else {
@ -79,7 +80,7 @@ public class MainThreadCheckTask extends TimerTask {
private void tick() { private void tick() {
stopTime += 5; stopTime += 5;
if (stopTime >= 45) { if (stopTime >= 45) {
PluginKit.sc(String.format(prefix + deliver, stopTime)); Log.console(prefix + deliver, stopTime);
ServerKit.tick(); ServerKit.tick();
} }
} }