-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbc_gender.llse.js
executable file
·189 lines (172 loc) · 6.3 KB
/
bc_gender.llse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// LiteLoader-AIDS automatic generated
/// <reference path="d:\mc_bds\bds_api/dts/helperlib/src/index.d.ts"/>
// 基础信息sql
const { sqlite } = require('./api/yoyoSqlite-2.0.5');
var table_name = 'gender'
mc.listen("onServerStarted", () => {
colorLog("blue", "————————————————————————————————————————————————————")
colorLog("pink", "plugin_name:", language.plugin_name)
colorLog("green", "author:", "banchen")
colorLog("green", "Mail:", "[email protected]")
colorLog("green", "QQ:", "738270843")
colorLog("green", "language:", language.language)
createTable()
setup_com()
colorLog("blue", "————————————————————————————————————————————————————")
})
function createTable() {
/* 多个参数的时候你可以传对象 */
var isSetConfig = sqlite.connectDb({
path: '.\\plugins\\bc\\data\\player.db',
create: true,/* 不存在是否自动创建 */
});
let sql = sqlite.createTable(table_name, {
realName: {
type: 'TEXT',//字段类型
unique: true//是否保持唯一值
},
gender: {
type: 'INTEGER',//字段类型
default: 'INTEGER DEFAULT 0 not null'
}
});
colorLog("yellow", 'Initialize table:', sql ? 'OK' : 'NOT');
}
var config = new JsonConfigFile('.\\plugins\\bc\\gender\\gender_config.json')
config.init("language", "zh_CN")
const config_language_json = data.openConfig(`.\\plugins\\bc\\gender\\${config.get("language")}.json`, "json", JSON.stringify({
plugin_name: "性别模块",
boy: "男",
girl: "女",
setok: "设置成功",
setno: "设置失败",
}));
const language = {
language: config.get("language"),
plugin_name: config_language_json.get("plugin_name"),
boy: config_language_json.get("boy"),
girl: config_language_json.get("girl"),
setok: config_language_json.get("setok"),
setno: config_language_json.get("setno"),
}
mc.listen("onJoin", (pl) => {
init_pl_data(pl.realName)
})
function init_pl_data(realName) {
try {
const randomNumber = Math.floor(Math.random() * 2);
var result = sqlite.table(table_name)
.field(['realName', 'gender'])
.insert([realName, randomNumber]);
} catch {
}
}
//获取玩家性别-realName
function getplayerrealName_gender(realName) {
var result = sqlite.table(table_name)//需要操作的完整表名
.where('realName', realName)//获取你可以添加一些条件 (id = 1)
.find();//查询一条数据
return result.gender;
}
function tellpl(pl, msg) {
pl.tell(`【${language.plugin_name}】${msg}`)
}
function setup_com() {
let cmd = mc.newCommand("gender", language.plugin_name)
cmd.setAlias("gd")
cmd.setEnum("ChangeAction", ["set", "random"]);
cmd.mandatory("action", ParamType.Enum, "ChangeAction", 1);
cmd.mandatory("playarr", ParamType.Player);
cmd.mandatory("number", ParamType.Int);
cmd.overload(["ChangeAction", "playarr", "number"]);
cmd.overload(["ChangeAction", "playarr"]);
cmd.setCallback((_cmd, _ori, out, res) => {
switch (res.action) {
case "set":
const isupdateset = updategender_arr(res.playarr, res.number)
const msgset = isupdateset ? language.setok : language.setno;
return out.success(msgset)
case "random":
const isupdaterandom = randomupdate(res.playarr)
const msgrandom = isupdaterandom ? language.setok : language.setno;
return out.success(msgrandom)
}
});
cmd.setup();
}
function randomupdate(playarr) {
return updategender_arr(playarr, null)
}
function updategender_arr(playarr, number) {
if (number == 0 || number == 1) {
playarr.forEach((pl, id) => {
var result = sqlite.table(table_name)//需要操作的完整表名
.where('realName', pl.realName)//获取你可以添加一些条件 (id = 1)
.update({
gender: number,
});
})
return true;
} else if (number == null) {
playarr.forEach((pl, id) => {
const randomNumber = Math.floor(Math.random() * 2);
var result = sqlite.table(table_name)//需要操作的完整表名
.where('realName', pl.realName)//获取你可以添加一些条件 (id = 1)
.update({
gender: randomNumber,
});
})
return true;
}
return false;
}
function update_pl_gender(player, number) {
if (number == 0 || number == 1) {
var result = sqlite.table(table_name)//需要操作的完整表名
.where('realName', player.realName)//获取你可以添加一些条件 (id = 1)
.update({
gender: number,
});
return true;
} else if (number == null) {
const randomNumber = Math.floor(Math.random() * 2);
var result = sqlite.table(table_name)//需要操作的完整表名
.where('realName', pl.realName)//获取你可以添加一些条件 (id = 1)
.update({
gender: randomNumber,
});
return true;
}
return false;
}
class gender {
/**
*
* @param {数组化的玩家} playarr
* @param {性别} number
* @returns 布尔值
*/
static update_players_gender(playarr, number){
return updategender_arr(playarr, number)
}
/**
*
* @param {单个玩家} player
* @param {性别} number
* @returns 布尔值
*/
static update_player_gender(player, number){
return update_pl_gender(player, number)
}
/**
*
* @param {单个玩家} player
* @returns 0|1
*/
static getplayerrealName_gender(player){
return getplayerrealName_gender(player.realName)
}
}
module.exports = {
gender
};