├── .github └── workflows │ └── gradle.yml ├── .gitignore ├── README.md ├── core ├── ASide.java ├── Minecraft_QQ.java ├── api │ ├── IGroupEvent.java │ ├── ILogger.java │ ├── ISide.java │ └── Placeholder.java ├── bstats │ ├── MetricsBase.java │ ├── charts │ │ ├── AdvancedBarChart.java │ │ ├── AdvancedPie.java │ │ ├── CustomChart.java │ │ ├── DrilldownPie.java │ │ ├── MultiLineChart.java │ │ ├── SimpleBarChart.java │ │ ├── SimplePie.java │ │ └── SingleLineChart.java │ ├── config │ │ └── MetricsConfig.java │ └── json │ │ └── JsonObjectBuilder.java ├── command │ ├── CommandEX.java │ └── CommandTab.java ├── config │ ├── ConfigOBJ.java │ ├── LanguageOBJ.java │ ├── LogsOBJ.java │ ├── MessageOBJ.java │ ├── PlaceholderOBJ.java │ ├── SendAllServerOBJ.java │ ├── ServerSetOBJ.java │ ├── SystemOBJ.java │ └── UserOBJ.java ├── json │ ├── ReadObj.java │ └── SendObj.java └── utils │ ├── Logs.java │ ├── PackDecode.java │ ├── PackEncode.java │ └── SocketUtils.java ├── link.cmd ├── remove.cmd └── server ├── .gitattributes ├── .gitignore ├── LICENSE ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main ├── java └── com │ └── coloryr │ └── minecraft_qq │ ├── MBC.java │ ├── MBukkit.java │ ├── MVelocity.java │ └── side │ ├── bc │ ├── Command.java │ ├── Commander.java │ ├── EventListener.java │ ├── GroupEvent.java │ ├── Log.java │ ├── Metrics.java │ └── Side.java │ ├── bukkit │ ├── Command.java │ ├── Commander.java │ ├── EventListener.java │ ├── GroupEvent.java │ ├── Log.java │ ├── Metrics.java │ └── Side.java │ └── velocity │ ├── Command.java │ ├── Commander.java │ ├── EventListener.java │ ├── GroupEvent.java │ ├── Log.java │ ├── Metrics.java │ └── Side.java └── resources ├── bungee.yml ├── config.json └── plugin.yml /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | name: Gradle构建 2 | on: 3 | push: 4 | # Sequence of patterns matched against refs/heads 5 | branches: 6 | - 'releases/**' 7 | # Sequence of patterns matched against refs/tags 8 | tags: 9 | - '*' 10 | 11 | jobs: 12 | build: 13 | runs-on: windows-latest 14 | permissions: 15 | contents: read 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: Set up JDK 8 19 | uses: actions/setup-java@v4 20 | with: 21 | java-version: '8' 22 | distribution: 'temurin' 23 | - name: Setup Gradle 24 | uses: gradle/actions/setup-gradle@v3 # v3.1.0 25 | - name: build 26 | shell: cmd 27 | run: | 28 | link.cmd && cd server && gradlew build 29 | - name: update 30 | uses: actions/upload-artifact@v4 31 | with: 32 | name: "Minecraft_QQ" 33 | path: build/libs/ 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # eclipse 2 | bin 3 | *.launch 4 | .settings 5 | .metadata 6 | .classpath 7 | .project 8 | 9 | # idea 10 | out 11 | *.ipr 12 | *.iws 13 | *.iml 14 | .idea 15 | 16 | # gradle 17 | build 18 | .gradle 19 | 20 | # other 21 | eclipse 22 | run 23 | 24 | # Files from Forge MDK 25 | forge*changelog.txt 26 | 27 | lib 28 | **/minecraft_qq/core/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Minecraft服务器与QQ群聊天的插件 2 | 该仓库为Minecraft_QQ服务器插件(bukkit/bungeecord)仓库 3 | 4 | [配套使用](https://github.com/Coloryr/Minecraft_QQ-C-Server-) 5 | [Minebbs帖子](https://www.minebbs.com/resources/minecraft_qq.8250/) 6 | 7 | 基础指令 8 | - help 获取帮助 9 | - chat 是否开启群聊天 10 | 11 | 管理员指令 12 | - say [内容] 管理员测试用发送群消息 13 | - socket 重连Minecraft_QQ 14 | - drop 断开链接Minecraft_QQ 15 | - reload 重读配置文件 16 | 17 | 配置文件 18 | ```json 19 | { 20 | "Join": { 21 | "Message": "%player%加入了服务器", 22 | "Send": true 23 | }, 24 | "Quit": { 25 | "Message": "%player%退出了服务器", 26 | "Send": true 27 | }, 28 | "ChangeServer": { 29 | "Message": "%player%加入了子服%server%", 30 | "Send": true 31 | }, 32 | "ServerSet": { 33 | "ServerName": "MC服务器", 34 | "Check": "群:", 35 | "Message": "[%servername%]-%server%-%player%:%message%", 36 | "Say": "[%servername%][群消息]%player%:%message%", 37 | //对话模式 0 不启用对话 1 检测发送对话 2 始终发送对话 38 | //模式1的时候,玩家只要在说的话前面加上 配置文件的Check中的值 就会把消息发送到群里 39 | "Mode": 1, 40 | //是否发送子服的人名单 41 | "SendOneByOne": true, 42 | "SendOneByOneMessage": "[%server%-%playernumber%]-%playerlist%", 43 | //是否隐藏空的子服 44 | "HideEmptyServer": true, 45 | "PlayerListMessage": "%servername%当前在线人数:%playernumber%,玩家列表:%playerlist%", 46 | "ServerOnlineMessage": "%servername%服务器在线", 47 | //顶层模式 开启后不参与对话,只会执行群内发送服务器指令 48 | "TopMode": false, 49 | "CommandDelay": 2000 50 | }, 51 | "Servers": { 52 | "lobby": "登陆大厅", 53 | "server": "服务器" 54 | }, 55 | "SendAllServer": { 56 | //将消息发送到所有子服 57 | "Enable": true, 58 | "Message": "[%servername%-%server%]玩家:[%player%]发送群消息:[%message%]", 59 | //只发送给其他子服 60 | "OnlySideServer": true 61 | }, 62 | "System": { 63 | "IP": "127.0.0.1", 64 | "Port": 25555, 65 | "AutoConnectTime": 10, 66 | "Debug": false 67 | }, 68 | "User": { 69 | //不发送玩家的指令到群中 70 | "NotSendCommand": true 71 | }, 72 | "Logs": { 73 | "Group": true, 74 | "Server": true 75 | }, 76 | "Placeholder": { 77 | "Message": "%message%", 78 | "Player": "%player%", 79 | "ServerName": "%servername%", 80 | "Server": "%server%", 81 | "PlayerNumber": "%playernumber%", 82 | "PlayerList": "%playerlist%" 83 | }, 84 | "Language": { 85 | "MessageOFF": "§2你已不会在收到群消息", 86 | "MessageON": "§2你开始接受群消息" 87 | }, 88 | "Mute": [], 89 | "Version": "3.0.4" 90 | } 91 | ``` -------------------------------------------------------------------------------- /core/ASide.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core; 2 | 3 | import com.coloryr.minecraft_qq.core.Minecraft_QQ; 4 | import com.coloryr.minecraft_qq.core.api.Placeholder; 5 | import com.coloryr.minecraft_qq.core.config.ConfigOBJ; 6 | import com.coloryr.minecraft_qq.core.json.ReadObj; 7 | import com.coloryr.minecraft_qq.core.utils.Logs; 8 | import com.coloryr.minecraft_qq.core.utils.SocketUtils; 9 | import com.google.gson.Gson; 10 | 11 | public class ASide { 12 | public static void globeCheck(ReadObj readobj) { 13 | if (readobj.command.equalsIgnoreCase(Placeholder.server)) { 14 | String send = Minecraft_QQ.config.ServerSet.ServerOnlineMessage; 15 | send = send.replaceAll(Minecraft_QQ.config.Placeholder.ServerName, Minecraft_QQ.config.ServerSet.ServerName); 16 | SocketUtils.sendData(Placeholder.data, readobj.group, "无", send); 17 | if (Minecraft_QQ.config.Logs.Group) { 18 | Logs.logWrite("[group]查询服务器状态"); 19 | } 20 | if (Minecraft_QQ.config.System.Debug) 21 | Minecraft_QQ.log.info("§d[Minecraft_QQ]§5[Debug]查询服务器状态"); 22 | } else if (readobj.command.equalsIgnoreCase(Placeholder.pause)) { 23 | SocketUtils.sendData(Placeholder.pause, readobj.group, "无", "data"); 24 | } else if (readobj.command.equalsIgnoreCase(Placeholder.config)) { 25 | String config = new Gson().toJson(Minecraft_QQ.config); 26 | SocketUtils.sendData(Placeholder.config, readobj.group, "无", config); 27 | } else if (readobj.command.equalsIgnoreCase(Placeholder.set)) { 28 | try { 29 | Minecraft_QQ.config = new Gson().fromJson(readobj.message, ConfigOBJ.class); 30 | Minecraft_QQ.save(); 31 | } catch (Exception e) { 32 | Minecraft_QQ.log.warning("配置文件动态更新失败"); 33 | e.printStackTrace(); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /core/Minecraft_QQ.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core; 2 | 3 | import com.coloryr.minecraft_qq.core.api.ILogger; 4 | import com.coloryr.minecraft_qq.core.api.ISide; 5 | import com.coloryr.minecraft_qq.core.config.ConfigOBJ; 6 | import com.coloryr.minecraft_qq.core.utils.Logs; 7 | import com.coloryr.minecraft_qq.core.utils.SocketUtils; 8 | import com.google.gson.Gson; 9 | 10 | import java.io.*; 11 | import java.nio.charset.StandardCharsets; 12 | import java.nio.file.Files; 13 | 14 | public class Minecraft_QQ { 15 | public final static String version = "3.0.4"; 16 | public static ISide side; 17 | public static ConfigOBJ config; 18 | public static ILogger log; 19 | private static File fileName; 20 | 21 | public static void load() { 22 | try { 23 | InputStreamReader reader = new InputStreamReader(Files.newInputStream(fileName.toPath()), StandardCharsets.UTF_8); 24 | BufferedReader bf = new BufferedReader(reader); 25 | config = new Gson().fromJson(bf, ConfigOBJ.class); 26 | if (config == null || config.System == null 27 | || config.ServerSet == null || config.Mute == null 28 | || config.Language == null || config.User == null 29 | || config.SendAllServer == null || config.Join == null) { 30 | config = new ConfigOBJ(); 31 | throw (new Throwable("配置文件为空")); 32 | } 33 | } catch (Throwable e) { 34 | log.warning("§d[Minecraft_QQ]§c配置文件读取发生错误"); 35 | e.printStackTrace(); 36 | } 37 | } 38 | 39 | public static void save() { 40 | try { 41 | String data = new Gson().toJson(config); 42 | if (fileName.exists()) { 43 | FileOutputStream out = new FileOutputStream(fileName); 44 | OutputStreamWriter write = new OutputStreamWriter( 45 | out, StandardCharsets.UTF_8); 46 | write.write(data); 47 | write.close(); 48 | out.close(); 49 | } 50 | } catch (Exception e) { 51 | log.warning("§d[Minecraft_QQ]§c配置文件保存错误"); 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | public static void start() { 57 | SocketUtils.start(); 58 | log.info("§d[Minecraft_QQ]§e已启动-" + Minecraft_QQ.version); 59 | log.info("§d[Minecraft_QQ]§eDebug模式" + Minecraft_QQ.config.System.Debug); 60 | } 61 | 62 | public static void stop() { 63 | SocketUtils.stop(); 64 | log.info("§d[Minecraft_QQ]§e已停止,感谢使用"); 65 | } 66 | 67 | public void init(File file) { 68 | try { 69 | log.info("§d[Minecraft_QQ]§e正在启动,感谢使用,本插件交流群:571239090"); 70 | if (fileName == null) { 71 | fileName = new File(file, "config.json"); 72 | if (!file.exists()) { 73 | file.mkdir(); 74 | } 75 | } 76 | if (!fileName.exists()) { 77 | Files.copy(this.getClass().getResourceAsStream("/config.json"), fileName.toPath()); 78 | } 79 | Logs.init(file); 80 | load(); 81 | } catch (Exception e) { 82 | log.warning("§d[Minecraft_QQ]§c配置文件初始化错误"); 83 | e.printStackTrace(); 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /core/api/IGroupEvent.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.api; 2 | 3 | public interface IGroupEvent { 4 | String getGroup(); 5 | 6 | String getMessage(); 7 | 8 | String getPlayer(); 9 | 10 | String getCommand(); 11 | 12 | boolean isCommand(); 13 | } 14 | -------------------------------------------------------------------------------- /core/api/ILogger.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.api; 2 | 3 | public interface ILogger { 4 | void warning(String data); 5 | 6 | void info(String data); 7 | } 8 | -------------------------------------------------------------------------------- /core/api/ISide.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.api; 2 | 3 | import com.coloryr.minecraft_qq.core.json.ReadObj; 4 | 5 | public interface ISide { 6 | void message(ReadObj message); 7 | 8 | void send(Object sender, String message); 9 | } 10 | -------------------------------------------------------------------------------- /core/api/Placeholder.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.api; 2 | 3 | public class Placeholder { 4 | public static final String data = "data"; 5 | public static final String group = "group"; 6 | public static final String start = "start"; 7 | public static final String pause = "pause"; 8 | public static final String config = "config"; 9 | public static final String server = "server"; 10 | public static final String set = "set"; 11 | public static final String speak = "speak"; 12 | public static final String online = "online"; 13 | } 14 | -------------------------------------------------------------------------------- /core/bstats/MetricsBase.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.bstats; 2 | 3 | import com.coloryr.minecraft_qq.core.bstats.charts.CustomChart; 4 | import com.coloryr.minecraft_qq.core.bstats.json.JsonObjectBuilder; 5 | 6 | import javax.net.ssl.HttpsURLConnection; 7 | import java.io.*; 8 | import java.net.URL; 9 | import java.nio.charset.StandardCharsets; 10 | import java.util.HashSet; 11 | import java.util.Objects; 12 | import java.util.Set; 13 | import java.util.concurrent.Executors; 14 | import java.util.concurrent.ScheduledExecutorService; 15 | import java.util.concurrent.TimeUnit; 16 | import java.util.function.BiConsumer; 17 | import java.util.function.Consumer; 18 | import java.util.function.Supplier; 19 | import java.util.zip.GZIPOutputStream; 20 | 21 | public class MetricsBase { 22 | 23 | /** 24 | * The version of the Metrics class. 25 | */ 26 | public static final String METRICS_VERSION = "2.1.0"; 27 | 28 | private static final ScheduledExecutorService scheduler = 29 | Executors.newScheduledThreadPool(1, task -> new Thread(task, "bStats-Metrics")); 30 | private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s"; 31 | 32 | private final String platform; 33 | private final String serverUuid; 34 | private final int serviceId; 35 | private final Consumer appendPlatformDataConsumer; 36 | private final Consumer appendServiceDataConsumer; 37 | private final Consumer submitTaskConsumer; 38 | private final Supplier checkServiceEnabledSupplier; 39 | 40 | private final BiConsumer errorLogger; 41 | private final Consumer infoLogger; 42 | 43 | private final boolean logErrors; 44 | private final boolean logSentData; 45 | private final boolean logResponseStatusText; 46 | 47 | private final Set customCharts = new HashSet<>(); 48 | private final boolean enabled; 49 | 50 | /** 51 | * Creates a new MetricsBase class instance. 52 | * 53 | * @param platform The platform of the service. 54 | * @param serviceId The id of the service. 55 | * @param serverUuid The server uuid. 56 | * @param enabled Whether or not data sending is enabled. 57 | * @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and appends all 58 | * platform-specific data. 59 | * @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and appends all 60 | * service-specific data. 61 | * @param submitTaskConsumer A consumer that takes a runnable with the submit task. 62 | * This can be used to delegate the data collection to a another thread to prevent 63 | * errors caused by concurrency. Can be {@code null}. 64 | * @param checkServiceEnabledSupplier A supplier to check if the service is still enabled. 65 | * @param errorLogger A consumer that accepts log message and an error. 66 | * @param infoLogger A consumer that accepts info log messages. 67 | * @param logErrors Whether or not errors should be logged. 68 | * @param logSentData Whether or not the sent data should be logged. 69 | * @param logResponseStatusText Whether or not the response status text should be logged. 70 | */ 71 | public MetricsBase( 72 | String platform, 73 | String serverUuid, 74 | int serviceId, 75 | boolean enabled, 76 | Consumer appendPlatformDataConsumer, 77 | Consumer appendServiceDataConsumer, 78 | Consumer submitTaskConsumer, 79 | Supplier checkServiceEnabledSupplier, 80 | BiConsumer errorLogger, 81 | Consumer infoLogger, 82 | boolean logErrors, 83 | boolean logSentData, 84 | boolean logResponseStatusText 85 | ) { 86 | this.platform = platform; 87 | this.serverUuid = serverUuid; 88 | this.serviceId = serviceId; 89 | this.enabled = enabled; 90 | this.appendPlatformDataConsumer = appendPlatformDataConsumer; 91 | this.appendServiceDataConsumer = appendServiceDataConsumer; 92 | this.submitTaskConsumer = submitTaskConsumer; 93 | this.checkServiceEnabledSupplier = checkServiceEnabledSupplier; 94 | this.errorLogger = errorLogger; 95 | this.infoLogger = infoLogger; 96 | this.logErrors = logErrors; 97 | this.logSentData = logSentData; 98 | this.logResponseStatusText = logResponseStatusText; 99 | 100 | checkRelocation(); 101 | 102 | if (enabled) { 103 | startSubmitting(); 104 | } 105 | } 106 | 107 | /** 108 | * Gzips the given string. 109 | * 110 | * @param str The string to gzip. 111 | * @return The gzipped string. 112 | */ 113 | private static byte[] compress(final String str) throws IOException { 114 | if (str == null) { 115 | return null; 116 | } 117 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 118 | try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { 119 | gzip.write(str.getBytes(StandardCharsets.UTF_8)); 120 | } 121 | return outputStream.toByteArray(); 122 | } 123 | 124 | public void addCustomChart(CustomChart chart) { 125 | this.customCharts.add(chart); 126 | } 127 | 128 | private void startSubmitting() { 129 | final Runnable submitTask = () -> { 130 | if (!enabled || !checkServiceEnabledSupplier.get()) { // Submitting data or service is disabled 131 | scheduler.shutdown(); 132 | return; 133 | } 134 | if (submitTaskConsumer != null) { 135 | submitTaskConsumer.accept(this::submitData); 136 | } else { 137 | this.submitData(); 138 | } 139 | }; 140 | 141 | // Many servers tend to restart at a fixed time at xx:00 which causes an uneven distribution of requests on the 142 | // bStats backend. To circumvent this problem, we introduce some randomness into the initial and second delay. 143 | // WARNING: You must not modify and part of this Metrics class, including the submit delay or frequency! 144 | // WARNING: Modifying this code will get your plugin banned on bStats. Just don't do it! 145 | long initialDelay = (long) (1000 * 60 * (3 + Math.random() * 3)); 146 | long secondDelay = (long) (1000 * 60 * (Math.random() * 30)); 147 | scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS); 148 | scheduler.scheduleAtFixedRate(submitTask, initialDelay + secondDelay, 1000 * 60 * 30, TimeUnit.MILLISECONDS); 149 | } 150 | 151 | private void submitData() { 152 | final JsonObjectBuilder baseJsonBuilder = new JsonObjectBuilder(); 153 | appendPlatformDataConsumer.accept(baseJsonBuilder); 154 | 155 | final JsonObjectBuilder serviceJsonBuilder = new JsonObjectBuilder(); 156 | appendServiceDataConsumer.accept(serviceJsonBuilder); 157 | 158 | JsonObjectBuilder.JsonObject[] chartData = customCharts.stream() 159 | .map(customChart -> customChart.getRequestJsonObject(errorLogger, logErrors)) 160 | .filter(Objects::nonNull) 161 | .toArray(JsonObjectBuilder.JsonObject[]::new); 162 | 163 | serviceJsonBuilder.appendField("id", serviceId); 164 | serviceJsonBuilder.appendField("customCharts", chartData); 165 | baseJsonBuilder.appendField("service", serviceJsonBuilder.build()); 166 | baseJsonBuilder.appendField("serverUUID", serverUuid); 167 | baseJsonBuilder.appendField("metricsVersion", METRICS_VERSION); 168 | 169 | JsonObjectBuilder.JsonObject data = baseJsonBuilder.build(); 170 | 171 | scheduler.execute(() -> { 172 | try { 173 | // Send the data 174 | sendData(data); 175 | } catch (Exception e) { 176 | // Something went wrong! :( 177 | if (logErrors) { 178 | errorLogger.accept("Could not submit bStats metrics data", e); 179 | } 180 | } 181 | }); 182 | } 183 | 184 | private void sendData(JsonObjectBuilder.JsonObject data) throws Exception { 185 | if (logSentData) { 186 | infoLogger.accept("Sent bStats metrics data: " + data.toString()); 187 | } 188 | 189 | String url = String.format(REPORT_URL, platform); 190 | HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection(); 191 | 192 | // Compress the data to save bandwidth 193 | byte[] compressedData = compress(data.toString()); 194 | 195 | connection.setRequestMethod("POST"); 196 | connection.addRequestProperty("Accept", "application/json"); 197 | connection.addRequestProperty("Connection", "close"); 198 | connection.addRequestProperty("Content-Encoding", "gzip"); 199 | connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); 200 | connection.setRequestProperty("Content-Type", "application/json"); 201 | connection.setRequestProperty("User-Agent", "Metrics-Service/1"); 202 | 203 | connection.setDoOutput(true); 204 | try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { 205 | outputStream.write(compressedData); 206 | } 207 | 208 | StringBuilder builder = new StringBuilder(); 209 | try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { 210 | String line; 211 | while ((line = bufferedReader.readLine()) != null) { 212 | builder.append(line); 213 | } 214 | } 215 | 216 | if (logResponseStatusText) { 217 | infoLogger.accept("Sent data to bStats and received response: " + builder); 218 | } 219 | } 220 | 221 | /** 222 | * Checks that the class was properly relocated. 223 | */ 224 | private void checkRelocation() { 225 | // You can use the property to disable the check in your test environment 226 | if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) { 227 | // Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D 228 | final String defaultPackage = new String( 229 | new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'}); 230 | final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); 231 | // We want to make sure no one just copy & pastes the example and uses the wrong package names 232 | if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage) || MetricsBase.class.getPackage().getName().startsWith(examplePackage)) { 233 | throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); 234 | } 235 | } 236 | } 237 | 238 | } 239 | -------------------------------------------------------------------------------- /core/bstats/charts/AdvancedBarChart.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.bstats.charts; 2 | 3 | import com.coloryr.minecraft_qq.core.bstats.json.JsonObjectBuilder; 4 | 5 | import java.util.Map; 6 | import java.util.concurrent.Callable; 7 | 8 | public class AdvancedBarChart extends CustomChart { 9 | 10 | private final Callable> callable; 11 | 12 | /** 13 | * Class constructor. 14 | * 15 | * @param chartId The id of the chart. 16 | * @param callable The callable which is used to request the chart data. 17 | */ 18 | public AdvancedBarChart(String chartId, Callable> callable) { 19 | super(chartId); 20 | this.callable = callable; 21 | } 22 | 23 | @Override 24 | protected JsonObjectBuilder.JsonObject getChartData() throws Exception { 25 | JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); 26 | Map map = callable.call(); 27 | if (map == null || map.isEmpty()) { 28 | // Null = skip the chart 29 | return null; 30 | } 31 | boolean allSkipped = true; 32 | for (Map.Entry entry : map.entrySet()) { 33 | if (entry.getValue().length == 0) { 34 | continue; // Skip this invalid 35 | } 36 | allSkipped = false; 37 | valuesBuilder.appendField(entry.getKey(), entry.getValue()); 38 | } 39 | if (allSkipped) { 40 | // Null = skip the chart 41 | return null; 42 | } 43 | 44 | return new JsonObjectBuilder() 45 | .appendField("values", valuesBuilder.build()) 46 | .build(); 47 | } 48 | } -------------------------------------------------------------------------------- /core/bstats/charts/AdvancedPie.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.bstats.charts; 2 | 3 | import com.coloryr.minecraft_qq.core.bstats.json.JsonObjectBuilder; 4 | 5 | import java.util.Map; 6 | import java.util.concurrent.Callable; 7 | 8 | public class AdvancedPie extends CustomChart { 9 | 10 | private final Callable> callable; 11 | 12 | /** 13 | * Class constructor. 14 | * 15 | * @param chartId The id of the chart. 16 | * @param callable The callable which is used to request the chart data. 17 | */ 18 | public AdvancedPie(String chartId, Callable> callable) { 19 | super(chartId); 20 | this.callable = callable; 21 | } 22 | 23 | @Override 24 | protected JsonObjectBuilder.JsonObject getChartData() throws Exception { 25 | JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); 26 | 27 | Map map = callable.call(); 28 | if (map == null || map.isEmpty()) { 29 | // Null = skip the chart 30 | return null; 31 | } 32 | boolean allSkipped = true; 33 | for (Map.Entry entry : map.entrySet()) { 34 | if (entry.getValue() == 0) { 35 | continue; // Skip this invalid 36 | } 37 | allSkipped = false; 38 | valuesBuilder.appendField(entry.getKey(), entry.getValue()); 39 | } 40 | if (allSkipped) { 41 | // Null = skip the chart 42 | return null; 43 | } 44 | 45 | return new JsonObjectBuilder() 46 | .appendField("values", valuesBuilder.build()) 47 | .build(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /core/bstats/charts/CustomChart.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.bstats.charts; 2 | 3 | import com.coloryr.minecraft_qq.core.bstats.json.JsonObjectBuilder; 4 | 5 | import java.util.function.BiConsumer; 6 | 7 | public abstract class CustomChart { 8 | 9 | private final String chartId; 10 | 11 | protected CustomChart(String chartId) { 12 | if (chartId == null) { 13 | throw new IllegalArgumentException("chartId must not be null"); 14 | } 15 | this.chartId = chartId; 16 | } 17 | 18 | public JsonObjectBuilder.JsonObject getRequestJsonObject(BiConsumer errorLogger, boolean logErrors) { 19 | JsonObjectBuilder builder = new JsonObjectBuilder(); 20 | builder.appendField("chartId", chartId); 21 | try { 22 | JsonObjectBuilder.JsonObject data = getChartData(); 23 | if (data == null) { 24 | // If the data is null we don't send the chart. 25 | return null; 26 | } 27 | builder.appendField("data", data); 28 | } catch (Throwable t) { 29 | if (logErrors) { 30 | 31 | errorLogger.accept("Failed to get data for custom chart with id " + chartId, t); 32 | } 33 | return null; 34 | } 35 | return builder.build(); 36 | } 37 | 38 | protected abstract JsonObjectBuilder.JsonObject getChartData() throws Exception; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /core/bstats/charts/DrilldownPie.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.bstats.charts; 2 | 3 | import com.coloryr.minecraft_qq.core.bstats.json.JsonObjectBuilder; 4 | 5 | import java.util.Map; 6 | import java.util.concurrent.Callable; 7 | 8 | public class DrilldownPie extends CustomChart { 9 | 10 | private final Callable>> callable; 11 | 12 | /** 13 | * Class constructor. 14 | * 15 | * @param chartId The id of the chart. 16 | * @param callable The callable which is used to request the chart data. 17 | */ 18 | public DrilldownPie(String chartId, Callable>> callable) { 19 | super(chartId); 20 | this.callable = callable; 21 | } 22 | 23 | @Override 24 | public JsonObjectBuilder.JsonObject getChartData() throws Exception { 25 | JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); 26 | 27 | Map> map = callable.call(); 28 | if (map == null || map.isEmpty()) { 29 | // Null = skip the chart 30 | return null; 31 | } 32 | boolean reallyAllSkipped = true; 33 | for (Map.Entry> entryValues : map.entrySet()) { 34 | JsonObjectBuilder valueBuilder = new JsonObjectBuilder(); 35 | boolean allSkipped = true; 36 | for (Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) { 37 | valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue()); 38 | allSkipped = false; 39 | } 40 | if (!allSkipped) { 41 | reallyAllSkipped = false; 42 | valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build()); 43 | } 44 | } 45 | if (reallyAllSkipped) { 46 | // Null = skip the chart 47 | return null; 48 | } 49 | 50 | return new JsonObjectBuilder() 51 | .appendField("values", valuesBuilder.build()) 52 | .build(); 53 | } 54 | } -------------------------------------------------------------------------------- /core/bstats/charts/MultiLineChart.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.bstats.charts; 2 | 3 | import com.coloryr.minecraft_qq.core.bstats.json.JsonObjectBuilder; 4 | 5 | import java.util.Map; 6 | import java.util.concurrent.Callable; 7 | 8 | public class MultiLineChart extends CustomChart { 9 | 10 | private final Callable> callable; 11 | 12 | /** 13 | * Class constructor. 14 | * 15 | * @param chartId The id of the chart. 16 | * @param callable The callable which is used to request the chart data. 17 | */ 18 | public MultiLineChart(String chartId, Callable> callable) { 19 | super(chartId); 20 | this.callable = callable; 21 | } 22 | 23 | @Override 24 | protected JsonObjectBuilder.JsonObject getChartData() throws Exception { 25 | JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); 26 | 27 | Map map = callable.call(); 28 | if (map == null || map.isEmpty()) { 29 | // Null = skip the chart 30 | return null; 31 | } 32 | boolean allSkipped = true; 33 | for (Map.Entry entry : map.entrySet()) { 34 | if (entry.getValue() == 0) { 35 | continue; // Skip this invalid 36 | } 37 | allSkipped = false; 38 | valuesBuilder.appendField(entry.getKey(), entry.getValue()); 39 | } 40 | if (allSkipped) { 41 | // Null = skip the chart 42 | return null; 43 | } 44 | 45 | return new JsonObjectBuilder() 46 | .appendField("values", valuesBuilder.build()) 47 | .build(); 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /core/bstats/charts/SimpleBarChart.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.bstats.charts; 2 | 3 | import com.coloryr.minecraft_qq.core.bstats.json.JsonObjectBuilder; 4 | 5 | import java.util.Map; 6 | import java.util.concurrent.Callable; 7 | 8 | public class SimpleBarChart extends CustomChart { 9 | 10 | private final Callable> callable; 11 | 12 | /** 13 | * Class constructor. 14 | * 15 | * @param chartId The id of the chart. 16 | * @param callable The callable which is used to request the chart data. 17 | */ 18 | public SimpleBarChart(String chartId, Callable> callable) { 19 | super(chartId); 20 | this.callable = callable; 21 | } 22 | 23 | @Override 24 | protected JsonObjectBuilder.JsonObject getChartData() throws Exception { 25 | JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); 26 | 27 | Map map = callable.call(); 28 | if (map == null || map.isEmpty()) { 29 | // Null = skip the chart 30 | return null; 31 | } 32 | for (Map.Entry entry : map.entrySet()) { 33 | valuesBuilder.appendField(entry.getKey(), new int[]{entry.getValue()}); 34 | } 35 | 36 | return new JsonObjectBuilder() 37 | .appendField("values", valuesBuilder.build()) 38 | .build(); 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /core/bstats/charts/SimplePie.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.bstats.charts; 2 | 3 | import com.coloryr.minecraft_qq.core.bstats.json.JsonObjectBuilder; 4 | 5 | import java.util.concurrent.Callable; 6 | 7 | public class SimplePie extends CustomChart { 8 | 9 | private final Callable callable; 10 | 11 | /** 12 | * Class constructor. 13 | * 14 | * @param chartId The id of the chart. 15 | * @param callable The callable which is used to request the chart data. 16 | */ 17 | public SimplePie(String chartId, Callable callable) { 18 | super(chartId); 19 | this.callable = callable; 20 | } 21 | 22 | @Override 23 | protected JsonObjectBuilder.JsonObject getChartData() throws Exception { 24 | String value = callable.call(); 25 | if (value == null || value.isEmpty()) { 26 | // Null = skip the chart 27 | return null; 28 | } 29 | return new JsonObjectBuilder() 30 | .appendField("value", value) 31 | .build(); 32 | } 33 | } -------------------------------------------------------------------------------- /core/bstats/charts/SingleLineChart.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.bstats.charts; 2 | 3 | import com.coloryr.minecraft_qq.core.bstats.json.JsonObjectBuilder; 4 | 5 | import java.util.concurrent.Callable; 6 | 7 | public class SingleLineChart extends CustomChart { 8 | 9 | private final Callable callable; 10 | 11 | /** 12 | * Class constructor. 13 | * 14 | * @param chartId The id of the chart. 15 | * @param callable The callable which is used to request the chart data. 16 | */ 17 | public SingleLineChart(String chartId, Callable callable) { 18 | super(chartId); 19 | this.callable = callable; 20 | } 21 | 22 | @Override 23 | protected JsonObjectBuilder.JsonObject getChartData() throws Exception { 24 | int value = callable.call(); 25 | if (value == 0) { 26 | // Null = skip the chart 27 | return null; 28 | } 29 | return new JsonObjectBuilder() 30 | .appendField("value", value) 31 | .build(); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /core/bstats/config/MetricsConfig.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.bstats.config; 2 | 3 | import java.io.*; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.Optional; 7 | import java.util.UUID; 8 | import java.util.regex.Pattern; 9 | import java.util.stream.Collectors; 10 | 11 | public class MetricsConfig { 12 | private final File file; 13 | private final boolean defaultEnabled; 14 | 15 | private String serverUUID; 16 | private boolean enabled; 17 | private boolean logErrors; 18 | private boolean logSentData; 19 | private boolean logResponseStatusText; 20 | 21 | private boolean didExistBefore = true; 22 | 23 | public MetricsConfig(File file, boolean defaultEnabled) throws IOException { 24 | this.file = file; 25 | this.defaultEnabled = defaultEnabled; 26 | 27 | setupConfig(); 28 | } 29 | 30 | public String getServerUUID() { 31 | return serverUUID; 32 | } 33 | 34 | public boolean isEnabled() { 35 | return enabled; 36 | } 37 | 38 | public boolean isLogErrorsEnabled() { 39 | return logErrors; 40 | } 41 | 42 | public boolean isLogSentDataEnabled() { 43 | return logSentData; 44 | } 45 | 46 | public boolean isLogResponseStatusTextEnabled() { 47 | return logResponseStatusText; 48 | } 49 | 50 | /** 51 | * Checks whether the config file did exist before or not. 52 | * 53 | * @return If the config did exist before. 54 | */ 55 | public boolean didExistBefore() { 56 | return didExistBefore; 57 | } 58 | 59 | /** 60 | * Creates the config file if it does not exist and read its content. 61 | */ 62 | private void setupConfig() throws IOException { 63 | if (!file.exists()) { 64 | didExistBefore = false; // Looks like it's the first time we create it (or someone deleted it). 65 | writeConfig(); 66 | } 67 | readConfig(); 68 | if (serverUUID == null) { 69 | // Found a malformed config file with no UUID. Let's recreate it. 70 | writeConfig(); 71 | readConfig(); 72 | } 73 | } 74 | 75 | /** 76 | * Creates a config file with teh default content. 77 | */ 78 | private void writeConfig() throws IOException { 79 | List configContent = new ArrayList<>(); 80 | configContent.add("# bStats collects some basic information for plugin authors, like how many people use"); 81 | configContent.add("# their plugin and their total player count. It's recommend to keep bStats enabled, but"); 82 | configContent.add("# if you're not comfortable with this, you can turn this setting off. There is no"); 83 | configContent.add("# performance penalty associated with having metrics enabled, and data sent to bStats"); 84 | configContent.add("# can't identify your server."); 85 | configContent.add("enabled=" + defaultEnabled); 86 | configContent.add("server-uuid=" + UUID.randomUUID().toString()); 87 | configContent.add("log-errors=false"); 88 | configContent.add("log-sent-data=false"); 89 | configContent.add("log-response-status-text=false"); 90 | writeFile(file, configContent); 91 | } 92 | 93 | /** 94 | * Reads the content of the config file. 95 | */ 96 | private void readConfig() throws IOException { 97 | List lines = readFile(file); 98 | if (lines == null) { 99 | throw new AssertionError("Content of newly created file is null"); 100 | } 101 | 102 | enabled = getConfigValue("enabled", lines).map("true"::equals).orElse(true); 103 | serverUUID = getConfigValue("server-uuid", lines).orElse(null); 104 | logErrors = getConfigValue("log-errors", lines).map("true"::equals).orElse(false); 105 | logSentData = getConfigValue("log-sent-data", lines).map("true"::equals).orElse(false); 106 | logResponseStatusText = getConfigValue("log-response-status-text", lines).map("true"::equals).orElse(false); 107 | } 108 | 109 | /** 110 | * Gets a config setting from the given list of lines of the file. 111 | * 112 | * @param key The key for the setting. 113 | * @param lines The lines of the file. 114 | * @return The value of the setting. 115 | */ 116 | private Optional getConfigValue(String key, List lines) { 117 | return lines.stream() 118 | .filter(line -> line.startsWith(key + "=")) 119 | .map(line -> line.replaceFirst(Pattern.quote(key + "="), "")) 120 | .findFirst(); 121 | } 122 | 123 | /** 124 | * Reads the text content of the given file. 125 | * 126 | * @param file The file to read. 127 | * @return The lines of the given file. 128 | */ 129 | private List readFile(File file) throws IOException { 130 | if (!file.exists()) { 131 | return null; 132 | } 133 | try ( 134 | FileReader fileReader = new FileReader(file); 135 | BufferedReader bufferedReader = new BufferedReader(fileReader) 136 | ) { 137 | return bufferedReader.lines().collect(Collectors.toList()); 138 | } 139 | } 140 | 141 | /** 142 | * Writes the given lines to the given file. 143 | * 144 | * @param file The file to write to. 145 | * @param lines The lines to write. 146 | */ 147 | private void writeFile(File file, List lines) throws IOException { 148 | if (!file.exists()) { 149 | file.getParentFile().mkdirs(); 150 | file.createNewFile(); 151 | } 152 | try ( 153 | FileWriter fileWriter = new FileWriter(file); 154 | BufferedWriter bufferedWriter = new BufferedWriter(fileWriter) 155 | ) { 156 | for (String line : lines) { 157 | bufferedWriter.write(line); 158 | bufferedWriter.newLine(); 159 | } 160 | } 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /core/bstats/json/JsonObjectBuilder.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.bstats.json; 2 | 3 | import java.util.Arrays; 4 | import java.util.stream.Collectors; 5 | 6 | /** 7 | * An extremely simple JSON builder. 8 | * 9 | *

While this class is neither feature-rich nor the most performant one, 10 | * it's sufficient enough for its use-case. 11 | */ 12 | public class JsonObjectBuilder { 13 | 14 | private StringBuilder builder = new StringBuilder(); 15 | private boolean hasAtLeastOneField = false; 16 | 17 | public JsonObjectBuilder() { 18 | builder.append("{"); 19 | } 20 | 21 | /** 22 | * Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt. 23 | * 24 | *

This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'. 25 | * Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n"). 26 | * 27 | * @param value The value to escape. 28 | * @return The escaped value. 29 | */ 30 | private static String escape(String value) { 31 | final StringBuilder builder = new StringBuilder(); 32 | for (int i = 0; i < value.length(); i++) { 33 | char c = value.charAt(i); 34 | if (c == '"') { 35 | builder.append("\\\""); 36 | } else if (c == '\\') { 37 | builder.append("\\\\"); 38 | } else if (c <= '\u000F') { 39 | builder.append("\\u000").append(Integer.toHexString(c)); 40 | } else if (c <= '\u001F') { 41 | builder.append("\\u00").append(Integer.toHexString(c)); 42 | } else { 43 | builder.append(c); 44 | } 45 | } 46 | return builder.toString(); 47 | } 48 | 49 | /** 50 | * Appends a null field to the JSON. 51 | * 52 | * @param key The key of the field. 53 | * @return A reference to this object. 54 | */ 55 | public JsonObjectBuilder appendNull(String key) { 56 | appendFieldUnescaped(key, "null"); 57 | return this; 58 | } 59 | 60 | /** 61 | * Appends a string field to the JSON. 62 | * 63 | * @param key The key of the field. 64 | * @param value The value of the field. 65 | * @return A reference to this object. 66 | */ 67 | public JsonObjectBuilder appendField(String key, String value) { 68 | if (value == null) { 69 | throw new IllegalArgumentException("JSON value must not be null"); 70 | } 71 | appendFieldUnescaped(key, "\"" + escape(value) + "\""); 72 | return this; 73 | } 74 | 75 | /** 76 | * Appends an integer field to the JSON. 77 | * 78 | * @param key The key of the field. 79 | * @param value The value of the field. 80 | * @return A reference to this object. 81 | */ 82 | public JsonObjectBuilder appendField(String key, int value) { 83 | appendFieldUnescaped(key, String.valueOf(value)); 84 | return this; 85 | } 86 | 87 | /** 88 | * Appends an object to the JSON. 89 | * 90 | * @param key The key of the field. 91 | * @param object The object. 92 | * @return A reference to this object. 93 | */ 94 | public JsonObjectBuilder appendField(String key, JsonObject object) { 95 | if (object == null) { 96 | throw new IllegalArgumentException("JSON object must not be null"); 97 | } 98 | appendFieldUnescaped(key, object.toString()); 99 | return this; 100 | } 101 | 102 | /** 103 | * Appends a string array to the JSON. 104 | * 105 | * @param key The key of the field. 106 | * @param values The string array. 107 | * @return A reference to this object. 108 | */ 109 | public JsonObjectBuilder appendField(String key, String[] values) { 110 | if (values == null) { 111 | throw new IllegalArgumentException("JSON values must not be null"); 112 | } 113 | String escapedValues = Arrays.stream(values) 114 | .map(value -> "\"" + escape(value) + "\"") 115 | .collect(Collectors.joining(",")); 116 | appendFieldUnescaped(key, "[" + escapedValues + "]"); 117 | return this; 118 | } 119 | 120 | /** 121 | * Appends an integer array to the JSON. 122 | * 123 | * @param key The key of the field. 124 | * @param values The integer array. 125 | * @return A reference to this object. 126 | */ 127 | public JsonObjectBuilder appendField(String key, int[] values) { 128 | if (values == null) { 129 | throw new IllegalArgumentException("JSON values must not be null"); 130 | } 131 | String escapedValues = Arrays.stream(values) 132 | .mapToObj(String::valueOf) 133 | .collect(Collectors.joining(",")); 134 | appendFieldUnescaped(key, "[" + escapedValues + "]"); 135 | return this; 136 | } 137 | 138 | /** 139 | * Appends an object array to the JSON. 140 | * 141 | * @param key The key of the field. 142 | * @param values The integer array. 143 | * @return A reference to this object. 144 | */ 145 | public JsonObjectBuilder appendField(String key, JsonObject[] values) { 146 | if (values == null) { 147 | throw new IllegalArgumentException("JSON values must not be null"); 148 | } 149 | String escapedValues = Arrays.stream(values) 150 | .map(JsonObject::toString) 151 | .collect(Collectors.joining(",")); 152 | appendFieldUnescaped(key, "[" + escapedValues + "]"); 153 | return this; 154 | } 155 | 156 | /** 157 | * Appends a field to the object. 158 | * 159 | * @param key The key of the field. 160 | * @param escapedValue The escaped value of the field. 161 | */ 162 | private void appendFieldUnescaped(String key, String escapedValue) { 163 | if (builder == null) { 164 | throw new IllegalStateException("JSON has already been built"); 165 | } 166 | if (key == null) { 167 | throw new IllegalArgumentException("JSON key must not be null"); 168 | } 169 | if (hasAtLeastOneField) { 170 | builder.append(","); 171 | } 172 | builder.append("\"").append(escape(key)).append("\":").append(escapedValue); 173 | 174 | hasAtLeastOneField = true; 175 | } 176 | 177 | /** 178 | * Builds the JSON string and invalidates this builder. 179 | * 180 | * @return The built JSON string. 181 | */ 182 | public JsonObject build() { 183 | if (builder == null) { 184 | throw new IllegalStateException("JSON has already been built"); 185 | } 186 | JsonObject object = new JsonObject(builder.append("}").toString()); 187 | builder = null; 188 | return object; 189 | } 190 | 191 | /** 192 | * A super simple representation of a JSON object. 193 | * 194 | *

This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and 195 | * not allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String, JsonObject)}. 196 | */ 197 | public static class JsonObject { 198 | 199 | private final String value; 200 | 201 | private JsonObject(String value) { 202 | this.value = value; 203 | } 204 | 205 | @Override 206 | public String toString() { 207 | return value; 208 | } 209 | } 210 | 211 | } -------------------------------------------------------------------------------- /core/command/CommandEX.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.command; 2 | 3 | import com.coloryr.minecraft_qq.core.Minecraft_QQ; 4 | import com.coloryr.minecraft_qq.core.api.Placeholder; 5 | import com.coloryr.minecraft_qq.core.utils.SocketUtils; 6 | 7 | public class CommandEX { 8 | 9 | private static void reload(Object sender) { 10 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§e机器人IP: " + Minecraft_QQ.config.System.IP); 11 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§e机器人端口 " + Minecraft_QQ.config.System.Port); 12 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§e机器人模式 " + Minecraft_QQ.config.ServerSet.Mode); 13 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§eDebug模式 " + Minecraft_QQ.config.System.Debug); 14 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§e重载成功"); 15 | } 16 | 17 | public static void ex(Object sender, String name, String[] args, boolean hasPermission) { 18 | if (args.length == 0) { 19 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§c错误,请使用/qq help 获取帮助"); 20 | return; 21 | } 22 | if (args[0].equalsIgnoreCase("reload") && hasPermission) { 23 | Minecraft_QQ.load(); 24 | reload(sender); 25 | } else if (args[0].equalsIgnoreCase("socket") && hasPermission) { 26 | SocketUtils.socketReset(); 27 | } else if (args[0].equalsIgnoreCase("drop") && hasPermission) { 28 | SocketUtils.socketClose(); 29 | } else if (args[0].equalsIgnoreCase("help")) { 30 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§2帮助手册"); 31 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§2使用/qq chat 来启用关闭群聊天"); 32 | if (hasPermission) { 33 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§2使用/qq say 内容 往群里发送测试消息"); 34 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§2使用/qq reload 来重读插件配置文件"); 35 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§2使用/qq socket 来重置连接超时次数"); 36 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§2使用/qq drop 强制断开当前连接"); 37 | } 38 | } else if (args[0].equalsIgnoreCase("say") && hasPermission) { 39 | if (args.length > 1) { 40 | if (SocketUtils.isRun()) { 41 | SocketUtils.sendData(Placeholder.data, Placeholder.group, "无", args); 42 | } else 43 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§c错误,Minecraft_QQ_Cmd/Gui未连接"); 44 | } else { 45 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§c错误,请输入文本"); 46 | } 47 | } else if (args[0].equalsIgnoreCase("chat")) { 48 | if (!Minecraft_QQ.config.Mute.contains(name)) { 49 | Minecraft_QQ.config.Mute.add(name); 50 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]" + Minecraft_QQ.config.Language.MessageOFF); 51 | } else { 52 | Minecraft_QQ.config.Mute.remove(name); 53 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]" + Minecraft_QQ.config.Language.MessageON); 54 | } 55 | Minecraft_QQ.save(); 56 | } else { 57 | Minecraft_QQ.side.send(sender, "§d[Minecraft_QQ]§c错误,请使用/qq help 获取帮助"); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /core/command/CommandTab.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.command; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class CommandTab { 7 | public static List getList(boolean hasPermission, String[] args) { 8 | ArrayList arguments = new ArrayList<>(); 9 | arguments.add("chat"); 10 | if (hasPermission) { 11 | if (args.length != 0 && args[0].equalsIgnoreCase("reload")) { 12 | arguments.add("config"); 13 | arguments.add("socket"); 14 | } else { 15 | arguments.add("help"); 16 | arguments.add("say"); 17 | arguments.add("reload"); 18 | } 19 | } 20 | return arguments; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /core/config/ConfigOBJ.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.config; 2 | 3 | import com.coloryr.minecraft_qq.core.Minecraft_QQ; 4 | 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class ConfigOBJ { 11 | public MessageOBJ Join; 12 | public MessageOBJ Quit; 13 | public MessageOBJ ChangeServer; 14 | public ServerSetOBJ ServerSet; 15 | public Map Servers; 16 | public SendAllServerOBJ SendAllServer; 17 | public SystemOBJ System; 18 | public UserOBJ User; 19 | public LogsOBJ Logs; 20 | public PlaceholderOBJ Placeholder; 21 | public LanguageOBJ Language; 22 | public List Mute; 23 | public String Version; 24 | 25 | public ConfigOBJ() { 26 | Join = new MessageOBJ("%player%加入了服务器"); 27 | Quit = new MessageOBJ("%player%退出了服务器"); 28 | ChangeServer = new MessageOBJ("%player%加入了子服%server%"); 29 | ServerSet = new ServerSetOBJ(); 30 | Servers = new HashMap<>(); 31 | SendAllServer = new SendAllServerOBJ(); 32 | System = new SystemOBJ(); 33 | User = new UserOBJ(); 34 | Logs = new LogsOBJ(); 35 | Placeholder = new PlaceholderOBJ(); 36 | Language = new LanguageOBJ(); 37 | Mute = new ArrayList<>(); 38 | Version = Minecraft_QQ.version; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/config/LanguageOBJ.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.config; 2 | 3 | public class LanguageOBJ { 4 | public String MessageOFF; 5 | public String MessageON; 6 | 7 | public LanguageOBJ() { 8 | MessageOFF = "§2你已不会在收到群消息"; 9 | MessageON = "§2你开始接受群消息"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /core/config/LogsOBJ.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.config; 2 | 3 | public class LogsOBJ { 4 | public boolean Group; 5 | public boolean Server; 6 | 7 | public LogsOBJ() { 8 | Group = true; 9 | Server = true; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /core/config/MessageOBJ.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.config; 2 | 3 | public class MessageOBJ { 4 | public String Message; 5 | public boolean Send; 6 | 7 | public MessageOBJ(String Message) { 8 | this.Message = Message; 9 | Send = true; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /core/config/PlaceholderOBJ.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.config; 2 | 3 | public class PlaceholderOBJ { 4 | public String Message; 5 | public String Player; 6 | public String ServerName; 7 | public String Server; 8 | public String PlayerNumber; 9 | public String PlayerList; 10 | 11 | public PlaceholderOBJ() { 12 | Message = "%message%"; 13 | Player = "%player%"; 14 | ServerName = "%servername%"; 15 | Server = "%server%"; 16 | PlayerNumber = "%playernumber%"; 17 | PlayerList = "%playerlist%"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /core/config/SendAllServerOBJ.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.config; 2 | 3 | public class SendAllServerOBJ { 4 | public boolean Enable; 5 | public String Message; 6 | public boolean OnlySideServer; 7 | 8 | public SendAllServerOBJ() { 9 | Enable = true; 10 | Message = "[%servername%-%server%]玩家:[%player%]发送群消息:%message%"; 11 | OnlySideServer = true; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /core/config/ServerSetOBJ.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.config; 2 | 3 | public class ServerSetOBJ { 4 | public String ServerName; 5 | public String Check; 6 | public String Message; 7 | public String Say; 8 | public int Mode; 9 | public boolean SendOneByOne; 10 | public String SendOneByOneMessage; 11 | public boolean HideEmptyServer; 12 | public String PlayerListMessage; 13 | public String ServerOnlineMessage; 14 | public boolean TopMode; 15 | public int CommandDelay; 16 | 17 | public ServerSetOBJ() { 18 | ServerName = "[MC服务器]"; 19 | Check = "群:"; 20 | Message = "%servername%-%server%-%player%:%message%"; 21 | Say = "[%servername%][群消息]%message%"; 22 | Mode = 1; 23 | SendOneByOne = true; 24 | SendOneByOneMessage = "\n[%server%-%playernumber%]-%playerlist%"; 25 | HideEmptyServer = true; 26 | PlayerListMessage = "%servername%当前在线人数:%playernumber%,玩家列表:%playerlist%"; 27 | ServerOnlineMessage = "%servername%服务器在线"; 28 | TopMode = false; 29 | CommandDelay = 2000; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /core/config/SystemOBJ.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.config; 2 | 3 | public class SystemOBJ { 4 | public String IP; 5 | public int Port; 6 | public int AutoConnectTime; 7 | public boolean Debug; 8 | 9 | public SystemOBJ() { 10 | IP = "localhost"; 11 | Port = 25555; 12 | AutoConnectTime = 10; 13 | Debug = false; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /core/config/UserOBJ.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.config; 2 | 3 | public class UserOBJ { 4 | public boolean NotSendCommand; 5 | 6 | public UserOBJ() { 7 | NotSendCommand = true; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /core/json/ReadObj.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.json; 2 | 3 | public class ReadObj { 4 | public String group; 5 | public String message; 6 | public String player; 7 | public boolean isCommand; 8 | public String command; 9 | } 10 | -------------------------------------------------------------------------------- /core/json/SendObj.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.json; 2 | 3 | public class SendObj { 4 | public String group; 5 | public String message; 6 | public String data; 7 | public String player; 8 | 9 | public SendObj(String data, String group, String player, String message) { 10 | this.data = data; 11 | this.group = group; 12 | this.message = message; 13 | this.player = player; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /core/utils/Logs.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.utils; 2 | 3 | import com.coloryr.minecraft_qq.core.Minecraft_QQ; 4 | 5 | import java.io.File; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.io.PrintWriter; 9 | import java.util.Date; 10 | 11 | public class Logs { 12 | public static File file; 13 | 14 | public static void init(File file) throws IOException { 15 | Logs.file = new File(file, "logs.log"); 16 | if (!Logs.file.exists()) { 17 | file.createNewFile(); 18 | } 19 | } 20 | 21 | public static void logWrite(String text) { 22 | FileWriter fw; 23 | try { 24 | fw = new FileWriter(file, true); 25 | Date date = new Date(); 26 | String year = String.format("%tF", date); 27 | String time = String.format("%tT", date); 28 | String write = "[" + year + "]" + "[" + time + "]" + text; 29 | PrintWriter pw = new PrintWriter(fw); 30 | pw.println(write); 31 | pw.flush(); 32 | fw.flush(); 33 | pw.close(); 34 | fw.close(); 35 | } catch (Exception e) { 36 | Minecraft_QQ.log.warning("§d[Minecraft_QQ]§c日志文件写入失败" + e.getMessage()); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /core/utils/PackDecode.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.utils; 2 | 3 | import com.coloryr.minecraft_qq.core.json.ReadObj; 4 | import io.netty.buffer.ByteBuf; 5 | 6 | import java.nio.charset.StandardCharsets; 7 | 8 | public class PackDecode { 9 | public static String readString(ByteBuf buff) { 10 | int length = buff.readInt(); 11 | byte[] temp = new byte[length]; 12 | buff.readBytes(temp, 0, length); 13 | return new String(temp, StandardCharsets.UTF_8); 14 | } 15 | 16 | public static ReadObj ToObj(ByteBuf buff) { 17 | ReadObj obj = new ReadObj(); 18 | obj.group = readString(buff); 19 | obj.message = readString(buff); 20 | obj.player = readString(buff); 21 | obj.command = readString(buff); 22 | obj.isCommand = buff.readBoolean(); 23 | return obj; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /core/utils/PackEncode.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.utils; 2 | 3 | import com.coloryr.minecraft_qq.core.json.SendObj; 4 | import io.netty.buffer.ByteBuf; 5 | import io.netty.buffer.Unpooled; 6 | 7 | import java.nio.charset.StandardCharsets; 8 | 9 | public class PackEncode { 10 | public static void writeString(ByteBuf buf, String data) { 11 | if (data == null) 12 | return; 13 | byte[] temp = data.getBytes(StandardCharsets.UTF_8); 14 | buf.writeInt(temp.length); 15 | buf.writeBytes(temp); 16 | } 17 | 18 | public static ByteBuf toPack(SendObj obj){ 19 | ByteBuf buff = Unpooled.buffer(); 20 | buff.writeInt(1); 21 | writeString(buff, obj.group); 22 | writeString(buff, obj.message); 23 | writeString(buff, obj.player); 24 | writeString(buff, obj.data); 25 | 26 | return buff; 27 | } 28 | 29 | public static ByteBuf packStart(String name) 30 | { 31 | ByteBuf buff = Unpooled.buffer(); 32 | buff.writeInt(0); 33 | writeString(buff, name); 34 | 35 | return buff; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /core/utils/SocketUtils.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.core.utils; 2 | 3 | import com.coloryr.minecraft_qq.core.Minecraft_QQ; 4 | import com.coloryr.minecraft_qq.core.api.Placeholder; 5 | import com.coloryr.minecraft_qq.core.json.ReadObj; 6 | import com.coloryr.minecraft_qq.core.json.SendObj; 7 | import io.netty.bootstrap.Bootstrap; 8 | import io.netty.buffer.ByteBuf; 9 | import io.netty.buffer.Unpooled; 10 | import io.netty.channel.*; 11 | import io.netty.channel.nio.NioEventLoopGroup; 12 | import io.netty.channel.socket.SocketChannel; 13 | import io.netty.channel.socket.nio.NioSocketChannel; 14 | import io.netty.handler.codec.LengthFieldBasedFrameDecoder; 15 | import io.netty.handler.codec.LengthFieldPrepender; 16 | 17 | import java.io.IOException; 18 | import java.util.Queue; 19 | import java.util.concurrent.ConcurrentLinkedQueue; 20 | 21 | public class SocketUtils { 22 | 23 | private static final Queue queueRead = new ConcurrentLinkedQueue<>(); 24 | private static final Queue queueSend = new ConcurrentLinkedQueue<>(); 25 | private static boolean isRun; 26 | private static boolean isConnect; 27 | private static int timeout; 28 | 29 | private static final NioEventLoopGroup group = new NioEventLoopGroup(); 30 | private static final Bootstrap bootstrap = new Bootstrap(); 31 | private static Channel client; 32 | 33 | public static void start() { 34 | bootstrap 35 | .group(group) 36 | .channel(NioSocketChannel.class) 37 | .option(ChannelOption.SO_BACKLOG, 100) 38 | .handler(new ChannelInitializer() { 39 | @Override 40 | protected void initChannel(SocketChannel ch) { 41 | ChannelPipeline pipeline = ch.pipeline(); 42 | pipeline.addLast(new LengthFieldPrepender(4)) 43 | .addLast(new LengthFieldBasedFrameDecoder(1024 * 1024 * 2, 0, 4, 0, 4)) 44 | .addLast(new ClientHandler()); 45 | } 46 | }); 47 | 48 | Thread readThread = new Thread(() -> { 49 | try { 50 | while (!isRun) { 51 | Thread.sleep(100); 52 | } 53 | } catch (Exception e) { 54 | e.printStackTrace(); 55 | } 56 | int b = 0; 57 | while (isRun) { 58 | try { 59 | if (!isConnect) { 60 | if (timeout < 10) { 61 | Minecraft_QQ.log.warning("§d[Minecraft_QQ]§5" + Minecraft_QQ.config.System.AutoConnectTime + "秒后重连"); 62 | try { 63 | int a = Minecraft_QQ.config.System.AutoConnectTime; 64 | while (isRun && a > 0) { 65 | Thread.sleep(1000); 66 | a--; 67 | } 68 | } catch (InterruptedException ignored) { 69 | 70 | } 71 | Minecraft_QQ.log.warning("§d[Minecraft_QQ]§5Minecraft_QQ_Cmd/Gui重连中"); 72 | reConnect(); 73 | } else if (timeout == 10) { 74 | Minecraft_QQ.log.warning("§d[Minecraft_QQ]§5自动重连失败次数过多,输入/qq socket 来重置连接超时次数"); 75 | timeout = 12; 76 | } 77 | } else { 78 | ByteBuf temp = queueRead.poll(); 79 | if (temp != null) { 80 | if (Minecraft_QQ.config.System.Debug) 81 | Minecraft_QQ.log.info("§d[Minecraft_QQ]§5[Debug]收到数据:" + temp); 82 | ReadObj obj = PackDecode.ToObj(temp); 83 | temp.release(); 84 | Minecraft_QQ.side.message(obj); 85 | } 86 | 87 | temp = queueSend.poll(); 88 | if (temp != null) { 89 | client.writeAndFlush(temp); 90 | } 91 | b++; 92 | if (b > 600) { 93 | b = 0; 94 | ByteBuf buff = Unpooled.buffer(); 95 | buff.writeInt(120); 96 | queueSend.add(buff); 97 | } 98 | } 99 | Thread.sleep(50); 100 | } catch (Exception e) { 101 | Minecraft_QQ.log.warning("§d[Minecraft_QQ]§5Socket错误"); 102 | e.printStackTrace(); 103 | isConnect = false; 104 | } 105 | } 106 | }); 107 | readThread.start(); 108 | isRun = true; 109 | } 110 | 111 | private static void reConnect() { 112 | try { 113 | Minecraft_QQ.log.info("§d[Minecraft_QQ]§5正在连接Minecraft_QQ_Cmd/Gui"); 114 | 115 | if(client!=null && client.isOpen()){ 116 | client.close().sync(); 117 | } 118 | 119 | client = bootstrap.connect(Minecraft_QQ.config.System.IP, Minecraft_QQ.config.System.Port).await().channel(); 120 | if (client.isActive()) { 121 | Thread.sleep(200); 122 | queueRead.clear(); 123 | queueSend.clear(); 124 | ByteBuf pack = PackEncode.packStart(Minecraft_QQ.config.ServerSet.ServerName); 125 | client.writeAndFlush(pack); 126 | 127 | Minecraft_QQ.log.info("§d[Minecraft_QQ]§5Minecraft_QQ_Cmd/Gui已连接"); 128 | isConnect = true; 129 | } else { 130 | Minecraft_QQ.log.info("§d[Minecraft_QQ]§cMinecraft_QQ_Cmd/Gui连接失败"); 131 | timeout++; 132 | } 133 | } catch (Exception e) { 134 | Minecraft_QQ.log.info("§d[Minecraft_QQ]§cMinecraft_QQ_Cmd/Gui连接失败"); 135 | timeout++; 136 | e.printStackTrace(); 137 | } 138 | } 139 | 140 | public static void stop() { 141 | Minecraft_QQ.log.info("§d[Minecraft_QQ]§5连接已断开"); 142 | isRun = false; 143 | if (client != null) { 144 | try{ 145 | client.close().sync(); 146 | group.shutdownGracefully().sync(); 147 | } 148 | catch (Exception e){ 149 | e.printStackTrace(); 150 | } 151 | 152 | } 153 | if (Minecraft_QQ.config.System.Debug) 154 | Minecraft_QQ.log.info("§d[Minecraft_QQ]§5[Debug]线程已关闭"); 155 | } 156 | 157 | public static void sendData(String data, String group, String player, String message) { 158 | SendObj obj = new SendObj(data, group, player, message); 159 | ByteBuf pack = PackEncode.toPack(obj); 160 | socketSend(pack, player, message); 161 | } 162 | 163 | private static String build(String[] arg) { 164 | StringBuilder builder = new StringBuilder(); 165 | for (int a = 1; a < arg.length; a++) { 166 | builder.append(arg[a]).append(" "); 167 | } 168 | return builder.toString(); 169 | } 170 | 171 | public static void sendData(String data, String group, String player, String[] arg) { 172 | String message = build(arg); 173 | SendObj obj = new SendObj(data, group, player, message); 174 | ByteBuf pack = PackEncode.toPack(obj); 175 | socketSend(pack, player, message); 176 | } 177 | 178 | private static void socketSend(ByteBuf send, String Player, String message) { 179 | queueSend.add(send); 180 | if (Minecraft_QQ.config.Logs.Server) { 181 | Logs.logWrite("[Server]" + (Player == null ? "测试" : Player) + ":" + message); 182 | } 183 | if (Minecraft_QQ.config.System.Debug) 184 | Minecraft_QQ.log.info("§d[Minecraft_QQ]§5[Debug]发送数据:" + send); 185 | } 186 | 187 | public static void socketClose() { 188 | if (client != null && isConnect) { 189 | client.close(); 190 | } 191 | } 192 | 193 | public static boolean isRun() { 194 | return isConnect; 195 | } 196 | 197 | public static void socketReset() { 198 | timeout = 0; 199 | } 200 | 201 | static class ClientHandler extends ChannelInboundHandlerAdapter { 202 | 203 | @Override 204 | public void channelRead(ChannelHandlerContext context, Object message) { 205 | ByteBuf byteBuf = (ByteBuf) message; 206 | queueRead.add(byteBuf); 207 | } 208 | 209 | @Override 210 | public void channelInactive(ChannelHandlerContext context) { 211 | isConnect = false; 212 | } 213 | 214 | @Override 215 | public void channelReadComplete(ChannelHandlerContext context) { 216 | context.flush(); 217 | } 218 | 219 | @Override 220 | public void exceptionCaught(ChannelHandlerContext context, Throwable cause) { 221 | cause.printStackTrace(); 222 | isConnect = false; 223 | context.close(); 224 | } 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /link.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | mkdir "build" 4 | mkdir ".gradle" 5 | 6 | mklink /j "server/src/main/java/com/coloryr/minecraft_qq/core" "core" 7 | 8 | mklink /j "server/build" "build" 9 | 10 | mklink /j "server/.gradle" ".gradle" -------------------------------------------------------------------------------- /remove.cmd: -------------------------------------------------------------------------------- 1 | rmdir "server/src/main/java/com/coloryr/minecraft_qq/core" 2 | 3 | rmdir "server/build" 4 | 5 | rmdir "server/.gradle" -------------------------------------------------------------------------------- /server/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /server/.gitignore: -------------------------------------------------------------------------------- 1 | # eclipse 2 | bin 3 | *.launch 4 | .settings 5 | .metadata 6 | .classpath 7 | .project 8 | 9 | # idea 10 | out 11 | *.ipr 12 | *.iws 13 | *.iml 14 | .idea 15 | 16 | # gradle 17 | build 18 | .gradle 19 | 20 | # other 21 | eclipse 22 | run 23 | classes 24 | 25 | # Files from Forge MDK 26 | forge*changelog.txt 27 | -------------------------------------------------------------------------------- /server/LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /server/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | 5 | configurations.all { 6 | resolutionStrategy.cacheChangingModulesFor 0, 'seconds' 7 | } 8 | 9 | version = "3.0.4" 10 | 11 | repositories { 12 | 13 | maven { 14 | name 'Spigot' 15 | url 'https://hub.spigotmc.org/nexus/content/groups/public' 16 | } 17 | maven { 18 | url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/' 19 | } 20 | maven { 21 | name 'velocity' 22 | url 'https://nexus.velocitypowered.com/repository/maven-public/' 23 | } 24 | } 25 | 26 | dependencies { 27 | compile 'org.spigotmc:spigot-api:1.18.1-R0.1-SNAPSHOT' 28 | compile 'net.md-5:bungeecord-api:1.18-R0.1-SNAPSHOT' 29 | compileOnly 'me.clip:placeholderapi:2.10.9' 30 | compileOnly 'com.velocitypowered:velocity-api:3.0.1' 31 | 32 | annotationProcessor 'com.velocitypowered:velocity-api:3.0.1' 33 | 34 | } 35 | 36 | tasks.withType(JavaCompile) { 37 | options.encoding = "UTF-8" 38 | } 39 | -------------------------------------------------------------------------------- /server/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coloryr/Minecraft_QQ/9392665b343a374834a01e1813268658d6e5d901/server/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /server/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /server/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save ( ) { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /server/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /server/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Minecraft_QQ' 2 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/MBC.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq; 2 | 3 | import com.coloryr.minecraft_qq.core.Minecraft_QQ; 4 | import com.coloryr.minecraft_qq.side.bc.*; 5 | import net.md_5.bungee.api.ProxyServer; 6 | import net.md_5.bungee.api.plugin.Plugin; 7 | 8 | import java.util.logging.Logger; 9 | 10 | public class MBC extends Plugin { 11 | 12 | public static Logger log; 13 | public static Plugin plugin; 14 | 15 | @Override 16 | public void onEnable() { 17 | plugin = this; 18 | log = ProxyServer.getInstance().getLogger(); 19 | 20 | Minecraft_QQ.log = new Log(log); 21 | Minecraft_QQ.side = new Side(); 22 | new Minecraft_QQ().init(plugin.getDataFolder()); 23 | 24 | ProxyServer.getInstance().getPluginManager().registerListener(this, new EventListener()); 25 | ProxyServer.getInstance().getPluginManager().registerCommand(this, new Command()); 26 | 27 | new Metrics(this, 6608); 28 | 29 | Minecraft_QQ.start(); 30 | } 31 | 32 | @Override 33 | public void onDisable() { 34 | Minecraft_QQ.stop(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/MBukkit.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq; 2 | 3 | import com.coloryr.minecraft_qq.core.Minecraft_QQ; 4 | import com.coloryr.minecraft_qq.side.bukkit.*; 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.plugin.Plugin; 7 | import org.bukkit.plugin.java.JavaPlugin; 8 | 9 | import java.util.logging.Logger; 10 | 11 | public class MBukkit extends JavaPlugin { 12 | 13 | public static Plugin plugin; 14 | public static Logger log; 15 | public static boolean PAPI = false; 16 | 17 | @Override 18 | public void onEnable() { 19 | plugin = this; 20 | log = getLogger(); 21 | Minecraft_QQ.log = new Log(log); 22 | Minecraft_QQ.side = new Side(); 23 | new Minecraft_QQ().init(getDataFolder()); 24 | 25 | if (!Minecraft_QQ.config.ServerSet.TopMode) { 26 | Bukkit.getPluginManager().registerEvents(new EventListener(), this); 27 | } 28 | 29 | Bukkit.getPluginCommand("qq").setExecutor(new Command()); 30 | Bukkit.getPluginCommand("qq").setTabCompleter(new Command()); 31 | 32 | new Metrics(this, 6608); 33 | 34 | if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { 35 | PAPI = true; 36 | log.info("§2PAPI支持已启动"); 37 | } else { 38 | log.info("§2PAPI未挂钩"); 39 | PAPI = false; 40 | } 41 | 42 | Minecraft_QQ.start(); 43 | } 44 | 45 | @Override 46 | public void onDisable() { 47 | Minecraft_QQ.stop(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/MVelocity.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq; 2 | 3 | import com.coloryr.minecraft_qq.core.Minecraft_QQ; 4 | import com.coloryr.minecraft_qq.side.velocity.*; 5 | import com.google.inject.Inject; 6 | import com.velocitypowered.api.command.CommandMeta; 7 | import com.velocitypowered.api.event.Subscribe; 8 | import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; 9 | import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; 10 | import com.velocitypowered.api.plugin.Plugin; 11 | import com.velocitypowered.api.plugin.annotation.DataDirectory; 12 | import com.velocitypowered.api.proxy.ProxyServer; 13 | import org.slf4j.Logger; 14 | 15 | import java.nio.file.Path; 16 | 17 | @Plugin(id = "minecraft_qq", name = "Minecraft_QQ", version = Minecraft_QQ.version, 18 | url = "https://github.com/Coloryr/Minecraft_QQ", description = "QQ群与服务器互联", authors = {"Color_yr"}) 19 | public class MVelocity { 20 | public static MVelocity plugin; 21 | public final ProxyServer server; 22 | public final Path dataDirectory; 23 | private final Logger logger; 24 | private final Metrics.Factory metricsFactory; 25 | 26 | @Inject 27 | public MVelocity(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory, Metrics.Factory metricsFactory) { 28 | this.server = server; 29 | this.logger = logger; 30 | this.dataDirectory = dataDirectory; 31 | this.metricsFactory = metricsFactory; 32 | } 33 | 34 | @Subscribe 35 | public void onProxyInitialization(ProxyInitializeEvent event) { 36 | plugin = this; 37 | Minecraft_QQ.log = new Log(logger); 38 | new Minecraft_QQ().init(dataDirectory.toFile()); 39 | Minecraft_QQ.side = new Side(); 40 | CommandMeta meta = server.getCommandManager().metaBuilder("qq") 41 | .aliases("minecraft_qq") 42 | .build(); 43 | server.getCommandManager().register(meta, new Command()); 44 | server.getEventManager().register(this, new EventListener()); 45 | metricsFactory.make(this, 6608); 46 | 47 | Minecraft_QQ.start(); 48 | } 49 | 50 | @Subscribe 51 | public void onStop(ProxyShutdownEvent event) { 52 | Minecraft_QQ.stop(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/bc/Command.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.bc; 2 | 3 | import com.coloryr.minecraft_qq.core.command.CommandEX; 4 | import com.coloryr.minecraft_qq.core.command.CommandTab; 5 | import net.md_5.bungee.api.CommandSender; 6 | import net.md_5.bungee.api.plugin.TabExecutor; 7 | 8 | public class Command extends net.md_5.bungee.api.plugin.Command implements TabExecutor { 9 | 10 | public Command() { 11 | super("qq"); 12 | } 13 | 14 | public void execute(CommandSender sender, String[] args) { 15 | CommandEX.ex(sender, sender.getName(), args, sender.hasPermission("Minecraft_QQ.admin")); 16 | } 17 | 18 | @Override 19 | public Iterable onTabComplete(CommandSender sender, String[] args) { 20 | return CommandTab.getList(sender.hasPermission("Minecraft_QQ.admin"), args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/bc/Commander.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.bc; 2 | 3 | import net.md_5.bungee.api.CommandSender; 4 | import net.md_5.bungee.api.chat.BaseComponent; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.Collection; 9 | import java.util.List; 10 | 11 | public class Commander implements CommandSender { 12 | public List message = new ArrayList(); 13 | public String player; 14 | 15 | @Override 16 | public String getName() { 17 | return player; 18 | } 19 | 20 | @Override 21 | public void sendMessage(String message) { 22 | this.message.add(message); 23 | } 24 | 25 | @Override 26 | public void sendMessages(String... messages) { 27 | message.addAll(Arrays.asList(messages)); 28 | } 29 | 30 | @Override 31 | public void sendMessage(BaseComponent... message) { 32 | this.message.add(Arrays.toString(message)); 33 | } 34 | 35 | @Override 36 | public void sendMessage(BaseComponent message) { 37 | this.message.add(message.toLegacyText()); 38 | } 39 | 40 | @Override 41 | public Collection getGroups() { 42 | return null; 43 | } 44 | 45 | @Override 46 | public void addGroups(String... groups) { 47 | 48 | } 49 | 50 | @Override 51 | public void removeGroups(String... groups) { 52 | 53 | } 54 | 55 | @Override 56 | public boolean hasPermission(String permission) { 57 | return true; 58 | } 59 | 60 | @Override 61 | public void setPermission(String permission, boolean value) { 62 | 63 | } 64 | 65 | @Override 66 | public Collection getPermissions() { 67 | return null; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/bc/EventListener.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.bc; 2 | 3 | import com.coloryr.minecraft_qq.core.Minecraft_QQ; 4 | import com.coloryr.minecraft_qq.core.api.Placeholder; 5 | import com.coloryr.minecraft_qq.core.utils.SocketUtils; 6 | import net.md_5.bungee.api.ChatColor; 7 | import net.md_5.bungee.api.ProxyServer; 8 | import net.md_5.bungee.api.chat.TextComponent; 9 | import net.md_5.bungee.api.connection.ProxiedPlayer; 10 | import net.md_5.bungee.api.event.ChatEvent; 11 | import net.md_5.bungee.api.event.PlayerDisconnectEvent; 12 | import net.md_5.bungee.api.event.PostLoginEvent; 13 | import net.md_5.bungee.api.event.ServerSwitchEvent; 14 | import net.md_5.bungee.api.plugin.Listener; 15 | import net.md_5.bungee.event.EventHandler; 16 | 17 | public class EventListener implements Listener { 18 | 19 | private String message(String message, String playerName) { 20 | message = message.replaceAll(Minecraft_QQ.config.Placeholder.Player, playerName); 21 | message = ChatColor.translateAlternateColorCodes('&', message); 22 | return message; 23 | } 24 | 25 | @EventHandler 26 | public void onPostLogin(PostLoginEvent event) { 27 | if (SocketUtils.isRun() && Minecraft_QQ.config.Join.Send) { 28 | String playerName = event.getPlayer().getName(); 29 | SocketUtils.sendData(Placeholder.data, Placeholder.group, 30 | playerName, message(Minecraft_QQ.config.Join.Message, playerName)); 31 | } 32 | } 33 | 34 | @EventHandler 35 | public void onPlayerquit(PlayerDisconnectEvent event) { 36 | if (SocketUtils.isRun() && Minecraft_QQ.config.Quit.Send) { 37 | String playerName = event.getPlayer().getName(); 38 | SocketUtils.sendData(Placeholder.data, Placeholder.group, 39 | playerName, message(Minecraft_QQ.config.Quit.Message, playerName)); 40 | } 41 | } 42 | 43 | @EventHandler 44 | public void onPlayerChangeServer(ServerSwitchEvent event) { 45 | if (SocketUtils.isRun() && Minecraft_QQ.config.ChangeServer.Send) { 46 | String message = Minecraft_QQ.config.ChangeServer.Message; 47 | ProxiedPlayer player = event.getPlayer(); 48 | String playerName = player.getName(); 49 | String server = Minecraft_QQ.config.Servers.get(player.getServer().getInfo().getName()); 50 | if (server == null || server.isEmpty()) { 51 | server = player.getServer().getInfo().getName(); 52 | } 53 | message = message.replaceAll(Minecraft_QQ.config.Placeholder.Player, playerName) 54 | .replaceAll(Minecraft_QQ.config.Placeholder.Server, server); 55 | message = ChatColor.translateAlternateColorCodes('&', message); 56 | SocketUtils.sendData(Placeholder.data, Placeholder.group, playerName, message); 57 | } 58 | } 59 | 60 | @EventHandler 61 | public void onChar(ChatEvent event) { 62 | String playerMessage = event.getMessage(); 63 | ProxiedPlayer player = (ProxiedPlayer) event.getSender(); 64 | if (Minecraft_QQ.config.User.NotSendCommand) { 65 | if (playerMessage.startsWith("/")) 66 | return; 67 | } else if (Minecraft_QQ.config.Mute.contains(player.getName())) 68 | return; 69 | if (Minecraft_QQ.config.ServerSet.Mode != 0 && SocketUtils.isRun()) { 70 | String message = Minecraft_QQ.config.ServerSet.Message; 71 | String playerName = player.getName(); 72 | String Server = Minecraft_QQ.config.Servers.get(player.getServer().getInfo().getName()); 73 | if (Server == null || Server.isEmpty()) { 74 | Server = player.getServer().getInfo().getName(); 75 | } 76 | message = message.replaceAll(Minecraft_QQ.config.Placeholder.Player, playerName) 77 | .replaceAll(Minecraft_QQ.config.Placeholder.ServerName, Minecraft_QQ.config.ServerSet.ServerName) 78 | .replaceAll(Minecraft_QQ.config.Placeholder.Server, Server); 79 | message = ChatColor.translateAlternateColorCodes('&', message); 80 | if (Minecraft_QQ.config.ServerSet.Mode == 1 81 | && playerMessage.indexOf(Minecraft_QQ.config.ServerSet.Check) == 0) { 82 | playerMessage = playerMessage.replaceFirst(Minecraft_QQ.config.ServerSet.Check, ""); 83 | message = message.replaceAll(Minecraft_QQ.config.Placeholder.Message, playerMessage); 84 | SocketUtils.sendData(Placeholder.data, Placeholder.group, playerName, message); 85 | } else if (Minecraft_QQ.config.ServerSet.Mode == 2) { 86 | message = message.replaceAll(Minecraft_QQ.config.Placeholder.Message, playerMessage); 87 | SocketUtils.sendData(Placeholder.data, Placeholder.group, playerName, message); 88 | } 89 | if (Minecraft_QQ.config.SendAllServer.Enable) { 90 | String SendAllServer_send = Minecraft_QQ.config.SendAllServer.Message; 91 | SendAllServer_send = SendAllServer_send 92 | .replaceAll(Minecraft_QQ.config.Placeholder.ServerName, Minecraft_QQ.config.ServerSet.ServerName) 93 | .replaceAll(Minecraft_QQ.config.Placeholder.Server, Server) 94 | .replaceAll(Minecraft_QQ.config.Placeholder.Player, playerName) 95 | .replaceAll(Minecraft_QQ.config.Placeholder.Message, playerMessage); 96 | SendAllServer_send = ChatColor.translateAlternateColorCodes('&', SendAllServer_send); 97 | if (Minecraft_QQ.config.SendAllServer.OnlySideServer) { 98 | for (ProxiedPlayer player1 : ProxyServer.getInstance().getPlayers()) { 99 | if (player.getServer() != null && player1.getServer() != null && 100 | !player1.getServer().getInfo().getName().equals(player.getServer().getInfo().getName())) 101 | player1.sendMessage(new TextComponent(SendAllServer_send)); 102 | } 103 | } else { 104 | for (ProxiedPlayer player1 : ProxyServer.getInstance().getPlayers()) { 105 | player1.sendMessage(new TextComponent(SendAllServer_send)); 106 | } 107 | event.setCancelled(true); 108 | } 109 | } 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/bc/GroupEvent.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.bc; 2 | 3 | import com.coloryr.minecraft_qq.core.api.IGroupEvent; 4 | import com.coloryr.minecraft_qq.core.json.ReadObj; 5 | import net.md_5.bungee.api.plugin.Event; 6 | 7 | public class GroupEvent extends Event implements IGroupEvent { 8 | private String group; 9 | private String message; 10 | private String player; 11 | private boolean isCommand; 12 | private String command; 13 | 14 | public GroupEvent(ReadObj obj) { 15 | this.group = obj.group; 16 | this.message = obj.message; 17 | this.player = obj.player; 18 | this.isCommand = obj.isCommand; 19 | this.command = obj.command; 20 | } 21 | 22 | @Override 23 | public String getGroup() { 24 | return group; 25 | } 26 | 27 | @Override 28 | public String getMessage() { 29 | return message; 30 | } 31 | 32 | @Override 33 | public String getPlayer() { 34 | return player; 35 | } 36 | 37 | @Override 38 | public String getCommand() { 39 | return command; 40 | } 41 | 42 | @Override 43 | public boolean isCommand() { 44 | return isCommand; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/bc/Log.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.bc; 2 | 3 | import com.coloryr.minecraft_qq.core.api.ILogger; 4 | 5 | import java.util.logging.Logger; 6 | 7 | public class Log implements ILogger { 8 | private final Logger logger; 9 | 10 | public Log(Logger Logger) { 11 | this.logger = Logger; 12 | } 13 | 14 | @Override 15 | public void warning(String data) { 16 | logger.warning(data); 17 | } 18 | 19 | @Override 20 | public void info(String data) { 21 | logger.info(data); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/bc/Metrics.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.bc; 2 | 3 | import com.coloryr.minecraft_qq.core.bstats.MetricsBase; 4 | import com.coloryr.minecraft_qq.core.bstats.charts.CustomChart; 5 | import com.coloryr.minecraft_qq.core.bstats.json.JsonObjectBuilder; 6 | import net.md_5.bungee.api.plugin.Plugin; 7 | import net.md_5.bungee.config.Configuration; 8 | import net.md_5.bungee.config.ConfigurationProvider; 9 | import net.md_5.bungee.config.YamlConfiguration; 10 | 11 | import java.io.BufferedWriter; 12 | import java.io.File; 13 | import java.io.FileWriter; 14 | import java.io.IOException; 15 | import java.util.UUID; 16 | import java.util.logging.Level; 17 | 18 | public class Metrics { 19 | private final Plugin plugin; 20 | private final MetricsBase metricsBase; 21 | 22 | private boolean enabled; 23 | private String serverUUID; 24 | private boolean logErrors = false; 25 | private boolean logSentData; 26 | private boolean logResponseStatusText; 27 | 28 | /** 29 | * Creates a new Metrics instance. 30 | * 31 | * @param plugin Your plugin instance. 32 | * @param serviceId The id of the service. 33 | * It can be found at What is my plugin id? 34 | */ 35 | public Metrics(Plugin plugin, int serviceId) { 36 | this.plugin = plugin; 37 | 38 | try { 39 | loadConfig(); 40 | } catch (IOException e) { 41 | // Failed to load configuration 42 | plugin.getLogger().log(Level.WARNING, "Failed to load bStats config!", e); 43 | metricsBase = null; 44 | return; 45 | } 46 | 47 | metricsBase = new MetricsBase( 48 | "bungeecord", 49 | serverUUID, 50 | serviceId, 51 | enabled, 52 | this::appendPlatformData, 53 | this::appendServiceData, 54 | null, 55 | () -> true, 56 | (message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error), 57 | (message) -> this.plugin.getLogger().log(Level.INFO, message), 58 | logErrors, 59 | logSentData, 60 | logResponseStatusText 61 | ); 62 | } 63 | 64 | /** 65 | * Loads the bStats configuration. 66 | */ 67 | private void loadConfig() throws IOException { 68 | File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); 69 | bStatsFolder.mkdirs(); 70 | File configFile = new File(bStatsFolder, "config.yml"); 71 | if (!configFile.exists()) { 72 | writeFile(configFile, 73 | "#bStats collects some data for plugin authors like how many servers are using their plugins.", 74 | "#To honor their work, you should not disable it.", 75 | "#This has nearly no effect on the server performance!", 76 | "#Check out https://bStats.org/ to learn more :)", 77 | "enabled: true", 78 | "serverUuid: \"" + UUID.randomUUID() + "\"", 79 | "logFailedRequests: false", 80 | "logSentData: false", 81 | "logResponseStatusText: false"); 82 | } 83 | 84 | Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile); 85 | 86 | // Load configuration 87 | enabled = configuration.getBoolean("enabled", true); 88 | serverUUID = configuration.getString("serverUuid"); 89 | logErrors = configuration.getBoolean("logFailedRequests", false); 90 | logSentData = configuration.getBoolean("logSentData", false); 91 | logResponseStatusText = configuration.getBoolean("logResponseStatusText", false); 92 | } 93 | 94 | private void writeFile(File file, String... lines) throws IOException { 95 | try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file))) { 96 | for (String line : lines) { 97 | bufferedWriter.write(line); 98 | bufferedWriter.newLine(); 99 | } 100 | } 101 | } 102 | 103 | /** 104 | * Adds a custom chart. 105 | * 106 | * @param chart The chart to add. 107 | */ 108 | public void addCustomChart(CustomChart chart) { 109 | metricsBase.addCustomChart(chart); 110 | } 111 | 112 | private void appendPlatformData(JsonObjectBuilder builder) { 113 | builder.appendField("playerAmount", plugin.getProxy().getOnlineCount()); 114 | builder.appendField("managedServers", plugin.getProxy().getServers().size()); 115 | builder.appendField("onlineMode", plugin.getProxy().getConfig().isOnlineMode() ? 1 : 0); 116 | builder.appendField("bungeecordVersion", plugin.getProxy().getVersion()); 117 | 118 | builder.appendField("javaVersion", System.getProperty("java.version")); 119 | builder.appendField("osName", System.getProperty("os.name")); 120 | builder.appendField("osArch", System.getProperty("os.arch")); 121 | builder.appendField("osVersion", System.getProperty("os.version")); 122 | builder.appendField("coreCount", Runtime.getRuntime().availableProcessors()); 123 | } 124 | 125 | private void appendServiceData(JsonObjectBuilder builder) { 126 | builder.appendField("pluginVersion", plugin.getDescription().getVersion()); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/bc/Side.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.bc; 2 | 3 | import com.coloryr.minecraft_qq.MBC; 4 | import com.coloryr.minecraft_qq.core.Minecraft_QQ; 5 | import com.coloryr.minecraft_qq.core.api.ISide; 6 | import com.coloryr.minecraft_qq.core.api.Placeholder; 7 | import com.coloryr.minecraft_qq.core.json.ReadObj; 8 | import com.coloryr.minecraft_qq.core.ASide; 9 | import com.coloryr.minecraft_qq.core.utils.Logs; 10 | import com.coloryr.minecraft_qq.core.utils.SocketUtils; 11 | import net.md_5.bungee.api.ChatColor; 12 | import net.md_5.bungee.api.CommandSender; 13 | import net.md_5.bungee.api.ProxyServer; 14 | import net.md_5.bungee.api.chat.TextComponent; 15 | import net.md_5.bungee.api.config.ServerInfo; 16 | import net.md_5.bungee.api.connection.ProxiedPlayer; 17 | 18 | import java.util.Collection; 19 | 20 | public class Side implements ISide { 21 | 22 | @Override 23 | public void send(Object sender, String message) { 24 | CommandSender temp = (CommandSender) sender; 25 | temp.sendMessage(new TextComponent(message)); 26 | } 27 | 28 | @Override 29 | public void message(ReadObj readobj) { 30 | try { 31 | if (Minecraft_QQ.config.System.Debug) 32 | Minecraft_QQ.log.info("处理数据:" + readobj.message); 33 | ProxyServer proxyserver = ProxyServer.getInstance(); 34 | try { 35 | MBC.plugin.getProxy().getScheduler().runAsync(MBC.plugin, () -> { 36 | GroupEvent eventBC = new GroupEvent(readobj); 37 | MBC.plugin.getProxy().getPluginManager().callEvent(eventBC); 38 | }); 39 | } catch (Exception e) { 40 | Minecraft_QQ.log.info("数据传输发生错误:"); 41 | e.printStackTrace(); 42 | return; 43 | } 44 | if (!readobj.isCommand) { 45 | if (readobj.command.equalsIgnoreCase(Placeholder.speak)) { 46 | String say = Minecraft_QQ.config.ServerSet.Say 47 | .replaceFirst(Minecraft_QQ.config.Placeholder.ServerName, Minecraft_QQ.config.ServerSet.ServerName) 48 | .replaceFirst(Minecraft_QQ.config.Placeholder.Message, readobj.message) 49 | .replaceFirst(Minecraft_QQ.config.Placeholder.Player, readobj.player); 50 | say = ChatColor.translateAlternateColorCodes('&', say); 51 | if (Minecraft_QQ.config.Logs.Group) { 52 | Logs.logWrite("[Group]" + say); 53 | } 54 | for (ProxiedPlayer player1 : ProxyServer.getInstance().getPlayers()) { 55 | if (!Minecraft_QQ.config.Mute.contains(player1.getName())) 56 | player1.sendMessage(new TextComponent(say)); 57 | } 58 | } else if (readobj.command.equalsIgnoreCase(Placeholder.online)) { 59 | int allPlayerNumber = 0; 60 | StringBuilder allServerPlayer = new StringBuilder(); 61 | String send = Minecraft_QQ.config.ServerSet.PlayerListMessage; 62 | if (Minecraft_QQ.config.ServerSet.SendOneByOne) { 63 | for (final ServerInfo serverinfo : proxyserver.getServers().values()) { 64 | String oneServerPlayer; 65 | int oneServerNumber; 66 | final Collection oneServerPlayers = serverinfo.getPlayers(); 67 | if (oneServerPlayers.size() == 0) { 68 | if (!Minecraft_QQ.config.ServerSet.HideEmptyServer) { 69 | String serverName = Minecraft_QQ.config.Servers.get(serverinfo.getName()); 70 | if (serverName == null || serverName.isEmpty()) { 71 | serverName = serverinfo.getName(); 72 | } 73 | oneServerPlayer = Minecraft_QQ.config.ServerSet.SendOneByOneMessage 74 | .replaceAll(Minecraft_QQ.config.Placeholder.Server, serverName) 75 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerNumber, "0") 76 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerList, "无"); 77 | allServerPlayer.append(oneServerPlayer); 78 | } 79 | } else { 80 | oneServerNumber = oneServerPlayers.size(); 81 | String serverName = Minecraft_QQ.config.Servers.get(serverinfo.getName()); 82 | if (serverName == null || serverName.isEmpty()) { 83 | serverName = serverinfo.getName(); 84 | } 85 | StringBuilder players = new StringBuilder(); 86 | for (ProxiedPlayer player : oneServerPlayers) { 87 | players.append(player.getName()).append(","); 88 | } 89 | String players1 = players.toString(); 90 | oneServerPlayer = Minecraft_QQ.config.ServerSet.SendOneByOneMessage 91 | .replaceAll(Minecraft_QQ.config.Placeholder.Server, serverName) 92 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerNumber, "" + oneServerNumber) 93 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerList, players1.substring(0, players1.length() - 1)); 94 | allPlayerNumber += oneServerNumber; 95 | allServerPlayer.append(oneServerPlayer); 96 | } 97 | } 98 | if (allPlayerNumber == 0) { 99 | send = send.replaceAll(Minecraft_QQ.config.Placeholder.PlayerNumber, "0") 100 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerList, "无"); 101 | } else { 102 | send = send.replaceAll(Minecraft_QQ.config.Placeholder.PlayerNumber, "" + allPlayerNumber) 103 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerList, allServerPlayer.toString()); 104 | } 105 | } else { 106 | final Collection players = proxyserver.getPlayers(); 107 | if (players.size() == 0) { 108 | send = send.replaceAll(Minecraft_QQ.config.Placeholder.PlayerNumber, "0") 109 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerList, "无"); 110 | } else { 111 | StringBuilder temp = new StringBuilder(); 112 | for (ProxiedPlayer player : players) { 113 | temp.append(player.getName()).append(","); 114 | } 115 | String players1 = temp.toString(); 116 | send = send.replaceAll(Minecraft_QQ.config.Placeholder.PlayerNumber, "" + players.size()) 117 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerList, players1.substring(0, players1.length() - 1)); 118 | } 119 | } 120 | send = send.replace(Minecraft_QQ.config.Placeholder.ServerName, Minecraft_QQ.config.ServerSet.ServerName); 121 | SocketUtils.sendData(Placeholder.data, readobj.group, "无", send); 122 | if (Minecraft_QQ.config.Logs.Group) { 123 | Logs.logWrite("[group]查询在线人数"); 124 | } 125 | } else { 126 | ASide.globeCheck(readobj); 127 | } 128 | } else { 129 | StringBuilder send_message; 130 | Commander send = new Commander(); 131 | send.player = readobj.player; 132 | if (Minecraft_QQ.config.Logs.Group) { 133 | Logs.logWrite("[Group]" + readobj.player + "执行命令" + readobj.command); 134 | } 135 | try { 136 | proxyserver.getPluginManager().dispatchCommand(send, readobj.command); 137 | Thread.sleep(Minecraft_QQ.config.ServerSet.CommandDelay); 138 | } catch (Exception e) { 139 | Minecraft_QQ.log.warning(e.toString()); 140 | } 141 | if (send.message.size() == 1) { 142 | send_message = new StringBuilder(send.message.get(0)); 143 | } else if (send.message.size() > 1) { 144 | send_message = new StringBuilder(send.message.get(0)); 145 | for (int i = 1; i < send.message.size(); i++) { 146 | send_message.append("\n"); 147 | send_message.append(send.message.get(i)); 148 | } 149 | } else 150 | send_message = new StringBuilder("已执行,指令无返回"); 151 | SocketUtils.sendData(Placeholder.data, readobj.group, 152 | "控制台", send_message.toString()); 153 | } 154 | } catch (Exception e) { 155 | Minecraft_QQ.log.warning("§d[Minecraft_QQ]§c发送错误:"); 156 | e.printStackTrace(); 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/bukkit/Command.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.bukkit; 2 | 3 | import com.coloryr.minecraft_qq.core.command.CommandEX; 4 | import com.coloryr.minecraft_qq.core.command.CommandTab; 5 | import org.bukkit.command.CommandExecutor; 6 | import org.bukkit.command.CommandSender; 7 | import org.bukkit.command.TabExecutor; 8 | 9 | import java.util.List; 10 | 11 | public class Command implements CommandExecutor, TabExecutor { 12 | 13 | @Override 14 | public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { 15 | if (command.getName().equalsIgnoreCase("qq")) { 16 | CommandEX.ex(sender, sender.getName(), args, sender.isOp()); 17 | } 18 | return true; 19 | } 20 | 21 | @Override 22 | public List onTabComplete(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) { 23 | if (command.getName().equalsIgnoreCase("qq")) { 24 | return CommandTab.getList(sender.isOp(), args); 25 | } 26 | return null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/bukkit/Commander.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.bukkit; 2 | 3 | import net.md_5.bungee.api.chat.BaseComponent; 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.Server; 6 | import org.bukkit.command.CommandSender; 7 | import org.bukkit.permissions.Permission; 8 | import org.bukkit.permissions.PermissionAttachment; 9 | import org.bukkit.permissions.PermissionAttachmentInfo; 10 | import org.bukkit.plugin.Plugin; 11 | import org.jetbrains.annotations.NotNull; 12 | import org.jetbrains.annotations.Nullable; 13 | 14 | import java.util.*; 15 | 16 | public class Commander implements CommandSender { 17 | public List message = new ArrayList<>(); 18 | public String player; 19 | 20 | @Override 21 | public void sendMessage(String message) { 22 | this.message.add(message); 23 | } 24 | 25 | @Override 26 | public void sendMessage(String[] messages) { 27 | message.addAll(Arrays.asList(messages)); 28 | } 29 | 30 | @Override 31 | public void sendMessage(@Nullable UUID sender, @NotNull String message) { 32 | this.message.add(message); 33 | } 34 | 35 | @Override 36 | public void sendMessage(@Nullable UUID sender, @NotNull String... messages) { 37 | message.addAll(Arrays.asList(messages)); 38 | } 39 | 40 | @Override 41 | public Server getServer() { 42 | return Bukkit.getServer(); 43 | } 44 | 45 | @Override 46 | public String getName() { 47 | return player; 48 | } 49 | 50 | @Override 51 | public Spigot spigot() { 52 | return new Spigot() { 53 | @Override 54 | public void sendMessage(BaseComponent component) { 55 | message.add(component.toLegacyText()); 56 | } 57 | 58 | @Override 59 | public void sendMessage(BaseComponent... components) { 60 | for (BaseComponent temp : components) 61 | message.add(temp.toLegacyText()); 62 | } 63 | }; 64 | } 65 | 66 | @Override 67 | public boolean isPermissionSet(String name) { 68 | return true; 69 | } 70 | 71 | @Override 72 | public boolean isPermissionSet(Permission perm) { 73 | return true; 74 | } 75 | 76 | @Override 77 | public boolean hasPermission(String name) { 78 | return true; 79 | } 80 | 81 | @Override 82 | public boolean hasPermission(Permission perm) { 83 | return true; 84 | } 85 | 86 | @Override 87 | public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) { 88 | return Bukkit.getConsoleSender().addAttachment(plugin, name, value); 89 | } 90 | 91 | @Override 92 | public PermissionAttachment addAttachment(Plugin plugin) { 93 | return Bukkit.getConsoleSender().addAttachment(plugin); 94 | } 95 | 96 | @Override 97 | public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) { 98 | return Bukkit.getConsoleSender().addAttachment(plugin, name, value, ticks); 99 | } 100 | 101 | @Override 102 | public PermissionAttachment addAttachment(Plugin plugin, int ticks) { 103 | return Bukkit.getConsoleSender().addAttachment(plugin, ticks); 104 | } 105 | 106 | @Override 107 | public void removeAttachment(PermissionAttachment attachment) { 108 | 109 | } 110 | 111 | @Override 112 | public void recalculatePermissions() { 113 | 114 | } 115 | 116 | @Override 117 | public Set getEffectivePermissions() { 118 | return Bukkit.getConsoleSender().getEffectivePermissions(); 119 | } 120 | 121 | @Override 122 | public boolean isOp() { 123 | return true; 124 | } 125 | 126 | @Override 127 | public void setOp(boolean value) { 128 | 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/bukkit/EventListener.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.bukkit; 2 | 3 | import com.coloryr.minecraft_qq.MBukkit; 4 | import com.coloryr.minecraft_qq.core.Minecraft_QQ; 5 | import com.coloryr.minecraft_qq.core.api.Placeholder; 6 | import com.coloryr.minecraft_qq.core.utils.SocketUtils; 7 | import me.clip.placeholderapi.PlaceholderAPI; 8 | import org.bukkit.ChatColor; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.event.EventHandler; 11 | import org.bukkit.event.Listener; 12 | import org.bukkit.event.player.AsyncPlayerChatEvent; 13 | import org.bukkit.event.player.PlayerJoinEvent; 14 | import org.bukkit.event.player.PlayerQuitEvent; 15 | 16 | public class EventListener implements Listener { 17 | 18 | private String message(String message, Player player) { 19 | if (MBukkit.PAPI) { 20 | message = PlaceholderAPI.setPlaceholders(player, message); 21 | } 22 | message = message.replaceAll(Minecraft_QQ.config.Placeholder.Player, player.getName()); 23 | message = ChatColor.translateAlternateColorCodes('&', message); 24 | return message; 25 | } 26 | 27 | @EventHandler 28 | public void onPlayerJoin(PlayerJoinEvent event) { 29 | if (SocketUtils.isRun() && Minecraft_QQ.config.Join.Send) { 30 | String playerName = event.getPlayer().getName(); 31 | SocketUtils.sendData(Placeholder.data, Placeholder.group, 32 | playerName, message(Minecraft_QQ.config.Join.Message, event.getPlayer())); 33 | } 34 | } 35 | 36 | @EventHandler 37 | public void onPlayerLeave(PlayerQuitEvent event) { 38 | if (SocketUtils.isRun() && Minecraft_QQ.config.Quit.Send) { 39 | String playerName = event.getPlayer().getName(); 40 | SocketUtils.sendData(Placeholder.data, Placeholder.group, 41 | playerName, message(Minecraft_QQ.config.Quit.Message, event.getPlayer())); 42 | } 43 | } 44 | 45 | @EventHandler 46 | public void onPlayerSay(AsyncPlayerChatEvent event) { 47 | String playerMessage = event.getMessage(); 48 | if (Minecraft_QQ.config.User.NotSendCommand) { 49 | if (playerMessage.startsWith("/")) 50 | return; 51 | } else if (Minecraft_QQ.config.Mute.contains(event.getPlayer().getName())) 52 | return; 53 | if (Minecraft_QQ.config.ServerSet.Mode != 0 && SocketUtils.isRun()) { 54 | Player player = event.getPlayer(); 55 | String message = Minecraft_QQ.config.ServerSet.Message; 56 | String playerName = player.getName(); 57 | message = message.replaceAll(Minecraft_QQ.config.Placeholder.Player, playerName) 58 | .replaceAll(Minecraft_QQ.config.Placeholder.ServerName, Minecraft_QQ.config.ServerSet.ServerName) 59 | .replaceAll(Minecraft_QQ.config.Placeholder.Server, ""); 60 | message = ChatColor.translateAlternateColorCodes('&', message); 61 | if (Minecraft_QQ.config.ServerSet.Mode == 1 && 62 | playerMessage.indexOf(Minecraft_QQ.config.ServerSet.Check) == 0) { 63 | playerMessage = playerMessage.replaceFirst(Minecraft_QQ.config.ServerSet.Check, ""); 64 | message = message.replaceAll(Minecraft_QQ.config.Placeholder.Message, playerMessage); 65 | SocketUtils.sendData(Placeholder.data, Placeholder.group, playerName, message); 66 | } else if (Minecraft_QQ.config.ServerSet.Mode == 2) { 67 | message = message.replaceAll(Minecraft_QQ.config.Placeholder.Message, playerMessage); 68 | if (MBukkit.PAPI) { 69 | message = PlaceholderAPI.setPlaceholders(player, message); 70 | } 71 | SocketUtils.sendData(Placeholder.data, Placeholder.group, playerName, message); 72 | } 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/bukkit/GroupEvent.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.bukkit; 2 | 3 | import com.coloryr.minecraft_qq.core.api.IGroupEvent; 4 | import com.coloryr.minecraft_qq.core.json.ReadObj; 5 | import org.bukkit.event.Event; 6 | import org.bukkit.event.HandlerList; 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | public class GroupEvent extends Event implements IGroupEvent { 10 | private static final HandlerList handlers = new HandlerList(); 11 | private String group; 12 | private String message; 13 | private String player; 14 | private boolean isCommand; 15 | private String command; 16 | 17 | public GroupEvent(ReadObj obj) { 18 | this.group = obj.group; 19 | this.message = obj.message; 20 | this.player = obj.player; 21 | this.isCommand = obj.isCommand; 22 | this.command = obj.command; 23 | } 24 | 25 | @Override 26 | public String getGroup() { 27 | return group; 28 | } 29 | 30 | @Override 31 | public String getMessage() { 32 | return message; 33 | } 34 | 35 | @Override 36 | public String getPlayer() { 37 | return player; 38 | } 39 | 40 | @Override 41 | public String getCommand() { 42 | return command; 43 | } 44 | 45 | @Override 46 | public boolean isCommand() { 47 | return isCommand; 48 | } 49 | 50 | @NotNull 51 | @Override 52 | public HandlerList getHandlers() { 53 | return handlers; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/bukkit/Log.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.bukkit; 2 | 3 | import com.coloryr.minecraft_qq.core.api.ILogger; 4 | 5 | import java.util.logging.Logger; 6 | 7 | public class Log implements ILogger { 8 | private final Logger logger; 9 | 10 | public Log(Logger Logger) { 11 | this.logger = Logger; 12 | } 13 | 14 | @Override 15 | public void warning(String data) { 16 | logger.warning(data); 17 | } 18 | 19 | @Override 20 | public void info(String data) { 21 | logger.info(data); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/bukkit/Metrics.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.bukkit; 2 | 3 | import com.coloryr.minecraft_qq.core.bstats.MetricsBase; 4 | import com.coloryr.minecraft_qq.core.bstats.charts.CustomChart; 5 | import com.coloryr.minecraft_qq.core.bstats.json.JsonObjectBuilder; 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.configuration.file.YamlConfiguration; 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.plugin.Plugin; 10 | import org.bukkit.plugin.java.JavaPlugin; 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.lang.reflect.Method; 15 | import java.util.Collection; 16 | import java.util.UUID; 17 | import java.util.logging.Level; 18 | 19 | public class Metrics { 20 | private final Plugin plugin; 21 | private final MetricsBase metricsBase; 22 | 23 | /** 24 | * Creates a new Metrics instance. 25 | * 26 | * @param plugin Your plugin instance. 27 | * @param serviceId The id of the service. 28 | * It can be found at What is my plugin id? 29 | */ 30 | public Metrics(JavaPlugin plugin, int serviceId) { 31 | this.plugin = plugin; 32 | 33 | // Get the config file 34 | File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); 35 | File configFile = new File(bStatsFolder, "config.yml"); 36 | YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); 37 | 38 | if (!config.isSet("serverUuid")) { 39 | config.addDefault("enabled", true); 40 | config.addDefault("serverUuid", UUID.randomUUID().toString()); 41 | config.addDefault("logFailedRequests", false); 42 | config.addDefault("logSentData", false); 43 | config.addDefault("logResponseStatusText", false); 44 | 45 | // Inform the server owners about bStats 46 | config.options().header( 47 | "bStats collects some data for plugin authors like how many servers are using their plugins.\n" + 48 | "To honor their work, you should not disable it.\n" + 49 | "This has nearly no effect on the server performance!\n" + 50 | "Check out https://bStats.org/ to learn more :)" 51 | ).copyDefaults(true); 52 | try { 53 | config.save(configFile); 54 | } catch (IOException ignored) { 55 | } 56 | } 57 | 58 | // Load the data 59 | boolean enabled = config.getBoolean("enabled", true); 60 | String serverUUID = config.getString("serverUuid"); 61 | boolean logErrors = config.getBoolean("logFailedRequests", false); 62 | boolean logSentData = config.getBoolean("logSentData", false); 63 | boolean logResponseStatusText = config.getBoolean("logResponseStatusText", false); 64 | 65 | metricsBase = new MetricsBase( 66 | "bukkit", 67 | serverUUID, 68 | serviceId, 69 | enabled, 70 | this::appendPlatformData, 71 | this::appendServiceData, 72 | submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask), 73 | plugin::isEnabled, 74 | (message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error), 75 | (message) -> this.plugin.getLogger().log(Level.INFO, message), 76 | logErrors, 77 | logSentData, 78 | logResponseStatusText 79 | ); 80 | } 81 | 82 | /** 83 | * Adds a custom chart. 84 | * 85 | * @param chart The chart to add. 86 | */ 87 | public void addCustomChart(CustomChart chart) { 88 | metricsBase.addCustomChart(chart); 89 | } 90 | 91 | private void appendPlatformData(JsonObjectBuilder builder) { 92 | builder.appendField("playerAmount", getPlayerAmount()); 93 | builder.appendField("onlineMode", Bukkit.getOnlineMode() ? 1 : 0); 94 | builder.appendField("bukkitVersion", Bukkit.getVersion()); 95 | builder.appendField("bukkitName", Bukkit.getName()); 96 | 97 | builder.appendField("javaVersion", System.getProperty("java.version")); 98 | builder.appendField("osName", System.getProperty("os.name")); 99 | builder.appendField("osArch", System.getProperty("os.arch")); 100 | builder.appendField("osVersion", System.getProperty("os.version")); 101 | builder.appendField("coreCount", Runtime.getRuntime().availableProcessors()); 102 | } 103 | 104 | private void appendServiceData(JsonObjectBuilder builder) { 105 | builder.appendField("pluginVersion", plugin.getDescription().getVersion()); 106 | } 107 | 108 | private int getPlayerAmount() { 109 | try { 110 | // Around MC 1.8 the return type was changed from an array to a collection, 111 | // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; 112 | Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); 113 | return onlinePlayersMethod.getReturnType().equals(Collection.class) 114 | ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())).size() 115 | : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; 116 | } catch (Exception e) { 117 | return Bukkit.getOnlinePlayers().size(); // Just use the new method if the reflection failed 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/bukkit/Side.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.bukkit; 2 | 3 | import com.coloryr.minecraft_qq.MBukkit; 4 | import com.coloryr.minecraft_qq.core.Minecraft_QQ; 5 | import com.coloryr.minecraft_qq.core.api.ISide; 6 | import com.coloryr.minecraft_qq.core.api.Placeholder; 7 | import com.coloryr.minecraft_qq.core.json.ReadObj; 8 | import com.coloryr.minecraft_qq.core.ASide; 9 | import com.coloryr.minecraft_qq.core.utils.Logs; 10 | import com.coloryr.minecraft_qq.core.utils.SocketUtils; 11 | import me.clip.placeholderapi.PlaceholderAPI; 12 | import org.bukkit.Bukkit; 13 | import org.bukkit.ChatColor; 14 | import org.bukkit.OfflinePlayer; 15 | import org.bukkit.command.CommandSender; 16 | import org.bukkit.entity.Player; 17 | 18 | import java.util.Collection; 19 | 20 | public class Side implements ISide { 21 | @Override 22 | public void send(Object sender, String message) { 23 | CommandSender temp = (CommandSender) sender; 24 | temp.sendMessage(message); 25 | } 26 | 27 | @Override 28 | public void message(ReadObj readobj) { 29 | try { 30 | if (Minecraft_QQ.config.System.Debug) 31 | Minecraft_QQ.log.info("处理数据:" + readobj.message); 32 | try { 33 | Bukkit.getScheduler().runTask(MBukkit.plugin, () -> { 34 | GroupEvent eventBukkit = new GroupEvent(readobj); 35 | Bukkit.getPluginManager().callEvent(eventBukkit); 36 | }); 37 | } catch (Exception e) { 38 | Minecraft_QQ.log.warning("§d[Minecraft_QQ]§c发生错误:"); 39 | e.printStackTrace(); 40 | return; 41 | } 42 | if (!readobj.isCommand && !Minecraft_QQ.config.ServerSet.TopMode) { 43 | if (readobj.command.equalsIgnoreCase(Placeholder.speak)) { 44 | String say = Minecraft_QQ.config.ServerSet.Say 45 | .replaceFirst(Minecraft_QQ.config.Placeholder.ServerName, Minecraft_QQ.config.ServerSet.ServerName) 46 | .replaceFirst(Minecraft_QQ.config.Placeholder.Message, readobj.message) 47 | .replaceFirst(Minecraft_QQ.config.Placeholder.Player, readobj.player); 48 | say = ChatColor.translateAlternateColorCodes('&', say); 49 | if (MBukkit.PAPI && readobj.player != null) { 50 | OfflinePlayer player = Bukkit.getPlayer(readobj.player); 51 | if (player != null) 52 | say = PlaceholderAPI.setBracketPlaceholders(player, say); 53 | } 54 | final String finalSay = say; 55 | if (Minecraft_QQ.config.Logs.Group) { 56 | Logs.logWrite("[Group]" + say); 57 | } 58 | Bukkit.getScheduler().runTask(MBukkit.plugin, () -> { 59 | try { 60 | for (Player b : Bukkit.getOnlinePlayers()) { 61 | if (!Minecraft_QQ.config.Mute.contains(b.getName())) 62 | b.sendMessage(finalSay); 63 | } 64 | } catch (Exception e) { 65 | Minecraft_QQ.log.warning("§d[Minecraft_QQ]§c发生错误:"); 66 | e.printStackTrace(); 67 | } 68 | }); 69 | } else if (readobj.command.equalsIgnoreCase(Placeholder.online)) { 70 | String send = Minecraft_QQ.config.ServerSet.PlayerListMessage; 71 | Collection players = Bukkit.getOnlinePlayers(); 72 | if (players.size() == 0) { 73 | try { 74 | send = send.replaceAll(Minecraft_QQ.config.Placeholder.ServerName, Minecraft_QQ.config.ServerSet.ServerName) 75 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerNumber, "0") 76 | .replaceAll(Minecraft_QQ.config.Placeholder.Server, "") 77 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerList, "无"); 78 | } catch (Exception e) { 79 | Minecraft_QQ.log.warning("§d[Minecraft_QQ]§c发生错误:"); 80 | e.printStackTrace(); 81 | } 82 | } else { 83 | StringBuilder temp = new StringBuilder(); 84 | for (Player player1 : players) { 85 | temp.append(player1.getName()).append(","); 86 | } 87 | String player = temp.toString(); 88 | 89 | send = send.replaceAll(Minecraft_QQ.config.Placeholder.ServerName, Minecraft_QQ.config.ServerSet.ServerName) 90 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerNumber, "" + players.size()) 91 | .replaceAll(Minecraft_QQ.config.Placeholder.Server, "") 92 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerList, player.substring(0, player.length() - 1)); 93 | } 94 | if (MBukkit.PAPI && readobj.player != null) { 95 | OfflinePlayer player = Bukkit.getPlayer(readobj.player); 96 | if (player != null) 97 | send = PlaceholderAPI.setBracketPlaceholders(player, send); 98 | } 99 | if (Minecraft_QQ.config.Logs.Group) 100 | Logs.logWrite("[group]查询在线人数"); 101 | if (Minecraft_QQ.config.System.Debug) 102 | Minecraft_QQ.log.info("§d[Minecraft_QQ]§5[Debug]查询在线人数"); 103 | SocketUtils.sendData(Placeholder.data, readobj.group, "无", send); 104 | } else { 105 | ASide.globeCheck(readobj); 106 | } 107 | } else if (readobj.isCommand) { 108 | StringBuilder send_message; 109 | Commander send = new Commander(); 110 | send.player = readobj.player; 111 | if (Minecraft_QQ.config.Logs.Group) { 112 | Logs.logWrite("[Group]" + readobj.player + "执行命令" + readobj.command); 113 | } 114 | try { 115 | Bukkit.getScheduler().callSyncMethod(MBukkit.plugin, () -> 116 | Bukkit.dispatchCommand(send, readobj.command)).get(); 117 | Thread.sleep(Minecraft_QQ.config.ServerSet.CommandDelay); 118 | } catch (Exception e) { 119 | Minecraft_QQ.log.warning("§d[Minecraft_QQ]§c指令执行出现错误"); 120 | e.printStackTrace(); 121 | } 122 | if (send.message.size() == 1) { 123 | send_message = new StringBuilder(send.message.get(0)); 124 | } else if (send.message.size() > 1) { 125 | send_message = new StringBuilder(send.message.get(0)); 126 | for (int i = 1; i < send.message.size(); i++) { 127 | send_message.append("\n"); 128 | send_message.append(send.message.get(i)); 129 | } 130 | } else 131 | send_message = new StringBuilder("已执行,指令无返回"); 132 | SocketUtils.sendData(Placeholder.data, readobj.group, "控制台", send_message.toString()); 133 | } 134 | } catch (Exception e) { 135 | Minecraft_QQ.log.warning("§d[Minecraft_QQ]§c发生错误:"); 136 | e.printStackTrace(); 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/velocity/Command.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.velocity; 2 | 3 | import com.coloryr.minecraft_qq.MVelocity; 4 | import com.coloryr.minecraft_qq.core.command.CommandEX; 5 | import com.velocitypowered.api.command.CommandSource; 6 | import com.velocitypowered.api.command.SimpleCommand; 7 | import com.velocitypowered.api.proxy.Player; 8 | 9 | import java.util.concurrent.ExecutionException; 10 | 11 | public class Command implements SimpleCommand { 12 | @Override 13 | public void execute(final Invocation invocation) { 14 | CommandSource source = invocation.source(); 15 | String[] args = invocation.arguments(); 16 | String name = "CONSOLE"; 17 | if (invocation.source() instanceof Player) { 18 | Player player = (Player) invocation.source(); 19 | name = player.getUsername(); 20 | } 21 | if (args[0].equalsIgnoreCase("test")) { 22 | Commander send = new Commander("test"); 23 | try { 24 | MVelocity.plugin.server.getCommandManager().executeAsync(send, "music help").get(); 25 | } catch (InterruptedException e) { 26 | e.printStackTrace(); 27 | } catch (ExecutionException e) { 28 | e.printStackTrace(); 29 | } 30 | return; 31 | } 32 | CommandEX.ex(source, name, args, invocation.source().hasPermission("Minecraft_QQ.admin")); 33 | } 34 | 35 | @Override 36 | public boolean hasPermission(final Invocation invocation) { 37 | return true; 38 | } 39 | } -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/velocity/Commander.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.velocity; 2 | 3 | import com.coloryr.minecraft_qq.MVelocity; 4 | import com.velocitypowered.api.network.ProtocolVersion; 5 | import com.velocitypowered.api.permission.Tristate; 6 | import com.velocitypowered.api.proxy.ConnectionRequestBuilder; 7 | import com.velocitypowered.api.proxy.Player; 8 | import com.velocitypowered.api.proxy.ServerConnection; 9 | import com.velocitypowered.api.proxy.messages.ChannelIdentifier; 10 | import com.velocitypowered.api.proxy.player.PlayerSettings; 11 | import com.velocitypowered.api.proxy.player.ResourcePackInfo; 12 | import com.velocitypowered.api.proxy.player.TabList; 13 | import com.velocitypowered.api.proxy.server.RegisteredServer; 14 | import com.velocitypowered.api.util.GameProfile; 15 | import com.velocitypowered.api.util.ModInfo; 16 | import net.kyori.adventure.audience.MessageType; 17 | import net.kyori.adventure.identity.Identity; 18 | import net.kyori.adventure.text.Component; 19 | import net.kyori.adventure.text.TextComponent; 20 | import org.checkerframework.checker.nullness.qual.NonNull; 21 | import org.checkerframework.checker.nullness.qual.Nullable; 22 | import org.jetbrains.annotations.NotNull; 23 | 24 | import java.net.InetSocketAddress; 25 | import java.util.*; 26 | 27 | public class Commander implements Player { 28 | public List message = new ArrayList(); 29 | public String player; 30 | public Player play; 31 | private final boolean havePlayer; 32 | 33 | public Commander(String player) { 34 | this.player = player; 35 | havePlayer = MVelocity.plugin.server.getPlayer(player).isPresent(); 36 | if (havePlayer) { 37 | play = MVelocity.plugin.server.getPlayer(player).get(); 38 | } 39 | } 40 | 41 | @Override 42 | public String getUsername() { 43 | return player; 44 | } 45 | 46 | @Override 47 | public @Nullable Locale getEffectiveLocale() { 48 | if (havePlayer) { 49 | return play.getEffectiveLocale(); 50 | } 51 | return null; 52 | } 53 | 54 | @Override 55 | public void setEffectiveLocale(Locale locale) { 56 | if (havePlayer) { 57 | play.setEffectiveLocale(locale); 58 | } 59 | } 60 | 61 | @Override 62 | public UUID getUniqueId() { 63 | if (havePlayer) { 64 | return play.getUniqueId(); 65 | } 66 | return null; 67 | } 68 | 69 | @Override 70 | public Optional getCurrentServer() { 71 | if (havePlayer) 72 | return play.getCurrentServer(); 73 | return Optional.empty(); 74 | } 75 | 76 | @Override 77 | public PlayerSettings getPlayerSettings() { 78 | if (havePlayer) 79 | return play.getPlayerSettings(); 80 | return null; 81 | } 82 | 83 | @Override 84 | public Optional getModInfo() { 85 | if (havePlayer) 86 | return play.getModInfo(); 87 | return Optional.empty(); 88 | } 89 | 90 | @Override 91 | public long getPing() { 92 | if (havePlayer) 93 | return play.getPing(); 94 | return 0; 95 | } 96 | 97 | @Override 98 | public boolean isOnlineMode() { 99 | if (havePlayer) 100 | return play.isOnlineMode(); 101 | return false; 102 | } 103 | 104 | @Override 105 | public void sendMessage(@NonNull Identity identity, net.kyori.adventure.text.@NotNull Component message1, @NonNull MessageType type) { 106 | net.kyori.adventure.text.TextComponent obj = (net.kyori.adventure.text.TextComponent) message1; 107 | message.add(obj.content()); 108 | } 109 | 110 | @Override 111 | public void sendMessage(@NotNull Component component) { 112 | if (component instanceof TextComponent) { 113 | TextComponent obj = (TextComponent) component; 114 | message.add(obj.content()); 115 | } 116 | } 117 | 118 | @Override 119 | public ConnectionRequestBuilder createConnectionRequest(RegisteredServer server) { 120 | if (havePlayer) 121 | return play.createConnectionRequest(server); 122 | return null; 123 | } 124 | 125 | @Override 126 | public List getGameProfileProperties() { 127 | if (havePlayer) 128 | return play.getGameProfileProperties(); 129 | return null; 130 | } 131 | 132 | @Override 133 | public void setGameProfileProperties(List properties) { 134 | if (havePlayer) 135 | play.setGameProfileProperties(properties); 136 | } 137 | 138 | @Override 139 | public GameProfile getGameProfile() { 140 | if (havePlayer) 141 | return play.getGameProfile(); 142 | return null; 143 | } 144 | 145 | @Override 146 | public void clearHeaderAndFooter() { 147 | if (havePlayer) 148 | play.clearHeaderAndFooter(); 149 | } 150 | 151 | @Override 152 | public net.kyori.adventure.text.Component getPlayerListHeader() { 153 | if (havePlayer) 154 | play.getPlayerListHeader(); 155 | return null; 156 | } 157 | 158 | @Override 159 | public net.kyori.adventure.text.Component getPlayerListFooter() { 160 | if (havePlayer) 161 | play.getPlayerListFooter(); 162 | return null; 163 | } 164 | 165 | @Override 166 | public TabList getTabList() { 167 | if (havePlayer) 168 | play.getTabList(); 169 | return null; 170 | } 171 | 172 | 173 | @Override 174 | public void disconnect(net.kyori.adventure.text.Component reason) { 175 | if (havePlayer) 176 | play.disconnect(reason); 177 | } 178 | 179 | @Override 180 | public void spoofChatInput(String input) { 181 | if (havePlayer) 182 | play.spoofChatInput(input); 183 | } 184 | 185 | @Override 186 | public void sendResourcePack(String url) { 187 | if (havePlayer) 188 | play.sendResourcePack(url); 189 | } 190 | 191 | @Override 192 | public void sendResourcePack(String url, byte[] hash) { 193 | if (havePlayer) 194 | play.sendResourcePack(url, hash); 195 | } 196 | 197 | @Override 198 | public void sendResourcePackOffer(ResourcePackInfo packInfo) { 199 | if (havePlayer) 200 | play.sendResourcePackOffer(packInfo); 201 | } 202 | 203 | @Override 204 | public @Nullable ResourcePackInfo getAppliedResourcePack() { 205 | if (havePlayer) 206 | return play.getAppliedResourcePack(); 207 | return null; 208 | } 209 | 210 | @Override 211 | public @Nullable ResourcePackInfo getPendingResourcePack() { 212 | if (havePlayer) 213 | return play.getPendingResourcePack(); 214 | return null; 215 | } 216 | 217 | @Override 218 | public Tristate getPermissionValue(String permission) { 219 | return Tristate.TRUE; 220 | } 221 | 222 | public void setPlayer(String player) { 223 | this.player = player; 224 | } 225 | 226 | @Override 227 | public InetSocketAddress getRemoteAddress() { 228 | if (havePlayer) 229 | return play.getRemoteAddress(); 230 | return null; 231 | } 232 | 233 | @Override 234 | public Optional getVirtualHost() { 235 | if (havePlayer) 236 | return play.getVirtualHost(); 237 | return Optional.empty(); 238 | } 239 | 240 | @Override 241 | public boolean isActive() { 242 | if (havePlayer) 243 | return play.isActive(); 244 | return false; 245 | } 246 | 247 | @Override 248 | public ProtocolVersion getProtocolVersion() { 249 | if (havePlayer) 250 | return play.getProtocolVersion(); 251 | return null; 252 | } 253 | 254 | @Override 255 | public boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data) { 256 | if (havePlayer) 257 | return play.sendPluginMessage(identifier, data); 258 | return false; 259 | } 260 | 261 | @Override 262 | public String getClientBrand() { 263 | if (havePlayer) 264 | return play.getClientBrand(); 265 | return null; 266 | } 267 | 268 | @Override 269 | public @NonNull Identity identity() { 270 | if (havePlayer) 271 | return play.identity(); 272 | return Identity.nil(); 273 | } 274 | } 275 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/velocity/EventListener.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.velocity; 2 | 3 | import com.coloryr.minecraft_qq.MVelocity; 4 | import com.coloryr.minecraft_qq.core.Minecraft_QQ; 5 | import com.coloryr.minecraft_qq.core.api.Placeholder; 6 | import com.coloryr.minecraft_qq.core.utils.SocketUtils; 7 | import com.velocitypowered.api.event.Subscribe; 8 | import com.velocitypowered.api.event.connection.DisconnectEvent; 9 | import com.velocitypowered.api.event.connection.PostLoginEvent; 10 | import com.velocitypowered.api.event.player.PlayerChatEvent; 11 | import com.velocitypowered.api.event.player.ServerConnectedEvent; 12 | import com.velocitypowered.api.proxy.Player; 13 | import net.kyori.adventure.text.Component; 14 | 15 | public class EventListener { 16 | private String message(String message, String playerName) { 17 | message = message.replaceAll(Minecraft_QQ.config.Placeholder.Player, playerName); 18 | message = message.replaceAll("&", "§"); 19 | return message; 20 | } 21 | 22 | @Subscribe 23 | public void onPlayerQuit(final PostLoginEvent event) { 24 | if (SocketUtils.isRun() && Minecraft_QQ.config.Join.Send) { 25 | String playerName = event.getPlayer().getUsername(); 26 | SocketUtils.sendData(Placeholder.data, Placeholder.group, 27 | playerName, message(Minecraft_QQ.config.Join.Message, playerName)); 28 | } 29 | } 30 | 31 | @Subscribe 32 | public void onPlayerquit(DisconnectEvent event) { 33 | if (SocketUtils.isRun() && Minecraft_QQ.config.Quit.Send) { 34 | String playerName = event.getPlayer().getUsername(); 35 | SocketUtils.sendData(Placeholder.data, Placeholder.group, 36 | playerName, message(Minecraft_QQ.config.Quit.Message, playerName)); 37 | } 38 | } 39 | 40 | @Subscribe 41 | public void onPlayerChangeServer(ServerConnectedEvent event) { 42 | if (SocketUtils.isRun() && Minecraft_QQ.config.ChangeServer.Send) { 43 | String message = Minecraft_QQ.config.ChangeServer.Message; 44 | Player player = event.getPlayer(); 45 | String playerName = player.getUsername(); 46 | String server = Minecraft_QQ.config.Servers.get(event.getServer().getServerInfo().getName()); 47 | if (server == null || server.isEmpty()) { 48 | server = event.getServer().getServerInfo().getName(); 49 | } 50 | message = message.replaceAll(Minecraft_QQ.config.Placeholder.Player, playerName) 51 | .replaceAll(Minecraft_QQ.config.Placeholder.Server, server); 52 | message = message.replaceAll("&", "§"); 53 | SocketUtils.sendData(Placeholder.data, Placeholder.group, playerName, message); 54 | } 55 | } 56 | 57 | @Subscribe 58 | public void onChar(PlayerChatEvent event) { 59 | String playerMessage = event.getMessage(); 60 | Player player = event.getPlayer(); 61 | if (Minecraft_QQ.config.User.NotSendCommand) { 62 | if (playerMessage.startsWith("/")) 63 | return; 64 | } else if (Minecraft_QQ.config.Mute.contains(player.getUsername())) 65 | return; 66 | if (Minecraft_QQ.config.ServerSet.Mode != 0 && SocketUtils.isRun()) { 67 | String message = Minecraft_QQ.config.ServerSet.Message; 68 | String playerName = player.getUsername(); 69 | if (player.getCurrentServer().isPresent()) { 70 | String Server = Minecraft_QQ.config.Servers.get(player.getCurrentServer().get().getServerInfo().getName()); 71 | if (Server == null || Server.isEmpty()) { 72 | Server = player.getCurrentServer().get().getServerInfo().getName(); 73 | } 74 | message = message.replaceAll(Minecraft_QQ.config.Placeholder.Player, playerName) 75 | .replaceAll(Minecraft_QQ.config.Placeholder.ServerName, Minecraft_QQ.config.ServerSet.ServerName) 76 | .replaceAll(Minecraft_QQ.config.Placeholder.Server, Server) 77 | .replaceAll("&", "§"); 78 | if (Minecraft_QQ.config.ServerSet.Mode == 1 79 | && playerMessage.indexOf(Minecraft_QQ.config.ServerSet.Check) == 0) { 80 | playerMessage = playerMessage.replaceFirst(Minecraft_QQ.config.ServerSet.Check, ""); 81 | message = message.replaceAll(Minecraft_QQ.config.Placeholder.Message, playerMessage); 82 | SocketUtils.sendData(Placeholder.data, Placeholder.group, playerName, message); 83 | } else if (Minecraft_QQ.config.ServerSet.Mode == 2) { 84 | message = message.replaceAll(Minecraft_QQ.config.Placeholder.Message, playerMessage); 85 | SocketUtils.sendData(Placeholder.data, Placeholder.group, playerName, message); 86 | } 87 | if (Minecraft_QQ.config.SendAllServer.Enable) { 88 | String SendAllServer_send = Minecraft_QQ.config.SendAllServer.Message; 89 | SendAllServer_send = SendAllServer_send 90 | .replaceAll(Minecraft_QQ.config.Placeholder.ServerName, Minecraft_QQ.config.ServerSet.ServerName) 91 | .replaceAll(Minecraft_QQ.config.Placeholder.Server, Server) 92 | .replaceAll(Minecraft_QQ.config.Placeholder.Player, playerName) 93 | .replaceAll(Minecraft_QQ.config.Placeholder.Message, playerMessage); 94 | SendAllServer_send = SendAllServer_send.replaceAll("&", "§"); 95 | if (Minecraft_QQ.config.SendAllServer.OnlySideServer) { 96 | for (Player player1 : MVelocity.plugin.server.getAllPlayers()) { 97 | if (player.getCurrentServer().isPresent() && player1.getCurrentServer().isPresent() && 98 | !player1.getCurrentServer().get().getServerInfo().getName().equals(player.getCurrentServer().get().getServerInfo().getName())) 99 | player1.sendMessage(Component.text(SendAllServer_send)); 100 | } 101 | } else { 102 | for (Player player1 : MVelocity.plugin.server.getAllPlayers()) { 103 | player1.sendMessage(Component.text(SendAllServer_send)); 104 | } 105 | event.setResult(PlayerChatEvent.ChatResult.denied()); 106 | } 107 | } 108 | } else { 109 | Minecraft_QQ.log.warning("§d[Minecraft_QQ]§c玩家:" + playerName + "服务器错误"); 110 | } 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/velocity/GroupEvent.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.velocity; 2 | 3 | import com.coloryr.minecraft_qq.core.api.IGroupEvent; 4 | import com.coloryr.minecraft_qq.core.json.ReadObj; 5 | 6 | public class GroupEvent implements IGroupEvent { 7 | private String group; 8 | private String message; 9 | private String player; 10 | private boolean isCommand; 11 | private String command; 12 | 13 | public GroupEvent(ReadObj obj) { 14 | this.group = obj.group; 15 | this.message = obj.message; 16 | this.player = obj.player; 17 | this.isCommand = obj.isCommand; 18 | this.command = obj.command; 19 | } 20 | 21 | @Override 22 | public String getGroup() { 23 | return group; 24 | } 25 | 26 | @Override 27 | public String getMessage() { 28 | return message; 29 | } 30 | 31 | @Override 32 | public String getPlayer() { 33 | return player; 34 | } 35 | 36 | @Override 37 | public String getCommand() { 38 | return command; 39 | } 40 | 41 | @Override 42 | public boolean isCommand() { 43 | return isCommand; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/velocity/Log.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.velocity; 2 | 3 | import com.coloryr.minecraft_qq.core.api.ILogger; 4 | import org.slf4j.Logger; 5 | 6 | public class Log implements ILogger { 7 | private final Logger logger; 8 | 9 | public Log(Logger logger) { 10 | this.logger = logger; 11 | } 12 | 13 | @Override 14 | public void warning(String data) { 15 | logger.warn(data); 16 | } 17 | 18 | @Override 19 | public void info(String data) { 20 | logger.info(data); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/velocity/Metrics.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.velocity; 2 | 3 | import com.coloryr.minecraft_qq.core.bstats.MetricsBase; 4 | import com.coloryr.minecraft_qq.core.bstats.charts.CustomChart; 5 | import com.coloryr.minecraft_qq.core.bstats.config.MetricsConfig; 6 | import com.coloryr.minecraft_qq.core.bstats.json.JsonObjectBuilder; 7 | import com.google.inject.Inject; 8 | import com.velocitypowered.api.plugin.PluginContainer; 9 | import com.velocitypowered.api.plugin.PluginDescription; 10 | import com.velocitypowered.api.plugin.annotation.DataDirectory; 11 | import com.velocitypowered.api.proxy.ProxyServer; 12 | import org.slf4j.Logger; 13 | 14 | import java.io.File; 15 | import java.io.IOException; 16 | import java.nio.file.Path; 17 | 18 | public class Metrics { 19 | private final PluginContainer pluginContainer; 20 | private final ProxyServer server; 21 | private MetricsBase metricsBase; 22 | 23 | private Metrics(Object plugin, ProxyServer server, Logger logger, Path dataDirectory, int serviceId) { 24 | pluginContainer = server.getPluginManager().fromInstance(plugin) 25 | .orElseThrow(() -> new IllegalArgumentException("The provided instance is not a plugin")); 26 | this.server = server; 27 | 28 | File configFile = dataDirectory.getParent().resolve("bStats").resolve("config.txt").toFile(); 29 | MetricsConfig config; 30 | try { 31 | config = new MetricsConfig(configFile, true); 32 | } catch (IOException e) { 33 | logger.error("Failed to create bStats config", e); 34 | return; 35 | } 36 | 37 | metricsBase = new MetricsBase( 38 | "velocity", 39 | config.getServerUUID(), 40 | serviceId, 41 | config.isEnabled(), 42 | this::appendPlatformData, 43 | this::appendServiceData, 44 | task -> server.getScheduler().buildTask(plugin, task).schedule(), 45 | () -> true, 46 | logger::warn, 47 | logger::info, 48 | config.isLogErrorsEnabled(), 49 | config.isLogSentDataEnabled(), 50 | config.isLogResponseStatusTextEnabled() 51 | ); 52 | 53 | if (!config.didExistBefore()) { 54 | // Send an info message when the bStats config file gets created for the first time 55 | logger.info("Velocity and some of its plugins collect metrics and send them to bStats (https://bStats.org)."); 56 | logger.info("bStats collects some basic information for plugin authors, like how many people use"); 57 | logger.info("their plugin and their total player count. It's recommend to keep bStats enabled, but"); 58 | logger.info("if you're not comfortable with this, you can opt-out by editing the config.txt file in"); 59 | logger.info("the '/plugins/bStats/' folder and setting enabled to false."); 60 | } 61 | } 62 | 63 | /** 64 | * Adds a custom chart. 65 | * 66 | * @param chart The chart to add. 67 | */ 68 | public void addCustomChart(CustomChart chart) { 69 | if (metricsBase != null) { 70 | metricsBase.addCustomChart(chart); 71 | } 72 | } 73 | 74 | private void appendPlatformData(JsonObjectBuilder builder) { 75 | builder.appendField("playerAmount", server.getPlayerCount()); 76 | builder.appendField("managedServers", server.getAllServers().size()); 77 | builder.appendField("onlineMode", server.getConfiguration().isOnlineMode() ? 1 : 0); 78 | builder.appendField("velocityVersionVersion", server.getVersion().getVersion()); 79 | builder.appendField("velocityVersionName", server.getVersion().getName()); 80 | builder.appendField("velocityVersionVendor", server.getVersion().getVendor()); 81 | 82 | builder.appendField("javaVersion", System.getProperty("java.version")); 83 | builder.appendField("osName", System.getProperty("os.name")); 84 | builder.appendField("osArch", System.getProperty("os.arch")); 85 | builder.appendField("osVersion", System.getProperty("os.version")); 86 | builder.appendField("coreCount", Runtime.getRuntime().availableProcessors()); 87 | } 88 | 89 | private void appendServiceData(JsonObjectBuilder builder) { 90 | builder.appendField("pluginVersion", pluginContainer.getDescription().getVersion().orElse("unknown")); 91 | } 92 | 93 | /** 94 | * A factory to create new Metrics classes. 95 | */ 96 | public static class Factory { 97 | 98 | private final ProxyServer server; 99 | private final Logger logger; 100 | private final Path dataDirectory; 101 | 102 | // The constructor is not meant to be called by the user. 103 | // The instance is created using Dependency Injection 104 | @Inject 105 | private Factory(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) { 106 | this.server = server; 107 | this.logger = logger; 108 | this.dataDirectory = dataDirectory; 109 | } 110 | 111 | /** 112 | * Creates a new Metrics class. 113 | * 114 | * @param plugin The plugin instance. 115 | * @param serviceId The id of the service. 116 | * It can be found at What is my plugin id? 117 | *

Not to be confused with Velocity's {@link PluginDescription#getId()} method! 118 | * @return A Metrics instance that can be used to register custom charts. 119 | *

The return value can be ignored, when you do not want to register custom charts. 120 | */ 121 | public Metrics make(Object plugin, int serviceId) { 122 | return new Metrics(plugin, server, logger, dataDirectory, serviceId); 123 | } 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /server/src/main/java/com/coloryr/minecraft_qq/side/velocity/Side.java: -------------------------------------------------------------------------------- 1 | package com.coloryr.minecraft_qq.side.velocity; 2 | 3 | import com.coloryr.minecraft_qq.MVelocity; 4 | import com.coloryr.minecraft_qq.core.Minecraft_QQ; 5 | import com.coloryr.minecraft_qq.core.api.ISide; 6 | import com.coloryr.minecraft_qq.core.api.Placeholder; 7 | import com.coloryr.minecraft_qq.core.json.ReadObj; 8 | import com.coloryr.minecraft_qq.core.ASide; 9 | import com.coloryr.minecraft_qq.core.utils.Logs; 10 | import com.coloryr.minecraft_qq.core.utils.SocketUtils; 11 | import com.velocitypowered.api.command.CommandSource; 12 | import com.velocitypowered.api.proxy.Player; 13 | import com.velocitypowered.api.proxy.ProxyServer; 14 | import com.velocitypowered.api.proxy.server.RegisteredServer; 15 | import net.kyori.adventure.text.Component; 16 | 17 | import java.util.Collection; 18 | 19 | public class Side implements ISide { 20 | @Override 21 | public void send(Object sender, String message) { 22 | CommandSource temp = (CommandSource) sender; 23 | temp.sendMessage(Component.text(message)); 24 | } 25 | 26 | @Override 27 | public void message(ReadObj readobj) { 28 | try { 29 | if (Minecraft_QQ.config.System.Debug) 30 | Minecraft_QQ.log.info("处理数据:" + readobj.message); 31 | ProxyServer proxyserver = MVelocity.plugin.server; 32 | try { 33 | MVelocity.plugin.server.getScheduler().buildTask(MVelocity.plugin, () -> { 34 | GroupEvent eventVelocity = new GroupEvent(readobj); 35 | MVelocity.plugin.server.getEventManager().fireAndForget(eventVelocity); 36 | }).schedule(); 37 | } catch (Exception e) { 38 | Minecraft_QQ.log.info("数据传输发生错误:"); 39 | e.printStackTrace(); 40 | return; 41 | } 42 | if (!readobj.isCommand) { 43 | if (readobj.command.equalsIgnoreCase(Placeholder.speak)) { 44 | String say = Minecraft_QQ.config.ServerSet.Say 45 | .replaceFirst(Minecraft_QQ.config.Placeholder.ServerName, Minecraft_QQ.config.ServerSet.ServerName) 46 | .replaceFirst(Minecraft_QQ.config.Placeholder.Message, readobj.message) 47 | .replaceFirst(Minecraft_QQ.config.Placeholder.Player, readobj.player); 48 | say = say.replaceAll("&", "§"); 49 | if (Minecraft_QQ.config.Logs.Group) { 50 | Logs.logWrite("[Group]" + say); 51 | } 52 | for (Player player1 : proxyserver.getAllPlayers()) { 53 | if (!Minecraft_QQ.config.Mute.contains(player1.getUsername())) 54 | player1.sendMessage(Component.text(say)); 55 | } 56 | } else if (readobj.command.equalsIgnoreCase(Placeholder.online)) { 57 | int allPlayerNumber = 0; 58 | StringBuilder allServerPlayer = new StringBuilder(); 59 | String send = Minecraft_QQ.config.ServerSet.PlayerListMessage; 60 | if (Minecraft_QQ.config.ServerSet.SendOneByOne) { 61 | for (final RegisteredServer serverinfo : proxyserver.getAllServers()) { 62 | String oneServerPlayer; 63 | int oneServerNumber; 64 | final Collection oneServerPlayers = serverinfo.getPlayersConnected(); 65 | if (oneServerPlayers.size() == 0) { 66 | if (!Minecraft_QQ.config.ServerSet.HideEmptyServer) { 67 | String serverName = Minecraft_QQ.config.Servers.get(serverinfo.getServerInfo().getName()); 68 | if (serverName == null || serverName.isEmpty()) { 69 | serverName = serverinfo.getServerInfo().getName(); 70 | } 71 | oneServerPlayer = Minecraft_QQ.config.ServerSet.SendOneByOneMessage 72 | .replaceAll(Minecraft_QQ.config.Placeholder.Server, serverName) 73 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerNumber, "0") 74 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerList, "无"); 75 | allServerPlayer.append(oneServerPlayer); 76 | } 77 | } else { 78 | oneServerNumber = oneServerPlayers.size(); 79 | String serverName = Minecraft_QQ.config.Servers.get(serverinfo.getServerInfo().getName()); 80 | if (serverName == null || serverName.isEmpty()) { 81 | serverName = serverinfo.getServerInfo().getName(); 82 | } 83 | StringBuilder players = new StringBuilder(); 84 | for (Player player : oneServerPlayers) { 85 | players.append(player.getUsername()).append(","); 86 | } 87 | String players1 = players.toString(); 88 | oneServerPlayer = Minecraft_QQ.config.ServerSet.SendOneByOneMessage 89 | .replaceAll(Minecraft_QQ.config.Placeholder.Server, serverName) 90 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerNumber, "" + oneServerNumber) 91 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerList, players1.substring(0, players1.length() - 1)); 92 | allPlayerNumber += oneServerNumber; 93 | allServerPlayer.append(oneServerPlayer); 94 | } 95 | } 96 | if (allPlayerNumber == 0) { 97 | send = send.replaceAll(Minecraft_QQ.config.Placeholder.PlayerNumber, "0") 98 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerList, "无"); 99 | } else { 100 | send = send.replaceAll(Minecraft_QQ.config.Placeholder.PlayerNumber, "" + allPlayerNumber) 101 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerList, allServerPlayer.toString()); 102 | } 103 | } else { 104 | final Collection players = proxyserver.getAllPlayers(); 105 | if (players.size() == 0) { 106 | send = send.replaceAll(Minecraft_QQ.config.Placeholder.PlayerNumber, "0") 107 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerList, "无"); 108 | } else { 109 | StringBuilder temp = new StringBuilder(); 110 | for (Player player : players) { 111 | temp.append(player.getUsername()).append(","); 112 | } 113 | String players1 = temp.toString(); 114 | send = send.replaceAll(Minecraft_QQ.config.Placeholder.PlayerNumber, "" + players.size()) 115 | .replaceAll(Minecraft_QQ.config.Placeholder.PlayerList, players1.substring(0, players1.length() - 1)); 116 | } 117 | } 118 | send = send.replace(Minecraft_QQ.config.Placeholder.ServerName, Minecraft_QQ.config.ServerSet.ServerName); 119 | SocketUtils.sendData(Placeholder.data, readobj.group, "无", send); 120 | if (Minecraft_QQ.config.Logs.Group) { 121 | Logs.logWrite("[group]查询在线人数"); 122 | } 123 | } else { 124 | ASide.globeCheck(readobj); 125 | } 126 | } else { 127 | StringBuilder send_message; 128 | Commander send = new Commander(readobj.player); 129 | if (Minecraft_QQ.config.Logs.Group) { 130 | Logs.logWrite("[Group]" + readobj.player + "执行命令" + readobj.command); 131 | } 132 | try { 133 | proxyserver.getCommandManager().executeAsync(send, readobj.command).get(); 134 | Thread.sleep(Minecraft_QQ.config.ServerSet.CommandDelay); 135 | if (send.message.size() == 1) { 136 | send_message = new StringBuilder(send.message.get(0)); 137 | } else if (send.message.size() > 1) { 138 | send_message = new StringBuilder(send.message.get(0)); 139 | for (int i = 1; i < send.message.size(); i++) { 140 | send_message.append("\n"); 141 | send_message.append(send.message.get(i)); 142 | } 143 | } else 144 | send_message = new StringBuilder("已执行,指令无返回"); 145 | } catch (Exception e) { 146 | send_message = new StringBuilder("执行发生错误"); 147 | Minecraft_QQ.log.warning("指令执行发生错误"); 148 | e.printStackTrace(); 149 | } 150 | SocketUtils.sendData(Placeholder.data, readobj.group, 151 | "控制台", send_message.toString()); 152 | } 153 | } catch (Exception e) { 154 | Minecraft_QQ.log.warning("§d[Minecraft_QQ]§c发送错误:"); 155 | e.printStackTrace(); 156 | } 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /server/src/main/resources/bungee.yml: -------------------------------------------------------------------------------- 1 | name: Minecraft_QQ 2 | main: com.coloryr.minecraft_qq.MBC 3 | author: Color_yr 4 | version: 3.0.4 5 | -------------------------------------------------------------------------------- /server/src/main/resources/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "Join": { 3 | "Message": "%player%加入了服务器", 4 | "Send": true 5 | }, 6 | "Quit": { 7 | "Message": "%player%退出了服务器", 8 | "Send": true 9 | }, 10 | "ChangeServer": { 11 | "Message": "%player%加入了子服%server%", 12 | "Send": true 13 | }, 14 | "ServerSet": { 15 | "ServerName": "MC服务器", 16 | "Check": "群:", 17 | "Message": "[%servername%]-%server%-%player%:%message%", 18 | "Say": "[%servername%][群消息]%player%:%message%", 19 | "Mode": 1, 20 | "SendOneByOne": true, 21 | "SendOneByOneMessage": "[%server%-%playernumber%]-%playerlist%", 22 | "HideEmptyServer": true, 23 | "PlayerListMessage": "%servername%当前在线人数:%playernumber%,玩家列表:%playerlist%", 24 | "ServerOnlineMessage": "%servername%服务器在线", 25 | "TopMode": false, 26 | "CommandDelay": 2000 27 | }, 28 | "Servers": { 29 | "lobby": "登陆大厅", 30 | "server": "服务器" 31 | }, 32 | "SendAllServer": { 33 | "Enable": true, 34 | "Message": "[%servername%-%server%]玩家:[%player%]发送群消息:[%message%]", 35 | "OnlySideServer": true 36 | }, 37 | "System": { 38 | "IP": "127.0.0.1", 39 | "Port": 25555, 40 | "AutoConnectTime": 10, 41 | "Debug": false 42 | }, 43 | "User": { 44 | "NotSendCommand": true 45 | }, 46 | "Logs": { 47 | "Group": true, 48 | "Server": true 49 | }, 50 | "Placeholder": { 51 | "Message": "%message%", 52 | "Player": "%player%", 53 | "ServerName": "%servername%", 54 | "Server": "%server%", 55 | "PlayerNumber": "%playernumber%", 56 | "PlayerList": "%playerlist%" 57 | }, 58 | "Language": { 59 | "MessageOFF": "§2你已不会在收到群消息", 60 | "MessageON": "§2你开始接受群消息" 61 | }, 62 | "Mute": [], 63 | "Version": "3.0.4" 64 | } -------------------------------------------------------------------------------- /server/src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: Minecraft_QQ 2 | main: com.coloryr.minecraft_qq.MBukkit 3 | author: Color_yr 4 | version: 3.0.4 5 | 6 | softdepend: [PlaceholderAPI] 7 | 8 | commands: 9 | qq: 10 | description: Minecraft_QQ的主要指令 11 | usage: §4[Minecraft_QQ]§6/qq help来查看帮助 12 | --------------------------------------------------------------------------------