Skip to content

Commit

Permalink
Merge pull request #51 from Blue-Millennium/functions-test
Browse files Browse the repository at this point in the history
Functions update
  • Loading branch information
Suisuroru authored Feb 24, 2025
2 parents baa2ff8 + 3b31ac3 commit 647f0f8
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto_build_jar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
if [[ "$COMMIT_MESSAGE" == "[skip]"* || "$BRANCH_NAME" != "master" ]]; then
if [[ "$COMMIT_MESSAGE" == "[skip]"* || ("$BRANCH_NAME" != "master" && "$COMMIT_MESSAGE" != "[ci]"*) ]]; then
echo "SKIP_RELEASE=true" >> $GITHUB_ENV
else
echo "SKIP_RELEASE=false" >> $GITHUB_ENV
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import fun.blue_millennium.config.Config;
import fun.blue_millennium.data.Report.ReportDataManager;
import fun.blue_millennium.message.WebhookForEmail;
import fun.blue_millennium.module.impl.Reporter;
import fun.blue_millennium.util.TimeUtil;
import net.mamoe.mirai.contact.Group;
import net.mamoe.mirai.contact.MemberPermission;
Expand All @@ -20,12 +19,12 @@
import java.util.Objects;

import static fun.blue_millennium.Chamomile.LOGGER;
import static fun.blue_millennium.module.impl.Reporter.ReportGroups;

public class Report implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (sender instanceof Player) {
Group reportGroup = ((Reporter) Chamomile.INSTANCE.moduleManager.getModuleByName("Reporter")).reportGroup;

if (args.length == 0) {
if (command.getName().equals("report")) {
Expand All @@ -36,7 +35,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
sender.sendMessage("§c/cm report <玩家名> <原因>");
}
} else {
if (reportGroup != null) {
if (!ReportGroups.isEmpty()) {
if (Bukkit.getServer().getPlayer(args[0]) == null) {
sender.sendMessage("§c玩家不存在");
} else if (Objects.requireNonNull(Bukkit.getServer().getPlayer(args[0])).getUniqueId().equals(((Player) sender).getUniqueId())) {
Expand Down Expand Up @@ -68,22 +67,25 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
sender.sendMessage("§c邮件发送失败");
LOGGER.warning(e.getMessage());
}
MessageChainBuilder builder_qq = new MessageChainBuilder();

if (Config.QQRobotEnabled) {
if (reportGroup.getBotPermission() == MemberPermission.ADMINISTRATOR || reportGroup.getBotPermission() == MemberPermission.OWNER) {
builder_qq.append(" ").append(AtAll.INSTANCE).append("\n");
}
if (Config.QQRobotEnabled && !Config.BotModeOfficial) {
for (long groupId : ReportGroups) {
MessageChainBuilder builder_qq = new MessageChainBuilder();
Group reportGroup = Chamomile.BOT.getGroup(groupId);
if (reportGroup.getBotPermission() == MemberPermission.ADMINISTRATOR || reportGroup.getBotPermission() == MemberPermission.OWNER) {
builder_qq.append(" ").append(AtAll.INSTANCE).append("\n");
}

builder_qq.append(TimeUtil.getNowTime()).append('\n')
.append("玩家 ").append(args[0]).append(" 被 ")
.append(sender.getName()).append(" 报告,原因:")
.append(reason.isEmpty() ? "无" : reason)
.append('\n')
.append("编号: ").append(number);
builder_qq.append(TimeUtil.getNowTime()).append('\n')
.append("玩家 ").append(args[0]).append(" 被 ")
.append(sender.getName()).append(" 报告,原因:")
.append(reason.isEmpty() ? "无" : reason)
.append('\n')
.append("编号: ").append(number);

reportGroup.sendMessage(builder_qq.build());
sender.sendMessage("§a已发送报告 编号: " + number);
reportGroup.sendMessage(builder_qq.build());
sender.sendMessage("§a已发送报告 编号: " + number);
}
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fun.blue_millennium.Chamomile;
import fun.blue_millennium.config.Config;
import fun.blue_millennium.message.WebhookForEmail;
import net.mamoe.mirai.contact.Group;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand All @@ -13,6 +14,8 @@
import java.util.Arrays;

import static fun.blue_millennium.data.UnionBan.LocalProcess.ReportedDataProcess.reportBanData;
import static fun.blue_millennium.module.impl.Reporter.ReportGroups;
import static fun.blue_millennium.module.impl.SyncChat.SyncGroups;

/**
* @author Suisuroru
Expand All @@ -25,8 +28,14 @@ public static void BanMessage(String origin, String message) {
Bukkit.broadcastMessage(origin + " Ban : " + message);
if (Config.QQRobotEnabled & !Config.BotModeOfficial) {
try {
Chamomile.BOT.getGroup(Config.SyncChatGroup).sendMessage(message);
Chamomile.BOT.getGroup(Config.ReportGroup).sendMessage(message);
for (long groupId : ReportGroups) {
Group reportGroup = Chamomile.BOT.getGroup(groupId);
reportGroup.sendMessage(message);
}
for (long groupId : SyncGroups) {
Group reportGroup = Chamomile.BOT.getGroup(groupId);
reportGroup.sendMessage(message);
}
} catch (Exception e) {
Chamomile.LOGGER.info("Error when report message to QQ group");
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fun/blue_millennium/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public class Config {
public static boolean UnionBanEnabled = false;
public static boolean VanillaCommandsRewritten = true;
public static int RconPort = 25575;
public static long ReportGroup = 123456L;
public static long SyncChatGroup = 123456L;
public static String BotWsToken = "114514";
public static String BotWsUrl = "ws://0.0.0.0:3001";
public static String DisTitle = "[QQLogin] 请完成登录验证, 验证码: %CODE%";
Expand All @@ -30,10 +28,12 @@ public class Config {
public static String RconEnabledGroups = "123456;234567";
public static String RconIP = "0.0.0.0";
public static String RconPassword = "password";
public static String ReportGroup = "123456;234567";
public static String ReportMessage = "%NAME% was logging in \nIP: %IP% %IPINFO% \nLoginResult: %RESULT%";
public static String SayQQMessage = "[QQ] %NAME%: %MESSAGE%";
public static String SayServerMessage = "%NAME%: %MESSAGE%";
public static String ServerName = "ServerName";
public static String SyncChatGroup = "123456;234567";
public static String SyncChatStartWord = "Send";
public static String UnionBanCheckUrl = "https://example.com";
public static String UnionBanReportKey = "your_report_key";
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/fun/blue_millennium/data/AuthData/DataProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import fun.blue_millennium.data.Data;
import fun.blue_millennium.data.OldUsedName;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -73,11 +74,26 @@ private static void appendPlayerData(StringBuilder result, Data data) {
if (data.playerData != null) {
appendIfNotNull(result, "玩家名称: ", data.playerData.playerName);
appendIfNotNull(result, "玩家UUID: ", data.playerData.playerUuid);
appendOldNameData(result, data.playerData.oldNames);
} else {
LOGGER.warning("Player data is Null.");
}
}

private static void appendOldNameData(StringBuilder result, List<OldUsedName> oldNamesList) {
if (!oldNamesList.isEmpty()) {
appendIfNotNull(result, "旧的玩家名称: ", "存在,共 " + oldNamesList.size() + " 个");
int i = 1;
for (OldUsedName oldName : oldNamesList) {
appendIfNotNull(result, "玩家名称 " + i + " : ", oldName.oldName);
appendIfNotNull(result, "玩家名称 " + i + " 服务器内被替换时间: ", transferTime(oldName.updateTime));
appendIfNotNull(result, "玩家名称 " + i++ + " 服务器内被替换时间(原始): ", oldName.updateTime);
}
} else {
LOGGER.warning("Old name data is Null.");
}
}

private static String transferBoolean(Boolean value) {
try {
if (value) {
Expand All @@ -97,14 +113,18 @@ public static boolean ProcessFinalData(@NotNull CommandSender sender, String pla
Type listType = new TypeToken<List<Object>>() {
}.getType();
List<Object> playerList = gson.fromJson(playerJson, listType);
int Count = 1;
StringBuilder result = new StringBuilder();
result.append("\n");
appendIfNotNull(result, "§a", "-------------------");
appendIfNotNull(result, "§a", "查询到" + playerList.size() + "个玩家数据");
appendIfNotNull(result, "§a", "-------------------");
if (playerList.size() > 1) {
appendIfNotNull(result, "§a", "查询到多个玩家数据,共 " + playerList.size() + " 个");
appendIfNotNull(result, "§a", "-------------------");
}
int Count = 1;
for (Object player : playerList) {
appendIfNotNull(result, "§a", "第" + Count++ + "个玩家数据");
if (playerList.size() > 1) {
appendIfNotNull(result, "§a", "第 " + Count++ + " 个玩家数据");
}
String processedData = DataProcess.processData(gson.toJson(player));
appendIfNotNull(result, "§a", processedData);
appendIfNotNull(result, "§a", "-------------------");
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/fun/blue_millennium/data/OldUsedName.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package fun.blue_millennium.data;

public class OldUsedName {
public String oldName;
public long updateTime;
}
2 changes: 2 additions & 0 deletions src/main/java/fun/blue_millennium/data/PlayerData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fun.blue_millennium.data;

import java.util.List;
import java.util.UUID;

/**
Expand All @@ -9,4 +10,5 @@
public class PlayerData {
public String playerName;
public UUID playerUuid;
public List<OldUsedName> oldNames;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fun.blue_millennium.data.Report;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -48,7 +48,7 @@ public static void writeNewData(List<String> newData) {
}

private static void saveToCsv(List<List<String>> data) {
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(REPORT_DATA_FILE), StandardCharsets.UTF_8))) {
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(REPORT_DATA_FILE), Charset.forName("GBK")))) {
for (List<String> row : data) {
bw.write(String.join(",", row));
bw.newLine();
Expand All @@ -62,7 +62,7 @@ List<List<String>> readCsvToList() {
List<List<String>> allRows = new ArrayList<>();
EnsureFileExist();

try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(REPORT_DATA_FILE), StandardCharsets.UTF_8))) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(REPORT_DATA_FILE), Charset.forName("GBK")))) {
String line;
while ((line = br.readLine()) != null) { // 逐行读取
String[] values = line.split(","); // 根据逗号分割
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/fun/blue_millennium/module/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public void onDisable() {

public void onLoad() {
}

public void onReload() {
onLoad();
}
}
35 changes: 20 additions & 15 deletions src/main/java/fun/blue_millennium/module/ModuleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,14 @@ public class ModuleManager {
public ArrayList<Module> modules = new ArrayList<>();

public void load() {
if (Config.QQRobotEnabled) {
modules.add(new QQCheck());
modules.add(new RconPreCheck());
modules.add(new SyncChat());
} else {
modules.add(new DataProcess());
LOGGER.info("QQRobot is disabled, DataProcess will be enabled.");
}
modules.add(new DamageDisable());
modules.add(new Reporter());
if (Config.UnionBanEnabled) {
modules.add(new UnionBan());
}

modulesSet();
modules.forEach(Module::onLoad);
}

public void reload() {
modules.clear();
load();
modulesSet();
modules.forEach(Module::onReload);
}

public void onEnable() {
Expand All @@ -44,6 +32,23 @@ public void onDisable() {
modules.forEach(Module::onDisable);
}

private void modulesSet() {
if (Config.QQRobotEnabled) {
modules.add(new QQCheck());
modules.add(new ExecuteRcon());
modules.add(new SyncChat());
modules.add(new Reporter());
} else {
modules.add(new DataProcess());
LOGGER.info("QQRobot is disabled, DataProcess will be enabled.");
}
modules.add(new DamageDisable());
if (Config.UnionBanEnabled) {
modules.add(new UnionBan());
}

}

public Module getModuleByName(String name) {
for (Module module : modules) {
if (module.moduleName.equals(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;

public class DamageDisable extends Module implements Listener {
public class DamageDisable extends Module {

public DamageDisable() {
super("DamageDisable");
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/fun/blue_millennium/module/impl/DataProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

import fun.blue_millennium.Chamomile;
import fun.blue_millennium.data.Data;
import fun.blue_millennium.data.OldUsedName;
import fun.blue_millennium.data.PlayerData;
import fun.blue_millennium.module.Module;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;

import java.util.ArrayList;
import java.util.List;

import static fun.blue_millennium.module.impl.QQCheck.NullCheck;

public class DataProcess extends Module implements Listener {
public class DataProcess extends Module {
public DataProcess() {
super("DataProcess");
}
Expand All @@ -22,6 +25,21 @@ public static void BaseDataProcess(AsyncPlayerPreLoginEvent event, Data data) {
playerData.playerName = event.getName();
playerData.playerUuid = event.getUniqueId();
data.playerData = playerData;
} else {
if (!data.playerData.playerName.equals(event.getName())) {
OldUsedName oldUsedName = new OldUsedName();
oldUsedName.oldName = data.playerData.playerName;
oldUsedName.updateTime = System.currentTimeMillis();
List<OldUsedName> oldNames;
try {
oldNames = data.playerData.oldNames == null ? new ArrayList<>() : data.playerData.oldNames;
} catch (NullPointerException e) {
oldNames = new ArrayList<>();
}
oldNames.add(oldUsedName);
data.playerData.oldNames = oldNames;
data.playerData.playerName = event.getName();
}
}
data.qqChecked = data.qqNumber > 0;
if (data.firstJoin < 0) {
Expand Down
Loading

0 comments on commit 647f0f8

Please sign in to comment.