Skip to content

Commit

Permalink
feat(server): implement end of tick event for fabric and forge
Browse files Browse the repository at this point in the history
Implement the `ITickEvent` for both fabric and forge servers, allowing for
additional mod compatibility and functionality at the end of each tick. This
change ensures that necessary actions are performed consistently at the end
of every game tick cycle.
  • Loading branch information
cnlimiter committed Aug 12, 2024
1 parent c914724 commit c934fb1
Show file tree
Hide file tree
Showing 13 changed files with 319 additions and 4 deletions.
77 changes: 77 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Bug Report / 报告bug
description: Create a report to help us improve./创建报告以帮助我们改进。
title: "[Bug/漏洞] "
labels: [ "bug" ]
body:
- type: checkboxes
id: checks
attributes:
label: Checks / 检查
description: |
Please check that you have done the following things before submitting an issue./在提交问题之前,请检查您是否已完成以下操作。
options:
- label: I confirm that I have [searched for existing issues / pull requests](https://github.com/cnlimiter/McBot/issues?q=) before reporting to avoid duplicate reporting./我确认在报告之前我已经搜索了[现有的问题或者拉取请求](https://github.com/cnlimiter/McBot/issues?q=),以避免重复报告。
required: true
- label: I confirm that I followed the Docs and read the [Changelog](https://github.com/cnlimiter/McBot/releases/latest), but this problem still exists./我确认我按照文档配置并阅读了[Changelog](https://github.com/cnlimiter/McBot/releases/latest),但这个问题仍然存在。
required: true
- label: I confirm that I noted that if I don't follow the instructions, the issue may be closed directly./我确认我已经检查,如果我不按照说明进行操作,该问题可能会被直接关闭。
required: true
- type: input
id: java_version
attributes:
label: Java Version / Java版本
description: |
The version of Java you are using?/您正在使用的 Java 版本?
placeholder: "Example: 17.0.6"
validations:
required: true
- type: input
id: minecraft_version
attributes:
label: Minecraft Version / Minecraft版本
description: |
The version of Minecraft you are using?/您正在使用的 Minecraft 版本?
placeholder: "Example: 1.19.4"
validations:
required: true
- type: input
id: mcbot_version
attributes:
label: McBot Version / McBot版本
description: |
The version of McBot you are using?/您正在使用的 McBot 版本?
placeholder: "Example: 2.1.6"
validations:
required: true
- type: textarea
id: description
attributes:
label: Description / 描述
description: |
Please tell us what the bug is with a clear and detailed description, add screenshots to help explain./请通过清晰详细的描述告诉我们错误是什么,添加屏幕截图以帮助解释。
validations:
required: true
- type: textarea
id: to_reproduce
attributes:
label: To Reproduce / 重现
description: |
How do you trigger this bug? Please walk us through it step by step./你如何触发这个错误?请逐步引导我们完成它。
validations:
required: true
- type: textarea
id: log
attributes:
label: Log / 日志
description: |
Please provide your full log here./请在此处提供您的完整日志。
validations:
required: true
- type: textarea
id: config
attributes:
label: Config / 配置
description: |
Please provide your McBot config file (mcbot.json) here, remember to remove the botToken,qqId,groupId./请在此处提供您的McBot配置文件(mcbot.json),请记住删除botToken,qqId,groupId。
validations:
required: true
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
blank_issues_enabled: false
contact_links:
- name: Example Issue / 议题实例
url: https://github.com/Nova-Committee/McBot/issues/99
about: You can refer to this example issue to fill in your issue.
- name: McBot Docs / McBot 文档
url: https://wiki.nova-committee.cn/project-1/doc-1/
about: Make sure you follow the docs to configure McBot!
- name: Latest Builds / 最新构建
url: https://github.com/Nova-Committee/McBot/actions
about: You can find the latest build JAR files at GitHub Actions.
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/enhancement.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Feature Request / 功能请求
description: Suggest an idea for this project.
title: "[Enhancement/功能请求] "
labels: [ "enhancement" ]
body:
- type: checkboxes
id: checks
attributes:
label: Checks/检查
description: |
Please check that you have done the following things before submitting an issue./在提交问题之前,请检查您是否已完成以下操作。
options:
- label: I confirm that I have [searched for existing issues / pull requests](https://github.com/cnlimiter/McBot/issues?q=) before reporting to avoid duplicate reporting./我确认在报告之前我已经搜索了[现有的问题或者拉取请求](https://github.com/cnlimiter/McBot/issues?q=),以避免重复报告。
required: true
- label: I confirm that I noted that if I don't follow the instructions, the issue may be closed directly./我确认我已经检查,如果我不按照说明进行操作,该问题可能会被直接关闭。
required: true
- type: textarea
id: description
attributes:
label: Description/描述
description: |
What new feature or change do you want? What does it improve? Please tell us what the new feature or change is with a clear and detailed description, add screenshots to help explain if possible./您想要什么新功能或改进?它有什么作用?请告诉我们新功能或改进是什么,并提供清晰详细的描述,如果可能,请添加截图以帮助解释。
validations:
required: true
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/question.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Question / 询问
description: Anything you don't understand.
title: "[Question / 询问] "
labels: [ "question" ]
body:
- type: checkboxes
id: checks
attributes:
label: Checks / 检查
description: |
Please check that you have done the following things before submitting an issue./在提交问题之前,请检查您是否已完成以下操作。
options:
- label: I confirm that I have [searched for existing issues / pull requests](https://github.com/cnlimiter/McBot/issues?q=) before reporting to avoid duplicate reporting./我确认在报告之前我已经搜索了[现有的问题或者拉取请求](https://github.com/cnlimiter/McBot/issues?q=),以避免重复报告。
required: true
- label: I confirm that I noted that if I don't follow the instructions, the issue may be closed directly./我确认我已经检查,如果我不按照说明进行操作,该问题可能会被直接关闭。
required: true
- type: textarea
id: description
attributes:
label: Description / 描述
description: |
Please tell us what the question is with a clear and detailed description, add screenshots to help explain if possible./请通过清晰详细的描述告诉我们问题是什么,如果可能的话,添加截图以帮助解释。
validations:
required: true
26 changes: 26 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- New Feature or Bug Fix Pull Request -->
<!-- Implement an idea for this project or implement a bug fix to help us improve. -->
<!---->
<!-- Insert "[Enhancement] " or "[Bug] " before the first word in the title. -->
<!-- Note that the PR may be closed directly if you do not follow the instructions. -->

### Checks / 检查

<!-- Please check that you have done the following things before submitting a pull request.在提交请求之前,请检查您是否已完成以下操作。 -->
<!-- Set [ ] to [X] -->

- [ ] I confirm that I have [searched for existing issues / pull requests](https://github.com/cnlimiter/McBot/issues?q=) before requesting to avoid duplicate requesting./我确认在报告之前我已经搜索了[现有的问题或者拉取请求](https://github.com/cnlimiter/McBot/issues?q=),以避免重复报告。
- [ ] I confirm that I noted that if I don't follow the instructions, the issue may be closed directly./我确认我已经检查,如果我不按照说明进行操作,该问题可能会被直接关闭。

### Related Issues

<!-- Any GitHub issues related to this PR? If not, please fill in N/A./是否有与此 PR 相关的任何 GitHub 问题?如果没有,请填写NA。 -->
<!-- Example: Fix #ISSUE-NUMBER -->

### Description

<!-- For Bug Fix Pull Request: -->
<!-- Please tell us what bug have you fixed with a clear and detailed description, add screenshots to help explain./请告诉我们您修复了哪些错误,并提供清晰详细的描述,并添加截图以帮助解释。 -->
<!---->
<!-- For New Feature Pull Request: -->
<!-- What new feature or change have you added? What does it improve? Please tell us what the new feature or change is with a clear and detailed description, add screenshots to help explain if possible./您添加了哪些新功能或更改?它有什么改善?请告诉我们新功能或更改是什么,并提供清晰详细的描述,如果可能,请添加截图以帮助解释。 -->
53 changes: 53 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Fabric Action

on:
push:
branches: [ "multi/" ]
workflow_dispatch:


jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
show-progress: false

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'zulu'
check-latest: true

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1

- name: Make Gradle Wrapper Executable
run: chmod +x ./fabric/gradlew

- name: Build
uses: gradle/gradle-build-action@v2
with:
arguments: build
build-root-directory: fabric

- name: Find Correct JAR
id: findjar
run: |
output="$(find build/libs/ ! -name "*-sources.jar" -type f -printf "%f\n")"
echo "::set-output name=jarname::$output"
- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ steps.findjar.outputs.jarname }}
path: build/libs/${{ steps.findjar.outputs.jarname }}
50 changes: 50 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Fabric Release

on:
push:
tags:
- 'v*'

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
show-progress: false

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'zulu'
check-latest: true

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1

- name: Make Gradle Wrapper Executable
run: chmod +x ./fabric/gradlew

- name: Build
uses: gradle/gradle-build-action@v2
with:
arguments: buildNeeded
build-root-directory: fabric

- name: Find Correct JAR
id: findjar
run: |
output="$(find build/libs/ ! -name "*-sources.jar" -type f -printf "%f\n")"
echo "::set-output name=jarname::$output"
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
name: McBot-${{ github.ref_name }}
files: build/libs/${{ steps.findjar.outputs.jarname }}
body: Please refer to [CHANGELOG.md](https://github.com/Nova-Committee/re-avaritia/blob/master/CHANGELOG.md) for details.
9 changes: 9 additions & 0 deletions common/src/main/java/cn/evole/mods/mcbot/McBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@


import cn.evole.mods.mcbot.api.config.ConfigManager;
import cn.evole.mods.mcbot.api.event.server.ServerGameEvents;
import cn.evole.mods.mcbot.common.config.*;
import cn.evole.mods.mcbot.core.event.IBotEvent;
import cn.evole.mods.mcbot.core.event.IChatEvent;
import cn.evole.mods.mcbot.core.event.IPlayerEvent;
import cn.evole.mods.mcbot.util.MsgThreadUtils;
import cn.evole.mods.mcbot.util.onebot.CQUtils;
import cn.evole.onebot.client.OneBotClient;
Expand All @@ -21,6 +24,11 @@ public static void init() {
} catch (Exception e) {
LOGGER.error("配置加载错误...");
}

ServerGameEvents.PLAYER_LOGGED_IN.register((server, player) -> IPlayerEvent.loggedIn(player.level(), player));
ServerGameEvents.PLAYER_LOGGED_OUT.register((server, player) -> IPlayerEvent.loggedOut(player.level(), player));
ServerGameEvents.PLAYER_ADVANCEMENT.register(IPlayerEvent::advancement);
ServerGameEvents.PLAYER_DEATH.register(IPlayerEvent::death);
}


Expand Down Expand Up @@ -52,6 +60,7 @@ public static void onServerStopping(MinecraftServer server) {
public static void onServerStopped(MinecraftServer server) {
CQUtils.shutdown();
MsgThreadUtils.shutdown();
ConfigManager.getInstance().saveAllConfig();
if (onebot != null) onebot.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ public void close() {
}
}

public void saveAllConfig() {
configs.forEach((aClass, configHandler) -> {
try {
configHandler.saveToFile();
} catch (ConfigurateException e) {
e.printStackTrace();
}
});

}

public void saveConfig(final Class<?> config) {
try {
configs.get(config).saveToFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
* Version: 1.0
*/
public final class ServerGameEvents {
public static final ToggleableEvent<PlayerTick> SERVER_TICK = ToggleableEvent.create(PlayerTick.class, callbacks -> (world, player) -> {
for (PlayerTick callback : callbacks) {
callback.onTick(world, player);
}
});

public static final ToggleableEvent<PlayerTick> PLAYER_TICK = ToggleableEvent.create(PlayerTick.class, callbacks -> (world, player) -> {
for (PlayerTick callback : callbacks) {
callback.onTick(world, player);
Expand Down
4 changes: 4 additions & 0 deletions fabric/src/main/java/cn/evole/mods/mcbot/McBotFabric.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import cn.evole.mods.mcbot.api.event.server.ServerGameEvents;
import cn.evole.mods.mcbot.core.event.ICmdEvent;
import cn.evole.mods.mcbot.core.event.ITickEvent;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;

public class McBotFabric implements ModInitializer {
Expand All @@ -20,5 +22,7 @@ public void onInitialize() {
ServerLifecycleEvents.SERVER_STARTED.register(McBot::onServerStarted);
ServerLifecycleEvents.SERVER_STOPPING.register(McBot::onServerStopping);
ServerLifecycleEvents.SERVER_STOPPED.register(McBot::onServerStopped);

ServerTickEvents.END_SERVER_TICK.register(ITickEvent::register);
}
}
18 changes: 15 additions & 3 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ mixin {
config("${mod_id}.forge.mixins.json")
}

configurations {
library
implementation.extendsFrom library
}


minecraft.runs.all {
lazyToken('minecraft_classpath') {
configurations.library.copyRecursive().resolve().collect { it.absolutePath }.join(File.pathSeparator)
}
}

minecraft {
mappings channel: 'official', version: minecraft_version

Expand Down Expand Up @@ -79,9 +91,9 @@ dependencies {
compileOnly project(":common")
compileOnly ("org.projectlombok:lombok:1.18.30")
annotationProcessor ("org.projectlombok:lombok:1.18.30")
implementation ("cn.evole.onebot:OneBot-Client:${onebot_client_version}"){transitive = false}
implementation ("org.spongepowered:configurate-yaml:${yaml_version}")
implementation("com.github.houbb:csv:0.2.0")
library ("cn.evole.onebot:OneBot-Client:${onebot_client_version}"){transitive = false}
library ("org.spongepowered:configurate-yaml:${yaml_version}")
library("com.github.houbb:csv:0.2.0")
annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT:processor")
}

Expand Down
Loading

0 comments on commit c934fb1

Please sign in to comment.