From e85f69e03a918ce2d2ef07bf3464d712f69e8bee Mon Sep 17 00:00:00 2001 From: 502647092 Date: Thu, 8 Dec 2016 20:34:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=B7=A8=E6=9C=8D?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 4 +- src/main/java/pw/yumc/MiaoChat/MiaoChat.java | 15 +- .../pw/yumc/MiaoChat/bungee/FileConfig.java | 193 ++++++++++++++++++ .../java/pw/yumc/MiaoChat/bungee/Log.java | 49 +++++ .../yumc/MiaoChat/config/ChatMessagePart.java | 11 +- .../yumc/MiaoChat/listeners/ChatListener.java | 2 +- 6 files changed, 256 insertions(+), 18 deletions(-) create mode 100644 src/main/java/pw/yumc/MiaoChat/bungee/FileConfig.java create mode 100644 src/main/java/pw/yumc/MiaoChat/bungee/Log.java diff --git a/pom.xml b/pom.xml index 370964d..05fb31d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 pw.yumc MiaoChat - 1.5.1 + 1.6 ${project.name} @@ -105,7 +105,7 @@ pw.yumc YumCore jar - 1.2 + 1.5 \ No newline at end of file diff --git a/src/main/java/pw/yumc/MiaoChat/MiaoChat.java b/src/main/java/pw/yumc/MiaoChat/MiaoChat.java index 3774cbd..a24c5c6 100644 --- a/src/main/java/pw/yumc/MiaoChat/MiaoChat.java +++ b/src/main/java/pw/yumc/MiaoChat/MiaoChat.java @@ -8,18 +8,19 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.messaging.PluginMessageListener; + import pw.yumc.MiaoChat.config.ChatConfig; import pw.yumc.MiaoChat.listeners.ChatListener; import pw.yumc.YumCore.bukkit.Log; import pw.yumc.YumCore.bukkit.compatible.C; -import pw.yumc.YumCore.commands.CommandManager; +import pw.yumc.YumCore.commands.CommandSub; import pw.yumc.YumCore.commands.annotation.Cmd; import pw.yumc.YumCore.commands.annotation.Help; -import pw.yumc.YumCore.commands.interfaces.CommandExecutor; +import pw.yumc.YumCore.commands.interfaces.Executor; import pw.yumc.YumCore.config.FileConfig; import pw.yumc.YumCore.global.L10N; -public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessageListener { +public class MiaoChat extends JavaPlugin implements Executor, PluginMessageListener { private FileConfig cfg; private ChatConfig chatConfig; @@ -36,20 +37,20 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessa @Help("关闭聊天功能") public void off(CommandSender sender) { ChatListener.offList.add(sender.getName()); - Log.toSender(sender, "§c聊天功能已关闭!"); + Log.sender(sender, "§c聊天功能已关闭!"); } @Cmd(permission = "MiaoChat.toggle") @Help("开启聊天功能") public void on(CommandSender sender) { ChatListener.offList.remove(sender.getName()); - Log.toSender(sender, "§a聊天功能已开启!"); + Log.sender(sender, "§a聊天功能已开启!"); } @Override public void onEnable() { new ChatListener(); - new CommandManager("MiaoChat", this); + new CommandSub("MiaoChat", this); if (getChatConfig().isBungeeCord()) { Log.info("已开启 BUngeeCord 模式!"); Bukkit.getMessenger().registerIncomingPluginChannel(this, MiaoMessage.CHANNEL, this); @@ -71,7 +72,7 @@ public class MiaoChat extends JavaPlugin implements CommandExecutor, PluginMessa public void reload(CommandSender sender) { cfg.reload(); chatConfig.reload(); - Log.toSender(sender, "§a配置文件已重载!"); + Log.sender(sender, "§a配置文件已重载!"); } public static void send(byte[] in) { diff --git a/src/main/java/pw/yumc/MiaoChat/bungee/FileConfig.java b/src/main/java/pw/yumc/MiaoChat/bungee/FileConfig.java new file mode 100644 index 0000000..fc0fc11 --- /dev/null +++ b/src/main/java/pw/yumc/MiaoChat/bungee/FileConfig.java @@ -0,0 +1,193 @@ +package pw.yumc.MiaoChat.bungee; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.List; + +import net.md_5.bungee.api.plugin.Plugin; +import net.md_5.bungee.config.Configuration; +import net.md_5.bungee.config.ConfigurationProvider; +import net.md_5.bungee.config.YamlConfiguration; + +/** + * + * Created by 蒋天蓓 on 2016/11/7 0007. + */ +public class FileConfig { + private File file; + private Configuration config; + + public FileConfig(Plugin plugin) { + this(plugin, "config.yml"); + } + + public T get(String path, T def) { + return config.get(path, def); + } + + public boolean contains(String path) { + return config.contains(path); + } + + public Object get(String path) { + return config.get(path); + } + + public Object getDefault(String path) { + return config.getDefault(path); + } + + public void set(String path, Object value) { + config.set(path, value); + } + + public Configuration getSection(String path) { + return config.getSection(path); + } + + public Collection getKeys() { + return config.getKeys(); + } + + public byte getByte(String path) { + return config.getByte(path); + } + + public byte getByte(String path, byte def) { + return config.getByte(path, def); + } + + public List getByteList(String path) { + return config.getByteList(path); + } + + public short getShort(String path) { + return config.getShort(path); + } + + public short getShort(String path, short def) { + return config.getShort(path, def); + } + + public List getShortList(String path) { + return config.getShortList(path); + } + + public int getInt(String path) { + return config.getInt(path); + } + + public int getInt(String path, int def) { + return config.getInt(path, def); + } + + public List getIntList(String path) { + return config.getIntList(path); + } + + public long getLong(String path) { + return config.getLong(path); + } + + public long getLong(String path, long def) { + return config.getLong(path, def); + } + + public List getLongList(String path) { + return config.getLongList(path); + } + + public float getFloat(String path) { + return config.getFloat(path); + } + + public float getFloat(String path, float def) { + return config.getFloat(path, def); + } + + public List getFloatList(String path) { + return config.getFloatList(path); + } + + public double getDouble(String path) { + return config.getDouble(path); + } + + public double getDouble(String path, double def) { + return config.getDouble(path, def); + } + + public List getDoubleList(String path) { + return config.getDoubleList(path); + } + + public boolean getBoolean(String path) { + return config.getBoolean(path); + } + + public boolean getBoolean(String path, boolean def) { + return config.getBoolean(path, def); + } + + public List getBooleanList(String path) { + return config.getBooleanList(path); + } + + public char getChar(String path) { + return config.getChar(path); + } + + public char getChar(String path, char def) { + return config.getChar(path, def); + } + + public List getCharList(String path) { + return config.getCharList(path); + } + + public String getString(String path) { + return config.getString(path); + } + + public String getString(String path, String def) { + return config.getString(path, def); + } + + public List getStringList(String path) { + return config.getStringList(path); + } + + public List getList(String path) { + return config.getList(path); + } + + public List getList(String path, List def) { + return config.getList(path, def); + } + + public FileConfig(Plugin plugin, String name) { + this.file = new File(plugin.getDataFolder(), name); + try { + this.config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file); + } catch (IOException e) { + Log.w("配置文件读取失败!"); + e.printStackTrace(); + } + } + + public Configuration getConfig() { + return config; + } + + public void save() { + try { + ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, file); + } catch (IOException e) { + Log.w("配置文件保存失败!"); + e.printStackTrace(); + } + + } + +} diff --git a/src/main/java/pw/yumc/MiaoChat/bungee/Log.java b/src/main/java/pw/yumc/MiaoChat/bungee/Log.java new file mode 100644 index 0000000..12fe61f --- /dev/null +++ b/src/main/java/pw/yumc/MiaoChat/bungee/Log.java @@ -0,0 +1,49 @@ +package pw.yumc.MiaoChat.bungee; + +import java.util.logging.Logger; + +import net.md_5.bungee.api.plugin.Plugin; + +/** + * 插件日志输出类 + * + * @author 喵♂呜 + * @since 2016年7月23日 上午9:11:01 + */ +public class Log { + private static boolean debug = false; + public static Plugin plugin; + public static Logger logger; + + public static void init(Plugin plugin) { + Log.plugin = plugin; + Log.logger = plugin.getLogger(); + } + + public static void d(String s, Exception e) { + if (debug) { + logger.info(s); + e.printStackTrace(); + } + } + + public static void i(String s, Object... objects) { + logger.info(String.format(s, objects)); + } + + public static void d(String s) { + if (debug) { + logger.info(s); + } + } + + public static void d(Exception e) { + if (debug) { + e.printStackTrace(); + } + } + + public static void w(String s, Object... objects) { + logger.warning(String.format(s, objects)); + } +} diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java b/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java index e47965e..b2afc33 100644 --- a/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java +++ b/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java @@ -39,16 +39,11 @@ public class ChatMessagePart extends InjectConfigurationSection { String tc = f(p, command); switch (type) { case COMMAND: - tr.command(tc); - break; + return tr.command(tc); case OPENURL: - tr.openurl(tc); - break; + return tr.openurl(tc); case SUGGEST: - tr.suggest(tc); - break; - default: - break; + return tr.suggest(tc); } } return tr; diff --git a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java index 8037127..1b71e08 100644 --- a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java +++ b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java @@ -157,7 +157,7 @@ public class ChatListener implements Listener { LinkedList il = handlePattern(message); // 如果返回null说明存在相同的物品 if (il == null) { - Log.toSender(player, "§c不允许展示相同的物品!"); + Log.sender(player, "§c不允许展示相同的物品!"); return; } LinkedList ml = handleMessage(il, message);