Skip to content

Commit

Permalink
Merge pull request #4 from 17TheWord/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
17TheWord authored Aug 28, 2024
2 parents 8c429a9 + 9e41a53 commit dae6fa3
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 196 deletions.
46 changes: 12 additions & 34 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,24 @@ env:
jobs:
generate-matrix:
runs-on: windows-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Generate Matrix
id: set-matrix
shell: pwsh
run: |
$matrix = .\matrix.ps1 -path "fabric","forge","spigot","velocity"
$matrixJson = $matrix | ConvertTo-Json
echo $matrixJson > matrix_output.json
# 将矩阵数据保存到工件中
- name: Upload matrix data
uses: actions/upload-artifact@v4
with:
name: matrix
path: matrix_output.json
run: .\matrix.ps1 -path "fabric","forge","spigot","velocity"

build:
runs-on: windows-latest
needs:
- generate-matrix
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
# 下载矩阵数据工件
- name: Download matrix data
uses: actions/download-artifact@v4
with:
name: matrix
path: .
- name: Load matrix
id: load-matrix
shell: pwsh
run: |
$matrix = Get-Content matrix_output.json
echo "MATRIX=$matrix" >> $env:GITHUB_ENV
- name: Choose JDK 21
- name: Chose JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
Expand All @@ -60,24 +43,20 @@ jobs:
run: |
$mod_version = Get-Content version.txt
Write-Host "Version: $mod_version"
echo "MOD_VERSION=$mod_version" >> $env:GITHUB_ENV
echo "MOD_VERSION=$mod_version" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_ENV
- name: Init Files
shell: pwsh
run: |
./init.ps1
run: ./init.ps1

- name: Build
env:
USERNAME: ${{ github.actor }}
PACKAGE_READ_ONLY_TOKEN: ${{ secrets.PACKAGE_READ_ONLY_TOKEN }}
run: |
$matrix = $env:MATRIX | ConvertFrom-Json
$matrix | ForEach-Object {
cd "$($_.mc-loader)/$($_.mc-loader)-$($_.mc-version)"
./gradlew clean build
cd ../..
}
cd ${{ matrix.config.mc-loader }}/${{ matrix.config.mc-loader }}-${{ matrix.config.mc-version }}
./gradlew clean build
cd ../..
- uses: actions/upload-artifact@v4
with:
Expand All @@ -86,5 +65,4 @@ jobs:

- name: Upload to Release
if: ${{ github.event_name == 'push' }}
run: |
gh release upload v${{ env.MOD_VERSION }} QueQiao-jar/${{ env.MOD_VERSION }}/QueQiao-${{ matrix.config.mc-loader }}+${{ matrix.config.mc-version }}-${{ env.MOD_VERSION }}.jar
run: gh release upload v${{ env.MOD_VERSION }} QueQiao-jar/${{ env.MOD_VERSION }}/QueQiao-${{ matrix.config.mc-loader }}+${{ matrix.config.mc-version }}-${{ env.MOD_VERSION }}.jar
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.github.theword.queqiao.handle;

import com.github.theword.queqiao.tool.handle.HandleApiService;
import com.github.theword.queqiao.tool.payload.MessageSegment;
import com.github.theword.queqiao.tool.payload.TitlePayload;
import com.github.theword.queqiao.tool.payload.modle.component.CommonTextComponent;
import com.github.theword.queqiao.tool.response.PrivateMessageResponse;
import com.github.theword.queqiao.utils.ParseJsonToEventImpl;
import com.github.theword.queqiao.tool.utils.Tool;
// IF >= fabric-1.20
Expand All @@ -21,7 +22,6 @@
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.MutableText;
import org.java_websocket.WebSocket;

import java.util.List;
import java.util.UUID;
Expand All @@ -31,18 +31,18 @@
// END IF

import static com.github.theword.queqiao.QueQiao.minecraftServer;
import static com.github.theword.queqiao.utils.FabricTool.getFabricPlayer;

public class HandleApiImpl implements HandleApiService {
private final ParseJsonToEventImpl parseJsonToEventImpl = new ParseJsonToEventImpl();

/**
* 广播消息
*
* @param webSocket websocket
* @param messageList 消息体
*/
@Override
public void handleBroadcastMessage(WebSocket webSocket, List<CommonTextComponent> messageList) {
public void handleBroadcastMessage(List<MessageSegment> messageList) {
MutableText mutableText = parseJsonToEventImpl.parsePerMessageToComponent(Tool.getPrefixComponent());
mutableText.append(parseJsonToEventImpl.parseMessageListToComponent(messageList));
// IF >= fabric-1.19.2
Expand All @@ -55,11 +55,10 @@ public void handleBroadcastMessage(WebSocket webSocket, List<CommonTextComponent
/**
* 广播 Send Title 消息
*
* @param webSocket websocket
* @param titlePayload Title 消息体
*/
@Override
public void handleSendTitleMessage(WebSocket webSocket, TitlePayload titlePayload) {
public void handleSendTitleMessage(TitlePayload titlePayload) {
// IF > fabric-1.16.5
// sendPacket(new TitleS2CPacket(parseJsonToEventImpl.parseMessageListToComponent(titlePayload.getTitle())));
// if (titlePayload.getSubtitle() != null)
Expand All @@ -75,11 +74,10 @@ public void handleSendTitleMessage(WebSocket webSocket, TitlePayload titlePayloa
/**
* 广播 Action Bar 消息
*
* @param webSocket websocket
* @param messageList Action Bar 消息体
*/
@Override
public void handleActionBarMessage(WebSocket webSocket, List<CommonTextComponent> messageList) {
public void handleSendActionBarMessage(List<MessageSegment> messageList) {
// IF >= fabric-1.19
// sendPacket(new GameMessageS2CPacket(parseJsonToEventImpl.parseMessageListToComponent(messageList), true));
// ELSE
Expand All @@ -90,38 +88,34 @@ public void handleActionBarMessage(WebSocket webSocket, List<CommonTextComponent
/**
* 私聊消息
*
* @param webSocket websocket
* @param targetPlayerName 目标玩家名称
* @param targetPlayerUuid 目标玩家 UUID
* @param messageList 消息体
* @param nickname 目标玩家名称
* @param uuid 目标玩家 UUID
* @param messageList 消息体
*/
@Override
public void handlePrivateMessage(WebSocket webSocket, String targetPlayerName, UUID targetPlayerUuid, List<CommonTextComponent> messageList) {
public PrivateMessageResponse handleSendPrivateMessage(String nickname, UUID uuid, List<MessageSegment> messageList) {
ServerPlayerEntity serverPlayerEntity;
if (targetPlayerUuid != null)
serverPlayerEntity = minecraftServer.getPlayerManager().getPlayer(targetPlayerUuid);
else if (targetPlayerName != null && !targetPlayerName.isEmpty())
serverPlayerEntity = minecraftServer.getPlayerManager().getPlayer(targetPlayerName);
if (uuid != null)
serverPlayerEntity = minecraftServer.getPlayerManager().getPlayer(uuid);
else if (nickname != null && !nickname.isEmpty())
serverPlayerEntity = minecraftServer.getPlayerManager().getPlayer(nickname);
else {
webSocket.send("{\"code\":400,\"message\":\"Target player not found.\"}");
return;
return PrivateMessageResponse.playerNotFound();
}

if (serverPlayerEntity == null) {
webSocket.send("{\"code\":400,\"message\":\"Target player is null.\"}");
return;
return PrivateMessageResponse.playerIsNull();
}

if (serverPlayerEntity.isDisconnected()) {
webSocket.send("{\"code\":400,\"message\":\"Target player is disconnected.\"}");
return;
return PrivateMessageResponse.playerNotOnline();
}
// IF >= fabric-1.19
// serverPlayerEntity.sendMessage(parseJsonToEventImpl.parseMessageListToComponent(messageList));
// ELSE
// serverPlayerEntity.sendMessage(parseJsonToEventImpl.parseMessageListToComponent(messageList), false);
// END IF
webSocket.send("{\"code\":200,\"message\":\"Private message sent.\"}");
return PrivateMessageResponse.sendSuccess(getFabricPlayer(serverPlayerEntity));
}

private void sendPacket(Packet<?> packet) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.theword.queqiao.utils;

import com.github.theword.queqiao.tool.handle.ParseJsonToEventService;
import com.github.theword.queqiao.tool.payload.MessageSegment;
import com.github.theword.queqiao.tool.payload.modle.component.CommonTextComponent;
import com.github.theword.queqiao.tool.payload.modle.hover.CommonHoverEntity;
import com.github.theword.queqiao.tool.payload.modle.hover.CommonHoverItem;
Expand All @@ -15,18 +16,23 @@
import java.util.Optional;
import java.util.UUID;

import static com.github.theword.queqiao.tool.utils.Tool.logger;

public class ParseJsonToEventImpl implements ParseJsonToEventService {

@Override
public Text parseMessageListToComponent(List<CommonTextComponent> myBaseComponentList) {
public Text parseMessageListToComponent(List<MessageSegment> myBaseComponentList) {
// IF > fabric-1.18.2
// MutableText mutableText = Text.empty();
// ELSE
// MutableText mutableText = LiteralText.EMPTY.copy();
// END IF
for (CommonTextComponent commonTextComponent : myBaseComponentList) {
mutableText.append(parsePerMessageToComponent(commonTextComponent));
StringBuilder msgLogText = new StringBuilder();
for (MessageSegment messageSegment : myBaseComponentList) {
mutableText.append(parsePerMessageToComponent(messageSegment.getData()));
msgLogText.append(messageSegment.getData().getText());
}
logger.info(msgLogText.toString());
return mutableText;
}

Expand Down Expand Up @@ -71,17 +77,34 @@ public MutableText parsePerMessageToComponent(CommonTextComponent commonTextComp
} else style.withColor(TextColor.fromFormatting(Formatting.WHITE));

// 配置 TextComponent 额外属性
if (commonTextComponent.getClickEvent() != null) {
// IF fabric-1.21
if (commonTextComponent.getClickEvent() != null)
style.withClickEvent(getClickEvent(commonTextComponent));

if (commonTextComponent.getHoverEvent() != null)
style.withHoverEvent(getHoverEvent(commonTextComponent));


// IF < fabric-1.21 && >= fabric-1.19
// MutableText mutableText = MutableText.of(tempTextContent);
// mutableText.setStyle(style);
// return mutableText;
// ELSE
// tempTextContent.setStyle(style);
// return tempTextContent;
// END IF
}

public ClickEvent getClickEvent(CommonTextComponent commonTextComponent) {
// IF fabric-1.21
// ClickEvent.Action tempAction = ClickEvent.Action.valueOf(commonTextComponent.getClickEvent().getAction());
// ELSE
// ClickEvent.Action tempAction = ClickEvent.Action.byName(commonTextComponent.getClickEvent().getAction());
// END IF
ClickEvent clickEvent = new ClickEvent(tempAction, commonTextComponent.getClickEvent().getValue());
style.withClickEvent(clickEvent);
}
// ELSE
// ClickEvent.Action tempAction = ClickEvent.Action.byName(commonTextComponent.getClickEvent().getAction());
// END IF
return new ClickEvent(tempAction, commonTextComponent.getClickEvent().getValue());
}

public HoverEvent getHoverEvent(CommonTextComponent commonTextComponent) {
HoverEvent hoverEvent = null;
// 语言级别 '8' 不支持 增强的 'switch' 块
switch (commonTextComponent.getHoverEvent().getAction().toLowerCase()) {
case "show_text":
if (commonTextComponent.getHoverEvent().getText() != null && !commonTextComponent.getHoverEvent().getText().isEmpty()) {
Expand All @@ -107,16 +130,6 @@ public MutableText parsePerMessageToComponent(CommonTextComponent commonTextComp
default:
break;
}
style.withHoverEvent(hoverEvent);


// IF < fabric-1.21 && >= fabric-1.19
// MutableText mutableText = MutableText.of(tempTextContent);
// mutableText.setStyle(style);
// return mutableText;
// ELSE
// tempTextContent.setStyle(style);
// return tempTextContent;
// END IF
return hoverEvent;
}
}
Loading

0 comments on commit dae6fa3

Please sign in to comment.