Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Refactor: Migrate to Mojang Mappings & Utilize Listener for Minecraft Events #216

Merged
merged 36 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2df617c
开始移植到Mojang Mappings
Xujiayao Feb 8, 2024
92d3244
暂时禁用其它MC版本
Xujiayao Feb 8, 2024
889b963
修复服务器TPS显示错误
Xujiayao Feb 8, 2024
b2e30b0
非Minecraft部分重构
Xujiayao Feb 8, 2024
72d1e19
处理 Join & Leave
Xujiayao Feb 8, 2024
603b1af
处理 Die
Xujiayao Feb 8, 2024
d19726f
处理 Advancement
Xujiayao Feb 8, 2024
6a43f83
测试GitHub Actions编译
Xujiayao Feb 8, 2024
9b307ac
移除无用类
Xujiayao Feb 8, 2024
e529721
处理 Message
Xujiayao Feb 8, 2024
91611d8
简化
Xujiayao Feb 8, 2024
13741ef
处理 Command
Xujiayao Feb 8, 2024
b209913
处理 Server /say message
Xujiayao Feb 8, 2024
2183c64
多版本编译要求写全
Xujiayao Feb 8, 2024
dc96afc
CommandOutput -> CommandSource
Xujiayao Feb 9, 2024
d6845a8
使用Carpet法获取TPS和MSPT(1.20.3+)
Xujiayao Feb 9, 2024
e0742e0
删除已完成TODO
Xujiayao Feb 9, 2024
304a7a2
Compat TODO
Xujiayao Feb 9, 2024
04c0f01
兼容1.20.2
Xujiayao Feb 9, 2024
285961e
兼容1.20.1
Xujiayao Feb 9, 2024
5fccf6a
兼容1.19.4
Xujiayao Feb 9, 2024
42f6096
兼容1.19.3(或许不需要?)
Xujiayao Feb 9, 2024
d60baa3
兼容1.19.2
Xujiayao Feb 9, 2024
c870eb0
PLAYER_COMMAND 改为 (player, command)
Xujiayao Feb 9, 2024
b9f301d
兼容1.19
Xujiayao Feb 9, 2024
ed54cf6
PLAYER_COMMAND 传 / 开头的指令字符串
Xujiayao Feb 10, 2024
a28a873
SERVER_MESSAGE 和 PLAYER_MESSAGE 直接传字符串
Xujiayao Feb 10, 2024
2f3fe0c
兼容1.18.2
Xujiayao Feb 10, 2024
e3e97c6
兼容1.17.1(或许不需要?)
Xujiayao Feb 10, 2024
ea5a512
傻了
Xujiayao Feb 10, 2024
26ebc2a
兼容1.16.5
Xujiayao Feb 10, 2024
a138b4f
兼容1.15.2,开始检查各版本Runtime兼容性
Xujiayao Feb 10, 2024
1c8961d
死亡消息优化:更好的多语言支持
Xujiayao Feb 10, 2024
41df66e
Compat
Xujiayao Feb 10, 2024
3fd5fb3
修复各版本Mixin报错
Xujiayao Feb 10, 2024
979f18f
MixinLanguage
Xujiayao Feb 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ plugins {
}

preprocess {
def mc1152 = createNode("compat_1.15.2", 1_15_02, "yarn")
def mc1165 = createNode("compat_1.16.5", 1_16_05, "yarn")
def mc1171 = createNode("compat_1.17.1", 1_17_01, "yarn")
def mc1182 = createNode("compat_1.18.2", 1_18_02, "yarn")
def mc1190 = createNode("compat_1.19" , 1_19_00, "yarn")
def mc1192 = createNode("1.19.2", 1_19_02, "yarn")
def mc1193 = createNode("1.19.3", 1_19_03, "yarn")
def mc1194 = createNode("1.19.4", 1_19_04, "yarn")
def mc1201 = createNode("1.20.1", 1_20_01, "yarn")
def mc1202 = createNode("1.20.2", 1_20_02, "yarn")
def mc1204 = createNode("1.20.4", 1_20_04, "yarn")
def mc1152 = createNode("compat_1.15.2", 1_15_02, "mojang")
def mc1165 = createNode("compat_1.16.5", 1_16_05, "mojang")
def mc1171 = createNode("compat_1.17.1", 1_17_01, "mojang")
def mc1182 = createNode("compat_1.18.2", 1_18_02, "mojang")
def mc1190 = createNode("compat_1.19" , 1_19_00, "mojang")
def mc1192 = createNode("1.19.2", 1_19_02, "mojang")
def mc1193 = createNode("1.19.3", 1_19_03, "mojang")
def mc1194 = createNode("1.19.4", 1_19_04, "mojang")
def mc1201 = createNode("1.20.1", 1_20_01, "mojang")
def mc1202 = createNode("1.20.2", 1_20_02, "mojang")
def mc1204 = createNode("1.20.4", 1_20_04, "mojang")

mc1152.link(mc1165, null)
mc1152.link(mc1165, file("versions/mapping-1.15.2-1.16.5.txt"))
mc1165.link(mc1171, null)
mc1171.link(mc1182, null)
mc1182.link(mc1190, null)
mc1190.link(mc1192, null)
mc1192.link(mc1193, null)
mc1192.link(mc1193, file("versions/mapping-1.19.2-1.19.3.txt"))
mc1193.link(mc1194, null)
mc1194.link(mc1201, null)
mc1201.link(mc1202, null)
mc1201.link(mc1202, file("versions/mapping-1.20.1-1.20.2.txt"))
mc1202.link(mc1204, null)
}
2 changes: 1 addition & 1 deletion common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ base {

dependencies {
minecraft("com.mojang:minecraft:${minecraft_version}")
mappings("net.fabricmc:yarn:${yarn_mappings}:v2")
mappings(loom.officialMojangMappings())

modImplementation("net.fabricmc:fabric-loader:${loader_version}")
modApi("net.fabricmc.fabric-api:fabric-api:${fabric_version}")
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ archives_base_name=MC-Discord-Chat
# Wrapper Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.6
fabric_version=0.93.1+1.20.4
# cannot use 0.94.0 (loom & okio)
3 changes: 3 additions & 0 deletions src/main/java/com/xujiayao/mcdiscordchat/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xujiayao.mcdiscordchat;

import com.xujiayao.mcdiscordchat.minecraft.MinecraftEventListener;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Webhook;
Expand Down Expand Up @@ -212,6 +213,8 @@ public void onInitializeServer() {
shutdown();
}
});

MinecraftEventListener.init();
}

private void shutdown() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
package com.xujiayao.mcdiscordchat.discord;

import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.text.Text;
import net.minecraft.commands.CommandSource;
import net.minecraft.network.chat.Component;

import java.util.Timer;
import java.util.TimerTask;
//#if MC <= 11802
//#if MC < 11900
//$$ import java.util.UUID;
//#endif
import java.util.Timer;
import java.util.TimerTask;

/**
* @author Xujiayao
*/
public class DiscordCommandOutput implements CommandOutput {
public class DiscordCommandSource implements CommandSource {

private final SlashCommandInteractionEvent e;
private StringBuilder output = new StringBuilder("```\n");
private long lastOutputMillis = 0;

public DiscordCommandOutput(SlashCommandInteractionEvent e) {
public DiscordCommandSource(SlashCommandInteractionEvent e) {
this.e = e;
}

@Override
//#if MC >= 11900 || MC <= 11502
public void sendMessage(Text message) {
//#if MC >= 11900
public void sendSystemMessage(Component message) {
//#elseif MC > 11502
//$$ public void sendMessage(Component message, UUID uUID) {
//#else
//$$ public void sendSystemMessage(Text message, UUID sender) {
//$$ public void sendMessage(Component message) {
//#endif
long currentOutputMillis = System.currentTimeMillis();

Expand All @@ -54,18 +56,17 @@ public void run() {
}

@Override
public boolean shouldReceiveFeedback() {
public boolean acceptsSuccess() {
return true;
}

@Override
public boolean shouldTrackOutput() {
public boolean acceptsFailure() {
return true;
}

@Override
public boolean shouldBroadcastConsoleToOps() {
public boolean shouldInformAdmins() {
return true;
}

}
Loading
Loading