更新一下census

This commit is contained in:
shenjack 2022-05-11 12:13:29 +00:00 committed by Gitee
parent 4befe7ba98
commit 7500264600
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -1,10 +1,10 @@
// by shenjack // by shenjack
// write at carpet 1.16.5 1.4.31 v210407 // write at carpet 1.16.5 1.4.44
// with carpet-extra-1.16.5-1.4.30 // with carpet-extra-1.16.5-1.4.30
// with carpet-tis-addition-mc1.16.4-1.15.0+build.492 // with carpet-tis-addition-mc1.16.4-1.15.0+build.492
// with fabric-api-0.26.0+1.16 (because on server Api Version > 0.26 will cause bug) // with fabric-api-0.26.0+1.16 (because on server Api Version > 0.26 will cause bug)
global_version = '1.2.0'; global_version = '1.3.2';
global_carpet_version = split('\\+v',system_info('scarpet_version')); global_carpet_version = split('\\+v',system_info('scarpet_version'));
global_require_carpet_version = ['1.4.30', 210407]; global_require_carpet_version = ['1.4.30', 210407];
global_filename = system_info('app_name'); global_filename = system_info('app_name');
@ -29,23 +29,23 @@ __config() -> {
'legacy_command_type_support' -> true, 'legacy_command_type_support' -> true,
'requires' -> { 'requires' -> {
'minecraft' -> '>=1.16', // best at 1.16+ haven't test in 1.15.2 and 1.14.4 'minecraft' -> '>=1.16', // best at 1.16+ haven't test in 1.15.2 and 1.14.4
'fabric-api' -> '>=0.26.0', // for some reason api left in 0.26.0
'carpet' -> '>=1.4.31' // best at 1.4.31 because fix issue of read_file() 'carpet' -> '>=1.4.31' // best at 1.4.31 because fix issue of read_file()
}, },
'commands' -> { 'commands' -> {
'' -> 'help', '' -> 'help',
'help' -> 'help', 'help' -> 'help',
'print' -> ['print_score', 'mined'],
'reload' -> 'reload_script', 'reload' -> 'reload_script',
'score load' -> 'load_scores', 'score load' -> 'load_scores',
'score save' -> 'save_scores', 'score save' -> 'save_scores',
'score print' -> 'print_scores', 'score print' -> ['print_score', 'mined'],
'debug level' -> ['debug_level', null], 'debug level' -> ['debug_level', null],
'debug level <debug_level>' -> 'debug_level', 'debug level <debug_level>' -> 'debug_level',
'debug add_mine <player> <block>' -> 'add_mine', 'debug add_mine <player> <block>' -> 'add_mine',
}, },
'arguments' -> { 'arguments' -> {
'player' -> { 'player' -> {
'type' -> 'players' 'type' -> 'players',
}, },
'block' -> { 'block' -> {
'type' -> 'string', 'type' -> 'string',
@ -59,6 +59,51 @@ __config() -> {
}; };
}; };
// import('lib', 'callme');
help_message = {
'name': 'census',
'version': global_version,
'information': 'census 是一个用于统计玩家各类数据的 script',
'commands': {
'info': '同 /{app_name} help 显示帮助信息',
'hint': '然而并没有什么隐藏信息(确信)',
'run': '{app_name} help',
'sub_command': {
'help': {
'info': '显示你现在在看的这条帮助信息!',
'hint': 'g 你就在看着我呢~',
'run': '{command}',
},
'reload': {
'info': '重新加载script',
'hint': 'g 获得成就:我重载我自己',
'run': '{command}',
},
'score': {
'sub_command': {
'load': {
'info': '从数据文件夹中加载数据并覆盖现有数据',
'hint': 'rub 本操作会覆盖现有数据,所以请自行输入命令',
'copy': '{command}'
},
'save': {
'info': '保存现有数据',
'hint': 'ub 提醒:这个操作会覆盖文件数据(虽说其实没啥事)',
'run': '{command}',
},
'print': {
'info': '打印分数',
'hint': '获得成就:我打印了分数',
'run': '{command}',
}
}
}
}
}
};
__on_close() -> ( __on_close() -> (
// 保存一些debug信息 // 保存一些debug信息
debug_info = {'debug_level' -> global_debug_level}; debug_info = {'debug_level' -> global_debug_level};
@ -70,7 +115,7 @@ __on_close() -> (
printl(message, level = 2, say = false, reply = true) -> ( printl(message, level = 2, say = false, reply = true) -> (
if(global_debug_level <= level, if(global_debug_level <= level,
if(reply, print(message)); if(reply, print(message));
if(say, run('say' + message))); if(say, run('say ' + message)));
); );
debug_level(level) -> ( debug_level(level) -> (
@ -82,18 +127,26 @@ debug_level(level) -> (
logger(type = 'info', 'DEBUG等级已经设置为: ' + global_debug_level); logger(type = 'info', 'DEBUG等级已经设置为: ' + global_debug_level);
); );
// fmt_cmd(cmd, msg, hint, do = false) -> (
// if(do,
// command = '!/' + global_filename + cmd,
// command = '/' + global_filename + cmd);
// return(command);
// );
gloal_help_config = {};
help() -> ( help() -> (
print(format('y ' + '-'*10 + '帮助信息' + '-'*10)); print(format('y ' + '-'*10 + '帮助信息' + '-'*10));
print(format('m 提醒:大部分信息都可以点击来执行相对应的命令,所以请小心点击', '^g 包括我! 点我来执行 /' + global_filename, '! /' + global_filename)); print(format('m 提醒:大部分信息都可以点击来执行相对应的命令,所以请小心点击', '^g 包括我! 点我来执行 /' + global_filename, '!/' + global_filename));
print(format('e /' + global_filename + ' -> ', 'c 同 /' + global_filename + ' help')); print(format('e /' + global_filename + ' -> ', 'c 同 /' + global_filename + ' help'));
print(format('e /' + global_filename + ' help -> ', 'c 显示这条帮助信息', '^g 你就在看着我呢!', '! /' + global_filename + ' help')); print(format('e /' + global_filename + ' help -> ', 'c 显示这条帮助信息', '^g 你就在看着我呢!', '!/' + global_filename + ' help'));
print(format('e /' + global_filename + ' reload -> ', 'c 重新加载script', '^g 获得成就:我重载我自己', '! /' + global_filename + ' reload')); print(format('e /' + global_filename + ' reload -> ', 'c 重新加载script', '^g 获得成就:我重载我自己', '!/' + global_filename + ' reload'));
print(format('e /' + global_filename + ' score load -> ', 'c 加载各项榜单', '^rub 警告:这会覆盖游戏内的现有数据(所以请自行输入命令)')); print(format('e /' + global_filename + ' score load -> ', 'c 加载各项榜单', '^rub 警告:这会覆盖游戏内的现有数据(所以请自行输入命令)'));
print(format('e /' + global_filename + ' score save -> ', 'c 保存各项榜单', '^ub 提醒:这会覆盖文件数据', '! /' + global_filename + ' score save')); print(format('e /' + global_filename + ' score save -> ', 'c 保存各项榜单', '^ub 提醒:这会覆盖文件数据', '!/' + global_filename + ' score save'));
print(format('e /' + global_filename + ' score print -> ', 'c 输出各项榜单数据', '^gs 吐槽一下,scarpet的字符串处理真的麻烦死了', '! /' + global_filename + ' score print')); print(format('e /' + global_filename + ' score print -> ', 'c 输出各项榜单数据', '^gs 吐槽一下,scarpet的字符串处理真的麻烦死了', '!/' + global_filename + ' score print'));
print(format('e /' + global_filename + ' debug level -> ', 'c 显示DEBUG信息等级', '^g (没啥可吐槽的)', '! /' + global_filename + ' debug level')); print(format('e /' + global_filename + ' debug level -> ', 'c 显示DEBUG信息等级', '^g (没啥可吐槽的)', '!/' + global_filename + ' debug level'));
print(format('e /' + global_filename + ' debug level <debug_level> -> ', 'c 设置DEBUG信息等级为<debug_level> ', '^g <debug_level> 为 0-4的正整数,默认为2', '?/' + global_filename + ' debug level ')); print(format('e /' + global_filename + ' debug level <debug_level> -> ', 'c 设置DEBUG信息等级为<debug_level> ', '^g <debug_level> 为 0-4的正整数,默认为2', '?/' + global_filename + ' debug level '));
// print(format('e /' + global_filename + ' xxx -> ', 'c xxx', '^g xxx', '! /' + global_filename + ' xxx'));
print(format('y [系统信息]' + global_filename + ' 版本: ' + global_version)); print(format('y [系统信息]' + global_filename + ' 版本: ' + global_version));
print(format('y [系统信息]' + global_filename + ' 文件名: ' + global_filename)); print(format('y [系统信息]' + global_filename + ' 文件名: ' + global_filename));
print(format('y [插件信息]' + global_filename + ' 数据存储路径: ' + global_score_path)); print(format('y [插件信息]' + global_filename + ' 数据存储路径: ' + global_score_path));
@ -101,6 +154,7 @@ help() -> (
); );
reload_script() -> ( reload_script() -> (
save_scores();
print('script ' + global_filename + ' 重载中···'); print('script ' + global_filename + ' 重载中···');
run(str('script load ' + global_filename)); run(str('script load ' + global_filename));
); );
@ -117,7 +171,7 @@ load_scores() -> (
printl(data + '\n\n' + _, 1, false, true)); // DEBUG 输出 printl(data + '\n\n' + _, 1, false, true)); // DEBUG 输出
); );
print_scores() -> ( score_print(type) -> (
// 目前只会输出挖掘榜 // 目前只会输出挖掘榜
printl(global_score, 0, false, true); printl(global_score, 0, false, true);
print('§7' + '-'*10 + '挖掘榜' + '-'*10); // 输出标题 print('§7' + '-'*10 + '挖掘榜' + '-'*10); // 输出标题
@ -125,9 +179,11 @@ print_scores() -> (
max_len = 1; max_len = 1;
// 初始化两个数据 // 初始化两个数据
for(global_score, for(global_score,
if(global_score:_:'mined':'total' == null || global_score:_:'mined':'total' == '0',
continue(););
max_len = max(max_len, length(_)); max_len = max(max_len, length(_));
// 如果这个名字的长度大于之前的就把最大长度换成这个名字的 // 如果这个名字的长度大于之前的就把最大长度换成这个名字的
put(mine, 0, [_, global_score:_:'mine':'total'], 'insert')); put(mine, 0, [_, global_score:_:'mined':'total'], 'insert'));
// 把所有的数据加到mine里备用等待排序 // 把所有的数据加到mine里备用等待排序
mine = sort_key(mine, -_:1); // 根据每个挖掘数据的挖掘量进行排序(排序用的分数是挖掘量的倒数,这样可以倒序排列) mine = sort_key(mine, -_:1); // 根据每个挖掘数据的挖掘量进行排序(排序用的分数是挖掘量的倒数,这样可以倒序排列)
printl(mine, 1, false, true); printl(mine, 1, false, true);
@ -137,6 +193,16 @@ print_scores() -> (
); );
print_score(type) -> (
// 输出指定类型的榜单
mapper = {
'mined' -> '挖掘',
'killed' -> '击杀'
};
maped_type = mapper:type;
task_thread('temp', 'score_print', type);
);
save_scores() -> ( save_scores() -> (
print('计分数据保存中'); print('计分数据保存中');
for(global_score, for(global_score,
@ -146,7 +212,7 @@ save_scores() -> (
); );
make_player_score(player) -> ( make_player_score(player) -> (
score = {'mine'-> {'total'-> 0}, score = {'mined'-> {'total'-> 0},
'kill'-> {}}; // 基本信息 'kill'-> {}}; // 基本信息
put(global_score, player, score); // 加到列表里 put(global_score, player, score); // 加到列表里
); );
@ -166,21 +232,21 @@ __on_player_breaks_block(player, block) -> (
add_mine(player, block) -> ( add_mine(player, block) -> (
block = str(block); block = str(block);
splayer = player ~ 'name'; splayer = query(player, 'name');
if(!player(splayer), if(!player(splayer),
return()); return());
// 如果玩家列表里没有输入的玩家就返回 // 如果玩家列表里没有输入的玩家就返回
if(!has(global_score:splayer), if(!has(global_score:splayer),
make_player_score(splayer)); make_player_score(splayer));
// 如果榜单里没有玩家就加入玩家的榜单 // 如果榜单里没有玩家就加入玩家的榜单
if(!has(global_score:splayer:'mine', block), if(!has(global_score:splayer:'mined', block),
put(global_score:splayer:'mine':block, 1), put(global_score:splayer:'mined':block, 1),
// 如果玩家的记录里没有这个方块就把这个方块加到挖掘列表里 // 如果玩家的记录里没有这个方块就把这个方块加到挖掘列表里
score = get(global_score:splayer:'mine':block); score = get(global_score:splayer:'mined':block);
put(global_score:splayer:'mine':block, score + 1)); put(global_score:splayer:'mined':block, score + 1));
// 如果记录里有就 += 1 // 如果记录里有就 += 1
full_score = get(global_score:splayer:'mine':'total'); full_score = get(global_score:splayer:'mined':'total');
put(global_score:splayer:'mine':'total', full_score + 1); put(global_score:splayer:'mined':'total', full_score + 1);
// print(global_score); // print(global_score);
); );