File size: 35,595 Bytes
309ec79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
'use strict';

/**
 * โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
 *  Server Optimizer โ€” v1.0 | ุชุญุณูŠู† ุงู„ุณูŠุฑูุฑ ููŠ ุงู„ุฃูˆู‚ุงุช ุงู„ุญุฑุฌุฉ ูˆุงู„ู…ุชูˆุณุทุฉ     โ•‘
 * โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฃ
 *  โœ… ู…ุฑุงู‚ุจุฉ ู…ุณุชู…ุฑุฉ: TPS + RAM + Entities + Chunks + Players               โ•‘
 *  โœ… 3 ุฃูˆุถุงุน: CRITICAL / MODERATE / NORMAL                                โ•‘
 *  โœ… ุชุญุณูŠู† ุชู„ู‚ุงุฆูŠ: ุชู‚ู„ูŠู„ ุงู„ุจูˆุชุงุช + ุชุนุทูŠู„ Pathfinding + ุชู‚ู„ูŠู„ ุงู„ุฑุณุงุฆู„     โ•‘
 *  โœ… ุชุญู„ูŠู„ ุฐูƒูŠ: ุฃู†ู…ุงุท ุงู„ุฃุฏุงุก + ุชูˆุตูŠุงุช + ุชู†ุจุค ุจุงู„ู…ุดุงูƒู„                    โ•‘
 *  โœ… ุชู†ุณูŠู‚ ู…ุน ุงู„ุจูˆุชุงุช: ุฅุฑุณุงู„ ุฃูˆุงู…ุฑ ุชุนุทูŠู„/ุชูุนูŠู„ ุญุณุจ ุงู„ุญุงู„ุฉ               โ•‘
 *  โœ… ุชู‚ุงุฑูŠุฑ ุฏูˆุฑูŠุฉ: ู…ู„ุฎุต ุฃุฏุงุก ูƒู„ 5 ุฏู‚ุงุฆู‚                                  โ•‘
 * โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 */

const { EventEmitter } = require('events');

const tsNow = () => new Date().toISOString().replace('T', ' ').slice(0, 19);
const sleep = ms => new Promise(r => setTimeout(r, Math.max(0, ms)));

// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
//  ุงู„ุญุฏูˆุฏ ูˆุงู„ุนุชุจุงุช (Thresholds)
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

const THRESHOLDS = {
  // โ”€โ”€โ”€ CRITICAL (ุฃู‚ู„ ู…ู† ูƒุฏู‡ ุงู„ุณูŠุฑูุฑ ุจูŠู…ูˆุช) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  critical: {
    tps: 10,              // TPS ุฃู‚ู„ ู…ู† 10
    ram: 92,              // RAM ุฃุนู„ู‰ ู…ู† 92%
    entities: 200,        // Entities ุฃุนู„ู‰ ู…ู† 200
    chunkRate: 50,        // Chunks per second ุฃู‚ู„ ู…ู† 50
    playerPing: 500,      // Ping ุฃุนู„ู‰ ู…ู† 500ms
  },
  // โ”€โ”€โ”€ MODERATE (ููŠู‡ ุถุบุท ุจุณ ู„ุณู‡ ุดุบุงู„) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  moderate: {
    tps: 16,              // TPS ุฃู‚ู„ ู…ู† 16
    ram: 80,              // RAM ุฃุนู„ู‰ ู…ู† 80%
    entities: 120,        // Entities ุฃุนู„ู‰ ู…ู† 120
    chunkRate: 100,       // Chunks per second ุฃู‚ู„ ู…ู† 100
    playerPing: 300,      // Ping ุฃุนู„ู‰ ู…ู† 300ms
  },
  // โ”€โ”€โ”€ NORMAL (ูƒู„ ุญุงุฌุฉ ุชู…ุงู…) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  normal: {
    tps: 19,
    ram: 65,
    entities: 60,
    chunkRate: 200,
    playerPing: 150,
  }
};

// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
//  ุฅุนุฏุงุฏุงุช ูƒู„ ูˆุถุน
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

const MODE_CONFIGS = {
  // โ”€โ”€โ”€ CRITICAL: ุฃู‚ู„ ู†ุดุงุท ู…ู…ูƒู† โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  critical: {
    label: '๐Ÿ”ด ุญุฑุฌ',
    botActivity: 'minimal',      // ุฃู‚ู„ ู†ุดุงุท
    pathfinding: false,          // ุชุนุทูŠู„ Pathfinding ุชู…ุงู…ุงู‹
    chatFrequency: 0,            // ุชุนุทูŠู„ ุงู„ุฑุณุงุฆู„
    taskInterval: 60000,         // ุงู„ู…ู‡ุงู… ูƒู„ ุฏู‚ูŠู‚ุฉ
    maxActiveBots: 2,            // ุฃู‚ู„ ุนุฏุฏ ุจูˆุชุงุช ุดุบุงู„ุฉ
    autoEat: true,               // ุงู„ุฃูƒู„ ุดุบุงู„ ุฏุงูŠู…ุงู‹
    autoSleep: true,             // ุงู„ู†ูˆู… ุดุบุงู„
    combatResponse: 'flee',      // ุงู„ู‡ุฑูˆุจ ุจุณ
    miningEnabled: false,        // ุชุนุทูŠู„ ุงู„ุชุนุฏูŠู†
    buildingEnabled: false,      // ุชุนุทูŠู„ ุงู„ุจู†ุงุก
    farmingEnabled: false,       // ุชุนุทูŠู„ ุงู„ุฒุฑุงุนุฉ
    explorationEnabled: false,   // ุชุนุทูŠู„ ุงู„ุงุณุชูƒุดุงู
    tradingEnabled: false,       // ุชุนุทูŠู„ ุงู„ุชุฌุงุฑุฉ
    socialEnabled: false,        // ุชุนุทูŠู„ ุงู„ุชูุงุนู„
    dailyRoutine: false,         // ุชุนุทูŠู„ ุงู„ุฑูˆุชูŠู† ุงู„ูŠูˆู…ูŠ
    antiAfk: 'sleep',            // ุจุณ ู†ูˆู…
    viewDistance: 'tiny',        // ุฃู‚ู„ ู…ุณุงูุฉ ุฑุคูŠุฉ
  },

  // โ”€โ”€โ”€ MODERATE: ู†ุดุงุท ู…ุชูˆุณุท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  moderate: {
    label: '๐ŸŸก ู…ุชูˆุณุท',
    botActivity: 'reduced',      // ู†ุดุงุท ู…ุฎูู
    pathfinding: true,           // Pathfinding ุดุบุงู„ ุจุณ ุจุทูŠุก
    chatFrequency: 0.3,          // 30% ู…ู† ุงู„ุฑุณุงุฆู„ ุงู„ุนุงุฏูŠุฉ
    taskInterval: 30000,         // ุงู„ู…ู‡ุงู… ูƒู„ 30 ุซุงู†ูŠุฉ
    maxActiveBots: 4,            // 4 ุจูˆุชุงุช ูƒุญุฏ ุฃู‚ุตู‰
    autoEat: true,
    autoSleep: true,
    combatResponse: 'fight',     // ู‚ุชุงู„ ุนุงุฏูŠ
    miningEnabled: true,
    buildingEnabled: true,
    farmingEnabled: true,
    explorationEnabled: false,   // ุงู„ุงุณุชูƒุดุงู ู…ุชูˆู‚ู
    tradingEnabled: false,       // ุงู„ุชุฌุงุฑุฉ ู…ุชูˆู‚ูุฉ
    socialEnabled: true,
    dailyRoutine: true,
    antiAfk: 'moderate',         // ุญุฑูƒุฉ ู…ุชูˆุณุทุฉ
    viewDistance: 'short',       // ู…ุณุงูุฉ ุฑุคูŠุฉ ู‚ุตูŠุฑุฉ
  },

  // โ”€โ”€โ”€ NORMAL: ูƒู„ ุญุงุฌุฉ ุดุบุงู„ุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  normal: {
    label: '๐ŸŸข ุทุจูŠุนูŠ',
    botActivity: 'full',         // ู†ุดุงุท ูƒุงู…ู„
    pathfinding: true,
    chatFrequency: 1.0,          // ูƒู„ ุงู„ุฑุณุงุฆู„
    taskInterval: 15000,         // ุงู„ู…ู‡ุงู… ูƒู„ 15 ุซุงู†ูŠุฉ
    maxActiveBots: 10,           // ูƒู„ ุงู„ุจูˆุชุงุช
    autoEat: true,
    autoSleep: true,
    combatResponse: 'fight',
    miningEnabled: true,
    buildingEnabled: true,
    farmingEnabled: true,
    explorationEnabled: true,
    tradingEnabled: true,
    socialEnabled: true,
    dailyRoutine: true,
    antiAfk: 'full',             // ุญุฑูƒุฉ ูƒุงู…ู„ุฉ
    viewDistance: 'normal',       // ู…ุณุงูุฉ ุฑุคูŠุฉ ุนุงุฏูŠุฉ
  }
};

// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
//  ServerOptimizer Class
// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

class ServerOptimizer extends EventEmitter {
  constructor(config = {}) {
    super();
    this.config = {
      checkInterval: config.checkInterval || 10000,       // ูุญุต ูƒู„ 10 ุซูˆุงู†ูŠ
      reportInterval: config.reportInterval || 300000,    // ุชู‚ุฑูŠุฑ ูƒู„ 5 ุฏู‚ุงุฆู‚
      historySize: config.historySize || 300,             // 50 ุฏู‚ูŠู‚ุฉ ู…ู† ุงู„ุจูŠุงู†ุงุช
      recoveryDelay: config.recoveryDelay || 60000,       // ุฏู‚ูŠู‚ุฉ ู‚ุจู„ ุงู„ุฑุฌูˆุน ู…ู† CRITICAL
      autoModeSwitch: config.autoModeSwitch !== false,    // ุชุบูŠูŠุฑ ุชู„ู‚ุงุฆูŠ ู„ู„ูˆุถุน
      ...config
    };

    // โ”€โ”€โ”€ ุงู„ุญุงู„ุฉ ุงู„ุญุงู„ูŠุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    this.currentMode = 'normal';       // ุงู„ูˆุถุน ุงู„ุญุงู„ูŠ
    this.previousMode = 'normal';      // ุงู„ูˆุถุน ุงู„ุณุงุจู‚
    this.modeStartTime = Date.now();   // ูˆู‚ุช ุจุฏุก ุงู„ูˆุถุน ุงู„ุญุงู„ูŠ
    this.modeTransitionPending = null; // ุชุบูŠูŠุฑ ูˆุดูŠูƒ
    this.modeTransitionTimer = null;   // ู…ุคู‚ุช ุงู„ุชุบูŠูŠุฑ

    // โ”€โ”€โ”€ ุงู„ุจูŠุงู†ุงุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    this.metrics = {
      tps: 20,
      ram: 50,
      entities: 0,
      chunks: 0,
      players: 0,
      ping: 0,
      worldTime: 0,
      uptime: 0,
      botCount: 0,
      activeBots: 0,
    };

    this.history = [];
    this.alerts = [];
    this.optimizations = [];
    this.stats = {
      modeChanges: 0,
      optimizationsApplied: 0,
      criticalEvents: 0,
      moderateEvents: 0,
      normalEvents: 0,
      totalChecks: 0,
      avgTps: 20,
      avgRam: 50,
      worstTps: 20,
      worstRam: 50,
    };

    // โ”€โ”€โ”€ ุงู„ุจูˆุชุงุช ุงู„ู…ุชุตู„ุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    this.connectedBots = new Map();  // botId โ†’ { bot, mode, lastAction }

    this._running = false;
    this._checkTimer = null;
    this._reportTimer = null;

    this._log('OPTIMIZER', 'ุชู… ุฅู†ุดุงุก Server Optimizer v1.0');
  }

  _log(tag, msg) {
    console.log(`[${tsNow()}] [OPTIMIZER] ${tag}  ${msg}`);
  }

  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  //  ุจุฏุก/ุฅูŠู‚ุงู ุงู„ุชุญุณูŠู†
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

  start() {
    if (this._running) return;
    this._running = true;
    this._log('๐ŸŸข', 'ุจุฏุก ู…ุฑุงู‚ุจุฉ ูˆุชุญุณูŠู† ุงู„ุณูŠุฑูุฑ...');

    this._checkTimer = setInterval(() => this._check(), this.config.checkInterval);
    this._reportTimer = setInterval(() => this._report(), this.config.reportInterval);
    this._optimCycleTimer = setInterval(() => this._runOptimizationCycle(), 30000);

    this._check();
    this._report();
  }

  stop() {
    this._running = false;
    if (this._checkTimer) { clearInterval(this._checkTimer); this._checkTimer = null; }
    if (this._reportTimer) { clearInterval(this._reportTimer); this._reportTimer = null; }
    if (this.modeTransitionTimer) { clearTimeout(this.modeTransitionTimer); this.modeTransitionTimer = null; }
    if (this._optimCycleTimer) { clearInterval(this._optimCycleTimer); this._optimCycleTimer = null; }
    this._log('๐Ÿ”ด', 'ุฅูŠู‚ุงู Server Optimizer');
  }

  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  //  ุงู„ุชุญู‚ู‚ ุงู„ุฑุฆูŠุณูŠ (ูƒู„ 10 ุซูˆุงู†ูŠ)
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

  async _check() {
    if (!this._running) return;
    this.stats.totalChecks++;

    try {
      // โ”€โ”€โ”€ ุชุญู„ูŠู„ ุงู„ุญุงู„ุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
      const analysis = this._analyzeMetrics();
      const newMode = analysis.recommendedMode;

      // โ”€โ”€โ”€ ุชุญุฏูŠุซ ุงู„ุฅุญุตุงุฆูŠุงุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
      this._updateStats();

      // โ”€โ”€โ”€ ุญูุธ ููŠ ุงู„ุชุงุฑูŠุฎ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
      this.history.push({
        time: Date.now(),
        mode: this.currentMode,
        tps: this.metrics.tps,
        ram: this.metrics.ram,
        entities: this.metrics.entities,
        players: this.metrics.players,
        analysis: analysis.reasons
      });
      if (this.history.length > this.config.historySize) this.history.shift();

      // โ”€โ”€โ”€ ุชุบูŠูŠุฑ ุงู„ูˆุถุน ุฅุฐุง ู„ุฒู… โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
      if (this.config.autoModeSwitch && newMode !== this.currentMode) {
        this._requestModeChange(newMode, analysis.reasons);
      }

      // โ”€โ”€โ”€ ุชุทุจูŠู‚ ุงู„ุชุญุณูŠู†ุงุช ุนู„ู‰ ุงู„ุจูˆุชุงุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
      this._applyOptimizations();

      // โ”€โ”€โ”€ ุฅุฑุณุงู„ ุงู„ุฃุญุฏุงุซ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
      this.emit('check', { mode: this.currentMode, metrics: { ...this.metrics }, analysis });

    } catch (err) {
      this._log('โŒ', `ุฎุทุฃ ููŠ ุงู„ูุญุต: ${err.message}`);
    }
  }

  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  //  ุชุญู„ูŠู„ ุงู„ู…ู‚ุงูŠูŠุณ ูˆุชุญุฏูŠุฏ ุงู„ูˆุถุน
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

  _analyzeMetrics() {
    const m = this.metrics;
    const reasons = [];
    let score = 0;  // 0-100 (0=ุญุฑุฌ, 100=ู…ู…ุชุงุฒ)

    // โ”€โ”€โ”€ ุชุญู„ูŠู„ TPS โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    if (m.tps <= THRESHOLDS.critical.tps) {
      score -= 40;
      reasons.push(`TPS ุญุฑุฌ: ${m.tps}`);
    } else if (m.tps <= THRESHOLDS.moderate.tps) {
      score -= 20;
      reasons.push(`TPS ู…ู†ุฎูุถ: ${m.tps}`);
    } else {
      score += 20;
    }

    // โ”€โ”€โ”€ ุชุญู„ูŠู„ RAM โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    if (m.ram >= THRESHOLDS.critical.ram) {
      score -= 30;
      reasons.push(`RAM ุญุฑุฌ: ${m.ram}%`);
    } else if (m.ram >= THRESHOLDS.moderate.ram) {
      score -= 15;
      reasons.push(`RAM ู…ุฑุชูุน: ${m.ram}%`);
    } else {
      score += 15;
    }

    // โ”€โ”€โ”€ ุชุญู„ูŠู„ Entities โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    if (m.entities >= THRESHOLDS.critical.entities) {
      score -= 15;
      reasons.push(`Entities ูƒุชูŠุฑ: ${m.entities}`);
    } else if (m.entities >= THRESHOLDS.moderate.entities) {
      score -= 8;
      reasons.push(`Entities ู…ุชูˆุณุท: ${m.entities}`);
    } else {
      score += 10;
    }

    // โ”€โ”€โ”€ ุชุญู„ูŠู„ ุงู„ู„ุงุนุจูŠู† โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    if (m.players > 10) {
      score -= 10;
      reasons.push(`ู„ุงุนุจูŠู† ูƒุชูŠุฑ: ${m.players}`);
    } else if (m.players > 5) {
      score -= 5;
    } else {
      score += 5;
    }

    // โ”€โ”€โ”€ ุชุญู„ูŠู„ ุงู„ุจูˆุชุงุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    const activeBots = this.connectedBots.size;
    if (activeBots > 6) {
      score -= 10;
      reasons.push(`ุจูˆุชุงุช ูƒุชูŠุฑ ุดุบุงู„ุฉ: ${activeBots}`);
    } else if (activeBots > 3) {
      score -= 5;
    } else {
      score += 5;
    }

    // โ”€โ”€โ”€ ุชุญุฏูŠุฏ ุงู„ูˆุถุน โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    let recommendedMode;
    if (score <= 20) {
      recommendedMode = 'critical';
    } else if (score <= 35) {
      recommendedMode = 'moderate';
    } else {
      recommendedMode = 'normal';
    }

    // โ”€โ”€โ”€ ุชุญู„ูŠู„ ุงู„ุงุชุฌุงู‡ (ู‡ู„ Situation ุจุชุชุญุณู† ุฃูˆ ุจุช tแป‡ุŸ) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    const trend = this._analyzeTrend();

    return {
      score: Math.max(0, Math.min(100, score)),
      recommendedMode,
      reasons,
      trend,
      details: {
        tpsStatus: m.tps >= 19 ? '๐ŸŸข' : m.tps >= 16 ? '๐ŸŸก' : '๐Ÿ”ด',
        ramStatus: m.ram <= 65 ? '๐ŸŸข' : m.ram <= 80 ? '๐ŸŸก' : '๐Ÿ”ด',
        entityStatus: m.entities <= 60 ? '๐ŸŸข' : m.entities <= 120 ? '๐ŸŸก' : '๐Ÿ”ด',
      }
    };
  }

  _analyzeTrend() {
    if (this.history.length < 10) return 'stable';
    const recent = this.history.slice(-10);
    const older = this.history.slice(-20, -10);

    if (older.length === 0) return 'stable';

    const recentAvgTps = recent.reduce((s, h) => s + h.tps, 0) / recent.length;
    const olderAvgTps = older.reduce((s, h) => s + h.tps, 0) / older.length;

    if (recentAvgTps > olderAvgTps + 2) return 'improving';
    if (recentAvgTps < olderAvgTps - 2) return 'worsening';
    return 'stable';
  }

  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  //  ุชุบูŠูŠุฑ ุงู„ูˆุถุน
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

  _requestModeChange(newMode, reasons) {
    // โ”€โ”€โ”€ CRITICAL: ุชุบูŠูŠุฑ ููˆุฑูŠ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    if (newMode === 'critical') {
      this._switchMode(newMode, reasons);
      return;
    }

    // โ”€โ”€โ”€ MODERATE โ†’ NORMAL: ุงู†ุชุธุงุฑ 30 ุซุงู†ูŠุฉ ู„ู„ุชุฃูƒุฏ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    if (this.currentMode === 'critical' && newMode === 'moderate') {
      if (this.modeTransitionPending === 'moderate') {
        // ุงู†ุชุธุฑ ุฃูƒุซุฑ
        return;
      }
      this.modeTransitionPending = 'moderate';
      this._log('โณ', 'ุงู†ุชุธุงุฑ 30 ุซุงู†ูŠุฉ ู„ู„ุฑุฌูˆุน ู…ู† CRITICAL...');
      this.modeTransitionTimer = setTimeout(() => {
        this._switchMode('moderate', reasons);
        this.modeTransitionPending = null;
      }, 30000);
      return;
    }

    // โ”€โ”€โ”€ MODERATE โ†’ NORMAL: ุงู†ุชุธุงุฑ ุฏู‚ูŠู‚ุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    if (this.currentMode === 'moderate' && newMode === 'normal') {
      if (this.modeTransitionPending === 'normal') return;
      this.modeTransitionPending = 'normal';
      this._log('โณ', 'ุงู†ุชุธุงุฑ 60 ุซุงู†ูŠุฉ ู„ู„ุฑุฌูˆุน ู…ู† MODERATE...');
      this.modeTransitionTimer = setTimeout(() => {
        this._switchMode('normal', reasons);
        this.modeTransitionPending = null;
      }, 60000);
      return;
    }

    // โ”€โ”€โ”€ ุฃูŠ ุชุบูŠูŠุฑ ุชุงู†ูŠ: ููˆุฑูŠ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    this._switchMode(newMode, reasons);
  }

  _switchMode(newMode, reasons) {
    if (this.modeTransitionTimer) {
      clearTimeout(this.modeTransitionTimer);
      this.modeTransitionTimer = null;
    }
    this.modeTransitionPending = null;

    const oldMode = this.currentMode;
    this.previousMode = oldMode;
    this.currentMode = newMode;
    this.modeStartTime = Date.now();
    this.stats.modeChanges++;

    if (newMode === 'critical') this.stats.criticalEvents++;
    else if (newMode === 'moderate') this.stats.moderateEvents++;
    else this.stats.normalEvents++;

    const config = MODE_CONFIGS[newMode];
    this._log('๐Ÿ”„', `ุชุบูŠูŠุฑ ุงู„ูˆุถุน: ${MODE_CONFIGS[oldMode].label} โ†’ ${config.label}`);
    this._log('๐Ÿ“‹', `ุงู„ุฃุณุจุงุจ: ${reasons.join(', ')}`);

    // โ”€โ”€โ”€ ุฅุฑุณุงู„ ุฃุญุฏุงุซ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    this.emit('modeChange', {
      from: oldMode,
      to: newMode,
      config,
      reasons,
      timestamp: Date.now()
    });

    // โ”€โ”€โ”€ ุฅุดุนุงุฑ ุงู„ุจูˆุชุงุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    this._notifyBotsModeChange(newMode, config);
  }

  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  //  ุฅุฏุงุฑุฉ ุงู„ุจูˆุชุงุช ุงู„ู…ุชุตู„ุฉ
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

  registerBot(botId, bot) {
    this.connectedBots.set(botId, {
      bot,
      mode: this.currentMode,
      lastAction: Date.now(),
      disabled: false,
      pathfindingEnabled: true,
      chatEnabled: true,
    });
    this._log('๐Ÿค–', `ุจูˆุช ู…ุณุฌู„: ${botId} (${this.connectedBots.size} ุจูˆุช)`);
    this._applyBotMode(botId);
  }

  unregisterBot(botId) {
    this.connectedBots.delete(botId);
    this._log('๐Ÿ‘‹', `ุจูˆุช ุงู†ูุตู„: ${botId} (${this.connectedBots.size} ุจูˆุช)`);
  }

  _notifyBotsModeChange(newMode, config) {
    this.connectedBots.forEach((data, botId) => {
      data.mode = newMode;
      this._applyBotMode(botId);
    });
  }

  _applyBotMode(botId) {
    const data = this.connectedBots.get(botId);
    if (!data || !data.bot) return;

    const config = MODE_CONFIGS[this.currentMode];

    try {
      // โ”€โ”€โ”€ ุชุนุทูŠู„/ุชูุนูŠู„ Pathfinding โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
      data.pathfindingEnabled = config.pathfinding;

      // โ”€โ”€โ”€ ุชุนุทูŠู„/ุชูุนูŠู„ ุงู„ุฑุณุงุฆู„ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
      data.chatEnabled = config.chatFrequency > 0;

      // โ”€โ”€โ”€ ุชู‚ู„ูŠู„ ู†ุดุงุท ุงู„ุจูˆุช โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
      if (config.botActivity === 'minimal') {
        data.bot._optimizerMode = 'minimal';
      } else if (config.botActivity === 'reduced') {
        data.bot._optimizerMode = 'reduced';
      } else {
        data.bot._optimizerMode = 'full';
      }

      this._log('โš™๏ธ', ` Bot ${botId}: ูˆุถุน ${config.label}`);
    } catch (err) {
      this._log('โŒ', `ุฎุทุฃ ููŠ ุชุทุจูŠู‚ ุงู„ูˆุถุน ุนู„ู‰ ${botId}: ${err.message}`);
    }
  }

  _runOptimizationCycle() {
    const bots = [...this.connectedBots.values()].filter(d => d.bot && !d.disabled);
    if (bots.length === 0) return;
    const b = bots[0].bot;
    if (!b) return;
    try { b.chat('/tps'); } catch(_) {}
    setTimeout(() => {
      if (!b) return;
      try { b.chat('/lagg clear'); } catch(_) {}
      if (this.currentMode === 'critical') {
        setTimeout(() => {
          if (!b) return;
          try { b.chat('/lagg clear'); } catch(_) {}
          setTimeout(() => {
            if (!b) return;
            try { b.chat('/minecraft:kill @e[type=item]'); } catch(_) {}
          }, 500);
        }, 500);
      }
    }, 500);
  }

  _applyOptimizations() {
    const config = MODE_CONFIGS[this.currentMode];

    this.connectedBots.forEach((data, botId) => {
      if (!data.bot) return;

      try {
        // โ”€โ”€โ”€ ููŠ ุงู„ูˆุถุน ุงู„ุญุฑุฌ: ุชู‚ู„ูŠู„ ูƒู„ ุญุงุฌุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
        if (this.currentMode === 'critical') {
          // โ”€โ”€โ”€ ุฅูŠู‚ุงู ุฃูŠ ุญุฑูƒุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
          if (data.bot.pathfinder && data.pathfindingEnabled) {
            data.pathfindingEnabled = false;
          }

          // โ”€โ”€โ”€ ุฅูŠู‚ุงู ุงู„ุชุนุฏูŠู† โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
          if (data.bot._mining && config.miningEnabled === false) {
            data.bot._mining = false;
          }

          // โ”€โ”€โ”€ ุฅูŠู‚ุงู ุงู„ุจู†ุงุก โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
          if (data.bot._building && config.buildingEnabled === false) {
            data.bot._building = false;
          }
        }

        // โ”€โ”€โ”€ ููŠ ุงู„ูˆุถุน ุงู„ู…ุชูˆุณุท: ุชู‚ู„ูŠู„ ุงู„ู†ุดุงุท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
        if (this.currentMode === 'moderate') {
          // โ”€โ”€โ”€ ุชู‚ู„ูŠู„ ุณุฑุนุฉ Pathfinding โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
          if (data.bot.pathfinder && data.pathfindingEnabled) {
            data.bot.pathfinder.setTicksPerTick(2);  // ุจุทูŠุก
          }
        }

        // โ”€โ”€โ”€ ููŠ ุงู„ูˆุถุน ุงู„ุทุจูŠุนูŠ: ูƒู„ ุญุงุฌุฉ ุดุบุงู„ุฉ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
        if (this.currentMode === 'normal') {
          if (data.bot.pathfinder && !data.pathfindingEnabled) {
            data.pathfindingEnabled = true;
          }
          if (data.bot.pathfinder) {
            data.bot.pathfinder.setTicksPerTick(1);  // ุนุงุฏูŠ
          }
        }

      } catch (err) {
        // ุชุฌุงู‡ู„ ุงู„ุฃุฎุทุงุก
      }
    });
  }

  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  //  ุชุญุฏูŠุซ ุงู„ู…ู‚ุงูŠูŠุณ (ูŠุชู… ุงุณุชุฏุนุงุคู‡ ู…ู† ะฒะฝะตัˆะฝะธะต ุฃู†ุธู…ุฉ)
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

  updateMetrics(newMetrics) {
    Object.assign(this.metrics, newMetrics);
  }

  updateTps(tps) {
    this.metrics.tps = tps;
  }

  updateRam(ramPercent) {
    this.metrics.ram = ramPercent;
  }

  updateEntities(count) {
    this.metrics.entities = count;
  }

  updatePlayers(count) {
    this.metrics.players = count;
  }

  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  //  ุชุญุฏูŠุซ ุงู„ุฅุญุตุงุฆูŠุงุช
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

  _updateStats() {
    const m = this.metrics;
    const n = this.stats.totalChecks;

    this.stats.avgTps = ((this.stats.avgTps * (n - 1)) + m.tps) / n;
    this.stats.avgRam = ((this.stats.avgRam * (n - 1)) + m.ram) / n;
    this.stats.worstTps = Math.min(this.stats.worstTps, m.tps);
    this.stats.worstRam = Math.max(this.stats.worstRam, m.ram);
  }

  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  //  ุงู„ุชู‚ุงุฑูŠุฑ ุงู„ุฏูˆุฑูŠุฉ
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

  _report() {
    if (!this._running) return;

    const m = this.metrics;
    const config = MODE_CONFIGS[this.currentMode];
    const uptime = Date.now() - this.modeStartTime;
    const uptimeMin = Math.floor(uptime / 60000);

    this._log('๐Ÿ“Š', 'โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•');
    this._log('๐Ÿ“Š', `ุงู„ูˆุถุน ุงู„ุญุงู„ูŠ: ${config.label}`);
    this._log('๐Ÿ“Š', `TPS: ${m.tps} | RAM: ${m.ram}% | Entities: ${m.entities} | Players: ${m.players}`);
    this._log('๐Ÿ“Š', `ุจูˆุชุงุช ู…ุชุตู„ุฉ: ${this.connectedBots.size}`);
    this._log('๐Ÿ“Š', `ู…ุฏุฉ ุงู„ูˆุถุน ุงู„ุญุงู„ูŠ: ${uptimeMin} ุฏู‚ูŠู‚ุฉ`);
    this._log('๐Ÿ“Š', `ุชุบูŠูŠุฑุงุช ุงู„ูˆุถุน: ${this.stats.modeChanges} | ุฃุญุฏุงุซ ุญุฑุฌุฉ: ${this.stats.criticalEvents}`);
    this._log('๐Ÿ“Š', `TPS ุงู„ู…ุชูˆุณุท: ${this.stats.avgTps.toFixed(1)} | Worst: ${this.stats.worstTps}`);
    this._log('๐Ÿ“Š', `RAM ุงู„ู…ุชูˆุณุท: ${this.stats.avgRam.toFixed(1)}% | Worst: ${this.stats.worstRam}%`);
    this._log('๐Ÿ“Š', 'โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•');

    this.emit('report', this.getStatus());
  }

  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  //  ุงู„ุญุตูˆู„ ุนู„ู‰ ุงู„ุญุงู„ุฉ ุงู„ูƒุงู…ู„ุฉ
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

  getStatus() {
    const config = MODE_CONFIGS[this.currentMode];
    const uptime = Date.now() - this.modeStartTime;

    return {
      running: this._running,
      currentMode: this.currentMode,
      modeLabel: config.label,
      previousMode: this.previousMode,
      modeUptime: uptime,
      modeUptimeMin: Math.floor(uptime / 60000),
      metrics: { ...this.metrics },
      config: { ...config },
      stats: { ...this.stats },
      connectedBots: this.connectedBots.size,
      historySize: this.history.length,
      analysis: this._analyzeMetrics(),
      recommendations: this._getRecommendations(),
    };
  }

  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  //  ุงู„ุชูˆุตูŠุงุช ุงู„ุฐูƒูŠุฉ
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

  _getRecommendations() {
    const recs = [];
    const m = this.metrics;

    if (m.tps < 14) {
      recs.push({
        priority: 'high',
        type: 'tps',
        message: 'TPS ู…ู†ุฎูุถ ุฌุฏุงู‹ โ€” ู‚ู„ู„ ุนุฏุฏ ุงู„ุจูˆุชุงุช ุฃูˆ ุนุทู‘ู„ ุจุนุถ ุงู„ู…ูŠุฒุงุช',
        action: 'reduce_bots'
      });
    }

    if (m.ram > 85) {
      recs.push({
        priority: 'high',
        type: 'ram',
        message: 'RAM ุนุงู„ูŠ ุฌุฏุงู‹ โ€” ุดุบู‘ู„ GC ูŠุฏูˆูŠุงู‹ ุฃูˆ ู‚ู„ู„ ุงู„ูƒุงุด',
        action: 'force_gc'
      });
    }

    if (m.entities > 150) {
      recs.push({
        priority: 'medium',
        type: 'entities',
        message: 'ุนุฏุฏ Entities ูƒุจูŠุฑ โ€” ู‚ู„ู„ ู…ุณุงูุฉ ุงู„ุฑุคูŠุฉ ุฃูˆ ุนุทู‘ู„ ุจุนุถ ุงู„ู…ูŠุฒุงุช',
        action: 'reduce_view'
      });
    }

    if (this.connectedBots.size > 5) {
      recs.push({
        priority: 'medium',
        type: 'bots',
        message: `ุนุฏุฏ ุงู„ุจูˆุชุงุช ูƒุจูŠุฑ (${this.connectedBots.size}) โ€” ู‚ู„ู„ ุงู„ุนุฏุฏ`,
        action: 'reduce_bots'
      });
    }

    if (this.stats.worstTps < 8) {
      recs.push({
        priority: 'low',
        type: 'history',
        message: `ูˆุตู„ TPS ู„ู€ ${this.stats.worstTps} ู‚ุจู„ ูƒุฏู‡ โ€” ุฑุงู‚ุจ ุงู„ุฃุณุจุงุจ`,
        action: 'monitor'
      });
    }

    return recs;
  }

  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
  //  ุงู„ุชุญูƒู… ุงู„ูŠุฏูˆูŠ
  // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

  setMode(mode) {
    if (!MODE_CONFIGS[mode]) {
      this._log('โŒ', `ูˆุถุน ุบูŠุฑ ุตุญูŠุญ: ${mode}`);
      return false;
    }
    this._switchMode(mode, ['manual_override']);
    this._log(' manual', `ุชู… ุชุบูŠูŠุฑ ุงู„ูˆุถุน ูŠุฏูˆูŠุงู‹ ุฅู„ู‰: ${MODE_CONFIGS[mode].label}`);
    return true;
  }

  forceOptimization() {
    this._log('๐Ÿ”ง', 'ุชุญุณูŠู† ุฅุฌุจุงุฑูŠ...');
    this._applyOptimizations();
    this.stats.optimizationsApplied++;
    return true;
  }

  getModeConfig(mode) {
    return MODE_CONFIGS[mode] ? { ...MODE_CONFIGS[mode] } : null;
  }

  getHistory(minutes = 30) {
    const cutoff = Date.now() - (minutes * 60000);
    return this.history.filter(h => h.time >= cutoff);
  }

  destroy() {
    this.stop();
    this.connectedBots.clear();
    this.history = [];
    this.alerts = [];
    this.optimizations = [];
    this.removeAllListeners();
  }
}

module.exports = { ServerOptimizer, THRESHOLDS, MODE_CONFIGS };