From ba8869df5ced164ba09a915f602cbd0797af3438 Mon Sep 17 00:00:00 2001 From: Taskeren Date: Wed, 10 Jul 2019 20:58:47 +0800 Subject: [PATCH] =?UTF-8?q?[+]=20=E5=BE=88=E5=A4=9A=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 添加了更多中文翻译 2. 将/qq的功能分成了/qq和/qq-admin两个指令 3. 将权限组的更改进行应用 4. 现在会优先读取群名片了 --- build.gradle | 20 +++--------- .../ren/taske/nativebot/MinecraftPlugin.java | 3 ++ .../nativebot/bot/chatting/Chatting.java | 10 +++++- .../ren/taske/nativebot/i18n/I18nInit.java | 4 +++ .../minecraft/command/CommandQQ.java | 24 ++------------ .../minecraft/command/CommandQQAdmin.java | 31 +++++++++++++++++++ src/main/resources/i18n.txt | 5 +++ src/main/resources/plugin.yml | 20 ++++++++++-- 8 files changed, 77 insertions(+), 40 deletions(-) create mode 100644 src/main/java/ren/taske/nativebot/minecraft/command/CommandQQAdmin.java diff --git a/build.gradle b/build.gradle index 317cdab..349c1eb 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,8 @@ repositories { maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' } } +[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' + dependencies { implementation 'com.github.nitu2003:TConfig:1.0' implementation 'com.github.nitu2003:SimpleDataStorage:1.2' @@ -38,21 +40,9 @@ dependencies { } shadowJar { - classifier = "" - dependencies { - include(dependency("com.github.nitu2003:TConfig:1.0")) - include(dependency("com.github.nitu2003:SimpleDataStorage:1.2")) - include(dependency("com.github.nitu2003:T18n:1.1")) - include(dependency("commons-io:commons-io:2.4")) - include(dependency("com.github.hydevelop:PicqBotX:4.10.1.928")) - include(dependency("com.github.hydevelop:HyLogger:4.0.254")) - include(dependency("com.github.hydevelop:HyCommonUtils:1.3.5.130")) - include(dependency("cn.hutool:hutool-all:4.5.10")) - include(dependency("com.google.code.gson:gson:2.8.5")) - include(dependency("org.mariuszgromada.math:MathParser.org-mXparser:4.2.0")) - include(dependency("org.projectlombok:1.14.8")) - include(dependency("org.fusesource.jansi:jansi:1.17.1")) - + classifier = null + from("./") { + include 'build.gradle' } } diff --git a/src/main/java/ren/taske/nativebot/MinecraftPlugin.java b/src/main/java/ren/taske/nativebot/MinecraftPlugin.java index daf6e07..423eaf6 100644 --- a/src/main/java/ren/taske/nativebot/MinecraftPlugin.java +++ b/src/main/java/ren/taske/nativebot/MinecraftPlugin.java @@ -13,6 +13,7 @@ import ren.taske.nativebot.bot.chatting.TencentMessage; import ren.taske.nativebot.core.NativeBot; import ren.taske.nativebot.i18n.I18nInit; import ren.taske.nativebot.minecraft.command.CommandQQ; +import ren.taske.nativebot.minecraft.command.CommandQQAdmin; public class MinecraftPlugin extends JavaPlugin { @@ -23,6 +24,7 @@ public class MinecraftPlugin extends JavaPlugin { protected final TencentMessage tencentevent = new TencentMessage(this); protected final CommandQQ cmdqq = new CommandQQ(this); + protected final CommandQQAdmin cmdqqadmin = new CommandQQAdmin(); @Override public void onEnable() { @@ -35,6 +37,7 @@ public class MinecraftPlugin extends JavaPlugin { nativebot.onEnable(); getCommand("qq").setExecutor(cmdqq); + getCommand("qq-admin").setExecutor(cmdqqadmin); nativebot.getBot().register(tencentevent); getServer().getPluginManager().registerEvents(mcevent, this); diff --git a/src/main/java/ren/taske/nativebot/bot/chatting/Chatting.java b/src/main/java/ren/taske/nativebot/bot/chatting/Chatting.java index 84b31d9..5f59e1a 100644 --- a/src/main/java/ren/taske/nativebot/bot/chatting/Chatting.java +++ b/src/main/java/ren/taske/nativebot/bot/chatting/Chatting.java @@ -2,6 +2,8 @@ package ren.taske.nativebot.bot.chatting; import org.bukkit.event.player.AsyncPlayerChatEvent; +import cc.moecraft.icq.event.events.message.EventGroupMessage; +import cc.moecraft.icq.event.events.message.EventGroupOrDiscussMessage; import cc.moecraft.icq.event.events.message.EventMessage; import cc.moecraft.icq.user.User; import cc.moecraft.icq.utils.CQUtils; @@ -35,7 +37,13 @@ public class Chatting { long userid = user.getId(); UserTencent ut = UserTencent.of(userid); String message = evt.getMessage(); - String username = user.getInfo().getNickname(); + String username; + + if(evt instanceof EventGroupOrDiscussMessage) { + username = ((EventGroupOrDiscussMessage) evt).getGroupSender().getInfo().getCard(); + } else { + username = user.getInfo().getNickname(); + } if(!isPrefixed(message)) { return; diff --git a/src/main/java/ren/taske/nativebot/i18n/I18nInit.java b/src/main/java/ren/taske/nativebot/i18n/I18nInit.java index 36a7ee9..e3cfb9d 100644 --- a/src/main/java/ren/taske/nativebot/i18n/I18nInit.java +++ b/src/main/java/ren/taske/nativebot/i18n/I18nInit.java @@ -27,6 +27,10 @@ public class I18nInit { public static void init() { + if(FILE_I18N.exists() && Config.useJarLanguageFile) { + FILE_I18N.delete(); + } + if(!FILE_I18N.exists() || Config.useJarLanguageFile) { writeContextToFile(getContextFromJar()); } diff --git a/src/main/java/ren/taske/nativebot/minecraft/command/CommandQQ.java b/src/main/java/ren/taske/nativebot/minecraft/command/CommandQQ.java index c5ecb63..77d66ab 100644 --- a/src/main/java/ren/taske/nativebot/minecraft/command/CommandQQ.java +++ b/src/main/java/ren/taske/nativebot/minecraft/command/CommandQQ.java @@ -1,15 +1,13 @@ package ren.taske.nativebot.minecraft.command; -import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import cn.glycol.t18n.I18n; import ren.taske.data.util.ParseUtil; import ren.taske.nativebot.MinecraftPlugin; -import ren.taske.nativebot.commons.Reference; import ren.taske.nativebot.core.profile.UserMinecraft; -import ren.taske.nativebot.core.profile.UserTencent; public class CommandQQ implements CommandExecutor { @@ -28,30 +26,14 @@ public class CommandQQ implements CommandExecutor { if(qqid != null) { if(um.getTencentId() == -1L) { um.setTencentId(qqid); - sender.sendMessage("Your Tencent userid now is " + qqid); + sender.sendMessage(I18n.format("command.qq.done", qqid)); } else { - sender.sendMessage("You have set your Tencent userid!"); + sender.sendMessage(I18n.format("command.qq.undone", um.getTencentId())); } return true; } } - if(args.length == 2) { - UserMinecraft um = UserMinecraft.of(args[1]); - UserTencent ut = UserTencent.of(um.getTencentId()); - Long qqid = ParseUtil.parseLong(args[0]); - - if(ut.hasPermission(Reference.NODE_OP)) { - if(qqid != null) { - um.setTencentId(qqid); - sender.sendMessage(ChatColor.GOLD+um.getUserId()+ChatColor.RESET+"'s Tencent userid now is "+qqid); - } - } else { - sender.sendMessage("You have no permission!"); - } - return true; - } - return false; } diff --git a/src/main/java/ren/taske/nativebot/minecraft/command/CommandQQAdmin.java b/src/main/java/ren/taske/nativebot/minecraft/command/CommandQQAdmin.java new file mode 100644 index 0000000..fd9c7f0 --- /dev/null +++ b/src/main/java/ren/taske/nativebot/minecraft/command/CommandQQAdmin.java @@ -0,0 +1,31 @@ +package ren.taske.nativebot.minecraft.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +import cn.glycol.t18n.I18n; +import ren.taske.data.util.ParseUtil; +import ren.taske.nativebot.core.profile.UserMinecraft; + +public class CommandQQAdmin implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + + if(args.length == 2) { + Long qqid = ParseUtil.parseLong(args[0]); + + if(qqid != null) { + UserMinecraft oped = UserMinecraft.of(args[1]); + oped.setTencentId(qqid); + sender.sendMessage(I18n.format("command.qq-admin.done", oped.getUserId(), oped.getTencentId())); + return true; + } + + } + + return false; + } + +} diff --git a/src/main/resources/i18n.txt b/src/main/resources/i18n.txt index ad45f4d..ea5569a 100644 --- a/src/main/resources/i18n.txt +++ b/src/main/resources/i18n.txt @@ -4,6 +4,11 @@ message.using.set-qq-first=请先绑定QQ! message.unauthorized=您没有权限! +command.qq.done=您的账号绑定了QQ:%s。 +command.qq.undone=您的账号已经绑定了QQ:%s。 + +command.qq-admin.done=%1$s的账号绑定了QQ:%2$s。 + command.common.done=完成! command.common.fail=失败! command.common.argument=参数错误! diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 83a90e2..923c6d5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,21 @@ version: 1.0.0 commands: qq: - description: set your qq userid - usage: /qq [MinecraftName] + description: to set your qq userid + usage: /qq permission: nativebot.qq - permission-message: You don't have permission! \ No newline at end of file + permission-message: You don't have permission! + qq-admin: + description: to set a player's qq userid + usage: /qq-admin [MinecraftUser] + aliases: [qqadmin] + permission: nativebot.admin + permission-message: You don't have permission! + +permissions: + nativebot.admin: + description: A permission node used for command qq-admin + default: op + nativebot.qq: + description: A permission node used for command qq + default: true \ No newline at end of file