[+] 应用ExtraBot
1. 机器人部分重写,使用MixinBot 2. 添加新指令 /list 3. 修复 /reload 导致机器人不运作的错误 4. 统一使用 HyLogger 而不是 Java 的 Logger
This commit is contained in:
parent
d7c29c8917
commit
3f0c779b69
20
.classpath
20
.classpath
@ -31,6 +31,11 @@
|
|||||||
<attribute name="gradle_used_by_scope" value=""/>
|
<attribute name="gradle_used_by_scope" value=""/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry sourcepath="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/com.github.nitu2003/ExtraBot/v1.0p3/c2ed8b32762955844a355d1e2a33d4367210d6d7/ExtraBot-v1.0p3-sources.jar" kind="lib" path="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/com.github.nitu2003/ExtraBot/v1.0p3/14b8414a844182af9b3e3ebda4f2adcd08f46650/ExtraBot-v1.0p3.jar">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry sourcepath="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/com.github.nitu2003/TConfig/1.0/5b87c9cea241fac894987711cc4f7ee93d4605cf/TConfig-1.0-sources.jar" kind="lib" path="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/com.github.nitu2003/TConfig/1.0/7c8975f127c7606cb35ab0a8a3660963439bc139/TConfig-1.0.jar">
|
<classpathentry sourcepath="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/com.github.nitu2003/TConfig/1.0/5b87c9cea241fac894987711cc4f7ee93d4605cf/TConfig-1.0-sources.jar" kind="lib" path="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/com.github.nitu2003/TConfig/1.0/7c8975f127c7606cb35ab0a8a3660963439bc139/TConfig-1.0.jar">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||||
@ -96,6 +101,21 @@
|
|||||||
<attribute name="gradle_used_by_scope" value=""/>
|
<attribute name="gradle_used_by_scope" value=""/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry sourcepath="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/com.github.nitu2003/TUtils/588913ce05/d3bcc0878f0c56e0a863ca98e901e2893a84fa37/TUtils-588913ce05-sources.jar" kind="lib" path="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/com.github.nitu2003/TUtils/588913ce05/3f2bab14bebdbdf4136315c7f6da91b34dc13f8e/TUtils-588913ce05.jar">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry sourcepath="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-math3/3.6.1/8fab23986ea8886af34818daf32a718e81dc98ba/commons-math3-3.6.1-sources.jar" kind="lib" path="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-math3/3.6.1/e4ba98f1d4b3c80ec46392f25e094a6a2e58fcbf/commons-math3-3.6.1.jar">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry sourcepath="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/com.google.zxing/core/3.3.3/536b6ab3b3b4607ce86e2ff7f6643db11c473aa7/core-3.3.3-sources.jar" kind="lib" path="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/com.google.zxing/core/3.3.3/b640badcc97f18867c4dfd249ef8d20ec0204c07/core-3.3.3.jar">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry sourcepath="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/2.4/f2d8698c46d1167ff24b06a840a87d91a02db891/commons-io-2.4-sources.jar" kind="lib" path="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/2.4/b1b6ea3b7e4aa4f492509a4952029cd8e48019ad/commons-io-2.4.jar">
|
<classpathentry sourcepath="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/2.4/f2d8698c46d1167ff24b06a840a87d91a02db891/commons-io-2.4-sources.jar" kind="lib" path="C:/Users/Taskeren/.gradle/caches/modules-2/files-2.1/commons-io/commons-io/2.4/b1b6ea3b7e4aa4f492509a4952029cd8e48019ad/commons-io-2.4.jar">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
#Wed Jul 10 15:19:10 CST 2019
|
#Sat Aug 03 12:19:56 CST 2019
|
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
@ -30,6 +30,7 @@ repositories {
|
|||||||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation 'com.github.nitu2003:ExtraBot:v1.0p3'
|
||||||
implementation 'com.github.nitu2003:TConfig:1.0'
|
implementation 'com.github.nitu2003:TConfig:1.0'
|
||||||
implementation 'com.github.nitu2003:SimpleDataStorage:1.2'
|
implementation 'com.github.nitu2003:SimpleDataStorage:1.2'
|
||||||
implementation 'com.github.nitu2003:T18n:1.3'
|
implementation 'com.github.nitu2003:T18n:1.3'
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
package ren.taske.nativebot;
|
package ren.taske.nativebot;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import cc.moecraft.icq.event.events.message.EventMessage;
|
import cc.moecraft.icq.event.events.message.EventMessage;
|
||||||
|
import cc.moecraft.logger.HyLogger;
|
||||||
|
import cc.moecraft.logger.LoggerInstanceManager;
|
||||||
import cn.glycol.t18n.I18n;
|
import cn.glycol.t18n.I18n;
|
||||||
import ren.taske.nativebot.bot.chatting.Chatting;
|
import ren.taske.nativebot.bot.chatting.Chatting;
|
||||||
import ren.taske.nativebot.bot.chatting.MinecraftMessage;
|
import ren.taske.nativebot.bot.chatting.MinecraftMessage;
|
||||||
import ren.taske.nativebot.bot.chatting.TencentMessage;
|
import ren.taske.nativebot.bot.chatting.TencentMessage;
|
||||||
import ren.taske.nativebot.bot.listener.ServerLoadEventListener;
|
import ren.taske.nativebot.bot.listener.ServerLoadEventListener;
|
||||||
|
import ren.taske.nativebot.bot.permission.PermissionManager;
|
||||||
import ren.taske.nativebot.core.NativeBot;
|
import ren.taske.nativebot.core.NativeBot;
|
||||||
import ren.taske.nativebot.i18n.I18nInit;
|
import ren.taske.nativebot.i18n.I18nInit;
|
||||||
import ren.taske.nativebot.minecraft.command.CommandQQ;
|
import ren.taske.nativebot.minecraft.command.CommandQQ;
|
||||||
@ -29,22 +30,28 @@ public class NativeBotPlugin extends JavaPlugin {
|
|||||||
protected final CommandQQ cmdqq = new CommandQQ(this);
|
protected final CommandQQ cmdqq = new CommandQQ(this);
|
||||||
protected final CommandQQAdmin cmdqqadmin = new CommandQQAdmin();
|
protected final CommandQQAdmin cmdqqadmin = new CommandQQAdmin();
|
||||||
|
|
||||||
|
protected final HyLogger logger = new LoggerInstanceManager().getLoggerInstance("NaB", false);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
nativebotJavaPlugin = this;
|
nativebotJavaPlugin = this;
|
||||||
|
|
||||||
I18nInit.init();
|
I18nInit.init();
|
||||||
|
PermissionManager.init();
|
||||||
|
|
||||||
getLogger().info(I18n.format("message.common.welcome"));
|
getLogger().info(I18n.format("message.common.welcome"));
|
||||||
|
|
||||||
nativebot.onEnable();
|
nativebot.onEnable();
|
||||||
|
|
||||||
|
// 绑定QQ号指令
|
||||||
getCommand("qq").setExecutor(cmdqq);
|
getCommand("qq").setExecutor(cmdqq);
|
||||||
getCommand("qq-admin").setExecutor(cmdqqadmin);
|
getCommand("qq-admin").setExecutor(cmdqqadmin);
|
||||||
|
|
||||||
nativebot.getBot().register(tencentevent);
|
// 注册消息事件监听器
|
||||||
|
nativebot.getBot().addEventListenr(tencentevent);
|
||||||
getServer().getPluginManager().registerEvents(mcevent, this);
|
getServer().getPluginManager().registerEvents(mcevent, this);
|
||||||
|
|
||||||
|
// 注册服务器载入事件监听器
|
||||||
getServer().getPluginManager().registerEvents(botstartevent, this);
|
getServer().getPluginManager().registerEvents(botstartevent, this);
|
||||||
|
|
||||||
super.onEnable();
|
super.onEnable();
|
||||||
@ -53,7 +60,6 @@ public class NativeBotPlugin extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
nativebot.onDisable();
|
nativebot.onDisable();
|
||||||
super.onDisable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public NativeBot getBot() {
|
public NativeBot getBot() {
|
||||||
@ -68,10 +74,14 @@ public class NativeBotPlugin extends JavaPlugin {
|
|||||||
chatting.onMinecraftMessage(evt);
|
chatting.onMinecraftMessage(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NativeBotPlugin nativebotJavaPlugin;
|
private static NativeBotPlugin nativebotJavaPlugin;
|
||||||
|
|
||||||
public static Logger logger() {
|
public static NativeBotPlugin getPlugin() {
|
||||||
return nativebotJavaPlugin.getLogger();
|
return nativebotJavaPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HyLogger logger() {
|
||||||
|
return nativebotJavaPlugin.logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,94 +0,0 @@
|
|||||||
package ren.taske.nativebot.bot;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import cc.moecraft.icq.PicqBotX;
|
|
||||||
import cc.moecraft.icq.PicqConfig;
|
|
||||||
import cc.moecraft.icq.command.CommandManager;
|
|
||||||
import cc.moecraft.icq.command.interfaces.IcqCommand;
|
|
||||||
import cc.moecraft.icq.event.IcqListener;
|
|
||||||
import cc.moecraft.icq.sender.IcqHttpApi;
|
|
||||||
import cc.moecraft.logger.environments.ColorSupportLevel;
|
|
||||||
import ren.taske.nativebot.bot.permission.Permission;
|
|
||||||
import ren.taske.nativebot.bot.permission.PermissionManager;
|
|
||||||
import ren.taske.nativebot.commons.Config;
|
|
||||||
|
|
||||||
public class Bot extends Thread {
|
|
||||||
|
|
||||||
protected final PicqBotX bot;
|
|
||||||
|
|
||||||
public Bot() {
|
|
||||||
this(Config.port_in, Config.port_out, Config.url_out, Config.prefixes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* new bot!
|
|
||||||
* @param portIn the port to receive messages from HttpApi
|
|
||||||
* @param portOut the port to send messages to HttpApi
|
|
||||||
* @param urlOut the url to send messages to HttpApi
|
|
||||||
* @param prefixes the prefixes of commands in Tencent
|
|
||||||
*/
|
|
||||||
public Bot(int portIn, int portOut, String urlOut, String...prefixes) {
|
|
||||||
PicqConfig botconfig = new PicqConfig(portIn).setColorSupportLevel(ColorSupportLevel.DISABLED);
|
|
||||||
bot = new PicqBotX(botconfig);
|
|
||||||
bot.addAccount("NightBot", urlOut, portOut);
|
|
||||||
bot.enableCommandManager(prefixes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add commands for bot
|
|
||||||
* @param cmds the commands
|
|
||||||
*/
|
|
||||||
public void register(IcqCommand...cmds) {
|
|
||||||
bot.getCommandManager().registerCommands(cmds);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add commands for bot
|
|
||||||
* @param cmds the commands
|
|
||||||
*/
|
|
||||||
public void register(Collection<IcqCommand> cmds) {
|
|
||||||
register(cmds.toArray(new IcqCommand[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add event listener for bot
|
|
||||||
* @param listeners listeners
|
|
||||||
*/
|
|
||||||
public void register(IcqListener...listeners) {
|
|
||||||
bot.getEventManager().registerListeners(listeners);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* To start the bot. <br>
|
|
||||||
* But wait! Did you {@code register} the commands?
|
|
||||||
*/
|
|
||||||
public void run() {
|
|
||||||
PermissionManager.init();
|
|
||||||
Permission.lock();
|
|
||||||
bot.startBot();
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandManager getCommandManager() {
|
|
||||||
return bot.getCommandManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getCommands(){
|
|
||||||
return getCommandManager().getCommandNameList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IcqHttpApi getApi() {
|
|
||||||
return bot.getAccountManager().getNonAccountSpecifiedApi();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendGroupMessage(long gid, String msg) {
|
|
||||||
getApi().sendGroupMsg(gid, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendPrivateMessage(long uid, String msg) {
|
|
||||||
getApi().sendPrivateMsg(uid, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -2,7 +2,6 @@ package ren.taske.nativebot.bot.chatting;
|
|||||||
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
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.EventGroupOrDiscussMessage;
|
||||||
import cc.moecraft.icq.event.events.message.EventMessage;
|
import cc.moecraft.icq.event.events.message.EventMessage;
|
||||||
import cc.moecraft.icq.user.User;
|
import cc.moecraft.icq.user.User;
|
||||||
@ -10,6 +9,7 @@ import cc.moecraft.icq.utils.CQUtils;
|
|||||||
import cn.glycol.t18n.I18n;
|
import cn.glycol.t18n.I18n;
|
||||||
import ren.taske.nativebot.NativeBotPlugin;
|
import ren.taske.nativebot.NativeBotPlugin;
|
||||||
import ren.taske.nativebot.commons.Config;
|
import ren.taske.nativebot.commons.Config;
|
||||||
|
import ren.taske.nativebot.core.BotApi;
|
||||||
import ren.taske.nativebot.core.NativeBot;
|
import ren.taske.nativebot.core.NativeBot;
|
||||||
import ren.taske.nativebot.core.profile.UserMinecraft;
|
import ren.taske.nativebot.core.profile.UserMinecraft;
|
||||||
import ren.taske.nativebot.core.profile.UserTencent;
|
import ren.taske.nativebot.core.profile.UserTencent;
|
||||||
@ -105,7 +105,7 @@ public class Chatting {
|
|||||||
sb.append("\uff3b").append(username).append("\uff3d ");
|
sb.append("\uff3b").append(username).append("\uff3d ");
|
||||||
sb.append(message);
|
sb.append(message);
|
||||||
|
|
||||||
plugin.getBot().getBot().sendGroupMessage(Config.group_id, sb.toString());
|
BotApi.sendGroupMessage(Config.group_id, sb.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,10 +45,10 @@ public class CommandConsole extends CommandBase {
|
|||||||
|
|
||||||
public static Boolean callSyncDispatch(CommandSender sender, String command) {
|
public static Boolean callSyncDispatch(CommandSender sender, String command) {
|
||||||
try {
|
try {
|
||||||
return Bukkit.getScheduler().callSyncMethod(NativeBotPlugin.nativebotJavaPlugin, new Callable<Boolean>() {
|
return Bukkit.getScheduler().callSyncMethod(NativeBotPlugin.getPlugin(), new Callable<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public Boolean call() throws Exception {
|
public Boolean call() throws Exception {
|
||||||
NativeBotPlugin.logger().info("[$] "+command);
|
NativeBotPlugin.logger().log("[$] %s", command);
|
||||||
return Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), command);
|
return Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), command);
|
||||||
}
|
}
|
||||||
}).get();
|
}).get();
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package ren.taske.nativebot.bot.command;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import cc.moecraft.icq.event.events.message.EventMessage;
|
||||||
|
import cc.moecraft.icq.sender.message.MessageBuilder;
|
||||||
|
import cc.moecraft.icq.user.User;
|
||||||
|
import cn.glycol.t18n.I18n;
|
||||||
|
|
||||||
|
public class CommandList extends CommandBase {
|
||||||
|
|
||||||
|
public CommandList() {
|
||||||
|
super("list", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String execute(EventMessage evt, User user, long userid, String command, ArrayList<String> args) {
|
||||||
|
Collection<? extends Player> players = Bukkit.getServer().getOnlinePlayers();
|
||||||
|
MessageBuilder mb = new MessageBuilder();
|
||||||
|
mb.add(I18n.format("command.list.title")).newLine();
|
||||||
|
for(Player player : players) {
|
||||||
|
mb.add(I18n.format("command.list.prefix", player.getName())).newLine();
|
||||||
|
}
|
||||||
|
return mb.toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,7 +6,7 @@ import org.bukkit.event.HandlerList;
|
|||||||
|
|
||||||
import cc.moecraft.icq.command.interfaces.IcqCommand;
|
import cc.moecraft.icq.command.interfaces.IcqCommand;
|
||||||
import cc.moecraft.icq.event.IcqListener;
|
import cc.moecraft.icq.event.IcqListener;
|
||||||
import ren.taske.nativebot.bot.Bot;
|
import cn.glycol.extrabot.bot.MixinBot;
|
||||||
import ren.taske.nativebot.bot.permission.PermissionManager;
|
import ren.taske.nativebot.bot.permission.PermissionManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,25 +23,25 @@ public class EventBotRegistration extends Event {
|
|||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final Bot bot;
|
protected final MixinBot bot;
|
||||||
|
|
||||||
public EventBotRegistration(Bot bot) {
|
public EventBotRegistration(MixinBot bot) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获取机器人 */
|
/** 获取机器人 */
|
||||||
public Bot getBot() {
|
public MixinBot getBot() {
|
||||||
return bot;
|
return bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 注册指令 */
|
/** 注册指令 */
|
||||||
public void registerCommands(IcqCommand...cmds) {
|
public void registerCommands(IcqCommand command) {
|
||||||
bot.register(cmds);
|
bot.addCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 注册事件监听器 */
|
/** 注册事件监听器 */
|
||||||
public void registerListeners(IcqListener...listeners) {
|
public void registerListeners(IcqListener listener) {
|
||||||
bot.register(listeners);
|
bot.addEventListenr(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 注册权限 */
|
/** 注册权限 */
|
||||||
@ -59,7 +59,7 @@ public class EventBotRegistration extends Event {
|
|||||||
* 千万不要瞎jb调用它!
|
* 千万不要瞎jb调用它!
|
||||||
* @return 返回结果
|
* @return 返回结果
|
||||||
*/
|
*/
|
||||||
public static EventBotRegistration newEventAndCall(Bot bot) {
|
public static EventBotRegistration newEventAndCall(MixinBot bot) {
|
||||||
EventBotRegistration evt = new EventBotRegistration(bot);
|
EventBotRegistration evt = new EventBotRegistration(bot);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(evt);
|
Bukkit.getServer().getPluginManager().callEvent(evt);
|
||||||
return evt;
|
return evt;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package ren.taske.nativebot.bot.listener;
|
package ren.taske.nativebot.bot.listener;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.server.ServerLoadEvent;
|
import org.bukkit.event.server.ServerLoadEvent;
|
||||||
@ -16,14 +15,11 @@ public class ServerLoadEventListener implements Listener {
|
|||||||
LoadType type = evt.getType();
|
LoadType type = evt.getType();
|
||||||
|
|
||||||
if(type == LoadType.STARTUP) {
|
if(type == LoadType.STARTUP) {
|
||||||
NativeBotPlugin.nativebotJavaPlugin.getBot().start();
|
NativeBotPlugin.getPlugin().getBot().start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type == LoadType.RELOAD) {
|
if(type == LoadType.RELOAD) {
|
||||||
Bukkit.getServer().shutdown();
|
// server has already started. look up!
|
||||||
System.err.println("Don't try to reload NativeBot");
|
|
||||||
System.err.println("NativeBot CANNOT support reloading.");
|
|
||||||
System.err.println("不要尝试重载NativeBot,这个插件不能重载!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ public class PermissionManager {
|
|||||||
return !(Permission.of(node) == null);
|
return !(Permission.of(node) == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add defaults
|
// 注册权限节点
|
||||||
public static void init() {
|
public static void init() {
|
||||||
|
|
||||||
add(Reference.NODE_OP);
|
add(Reference.NODE_OP);
|
||||||
@ -38,5 +38,4 @@ public class PermissionManager {
|
|||||||
add(Chatting.NODE_CHATTING_MINECRAFT, true);
|
add(Chatting.NODE_CHATTING_MINECRAFT, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
26
src/main/java/ren/taske/nativebot/core/BotApi.java
Normal file
26
src/main/java/ren/taske/nativebot/core/BotApi.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package ren.taske.nativebot.core;
|
||||||
|
|
||||||
|
import cc.moecraft.icq.sender.IcqHttpApi;
|
||||||
|
|
||||||
|
public class BotApi {
|
||||||
|
|
||||||
|
private static IcqHttpApi api;
|
||||||
|
|
||||||
|
/* 初始化机器人时设定API */
|
||||||
|
public static void setApi(IcqHttpApi api) {
|
||||||
|
BotApi.api = api;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendPrivateMessage(long dest, String message) {
|
||||||
|
api.sendPrivateMsg(dest, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendGroupMessage(long dest, String message) {
|
||||||
|
api.sendGroupMsg(dest, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendDiscussMessage(long dest, String message) {
|
||||||
|
api.sendDiscussMsg(dest, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,44 +4,66 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import ren.taske.nativebot.bot.Bot;
|
import cc.moecraft.icq.command.interfaces.IcqCommand;
|
||||||
|
import cn.glycol.extrabot.ExtraBot;
|
||||||
|
import cn.glycol.extrabot.bot.MixinBot;
|
||||||
|
import cn.glycol.extrabot.bot.MixinBot.MixinBotConfiguration;
|
||||||
|
import cn.glycol.extrabot.registration.AutoRegister;
|
||||||
|
import cn.glycol.extrabot.registration.AutoRegister.Type;
|
||||||
|
import ren.taske.nativebot.bot.command.CommandAbout;
|
||||||
|
import ren.taske.nativebot.bot.command.CommandList;
|
||||||
|
import ren.taske.nativebot.bot.command.CommandOperator;
|
||||||
|
import ren.taske.nativebot.bot.command.CommandPermission;
|
||||||
import ren.taske.nativebot.bot.event.EventBotRegistration;
|
import ren.taske.nativebot.bot.event.EventBotRegistration;
|
||||||
import ren.taske.nativebot.util.ClassUtils;
|
import ren.taske.nativebot.commons.Config;
|
||||||
|
|
||||||
public class NativeBot {
|
public class NativeBot {
|
||||||
|
|
||||||
protected static Logger logger;
|
protected static Logger logger;
|
||||||
|
|
||||||
private static final String[] COMMANDS = new String[] {
|
@AutoRegister(Type.COMMAND)
|
||||||
"CommandAbout",
|
public static final IcqCommand CMD_ABOUT = new CommandAbout();
|
||||||
"CommandOperator",
|
|
||||||
"CommandPermission",
|
@AutoRegister(Type.COMMAND)
|
||||||
"CommandConsole"
|
public static final IcqCommand CMD_OPERATOR = new CommandOperator();
|
||||||
};
|
|
||||||
|
@AutoRegister(Type.COMMAND)
|
||||||
|
public static final IcqCommand CMD_PERMISSION = new CommandPermission();
|
||||||
|
|
||||||
|
@AutoRegister(Type.COMMAND)
|
||||||
|
public static final IcqCommand CMD_LIST = new CommandList();
|
||||||
|
|
||||||
protected final JavaPlugin plugin;
|
protected final JavaPlugin plugin;
|
||||||
protected final Bot bot;
|
protected final MixinBot bot;
|
||||||
|
|
||||||
public NativeBot(JavaPlugin plugin) {
|
public NativeBot(JavaPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.bot = new Bot();
|
|
||||||
|
bot = new MixinBot(new MixinBotConfiguration(Config.port_in));
|
||||||
|
bot.addAccount("Tbot", Config.url_out, Config.port_out);
|
||||||
|
bot.enableCommandManager(Config.prefixes);
|
||||||
|
|
||||||
|
BotApi.setApi(bot.getAccountManager().getNonAccountSpecifiedApi());
|
||||||
|
|
||||||
logger = plugin.getLogger();
|
logger = plugin.getLogger();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Logger logger() {
|
public static Logger logger() {
|
||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bot getBot() {
|
public MixinBot getBot() {
|
||||||
return this.bot;
|
return this.bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
bot.register(ClassUtils.instantiate(COMMANDS));
|
ExtraBot.register(NativeBot.class, bot);
|
||||||
handleRegistrationEvent();
|
handleRegistrationEvent();
|
||||||
for(String cmd : bot.getCommands()) logger.info("[C] "+cmd);
|
for(IcqCommand cmd : bot.getCommandManager().getCommandList()) logger.info("[C] "+cmd.properties().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDisable() {
|
||||||
|
// bot.stopBot();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,16 +75,7 @@ public class NativeBot {
|
|||||||
|
|
||||||
/** 启动机器人 */
|
/** 启动机器人 */
|
||||||
public void start() {
|
public void start() {
|
||||||
bot.start();
|
bot.startBot();
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public void onDisable() {
|
|
||||||
try {
|
|
||||||
bot.stop();
|
|
||||||
} catch(Exception e) {
|
|
||||||
logger.warning(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void bigWarning(String str, Object...format) {
|
public static void bigWarning(String str, Object...format) {
|
||||||
|
@ -23,6 +23,7 @@ command.about.message.3=/op - query if you're operator$/op* [uid] - set user as
|
|||||||
command.about.message.4=/perm* [uid] [node] - get the value of the node
|
command.about.message.4=/perm* [uid] [node] - get the value of the node
|
||||||
command.about.message.5=/perm* [uid] [node] [true/false] - set the value of the node
|
command.about.message.5=/perm* [uid] [node] [true/false] - set the value of the node
|
||||||
command.about.message.6=/console* [cmd] - to execute command as Console
|
command.about.message.6=/console* [cmd] - to execute command as Console
|
||||||
|
command.about.message.7=/list - to list all the online players
|
||||||
|
|
||||||
command.operator.yeap=您是管理员!
|
command.operator.yeap=您是管理员!
|
||||||
command.operator.nope=您不是管理员!
|
command.operator.nope=您不是管理员!
|
||||||
@ -33,3 +34,6 @@ command.permission.query=[%s]的%s权限状态为%s。
|
|||||||
command.permission.set=成功设置[%s]的%s权限状态为%s。
|
command.permission.set=成功设置[%s]的%s权限状态为%s。
|
||||||
command.permission.unregistered=莫得这种权限,你在抓梦jio?
|
command.permission.unregistered=莫得这种权限,你在抓梦jio?
|
||||||
|
|
||||||
|
command.list.title=[List]
|
||||||
|
command.list.prefix=* %s
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: NativeBot
|
name: NativeBot
|
||||||
main: ren.taske.nativebot.NativeBotPlugin
|
main: ren.taske.nativebot.NativeBotPlugin
|
||||||
version: 1.1.0
|
version: 1.2.0
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
qq:
|
qq:
|
||||||
|
Loading…
Reference in New Issue
Block a user