commit 4462a9baedc7bbecc3698d3830712a82ec4b71f4 Author: 502647092 Date: Mon Sep 5 15:59:11 2016 +0800 init: 项目初始化 Signed-off-by: 502647092 diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..db5b5e4 --- /dev/null +++ b/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..043fc2a --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +# Eclipse stuff +/.settings + +# netbeans +/nbproject + +# we use maven! +/build.xml + +# maven +/target +/repo + +# vim +.*.sw[a-p] + +# various other potential build files +/build +/bin +/dist +/manifest.mf + +/world + +# Mac filesystem dust +*.DS_Store + +# intellij +*.iml +*.ipr +*.iws +.idea/ + +# Project Stuff +/src/main/resources/Soulbound + +# Atlassian Stuff +/atlassian-ide-plugin.xml \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..f4db48b --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + MiaoChat + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/class.dict b/class.dict new file mode 100644 index 0000000..21fec61 --- /dev/null +++ b/class.dict @@ -0,0 +1,65 @@ +IIIIiI +IIiIiI +iiIIiI +Iiiiii +IIIIIi +IiIiII +iiIIIi +iIIIii +iIiiIi +iiiIiI +IiiIii +iIiiiI +iiiIIi +IIiIII +IIIIii +IIIiii +iiiiII +iIIiII +IIiiII +iiIIii +IiiIII +iIiIII +IiIIii +iiIiiI +iIiiII +IiiIiI +iiiIII +IIiIIi +iIiIiI +iiIiii +IiIiii +IiIIiI +IiiIIi +IiIIIi +IIiiIi +iIIiIi +iIIIII +IIIiIi +iiiiiI +iIiIIi +IIIiiI +iiiiIi +iiIiIi +IIiiiI +IiiiII +iIIiii +iIiIii +IiIiiI +IIiIii +IiIIII +IIIIII +iIIIIi +IIIiII +iiiiii +IiiiiI +IiIiIi +iiiIii +iIIIiI +iIIiiI +iIiiii +iiIiII +IIiiii +iiIIII +IiiiIi +llllll \ No newline at end of file diff --git a/lib/PlaceholderAPI.jar b/lib/PlaceholderAPI.jar new file mode 100644 index 0000000..87bd3ab Binary files /dev/null and b/lib/PlaceholderAPI.jar differ diff --git a/obf.dict b/obf.dict new file mode 100644 index 0000000..dcde616 --- /dev/null +++ b/obf.dict @@ -0,0 +1,24 @@ +if +try +for +int +new +true +null +this +else +void +enum +final +false +class +catch +import +double +public +static +boolean +package +finally +private +protected \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..3d1a15c --- /dev/null +++ b/pom.xml @@ -0,0 +1,134 @@ + + 4.0.0 + pw.yumc + MiaoChat + 1.0 + + ${project.name} + + + src/main/resources + true + + + + + maven-compiler-plugin + 3.3 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + false + true + + + pw.yumc:YumCore + cn.citycraft:PluginHelper + + + + + pw.yumc.YumCore + ${project.groupId}.${project.artifactId} + + + cn.citycraft.PluginHelper + ${project.groupId}.${project.artifactId} + + + + + + package + + shade + + + + + + com.github.wvengen + proguard-maven-plugin + + + package + + proguard + + + + + + + + ${java.home}/lib/rt.jar + + + + + + + + + Jenkins + http://ci.yumc.pw/job/${project.artifactId}/ + + + + + DEBUG + UTF-8 + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + yumc-repo + http://repo.yumc.pw/content/groups/public/ + + + + + jtb + YUMC + http://repo.yumc.pw/content/repositories/yumcenter/ + + + + + org.spigotmc + spigot-api + jar + 1.10.2-R0.1-SNAPSHOT + + + cn.citycraft + PluginHelper + jar + 1.0 + + + pw.yumc + YumCore + jar + 1.0 + + + pw.yumc + PlaceholderAPI + 1.0 + system + ${project.basedir}/lib/PlaceholderAPI.jar + + + \ No newline at end of file diff --git a/proguard.conf b/proguard.conf new file mode 100644 index 0000000..b6e74b0 --- /dev/null +++ b/proguard.conf @@ -0,0 +1,56 @@ +# -----不优化----- +-dontoptimize + +# -----忽略所有警告----- +-dontwarn +-dontnote + +# -----混淆时应用侵入式重载----- +-overloadaggressively + +# -----启用混淆字典----- +-obfuscationdictionary obf.dict +-classobfuscationdictionary class.dict +-packageobfuscationdictionary class.dict + +# -----保留所有属性 +-keepattributes ** + +# -----公共数据不混淆----- +-keep class cn.citycraft.CommonData.** {*;} + +# -----保护所有实体中的字段名称----- +-keepclassmembers class * implements java.io.Serializable { ; } + +# -----保护监听方法不被清理----- +-keepclassmembers class * implements org.bukkit.event.Listener { + @org.bukkit.event.EventHandler ; +} +# -----保护枚举方法的完整性----- +-keep enum ** {*;} +# -----保护配置注入不被清理----- +-keepclassmembers class * extends **.config.InjectConfigurationSection { + ; +} +-keepclassmembers class * extends **.config.InjectConfig { + ; +} +# -----保护注解命令方法不被清理----- +-keepclassmembers class **.commands.annotation.** { ; } +-keepclassmembers class * implements **.commands.CommandExecutor { ; } + +-keepclassmembers class **.commands.HandlerCommand { ; } +-keepclassmembers class * implements **.commands.HandlerCommands { + @**.commands.HandlerCommand ; + @**.commands.HandlerTabComplete ; +} +# -----保护注解NotProguard标记----- +-keep class **.NotProguard +-keep @**.NotProguard class * {*;} +-keepclassmembers class * { + @**.NotProguard ; + @**.NotProguard ; +} + +# -----保护命令解析正常----- +-keepnames class * extends **.commands.BaseCommand \ 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 new file mode 100644 index 0000000..2f6496c --- /dev/null +++ b/src/main/java/pw/yumc/MiaoChat/MiaoChat.java @@ -0,0 +1,47 @@ +package pw.yumc.MiaoChat; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import pw.yumc.MiaoChat.config.ChatConfig; +import pw.yumc.MiaoChat.listeners.ChatListener; +import pw.yumc.YumCore.commands.CommandArgument; +import pw.yumc.YumCore.commands.CommandExecutor; +import pw.yumc.YumCore.commands.CommandManager; +import pw.yumc.YumCore.commands.annotation.Cmd; +import pw.yumc.YumCore.commands.annotation.Help; +import pw.yumc.YumCore.config.FileConfig; + +public class MiaoChat extends JavaPlugin implements CommandExecutor { + private ChatConfig chatConfig; + private FileConfig config; + + public ChatConfig getChatConfig() { + return chatConfig; + } + + @Override + public FileConfiguration getConfig() { + return config; + } + + @Override + public void onEnable() { + new ChatListener(); + new CommandManager("MiaoChat", this); + } + + @Override + public void onLoad() { + config = new FileConfig(); + chatConfig = new ChatConfig(); + } + + @Cmd(permission = "MiaoChat.reload") + @Help("重载配置文件") + public void reload(final CommandArgument e) { + config.reload(); + chatConfig.reload(); + e.getSender().sendMessage("§a配置文件已重载!"); + } +} diff --git a/src/main/java/pw/yumc/MiaoChat/config/CLICKTYPE.java b/src/main/java/pw/yumc/MiaoChat/config/CLICKTYPE.java new file mode 100644 index 0000000..d933b3b --- /dev/null +++ b/src/main/java/pw/yumc/MiaoChat/config/CLICKTYPE.java @@ -0,0 +1,6 @@ +package pw.yumc.MiaoChat.config; + +public enum CLICKTYPE { + COMMAND, + SUGGEST; +} diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java b/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java new file mode 100644 index 0000000..65fc473 --- /dev/null +++ b/src/main/java/pw/yumc/MiaoChat/config/ChatConfig.java @@ -0,0 +1,51 @@ +package pw.yumc.MiaoChat.config; + +import java.util.LinkedList; +import java.util.List; + +import pw.yumc.YumCore.bukkit.P; +import pw.yumc.YumCore.config.FileConfig; + +public class ChatConfig { + private static String PrefixKey = "Format.Prefix"; + private static String SuffixKey = "Format.Suffix"; + private final FileConfig config; + private final List prefixs; + private final List suffixs; + private ChatMessagePart player; + + public ChatConfig() { + config = P.getConfig(); + prefixs = new LinkedList<>(); + suffixs = new LinkedList<>(); + reload(); + } + + public ChatMessagePart getPlayer() { + return player; + } + + public List getPrefixs() { + return prefixs; + } + + public List getSuffixs() { + return suffixs; + } + + public void reload() { + prefixs.clear(); + if (config.isSet(PrefixKey)) { + for (final String part : config.getConfigurationSection(PrefixKey).getKeys(false)) { + prefixs.add(new ChatMessagePart(config.getConfigurationSection(PrefixKey + "." + part))); + } + } + player = new ChatMessagePart(config.getConfigurationSection("Format.Player")); + suffixs.clear(); + if (config.isSet(SuffixKey)) { + for (final String part : config.getConfigurationSection(SuffixKey).getKeys(false)) { + suffixs.add(new ChatMessagePart(config.getConfigurationSection(SuffixKey + "." + part))); + } + } + } +} diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java b/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java new file mode 100644 index 0000000..98701cd --- /dev/null +++ b/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java @@ -0,0 +1,52 @@ +package pw.yumc.MiaoChat.config; + +import java.util.List; + +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; + +import me.clip.placeholderapi.PlaceholderAPI; +import pw.yumc.YumCore.config.ConfigNode; +import pw.yumc.YumCore.config.InjectConfigurationSection; +import pw.yumc.YumCore.tellraw.Tellraw; + +public class ChatMessagePart extends InjectConfigurationSection { + private String text; + private List tip; + @ConfigNode("click.type") + private String typestring; + private transient CLICKTYPE type = CLICKTYPE.SUGGEST; + @ConfigNode("click.command") + private String command; + + public ChatMessagePart(final ConfigurationSection config) { + super(config); + if (typestring != null) { + type = CLICKTYPE.valueOf(typestring); + } + } + + public Tellraw then(final Tellraw tr, final Player p) { + tr.then(f(p, text)); + if (tip != null && !tip.isEmpty()) { + tr.tip(f(p, tip)); + } + if (command != null && !command.isEmpty()) { + final String tc = f(p, command); + if (type == CLICKTYPE.SUGGEST) { + tr.suggest(tc); + } else if (type == CLICKTYPE.COMMAND) { + tr.command(tc); + } + } + return tr; + } + + private List f(final Player player, final List text) { + return PlaceholderAPI.setPlaceholders(player, text); + } + + private String f(final Player player, final String text) { + return PlaceholderAPI.setPlaceholders(player, text); + } +} diff --git a/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java new file mode 100644 index 0000000..573c11b --- /dev/null +++ b/src/main/java/pw/yumc/MiaoChat/listeners/ChatListener.java @@ -0,0 +1,44 @@ +package pw.yumc.MiaoChat.listeners; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import pw.yumc.MiaoChat.MiaoChat; +import pw.yumc.MiaoChat.config.ChatConfig; +import pw.yumc.MiaoChat.config.ChatMessagePart; +import pw.yumc.YumCore.bukkit.P; +import pw.yumc.YumCore.statistic.Statistics; +import pw.yumc.YumCore.tellraw.Tellraw; +import pw.yumc.YumCore.update.SubscribeTask; + +public class ChatListener implements Listener { + MiaoChat plugin = P.getPlugin(); + + public ChatListener() { + Bukkit.getPluginManager().registerEvents(this, P.instance); + new Statistics(); + new SubscribeTask(true, true); + } + + @EventHandler + public void onChat(final AsyncPlayerChatEvent e) { + e.setCancelled(true); + final Player p = e.getPlayer(); + final ChatConfig cc = plugin.getChatConfig(); + final String msg = e.getMessage(); + final Tellraw tr = Tellraw.create(); + for (final ChatMessagePart cmp : cc.getPrefixs()) { + cmp.then(tr, p); + } + cc.getPlayer().then(tr, p); + for (final ChatMessagePart cmp : cc.getSuffixs()) { + cmp.then(tr, p); + } + tr.then(ChatColor.translateAlternateColorCodes('&', msg)); + tr.broadcast(); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..3895522 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,40 @@ +#格式化配置 +Format: + #前缀配置 于玩家名称前 + Prefix: + #顺序 + 1: + #文本 支持PAPI变量 + text: '&6[&a%player_world%&6]' + #悬浮提示 支持PAPI + tip: + - '&6当前所在位置:' + - '&6世界: &d%layer_world%' + - '&6坐标: &aX:%layer_x% Y: %player_y% Z: %player_z%' + - '&c点击即可TP我!' + #点击操作 + click: + #操作类型: [COMMAND,SUGGEST] + #COMMAND代表执行命令 + #SUGGEST代表命令补全 + type: 'COMMAND' + #命令 支持PAPI + command: '/tpa %player_name%' + #玩家名称配置 + Player: + text: '&6[&b%player_name%&6] ' + tip: + - '点击与我聊天' + click: + type: 'SUGGEST' + command: '/tell %player_name%' +#后缀配置 于玩家名称后 由于一般没人用 我注释掉了 +# Suffix: +# 1: +# text: '[变量1]' +# tip: +# - '变量1提示' +# click: +# type: 'COMMAND' +# command: 'say 命令执行' + \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..3ad251a --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,22 @@ +name: ${project.artifactId} +description: ${project.description} +main: ${project.groupId}.${project.artifactId}.${project.artifactId} +version: ${project.version}-git-${env.GIT_COMMIT} +author: 喵♂呜 +website: ${ciManagement.url} +commands: + ${project.artifactId}: + description: ${project.artifactId} - ${project.description} + aliases: + - mct + - mchat + usage: §b使用/${project.artifactId} help 查看帮助! + permission: ${project.artifactId}.reload + permission-message: §c你没有 的权限来执行此命令! +permissions: + ${project.artifactId}.use: + description: ${project.artifactId} 使用! + default: true + ${project.artifactId}.reload: + description: 重新载入插件! + default: op \ No newline at end of file