From ffe693059977b91f41d70b7fc704badf1ded2f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=B6=E7=9A=93?= <8511461+harvey-husky@user.noreply.gitee.com> Date: Wed, 28 Dec 2022 07:28:06 +0800 Subject: [PATCH] fix --- .../global_message.mcfunction | 2 +- .../private_message.mcfunction | 2 +- scripts/fzsd_score.sc | 125 ++++++++++++++---- 3 files changed, 99 insertions(+), 30 deletions(-) diff --git a/data/fzsd/functions/module/last_nether_portal/global_message.mcfunction b/data/fzsd/functions/module/last_nether_portal/global_message.mcfunction index ec8fd85..eb18878 100644 --- a/data/fzsd/functions/module/last_nether_portal/global_message.mcfunction +++ b/data/fzsd/functions/module/last_nether_portal/global_message.mcfunction @@ -1,2 +1,2 @@ -execute if score @s fzsd.module.last_nether_portal.dimension matches -2147483648..2147483647 run tellraw @a [{"text": ""}, [{"selector": "@s"}, {"text": "说:我上次穿出的下界传送门位于", "color": "white"}, {"nbt": "fzsd.api.dimension.name", "interpret": true, "storage": "fzsd:global"}, [{"text": " [", "color": "green"}, {"score": {"name": "@s", "objective": "fzsd.module.last_nether_portal.x"}}, {"text": ", "}, {"score": {"name": "@s", "objective": "fzsd.module.last_nether_portal.z"}}, {"text": ", "}, {"score": {"name": "@s", "objective": "fzsd.module.last_nether_portal.z"}}, {"text": "]"}]]] +execute if score @s fzsd.module.last_nether_portal.dimension matches -2147483648..2147483647 run tellraw @a [{"text": ""}, [{"selector": "@s"}, {"text": "说:我上次穿出的下界传送门位于", "color": "white"}, {"nbt": "fzsd.api.dimension.name", "interpret": true, "storage": "fzsd:global"}, [{"text": " [", "color": "green"}, {"score": {"name": "@s", "objective": "fzsd.module.last_nether_portal.x"}}, {"text": ", "}, {"score": {"name": "@s", "objective": "fzsd.module.last_nether_portal.y"}}, {"text": ", "}, {"score": {"name": "@s", "objective": "fzsd.module.last_nether_portal.z"}}, {"text": "]"}]]] execute unless score @s fzsd.module.last_nether_portal.dimension matches -2147483648..2147483647 run tellraw @s {"text": "你从未穿出过下界传送门!"} \ No newline at end of file diff --git a/data/fzsd/functions/module/last_nether_portal/private_message.mcfunction b/data/fzsd/functions/module/last_nether_portal/private_message.mcfunction index b624a95..bbf6fff 100644 --- a/data/fzsd/functions/module/last_nether_portal/private_message.mcfunction +++ b/data/fzsd/functions/module/last_nether_portal/private_message.mcfunction @@ -1,2 +1,2 @@ -execute if score @s fzsd.module.last_nether_portal.dimension matches -2147483648..2147483647 run tellraw @s [{"text": "你上次穿出的下界传送门位于"}, {"nbt": "fzsd.api.dimension.name", "interpret": true, "storage": "fzsd:global"}, [{"text": " [", "color": "green"}, {"score": {"name": "@s", "objective": "fzsd.module.last_nether_portal.x"}}, {"text": ", "}, {"score": {"name": "@s", "objective": "fzsd.module.last_nether_portal.z"}}, {"text": ", "}, {"score": {"name": "@s", "objective": "fzsd.module.last_nether_portal.z"}}, {"text": "]"}]] +execute if score @s fzsd.module.last_nether_portal.dimension matches -2147483648..2147483647 run tellraw @s [{"text": "你上次穿出的下界传送门位于"}, {"nbt": "fzsd.api.dimension.name", "interpret": true, "storage": "fzsd:global"}, [{"text": " [", "color": "green"}, {"score": {"name": "@s", "objective": "fzsd.module.last_nether_portal.x"}}, {"text": ", "}, {"score": {"name": "@s", "objective": "fzsd.module.last_nether_portal.y"}}, {"text": ", "}, {"score": {"name": "@s", "objective": "fzsd.module.last_nether_portal.z"}}, {"text": "]"}]] execute unless score @s fzsd.module.last_nether_portal.dimension matches -2147483648..2147483647 run tellraw @s {"text": "你从未穿出过下界传送门!"} \ No newline at end of file diff --git a/scripts/fzsd_score.sc b/scripts/fzsd_score.sc index 152493e..491a5b8 100644 --- a/scripts/fzsd_score.sc +++ b/scripts/fzsd_score.sc @@ -1,7 +1,66 @@ // 计分板模块扩展插件 // 忽略假人分数 // **请勿修改文件名!!** -global_app_version = '1.0-beta.13'; + +//** 工具函数 **// + +contains(list, value) -> ( + return(list ~ value != null); +); + +debug(msg) -> ( + logger('debug', msg); + return(); +); + +require_not_null(value) -> ( + if(value == null, throw('空指针异常!')); + return(value); +); + +require_version(requirement) -> ( + req_0 = slice(requirement, 0, 1); + req_1 = slice(requirement, 1, 2); + if(req_0 == '>', + if(req_1 == '=', + req_ver = split('>=|\\.', requirement); + print(player('all'), req_ver); + cur_ver = split('\\.', global_carpet_version); + return(number(req_ver:1) >= number(cur_ver:0) + && number(req_ver:2) >= number(cur_ver:1) + && number(req_ver:3) >= number(cur_ver:2)); + ); + req_ver = split('>|\\.', requirement); + print(player('all'), req_ver); + cur_ver = split('\\.', global_carpet_version); + return(number(req_ver:1) > number(cur_ver:0) + && number(req_ver:2) > number(cur_ver:1) + && number(req_ver:3) > number(cur_ver:2)); + ); + if(req_0 == '<', + if(req_1 == '=', + req_ver = split('<=|\\.', requirement); + print(player('all'), req_ver); + cur_ver = split('\\.', global_carpet_version); + return(number(req_ver:1) <= number(cur_ver:0) + && number(req_ver:2) <= number(cur_ver:1) + && number(req_ver:3) <= number(cur_ver:2)); + ); + req_ver = split('<|\\.', requirement); + print(player('all'), req_ver); + cur_ver = split('\\.', global_carpet_version); + return(number(req_ver:1) < number(cur_ver:0) + && number(req_ver:2) < number(cur_ver:1) + && number(req_ver:3) < number(cur_ver:2)); + ); + return(false); +); + +//** 主要逻辑 **// + +global_app_name = system_info('app_name'); +global_app_version = '1.1-beta.1'; +global_carpet_version = split('\\+', system_info('scarpet_version')):0; global_current_scoreboard_list = [ 'fzsd.module.scoreboard.display.activation', 'fzsd.module.scoreboard.display.damage_taken', @@ -14,13 +73,12 @@ global_current_scoreboard_list = [ 'fzsd.module.scoreboard.display.aviating_distance', 'fzsd.module.scoreboard.display.placement_count' ]; -global_app_name = system_info('app_name'); __config() -> { 'scope' -> 'global', 'requires' -> { 'carpet' -> '>=1.4.45', - 'minecraft' -> '>=1.17' + 'minecraft' -> '>=1.18' }, 'command_permission' -> 2, 'commands' -> { @@ -34,8 +92,8 @@ __config() -> { 'restore player ' -> 'command_restore', 'restore whitelist ' -> _(custom, trade_count) -> command_restore_trade_count_confirm(custom, null, trade_count), 'restore player ' -> 'command_restore_trade_count_confirm', - 'recalculate ' -> 'recalculate_total_score', - 'recalculate' -> ['recalculate_total_score', null], + 'recalculate ' -> 'command_recalculate_total_score', + 'recalculate' -> ['command_recalculate_total_score', null], 'commandPlayer ' -> 'carpet_command_player', 'reset ' -> 'command_reset', 'reset ' -> ['command_reset', null], @@ -87,6 +145,22 @@ __config() -> { }; __on_start() -> ( + // 读取配置文件 + global_config = read_file('config', 'json'); + if(global_config == null, // carpet 1.4.69 兼容 + global_config = {}; + ); + if(length(global_config) == 0, // 读取失败或不存在 + delete_file('config', 'json'); // 避免一些意外的问题 + global_config:'config_version' = '1.0.0'; // 占位用,无实际作用 + if(require_version('>=1.99.99'), // 等待新功能支持 + global_config:'allow_spawn_whitelist_player' = false; + write_file('config', 'json', global_config); + , + // else + write_file('config', 'json', global_config); + ); + ); global_team_cache = read_file('team_cache', 'json'); if(global_team_cache == null, // carpet 1.4.69 兼容 global_team_cache = {}; @@ -99,6 +173,17 @@ __on_close() -> ( write_file('team_cache', 'json', global_team_cache); ); +if(require_version('>=1.99.99'), // 等待新功能支持 + __on_player_command(player, message) -> ( + print(player('all'), 'command!'); + if(length(message) > 7 + && slice(message, 0, 7) == '/player' + && !(global_config:'allow_spawn_whitelist_player'), + return('cancel'); + ); + ); +); + __on_player_connects(player) -> ( player_type = player ~ 'player_type'; player_team = player ~ 'team'; @@ -156,12 +241,12 @@ command_reset(player, scoreboard) -> ( for(scoreboard(), scoreboard_remove(_, player); ); - recalculate_total_score(null); + command_recalculate_total_score(null); print('已重置' + player + '的所有分数'); return(); ); scoreboard_remove(scoreboard, player); - recalculate_total_score(scoreboard); + command_recalculate_total_score(scoreboard); print('已重置' + player + '的' + scoreboard + '分数'); return(); ); @@ -269,7 +354,7 @@ command_update(fzsd_version) -> ( print('参数错误!'); return(); ); - recalculate_total_score(null); + command_recalculate_total_score(null); print('已从' + fzsd_version + '升级!'); return(); ); @@ -357,9 +442,9 @@ get_total_score_name_new(scoreboard) -> ( ); // 重算总分,scoreboard == null 时重算所有总分 -recalculate_total_score(scoreboard) -> ( +command_recalculate_total_score(scoreboard) -> ( if(scoreboard == null, - for(global_current_scoreboard_list, recalculate_total_score(_)); + for(global_current_scoreboard_list, command_recalculate_total_score(_)); return(); ); total_score_name_new = get_total_score_name_new(scoreboard); @@ -503,7 +588,7 @@ restore_score(player_name, scoreboard) -> ( print('未识别的计分板ID!' + scoreboard); return(false); ); - recalculate_total_score(scoreboard); + command_recalculate_total_score(scoreboard); if(player_is_offline, world_spawn = system_info('world_spawn_point'); run('spreadplayers ' + world_spawn:0 + ' ' + world_spawn:2 + ' 0 10 false ' + player); @@ -548,22 +633,6 @@ carpet_command_player(level) -> ( command_set(player, scoreboard, score) -> ( i = scoreboard(scoreboard, player, score); print('玩家' + player + '修改前的分数为:' + i); - recalculate_total_score(scoreboard); + command_recalculate_total_score(scoreboard); return(i); ); - -// 工具函数 - -contains(list, value) -> ( - return(list ~ value != null); -); - -debug(msg) -> ( - logger('debug', msg); - return(); -); - -require_not_null(value) -> ( - if(value == null, throw('空指针异常!')); - return(value); -); \ No newline at end of file