Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Commit

Permalink
加个获取TPS功能 添加漏掉的无权操作提示
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaMoHuaHuo-CN committed Jun 2, 2022
1 parent 2aeafdd commit 8e84aad
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 54 deletions.
4 changes: 4 additions & 0 deletions src/main/java/moe/xmcn/catsero/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import moe.xmcn.catsero.events.listeners.PlayerJoinQuitForward.OnGamePlayerQuit;
import moe.xmcn.catsero.utils.Config;
import moe.xmcn.catsero.utils.Metrics;
import moe.xmcn.catsero.utils.ServerTPS;
import moe.xmcn.xmcore.ThisAPI;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -46,6 +47,9 @@ public void onEnable() {
new Metrics((JavaPlugin) Config.INSTANCE.getPlugin(), pluginId);
}

// 启动TPS计算程序
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new ServerTPS(), 100L, 1L);

System.out.println("CatSero插件加载成功");

// 异步加载更新检查器
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package moe.xmcn.catsero.events.listeners.GetTPS;

import me.dreamvoid.miraimc.api.MiraiBot;
import me.dreamvoid.miraimc.bukkit.event.MiraiGroupMessageEvent;
import moe.xmcn.catsero.utils.Config;
import moe.xmcn.catsero.utils.ServerTPS;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Objects;

public class OnQQGroupMessage implements Listener {

@EventHandler
public void onMiraiGroupMessageEvent(MiraiGroupMessageEvent event) {

String message = event.getMessage();
String[] args = message.split(" ");
if (Objects.equals(args[0], "catsero") && Objects.equals(args[1], "kick") && Config.INSTANCE.getUsesConfig().getBoolean("tps.enabled") && event.getGroupID() == Config.INSTANCE.getUse_Group() && event.getBotID() == Config.INSTANCE.getUse_Bot()) {
if (event.getSenderID() == Config.INSTANCE.getQQ_OP()) {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(String.valueOf(ServerTPS.getTPS()));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
} else {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.no-permission"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,55 @@ public class OnQQGroupMessage implements Listener {
@EventHandler
public void onMiraiGroupMessageEvent(MiraiGroupMessageEvent event) {
if (Config.INSTANCE.getUsesConfig().getBoolean("pinghost.enabled") && event.getGroupID() == Config.INSTANCE.getUse_Group() && event.getBotID() == Config.INSTANCE.getUse_Bot()) {
if (!Config.INSTANCE.getUsesConfig().getBoolean("pinghost.op-only")) {
String msg = event.getMessage();
String[] args = msg.split(" ");
if (args[0].equalsIgnoreCase("catsero") && args[1].equalsIgnoreCase("ping")) {
try {
if (Config.INSTANCE.getUsesConfig().getBoolean("pinghost.op-only")) {
if (event.getSenderID() == Config.INSTANCE.getQQ_OP()) {
String msg = event.getMessage();
String[] args = msg.split(" ");
if (args[0].equalsIgnoreCase("catsero") && args[1].equalsIgnoreCase("ping")) {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.pinghost.doing"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
String result = PingHost.PingHostUtils(args[2]);
if (Objects.equals(result, "Error")) {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.pinghost.error"));
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.pinghost.doing"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
} else {
long flag = Long.parseLong(result);
String result = PingHost.PingHostUtils(args[2]);
if (Objects.equals(result, "Error")) {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.pinghost.error"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
} else {
long flag = Long.parseLong(result);
try {
String message = Config.INSTANCE.getMsgByMsID("qq.pinghost.success")
.replace("%address_original%", args[2])
.replace("%address_punycode%", Punycode.encodeURL(args[2]))
.replace("%withdraw%", String.valueOf(flag))
.replace("%lost%", String.valueOf(4 - flag))
.replace("%lost_percent%", String.valueOf((4 - flag) * 100 / 4));
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(message);
//MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(args[2] + "(" + (Punycode.encodeURL(args[2])) + ")" + " 的 Ping 统计信息:\n 数据包:已发送 = 4, 已接收 = " + flag + " ,丢失 = " + (4 - flag) + "(" + (4 - flag) * 100 / 4 + "% 丢失)");
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
}
} catch (UnknownHostException e) {
try {
String message = Config.INSTANCE.getMsgByMsID("qq.pinghost.success")
.replace("%address_original%", args[2])
.replace("%address_punycode%", Punycode.encodeURL(args[2]))
.replace("%withdraw%", String.valueOf(flag))
.replace("%lost%", String.valueOf(4 - flag))
.replace("%lost_percent%", String.valueOf((4 - flag) * 100 / 4));
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(message);
//MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(args[2] + "(" + (Punycode.encodeURL(args[2])) + ")" + " 的 Ping 统计信息:\n 数据包:已发送 = 4, 已接收 = " + flag + " ,丢失 = " + (4 - flag) + "(" + (4 - flag) * 100 / 4 + "% 丢失)");
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.pinghost.failed"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
}
} catch (UnknownHostException e) {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.pinghost.failed"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
}
} else {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.no-permission"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
}
} else if (event.getSenderID() == Config.INSTANCE.getQQ_OP()) {
} else {
String msg = event.getMessage();
String[] args = msg.split(" ");
if (args[0].equalsIgnoreCase("catsero") && args[1].equalsIgnoreCase("ping")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,82 @@ public void onMiraiGroupMessageEvent(MiraiGroupMessageEvent event) {
String msg = event.getMessage();
String[] args = msg.split(" ");
if (args[0].equalsIgnoreCase("catsero") && args[1].equalsIgnoreCase("weather")) {
if (args.length == 3 && event.getGroupID() == Config.INSTANCE.getUse_Group()) {
try {
if (Config.INSTANCE.getUsesConfig().getBoolean("weatherinfo.op-only")) {
if (event.getSenderID() == Config.INSTANCE.getQQ_OP()) {
if (args.length == 3 && event.getGroupID() == Config.INSTANCE.getUse_Group()) {
try {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.weatherinfo.doing"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
String[] resvi = WeatherUtils.getWeather(args[2]);
String message = Config.INSTANCE.getMsgByMsID("qq.weatherinfo.success")
.replace("%type%", resvi[4])
.replace("%temperature%", resvi[1])
.replace("%wind%", resvi[2])
.replace("%wind_direction%", resvi[3])
.replace("%date%", resvi[0]);
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(message);
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
} catch (UnsupportedEncodingException uee) {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.weatherinfo.error"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
}
} else {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.no-permission"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
}
} else {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.weatherinfo.doing"));
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.weatherinfo.null-city"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
String[] resvi = WeatherUtils.getWeather(args[2]);
String message = Config.INSTANCE.getMsgByMsID("qq.weatherinfo.success")
.replace("%type%", resvi[4])
.replace("%temperature%", resvi[1])
.replace("%wind%", resvi[2])
.replace("%wind_direction%", resvi[3])
.replace("%date%", resvi[0]);
}
} else {
if (args.length == 3 && event.getGroupID() == Config.INSTANCE.getUse_Group()) {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(message);
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.weatherinfo.doing"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
String[] resvi = WeatherUtils.getWeather(args[2]);
String message = Config.INSTANCE.getMsgByMsID("qq.weatherinfo.success")
.replace("%type%", resvi[4])
.replace("%temperature%", resvi[1])
.replace("%wind%", resvi[2])
.replace("%wind_direction%", resvi[3])
.replace("%date%", resvi[0]);
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(message);
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
} catch (UnsupportedEncodingException uee) {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.weatherinfo.error"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
}
} catch (UnsupportedEncodingException uee) {
} else {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.weatherinfo.error"));
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.no-permission"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
}

} else {
try {
MiraiBot.getBot(Config.INSTANCE.getUse_Bot()).getGroup(Config.INSTANCE.getUse_Group()).sendMessageMirai(Config.INSTANCE.getPrefix_QQ() + Config.INSTANCE.getMsgByMsID("qq.weatherinfo.null-city"));
} catch (NoSuchElementException nse) {
Config.INSTANCE.getPlugin().getLogger().warning(Config.INSTANCE.getMsgByMsID("general.send-message-qq.error").replace("%error%", nse + Arrays.toString(nse.getStackTrace())));
}
}
}
}
Expand Down
Loading

0 comments on commit 8e84aad

Please sign in to comment.