Skip to content
This repository has been archived by the owner on Mar 2, 2024. It is now read-only.

Commit

Permalink
Fix Test (#60)
Browse files Browse the repository at this point in the history
* fix: test2

* fix: test3

* fix: test4
  • Loading branch information
CoolLoong authored Feb 23, 2023
1 parent ca492fc commit 432d07f
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 40 deletions.
27 changes: 22 additions & 5 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,40 @@ jobs:
steps:
- name: checkout source
uses: actions/checkout@v3

- name: checkout PNX source
uses: actions/checkout@v3
with:
repository: 'PowerNukkitX/PowerNukkitX'
path: 'core'

- name: checkout LLSE Lib TestRuntime
uses: actions/checkout@v3
with:
repository: 'PowerNukkitX/LLSE-Lib-TestRuntime'
path: 'env'

- name: setup-graalvm-ce
uses: rinx/[email protected]
with:
graalvm-version: "22.1.0"
java-version: "java17"
native-image: "false"

- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: get-pom-version
id: pom-version
uses: CptMokoena/maven-get-version-action@master
uses: CptMokoena/maven-get-version-action@1.0.3
with:
path: core

- name: setup running environment
run: |
cd env
Expand All @@ -65,12 +71,20 @@ jobs:
cd core/ && mvn -B package -DskipTests=true -Darguments="-Dmaven.javadoc.skip=true" -P dev
cp target/libs -R ../env && cp target/powernukkitx-${{ steps.pom-version.outputs.version }}.jar ../env
cd ../ && mkdir -p env/plugins && cp @LLSELib @Test -R env/plugins
- name: run test
run: cd env && ls && ./pnx start --stdin=control.txt && chmod +x test.sh && ./test.sh
run: |
cd env && ls && ./pnx start --stdin=control.txt
value=`cat result.txt`
readarray -d ';' -t strarr <<<"$value"
error=${strarr[1]}
if (($error > 0)); then
echo "测试失败,失败数量:$error"
exit 1
else
echo "测试成功"
fi
id: test-result
- name: fail
if: ${{ steps.test-result.outputs.success == 'false' }}
uses: cutenode/[email protected]

build:
if: github.event_name == 'push' && (!contains(github.ref_name, 'patch'))
Expand All @@ -79,16 +93,19 @@ jobs:
steps:
- name: checkout source
uses: actions/checkout@master

- name: move
run: |
mkdir $GITHUB_WORKSPACE/src
mv $GITHUB_WORKSPACE/@LLSELib $GITHUB_WORKSPACE/src/@LLSELib
- name: compress
uses: nizarmah/[email protected]
with:
overwrite: true
directory: ./src/@LLSELib
js_engine: uglify-js

- name: upload artifact
uses: actions/upload-artifact@v3
with:
Expand Down
108 changes: 77 additions & 31 deletions @LLSELib/money/money.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,92 @@ import { data } from '../utils/data.js';
import { DBSession } from '../database/DBSession.js';
import { download, onlyOnceExecute, server } from '../utils/util.js';
import { File as JFile } from "java.io.File";
import { MoneyAddEvent } from "cn.coolloong.economyevent.MoneyAddEvent";
import { MoneyReduceEvent } from "cn.coolloong.economyevent.MoneyReduceEvent";
import { MoneySetEvent } from "cn.coolloong.economyevent.MoneySetEvent";
import { MoneyTransEvent } from "cn.coolloong.economyevent.MoneyTransEvent";
import { BeforeMoneyAddEvent } from "cn.coolloong.economyevent.BeforeMoneyAddEvent";
import { BeforeMoneyReduceEvent } from "cn.coolloong.economyevent.BeforeMoneyReduceEvent";
import { BeforeMoneySetEvent } from "cn.coolloong.economyevent.BeforeMoneySetEvent";
import { BeforeMoneyTransEvent } from "cn.coolloong.economyevent.BeforeMoneyTransEvent";

//define
/**
* @typedef {Object} Main
* @property {function(string,number): cn.nukkit.event.Event} createMoneyAddEvent
* @property {function(string,number): cn.nukkit.event.Event} createMoneyReduceEvent
* @property {function(string,number): cn.nukkit.event.Event} createMoneySetEvent
* @property {function(string,string,number): cn.nukkit.event.Event} createMoneyTransEvent
* @property {function(string,number): cn.nukkit.event.Event} createBeforeMoneyAddEvent
* @property {function(string,number): cn.nukkit.event.Event} createBeforeMoneyReduceEvent
* @property {function(string,number): cn.nukkit.event.Event} createBeforeMoneySetEvent
* @property {function(string,string,number): cn.nukkit.event.Event} createBeforeMoneyTransEvent
*/

/**
* @typedef {Object} _API.EconomyAPI
* @property {function} setMoney
* @property {function} myMoney
* @property {function} addMoney
* @property {function} reduceMoney
*/

/**
* @typedef {Object} _API.LlamaEconomy
* @property {function} setMoney
* @property {function} getMoney
* @property {function} addMoney
* @property {function} reduceMoney
*/


if (!contain('economyDB')) {// 防止重复database
exposeObject('economyDB', new DBSession('sqlite3', { path: './plugins/LiteLoaderLibs/economy.db' }));
exposeObject('economyDB', new DBSession('sqlite3', {path: './plugins/LiteLoaderLibs/economy.db'}));
}
export const economyDB = contain('economyDB');

import("cn.coolloong.economyevent.Main").then(() => {
/**
* @type {Object}
*/
let EconomyEvent;
/**
* @type {Object}
*/
let _API;

import("cn.coolloong.economyevent.Main").then(s => {
let {Main} = s;
EconomyEvent.createMoneyAddEvent = Main.createMoneyAddEvent;
EconomyEvent.createMoneyReduceEvent = Main.createMoneyReduceEvent;
EconomyEvent.createMoneySetEvent = Main.createMoneySetEvent;
EconomyEvent.createMoneyTransEvent = Main.createMoneyTransEvent;
EconomyEvent.createBeforeMoneyAddEvent = Main.createBeforeMoneyAddEvent;
EconomyEvent.createBeforeMoneyReduceEvent = Main.createBeforeMoneyReduceEvent;
EconomyEvent.createBeforeMoneySetEvent = Main.createBeforeMoneySetEvent;
EconomyEvent.createBeforeMoneyTransEvent = Main.createBeforeMoneyTransEvent;
}, e => {
onlyOnceExecute(() => {
console.log("没有找到经济事件前置,正在为你自动下载 EconomyEvent...");
const fileName = "EconomyEvent-1.0.jar";
const fileName = "EconomyEvent-1.0.1.jar";
const folder = "plugins";
download("https://cloudburstmc.org/resources/economyapi.14/download", folder, fileName, () => {
download("https://res.nullatom.com/file/pnx/EconomyEvent-1.0.1.jar", folder, fileName, () => {
const file = new JFile(folder, fileName);
server.getPluginManager().loadPlugin(file);
});
import("cn.coolloong.economyevent").then(s2 => {
let {Main} = s2;
EconomyEvent.createMoneyAddEvent = Main.createMoneyAddEvent;
EconomyEvent.createMoneyReduceEvent = Main.createMoneyReduceEvent;
EconomyEvent.createMoneySetEvent = Main.createMoneySetEvent;
EconomyEvent.createMoneyTransEvent = Main.createMoneyTransEvent;
EconomyEvent.createBeforeMoneyAddEvent = Main.createBeforeMoneyAddEvent;
EconomyEvent.createBeforeMoneyReduceEvent = Main.createBeforeMoneyReduceEvent;
EconomyEvent.createBeforeMoneySetEvent = Main.createBeforeMoneySetEvent;
EconomyEvent.createBeforeMoneyTransEvent = Main.createBeforeMoneyTransEvent;
})
}, "64D1B2FC-E3BA-44A8-DCD4-91F117D6397D");
})

/**
* @type {Object}
*/
let _API;
});
import('me.onebone.economyapi.EconomyAPI').then(s => {
let { EconomyAPI } = s;
let {EconomyAPI} = s;
_API.EconomyAPI = EconomyAPI.getInstance();
onlyOnceExecute(() => {
console.log("成功载入EconomyAPI");
}, "DD681B41-E68F-545F-8CDA-FC89D99F210B");
}, e => {
import('net.lldv.llamaeconomy.LlamaEconomy').then(s => {
let { LlamaEconomy } = s;
let {LlamaEconomy} = s;
_API.LlamaEconomy = LlamaEconomy.getAPI();
onlyOnceExecute(() => {
console.log("成功载入LlamaEconomy");
Expand Down Expand Up @@ -74,7 +120,7 @@ export class money {
* @returns {boolean} 是否成功
*/
static set(xuid, money) {
let ev1 = new BeforeMoneySetEvent(xuid, money);
let ev1 = EconomyEvent.createBeforeMoneySetEvent(xuid, money);
server.getPluginManager().callEvent(ev1);
if (ev1.isCancelled()) {
return false;
Expand All @@ -92,7 +138,7 @@ export class money {
UPDATE
SET Money=${money}`);

let ev2 = new MoneySetEvent(xuid, money);
let ev2 = EconomyEvent.createMoneySetEvent(xuid, money);
server.getPluginManager().callEvent(ev2);
return true;
}
Expand All @@ -103,7 +149,7 @@ export class money {
* @returns {number} 玩家的资金数值
*/
static get(xuid) {
var value = 0;
let value = 0
if (_API.EconomyAPI) {
value = _API.EconomyAPI.myMoney(data.str2name(xuid));
} else if (_API.LlamaEconomy) {
Expand All @@ -123,7 +169,7 @@ export class money {
* @returns {boolean} 是否成功
*/
static add(xuid, _money) {
let ev1 = new BeforeMoneyAddEvent(xuid, _money);
let ev1 = EconomyEvent.createBeforeMoneyAddEvent(xuid, _money);
server.getPluginManager().callEvent(ev1);
if (ev1.isCancelled()) {
return false;
Expand All @@ -136,7 +182,7 @@ export class money {
}
money.get(data.str2name(xuid));// 更新数据库

let ev2 = new MoneyAddEvent(xuid, _money);
let ev2 = EconomyEvent.createMoneyAddEvent(xuid, _money);
server.getPluginManager().callEvent(ev2);
return true;
}
Expand All @@ -148,7 +194,7 @@ export class money {
* @returns {boolean} 是否成功
*/
static reduce(xuid, _money) {
let ev1 = new BeforeMoneyReduceEvent(xuid, _money);
let ev1 = EconomyEvent.createBeforeMoneyReduceEvent(xuid, _money);
server.getPluginManager().callEvent(ev1);
if (ev1.isCancelled()) {
return false;
Expand All @@ -166,7 +212,7 @@ export class money {
}
money.get(data.str2name(xuid));// 更新数据库

let ev2 = new MoneyReduceEvent(xuid, _money);
let ev2 = EconomyEvent.createMoneyReduceEvent(xuid, _money);
server.getPluginManager().callEvent(ev2);
return true;
}
Expand All @@ -180,7 +226,7 @@ export class money {
* @returns {boolean} 是否成功
*/
static trans(xuid1, xuid2, money_, note = '') {
let ev1 = new BeforeMoneyTransEvent(xuid1, xuid2, money_);
let ev1 = EconomyEvent.createBeforeMoneyTransEvent(xuid1, xuid2, money_);
server.getPluginManager().callEvent(ev1);
if (ev1.isCancelled()) {
return false;
Expand All @@ -194,7 +240,7 @@ export class money {
money.get(data.str2name(xuid1));// 更新数据库
money.get(data.str2name(xuid2));

let ev2 = new MoneyTransEvent(xuid1, xuid2, money_);
let ev2 = EconomyEvent.createMoneyTransEvent(xuid1, xuid2, money_);
server.getPluginManager().callEvent(ev2);
return true;
}
Expand All @@ -217,7 +263,7 @@ export class money {
*/
static getHistory(xuid, time) {
let res = [];
let d = economyDB.qreuy(`SELECT *
let d = economyDB.query(`SELECT *
FROM mtrans
WHERE (tFrom = '${xuid}' OR tTo = '${xuid}')
AND Time BETWEEN ${~~(new Date().getTime() / 1e3)}
Expand All @@ -236,7 +282,7 @@ export class money {

/**
* 删除账单历史记录
* @param xuid {string} 要操作的玩家的Xuid标识符
*
* @param time {number} 删除从现在开始往前time秒的记录
* @returns {boolean} 是否删除成功
*/
Expand Down
11 changes: 8 additions & 3 deletions @LLSELib/object/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@ export class Entity {
*/
_PNXEntity;

/**
* @type {DirectionAngle}
*/
directionAngle;

/**
* @param {cn.nukkit.entity.Entity} entity
*/
constructor(entity) {
this._PNXEntity = entity;
this.DirectionAngle = new DirectionAngle(this._PNXEntity);
this.directionAngle = new DirectionAngle(this._PNXEntity);
}

/**
Expand Down Expand Up @@ -135,7 +140,7 @@ export class Entity {
* @returns {boolean}
*/
get inAir() {
if (this instanceof EntityLiving) {
if (this._PNXEntity instanceof EntityLiving) {
return this._PNXEntity.getAirTicks() > 0;
} else return false;
}
Expand Down Expand Up @@ -220,7 +225,7 @@ export class Entity {
* @returns {DirectionAngle}
*/
get direction() {
return this.DirectionAngle;
return this.directionAngle;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion @Test/object/TestEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ export const TestEntity = () => {
JSAssert.addTestSuite("Test Entity", {
testProperty: function () {
assertThat(entity.name).equals("Pig", "name属性读取异常");
assertThat(entity.type).equals("Pig", "type属性读取异常");
assertThat(entity.type).equals("minecraft:pig", "type属性读取异常");
assertThat(isNumber(entity.id)).isTrue("id属性读取异常");
assertThat(entity.pos.toString()).equals(`{"x":0,"y":300,"z":0,"dim":"world","dimid":0}`, "pos属性读取异常");
assertThat(entity.blockPos.toString()).equals(`{"x":0,"y":300,"z":0,"dim":"world","dimid":0}`, "blockPos属性读取异常");
assertThat(entity.maxHealth).equals(10, "maxHealth属性读取异常");
assertThat(entity.health).equals(10, "health属性读取异常");
console.log(entity.inAir);
assertThat(entity.inAir).equals(true, "inAir属性读取异常");
assertThat(entity.inWater).equals(false, "inWater属性读取异常");
assertThat(entity.speed).equals(0.10000000149011612, "speed属性读取异常");
Expand Down

0 comments on commit 432d07f

Please sign in to comment.