1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-12-25 07:08:52 +00:00

feat: 添加代理方法

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-07-25 13:53:57 +08:00
parent 73eeac2484
commit 1a7e967826
2 changed files with 107 additions and 77 deletions

View File

@ -1,48 +1,59 @@
package pw.yumc.YumCore.bukkit;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* 插件日志输出类
*
* @since 2016年7月23日 上午9:11:01
* @author
*/
public class Log {
private static Logger logger = P.instance.getLogger();
public static void addHandler(final Handler handler) throws SecurityException {
logger.addHandler(handler);
}
public static void info(final String msg) {
logger.info(msg);
}
public static void log(final Level level, final String msg) {
logger.log(level, msg);
}
public static void log(final Level level, final String msg, final Object param1) {
logger.log(level, msg, param1);
}
public static void log(final Level level, final String msg, final Object[] params) {
logger.log(level, msg, params);
}
public static void log(final Level level, final String msg, final Throwable thrown) {
logger.log(level, msg, thrown);
}
public static void severe(final String msg) {
logger.severe(msg);
}
public static void warning(final String msg) {
logger.warning(msg);
}
}
package pw.yumc.YumCore.bukkit;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
/**
* 插件日志输出类
*
* @since 2016年7月23日 上午9:11:01
* @author
*/
public class Log {
private static Logger logger = P.instance.getLogger();
private static String prefix = String.format("§6[§b%s§6]§r ", P.instance.getName());
private static CommandSender console = Bukkit.getConsoleSender();
public static void addHandler(final Handler handler) throws SecurityException {
logger.addHandler(handler);
}
public static void console(final String... msg) {
for (final String str : msg) {
console.sendMessage(prefix + str);
}
}
public static void info(final String msg) {
logger.info(msg);
}
public static void log(final Level level, final String msg) {
logger.log(level, msg);
}
public static void log(final Level level, final String msg, final Object param1) {
logger.log(level, msg, param1);
}
public static void log(final Level level, final String msg, final Object[] params) {
logger.log(level, msg, params);
}
public static void log(final Level level, final String msg, final Throwable thrown) {
logger.log(level, msg, thrown);
}
public static void severe(final String msg) {
logger.severe(msg);
}
public static void warning(final String msg) {
logger.warning(msg);
}
}

View File

@ -1,29 +1,48 @@
package pw.yumc.YumCore.bukkit;
import java.lang.reflect.Field;
import org.bukkit.plugin.java.JavaPlugin;
/**
* 插件Instance获取类
*
* @since 2016年7月23日 上午9:09:57
* @author
*/
public class P {
/**
* 插件实例
*/
public static JavaPlugin instance;
static {
final Object pluginClassLoader = P.class.getClassLoader();
try {
final Field field = pluginClassLoader.getClass().getDeclaredField("plugin");
field.setAccessible(true);
instance = (JavaPlugin) field.get(pluginClassLoader);
} catch (final Exception e) {
e.printStackTrace();
}
}
}
package pw.yumc.YumCore.bukkit;
import java.lang.reflect.Field;
import java.util.logging.Logger;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
/**
* 插件Instance获取类
*
* @since 2016年7月23日 上午9:09:57
* @author
*/
public class P {
/**
* 插件实例
*/
public static JavaPlugin instance;
static {
final Object pluginClassLoader = P.class.getClassLoader();
try {
final Field field = pluginClassLoader.getClass().getDeclaredField("plugin");
field.setAccessible(true);
instance = (JavaPlugin) field.get(pluginClassLoader);
} catch (final Exception e) {
e.printStackTrace();
}
}
public PluginCommand getCommand(final String name) {
return instance.getCommand(name);
}
public FileConfiguration getConfig() {
return instance.getConfig();
}
public final Logger getLogger() {
return instance.getLogger();
}
public final String getName() {
return instance.getName();
}
}