-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbot.js
1052 lines (953 loc) · 37.5 KB
/
bot.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const mineflayer = require('mineflayer')
const inventoryViewer = require('mineflayer-web-inventory')
const { pathfinder, Movements, goals: { GoalNear, GoalFollow, GoalBlock } } = require('mineflayer-pathfinder')
const pvp = require('mineflayer-pvp').plugin
const tpsPlugin = require('mineflayer-tps')(mineflayer)
const armorManager = require('mineflayer-armor-manager')
const collectBlock = require('mineflayer-collectblock').plugin
const autoeat = require('mineflayer-auto-eat').plugin
const rlsync = require('readline-sync')
let bacctype = rlsync.question(`Auth: `)
let bauth, bname, bpass;
if (bacctype === 'mojang') {
bauth = 'mojang';
bname = rlsync.question(`Email: `)
bpass = rlsync.question('Password: ');
} else if (bacctype === 'microsoft') {
bauth = 'microsoft';
bname = rlsync.question(`Email: `)
bpass = rlsync.question('Password: ');
} else {
bauth = 'offline';
bname = rlsync.question(`Name: `)
bpass = '';
}
let bip = rlsync.question(`Server: `)
let bver = rlsync.question(`Version: `)
let ip = bip.split(':');
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})
const opn = require('opn');
const path = require('path');
const options = {
username: bname,
host: ip[0],
port: ip[1],
version: bver,
auth: bauth,
password: bpass
}
createbot()
clientlog(`Dùng \x1b[38;2;38;88;252m.help\x1b[0m để hiển thị toàn bộ command`)
function createbot() {
const bot = mineflayer.createBot(options)
console.log(options)
bot.on('login', () => {
clientlog(`\x1b[38;2;252;246;50m${options.username} login in ${options.host}:${options.port}\x1b[0m`)
process.title = `${options.username} @ ${options.host}:${options.port}`
bot.on('message', (message) => clientlog(message.toAnsi()));
})
bot.on('spawn', () => {
const mcData = require('minecraft-data')(bot.version);
movements = new Movements(bot, mcData);
bot.pathfinder.setMovements(movements)
})
bot.loadPlugin(pathfinder)
bot.loadPlugin(pvp)
bot.loadPlugin(tpsPlugin)
bot.loadPlugin(armorManager)
bot.loadPlugin(collectBlock)
bot.loadPlugin(autoeat)
bot.armorManager.equipAll()
let invoptions = {
port: 4000,
}
inventoryViewer(bot, invoptions)
rl.on('line', (command) => {
let arg = command.split(' ')
let cmd = arg[0]
if (cmd.startsWith('.')) {
switch(cmd) {
case '.help':
const cguis = [
{
usage: ".help",
description: "Hiển thị danh sách lệnh"
},
{
usage: ".clear || .cls",
description: "Xóa màn hình console."
},
{
usage: ".meslog",
description: "Lọc tin nhắn và chat."
},
];
const cchats = [
{
usage: ".chat | .send | .say <message>",
description: "Gửi tin nhắn đến máy chủ"
},
{
usage: ".cmd | .command <command>",
description: "Gửi lệnh đến máy chủ mà không cần /"
},
{
usage: `.spam "<text>" <delay> <time> <antispamtype:length:customechars(optional)`,
description: "Spam gì đó vào đến máy chủ"
}
];
const cbotinfos = [
{
usage: ".coord | .coordinates",
description: "Gửi tin nhắn đến máy chủ"
},
{
usage: ".inv | .inventory",
description: "Hiển thị toàn bộ đồ của bot."
},
{
usage: ".item | .items",
description: "Hiển thị item trong túi đồ của bot."
},
{
usage: ".itemslot <slot> (1-44)",
description: "Hiển thị thông tin chi tiết của item trong slot được nhập."
},
{
usage: ".webinv | .showinv | .invsee",
description: "Hiển thị kho đồ trong túi đồ của bot trên web."
},
{
usage: ".server",
description: "Hiển thị thông tin về máy chủ."
},
{
usage: ".player | .players",
description: "Liệt kê tất cả người chơi đang online."
},
{
usage: ".playerinfo",
description: "Hiển thị thông tin chi tiết về một người chơi cụ thể."
},
{
usage: ".nbtitems",
description: "Hiển thị thông tin chi tiết của toàn bộ item trong inventory."
},
{
usage: ".nbtslot <slot> (1-44)",
description: ".Hiển thị thông tin chi tiết của slot chỉ định trong inventory."
},
{
usage: ".idslot",
description: "Hiển thị slot id."
},
{
usage: ".itemslot <slot>",
description: "Hiển thị thông tin slot."
},
];
const cmoments = [
{
usage: ".goto <player> <postion>",
description: "Di chuyển đến vị trí hoặc người chơi được chỉ định."
},
{
usage: ".stopgoto",
destination: "Dừng đi đến vị trí hoặc người chơi."
},
{
usage: ".follow <player>",
description: "Đi theo một người chơi khác trên máy chủ."
},
{
usage: ".unfollow",
description: "Thoát khỏi chế độ đi theo người chơi."
},
{
usage: ".fight <player>",
description: "PVP với một người chơi khác trên máy chủ."
},
{
usage: ".stopfight",
description: "Dừng PVP."
},
{
usage: ".sneak",
description: "Bật chế độ lén bước."
},
{
usage: ".unsneak",
description: "Tắt chế độ lén bước."
},
{
usage: ".jump",
description: "Nhảy lên."
},
{
usage: ".move",
description: "TODO."
},
{
usage: ".forcemove <Direction:forward|back|left|right> <duration>",
description: "Di chuyển."
},
{
usage: ".stopmove",
description: "Dừng di chuyển."
},
{
usage: ".hand | .hands | .handslot <1-8>",
description: "Chuyển hotbar được cầm."
},
{
usage: ".equip",
description: "Equip item trong túi đồ vào các vị trí như tay, đầu, thân thể,..."
},
{
usage: ".unequip",
description: "Tháo item khỏi các vị trí: đầu, thân thể,..."
},
{
usage: ".afk",
description: "Tự động di chuyển để tránh bị kick ra khi không hoạt động."
},
{
usage: ".stopafk",
description: "Dừng chế độ tự động đi lại."
},
{
usage: ".eat (Lỗi)",
description: "Cho bot tự ăn thức ăn."
},
{
usage: ".stopeat (Lỗi)",
description: "Dừng cho bot tự ăn thức ăn."
},
{
usage: ".guard (Chưa test)",
description: "Bảo vệ một khu vực (di chuyển và tấn công)."
},
{
usage: ".stopguard (Chưa test)",
description: "Dừng chế độ bảo vệ khu vực."
},
{
usage: ".mine (Chưa hoàn thiện)",
description: "Đào block."
},
{
usage: ".dropslot <slot> (1-44)",
description: "Vứt slot chỉ định trong inventory."
},
{
usage: ".dropall",
description: "Đang lỗi chưa tìm đc cách fix."
},
{
usage: ".login",
description: "Đổi tên cho bot."
},
{
usage: ".conn | .connect <ip:port> <version>",
description: "Cho bot vào server."
},
{
usage: ".disco | .disconnect",
description: "Cho bot rời server."
},
{
usage: ".reco | .reconnect",
description: "Cho bot vào lại server."
},
{
usage: ".exit | .quit | .leave",
description: "Cho bot rời server và thoát khỏi chương trình."
}
];
const ccreatives = [
{
usage: ".fly",
description: "Cho bot bay trong creative."
},
{
usage: ".stopfly",
description: "Cho bot không bay trong creative."
},
{
usage: ".setinvslot",
description: "Chx xg."
},
{
usage: ".clearslot <slot>",
description: "Xóa 1 ô đồ trong chế độ creative."
},
{
usage: ".clearinv | .clearinventory",
description: "Xóa 1 ô đồ trong chế độ creative."
}
]
clientlog("\x1b[38;2;222;128;40mDanh sách lệnh của bot:\x1b[0m");
clientlog(`\x1b[38;2;252;196;40mGui command:\x1b[0m`)
cguis.forEach(cgui => {
clientlog(`\x1b[38;2;71;242;48m${cgui.usage}\x1b[0m - ${cgui.description}`);
});
clientlog(`\x1b[38;2;252;196;40mChat command:\x1b[0m`)
cchats.forEach(cchat => {
clientlog(`\x1b[38;2;71;242;48m${cchat.usage}\x1b[0m - ${cchat.description}`);
});
clientlog(`\x1b[38;2;252;196;40mBot info command:\x1b[0m`)
cbotinfos.forEach(cbotinfo => {
clientlog(`\x1b[38;2;71;242;48m${cbotinfo.usage}\x1b[0m - ${cbotinfo.description}`);
});
clientlog(`\x1b[38;2;252;196;40mMoment command:\x1b[0m`)
cmoments.forEach(cmoment => {
clientlog(`\x1b[38;2;71;242;48m${cmoment.usage}\x1b[0m - ${cmoment.description}`);
});
clientlog(`\x1b[38;2;252;196;40mCreative command:\x1b[0m`)
ccreatives.forEach(ccreative => {
clientlog(`\x1b[38;2;71;242;48m${ccreative.usage}\x1b[0m - ${ccreative.description}`);
});
break;
case '.chat':
case '.send':
case '.say':
if (!arg[1]) {
clientlog('Chat must be need arguments')
}
bot.chat(arg[1].substring())
break;
case '.cmd':
case '.command':
if (!arg[1]) {
clientlog('Command must be need arguments')
}
bot.chat('/'+arg[1].substring())
break;
case '.spam':
let args = command.split(/ (?=(?:(?:[^"]*"){2})*[^"]*$)/);
if (args.length < 3) {
clientlog(`Usage: .spam "<text>" <delay> <time> <antispamtype:length:customechars(optional)`)
clientlog(`Anti spam type:all | number | letter | capitalize | lowercase | custom`)
return
}
let text = command.match(/"([^"]+)"/)[1];
let delay = parseInt(args[2]) * 1000
let time = parseInt(args[3]) * 1000
let antispam = args[4]
let prefix = (args[5] ?? '').split(':')
let randomChar = (chars) => chars[Math.floor(Math.random() * chars.length)]
let aspam, length, chars, left, right
if (antispam) {
aspam = antispam.split(':')
length = parseInt(aspam[1])
switch (aspam[0]) {
case 'all':
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+";
break
case 'number':
chars = "0123456789";
break
case 'letter':
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
break
case 'capitalize':
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
break
case 'lowercase':
chars = "abcdefghijklmnopqrstuvwxyz";
break
case 'custom':
chars = aspam[2]
break
default:
chars = "";
}
left = prefix[0] || '';
right = prefix[1] || '';
} else {
length = 0
left = ""
right = ""
}
function randomString(length, chars) {
let result = "";
for (let i = 0; i < length; i++) {
result += randomChar(chars);
}
return result
}
function spam() {
clientlog(`Bắt đầu spam "${text}" cách ${delay / 1000}s trong ${time/ 1000}s với antispam ${left} ${antispam} ${right}`);
intervalId = setInterval(() => {
let spam = `${text} ${left} ${randomString(length, chars)} ${right}`
bot.chat(spam)
}, delay);
setTimeout(() => {
clientlog('Kết thúc spam tin nhắn');
clearInterval(intervalId);
}, time + 1000);
}
spam();
break;
case '.stopspam':
if (intervalId) {
clearInterval(intervalId);
clientlog('Spamming stopped');
} else {
clientlog('No spamming in progress');
}
break;
case '.fly':
if (bot.player.gamemode != 1) {clientlog(`You need in creative to use`); return}
bot.creative.startFlying()
break;
case '.flyto':
if (bot.player.gamemode != 1) {clientlog(`You need in creative to use`); return}
bot.creative.flyTo(destination)
break
case '.stopfly':
if (bot.player.gamemode != 1) {clientlog(`You need in creative to use`); return}
bot.creative.stopFlying()
break;
case '.setinvslot': //unfinish
if (bot.player.gamemode != 1) {clientlog(`You need in creative to use`); return}
bot.creative.setInventorySlot(slot, item)
break;
case '.clearslot':
if (bot.player.gamemode != 1) {clientlog(`You need in creative to use`); return}
const cclearslot = arg[1]
bot.creative.clearSlot(cclearslot)
break;
case '.clearinv':
case '.clearinventory':
if (bot.player.gamemode != 1) {clientlog(`You need in creative to use`); return}
bot.creative.clearInventory()
break;
case '.coord':
case '.coordinates':
clientlog(`[Coordinates] ${bot.entity.position}`);
clientlog(`[World] ${bot.game.dimension}`);
break;
case '.info':
const worlds = bot.game.dimension
const world = worlds.split(':')
const worldname = world[1]
clientlog(`Health: ${bot.health} / Food: ${bot.food}`)
clientlog(`Oxygen: ${bot.oxygenLevel}`)
clientlog(`Coordinates: ${bot.entity.position} at ${worldname}`)
clientlog(`Spawn point: ${bot.spawnPoint}`)
clientlog(`Gamemode: ${bot.game.gameMode} (${bot.player.gamemode})`)
break;
case '.clear':
case '.cls':
console.clear()
clientlog(`\x1b[38;2;45;255;25mSuccessful clear\x1b[0m`)
break;
case '.inv':
case '.inventory':
clientlog(` BOT INVENTORY `)
clientlog(`| Slot | Slot Name | Name | Count | id_item |`)
clientlog(`=======================================================================================`)
const slots = bot.inventory.slots;
slots.forEach((item, index) => {
if (item) {
let slotName = '';
if (item.slot >= 36 && item.slot <= 44) {
slotName = `Hotbar ${item.slot - 35}`;
} else if (item.slot === 45) {
slotName = 'Off Hand';
}else if (item.slot === 5) {
slotName = 'Helmet';
}else if (item.slot === 6) {
slotName = 'Chestplate';
}else if (item.slot === 7) {
slotName = 'Leggings';
}else if (item.slot === 8) {
slotName = 'Boots';
} else if (item.slot >= 9 && item.slot <= 35) {
slotName = `Container ${item.slot - 8}`;
} else {
slotName = `Slot ${item.slot}`;
}
clientlog(`| ${item.slot.toString().padEnd(4)} | ${slotName.padEnd(12)} | ${item.displayName.padEnd(25)} | ${item.count.toString().padEnd(2)}/${item.stackSize.toString().padEnd(2)} | ${item.name.padEnd(25)} |`);
} else {
let slotName = '';
if (index >= 36 && index <= 44) {
slotName = `Hotbar ${index - 35}`;
} else if (index === 45) {
slotName = 'Off Hand';
}else if (index === 5) {
slotName = 'Helmet';
}else if (index === 6) {
slotName = 'Chestplate';
}else if (index === 7) {
slotName = 'Leggings';
}else if (index === 8) {
slotName = 'Boots';
} else if (index >= 9 && index <= 35) {
slotName = `Container ${index - 8}`;
} else {
slotName = `Slot ${index}`;
}
clientlog(`| ${index.toString().padEnd(4)} | ${slotName.padEnd(12)} | Empty | null | empty |`);
}
});
break;
case '.itemslot':
const itemslot = arg[1];
if (itemslot >= 0 && itemslot < 45) {
if (bot.inventory.slots[itemslot]) {
const item = bot.inventory.slots[itemslot]
clientlog(`Slot: ${item.slot}`)
clientlog(`Name: ${item.displayName}`)
clientlog(`Id: ${item.name}`)
clientlog(`Count: ${item.count}`)
clientlog(`Stack size: ${item.stackSize}`)
clientlog(`Durability: ${item.durabilityUsed}`)
clientlog(`Enchants: ${JSON.stringify(item.enchants)}`)
clientlog(`Item type: ${item.type}`)
clientlog(`Custome name: ${item.customName}`)
clientlog(`Custome lore: ${item.customLore}`)
clientlog(`Meta data: ${item.metadata}`)
clientlog(`Repair cost: ${item.repairCost}`)
} else {
clientlog(`This slot is empty`);
}
} else {
clientlog(`Invalid slot number. Use .itemslot (0-44)`);
}
break;
case '.item':
case '.items':
clientlog(`All item in bot inventory:`)
for (const item of bot.inventory.items()) {
clientlog(`[Item] Slot ${item.slot.toString().padEnd(2)} : ${item.name} x ${item.count} Enchants:${JSON.stringify(item.enchants)}`); item.enchants
}
break;
case '.nbtslot':
const nbtslot = arg[1];
if (nbtslot >= 0 && nbtslot < 45) {
if (bot.inventory.slots[nbtslot]) {
console.log(bot.inventory.slots[nbtslot]);
} else {
clientlog(`This slot is empty`);
}
} else {
clientlog(`Invalid slot number. Use .nbtslot (0-44)`);
}
break;
case '.nbtitems':
console.log(bot.inventory.slots)
break;
case '.hand':
case '.hands':
case '.handslot':
if (!arg[1]) { clientlog(`Change quickbar slot must be need a slot`); clientlog(`Example: ${arg[0]} 3`); return }
if (arg[1] < 1 || arg[1] > 9) { clientlog('Slot available (1-9)'); return }
clientlog('Change hands to slot ' + arg[1])
let bquickbarchange = (arg[1] - 1)
bot.setQuickBarSlot(bquickbarchange)
break;
case '.equip':
bot.armorManager.equipAll()
break;
case '.unequip':
if (arg[1] == 'head' || arg[1] == 'torso' || arg[1] == 'legs' || arg[1] == 'feet' || arg[1] == 'off-hand' || arg[1] == 'all') {
if (arg[1] !== 'all') {
clientlog(`Unequip ${arg[1]}`)
bot.unequip(arg[1])
} else if (arg[1] = 'all') {
unequipall()
}
} else {
clientlog(`Unequip available ( head | torso | legs | feet | off-hand | all)`)
}
async function unequipall() {
await bot.unequip('head')
await bot.unequip('torso')
await bot.unequip('legs')
await bot.unequip('feet')
await bot.unequip('off-hand')
await clientlog(`Unequip all`)
}
break;
case '.webinv':
case '.showinv':
case '.invsee':
clientlog("Open web inventory in http://localhost:"+ invoptions.port)
clientlog(`Open invslot`)
opn("http://localhost:"+ invoptions.port)
opn("https://camo.githubusercontent.com/83196104a7c585ce3a0143662ee2a1ecf40084782d647df5a344bbd33e626b10/68747470733a2f2f77696b692e76672f696d616765732f312f31332f496e76656e746f72792d736c6f74732e706e67")
break;
case '.dropslot':
let slot = arg[1]
if (!slot) return
if (slot < 1 || slot > 44) {clientlog('Slot available (1-44)\n Use ".idslot" to see slot id'); return}
let dropslot = bot.inventory.slots[slot]
if (dropslot && dropslot.type !== -1) {
bot.tossStack(dropslot)
clientlog(`Drop slot ${slot}`)
} else {
clientlog(`Slot ${slot} is empty or invalid`)
}
break;
case '.dropall':
tossInventory(bot)
async function tossInventory(bot) {
const items = bot.inventory.items()
for (const item of items) {
await bot.tossStack(item)
}
}
break;
case '.idslot':
opn("https://camo.githubusercontent.com/83196104a7c585ce3a0143662ee2a1ecf40084782d647df5a344bbd33e626b10/68747470733a2f2f77696b692e76672f696d616765732f312f31332f496e76656e746f72792d736c6f74732e706e67")
break;
case '.fight':
let target = null
if (!arg[1]) {
if (username == console) { clientlog(username, 'Can\'t fight with Console'); return }
target = bot.players[username].entity
} else {
target = bot.players[arg[1]].entity
}
if (!target) { clientlog(username, 'Can\'t see' + target?.username); return }
clientlog('Start PVP with ' + target.username)
followattack(target)
bot.pvp.attack(target)
setTimeout(() => {
const sword = bot.inventory.items().find(item => item.name.includes('sword'))
if (sword) bot.equip(sword, 'hand')
}, 250)
break;
case '.stopfight':
stopfollowattack()
bot.pvp.stop()
break;
case '.server':
clientlog(`IP: ${options.host}:${options.port}`)
clientlog(`Ver: ${options.version}`)
clientlog(`TPS: ${bot.getTps()}`)
clientlog(`Difficulty: ${bot.game.difficulty}`)
clientlog(`Hardcore: ${bot.game.hardcore}`)
clientlog(`Maxplayer: ${bot.game.maxPlayers}`)
clientlog(`World tpye: ${bot.game.levelType}`)
break;
case '.tps':
clientlog('Server tps: ' + bot.getTps())
break;
case '.player':
case '.players':
const players = Object.keys(bot.players).map((name) => `\x1b[32m${name}(${bot.players[name].ping}ms)\x1b[0m`).join(' | ');
clientlog(`[Player List] ${players}`);
break;
case '.playerinfo':
if (arg.length < 2) {
clientlog('[Player Info] .playerinfo <player>\n[Player Info] Example: .playerinfo bot');
} else {
const target = arg[1];
if (!bot.players[target]) {
clientlog(`[Player Info] ${target} is not on the server`);
} else {
const playerinfo = `\x1b[32m${target}(${bot.players[target]?.ping}ms)\x1b[0m UUID: ${bot.players[target]?.uuid}`;
clientlog(`[Player Info] ${playerinfo}`);
}
}
break;
case '.sneak':
bot.setControlState('sneak', true);
clientlog(`${bot.username} start sneak`);
break;
case '.unsneak':
bot.setControlState('sneak', false);
clientlog(`${bot.username} stop sneak`);
break;
case '.jump':
bot.setControlState('jump', true);
setTimeout(() => {bot.setControlState('jump', false)}, 500);
clientlog(`[Bot] ${bot.username} jump`);
break;
case '.lookat':
let targetPos;
if (arg.length === 2) {
// Nếu người chơi nhập tọa độ, sử dụng nó
const [x, y, z] = arg[1].split(',');
targetPos = new Vec3(parseFloat(x), parseFloat(y), parseFloat(z));
} else if (arg.length === 3) {
// Nếu người chơi nhập tên người chơi, sử dụng tọa độ của người chơi
const targetPlayer = arg[1];
const player = bot.players[targetPlayer];
if (!player) {
clientlog(`Không tìm thấy người chơi '${targetPlayer}'`);
return;
}
targetPos = player.entity.position;
} else {
clientlog(`Usage: .lookat <x,y,z> | <player>`);
return;
}
bot.lookAt(targetPos);
clientlog(`Đang nhìn về phía ${targetPos}`);
break;
case '.look':
const yaw = arg[1]
const pitch = arg[2]
if (arg.length < 2 ) {
clientlog(`Usage: .look <yaw> <pitch>`);
return;
}
bot.look(yaw, pitch, [force])
clientlog(`Đang nhìn về hướng ${yaw} ${pitch}`)
break
case '.move':
break;
case '.forcemove':
if (arg[0] === '.forcemove') {
const direction = arg[1];
const duration =parseFloat(arg[2]);
if (direction && ['forward', 'back', 'left', 'right'].includes(direction) && !isNaN(duration) && duration > 0) {
clientlog(`Moving ${direction} for ${duration} seconds`);
const controlState = {
forward: false,
back: false,
left: false,
right: false
};
controlState[direction] = true;
bot.setControlState(direction, true);
setTimeout(() => {
bot.setControlState(direction, false);
clientlog(`Stopped moving ${direction}`);
}, duration * 1000);
} else {
clientlog('Usage: .forcemove <Direction:forward|back|left|right> <duration>');
}
}
break;
case '.stopmove':
bot.setControlState('forward', false)
bot.setControlState('back', false)
bot.setControlState('left', false)
bot.setControlState('right', false)
bot.setControlState('jump', false)
bot.setControlState('sprint', false)
break;
case '.goto':
if (arg.length < 2 ) {
clientlog(`Usage: ${cmd} <x> <y> <z> or <player>`);
return;
}
const x = parseFloat(arg[1]);
const y = parseFloat(arg[2]);
const z = parseFloat(arg[3]);
if (isNaN(x) || isNaN(y) || isNaN(z)) {
const targetPlayer = bot.players[arg[1]];
if (targetPlayer) {
const position = targetPlayer.entity.position;
clientlog(`Going to ${arg[1]}'s position: ${position.x.toFixed(2)}, ${position.y.toFixed(2)}, ${position.z.toFixed(2)}`);
bot.pathfinder.setGoal(new GoalNear(position.x, position.y, position.z, 0));
} else {
clientlog(`Can't find player: ${arg[1]}`);
}
} else {
clientlog(`Going to coordinates: ${x.toFixed(2)}, ${y.toFixed(2)}, ${z.toFixed(2)}`);
bot.pathfinder.setGoal(new GoalNear(x, y, z, 0));
}
break;
case '.stopgoto':
bot.pathfinder.setGoal(null);
clientlog(`Stopped goto`);
break;
case '.follow':
followplayer();
break;
case '.unfollow':
unfollowPlayer();
break;
case '.afk':
clientlog('[AFK] Starting anti-afk');
isAFK = true;
startAFK();
break;
case '.stopafk':
clientlog('[AFK] Stop anti-afk');
isAFK = false;
clearTimeout(afktimer);
break;
case '.eat':
clientlog(`Enable auto-eat`)
bot.autoEat.enable()
break;
case '.stopeat':
clientlog(`Disable auto-eat`)
bot.autoEat.disable()
break;
case '.guard':
const guardpos = bot.entity.position
guardArea(guardposition)
break;
case '.stopguard':
clientlog('Stop guarding...')
stopGuarding
break;
case '.meslog':
if (!arg[1]) {
clientlog(`Usage '.meslog + off / mes / chat / all'`);
break;
}
const logs = arg[1];
bot.removeAllListeners('message');
bot.removeAllListeners('chat');
switch (logs) {
case 'all':
clientlog('Show all');
bot.on('message', (message) => {
clientlog(message.toAnsi());
});
break;
case 'mes':
clientlog('Show message');
bot.on('message', (message, position) => {
if (position !== 'game_info') {
clientlog(message.toAnsi());
}
});
break;
case 'chat':
clientlog('Show chat');
bot.on('chat', (username, message) => {
clientlog(`<${username}> ${message}`);
});
break;
case 'off':
clientlog('Message logged off');
break;
default:
clientlog(`Unknown logs: ${logs}`);
}
break;
case '.mine':
mineblock()
break;
case ".conn":
case '.connect':
bhost = arg[1];
let ip = bhost.split(':');
options.host = ip[0];
options.port = ip[1]
let bver = arg[2]
options.version = bver
createbot()
break;
case '.disco':
case '.disconnect':
bot.quit()
clientlog(`${options.username} left ${options.host}:${options.port}`)
break;
case '.reco':
case '.reconnect':
createbot()
break;
case '.exit':
case '.leave':
case '.quit':
clientlog(`${options.username} left ${options.host}:${options.port}`);
process.exit();
break;
default:
let newcmd = cmd.substring(1)
clientlog(`Unknown command: "${newcmd}". Type ".help" for a list of commands.`);
}
} else {
bot.chat(command);
}
function mineblock() {
clientlog('Chx xong')
}
function followplayer() {
if (!arg[1]) {
clientlog('Usage: .follow <player>');
return;
}
let followplayer = bot.players[arg[1]].entity;
if (!followplayer) {
clientlog(`Can't find player: ${arg[1]}`);
return;
}
bot.pathfinder.setGoal(new GoalFollow(followplayer, 1), true)
clientlog(`Following ${arg[1]}`);
}
function unfollowPlayer() {
bot.pathfinder.setGoal(null);
clientlog(`Stopped following player`);
}
function startAFK() {
if (!isAFK) return;
const mcData = require('minecraft-data')(bot.version);
let state = true;
afktimer = setTimeout(() => {
if (!state) {
bot.setControlState('jump', true);
state = true;
} else {
const direction = Math.floor(Math.random() * 5);
switch (direction) {
case 0:
bot.setControlState('forward', true);
break;
case 1:
bot.setControlState('back', true);
break;
case 2:
bot.setControlState('left', true);
break;
case 3:
bot.setControlState('right', true);