specprotocol 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +174 -0
  3. package/bin/specprotocol.js +136 -0
  4. package/dist/auth/microsoft.d.ts +23 -0
  5. package/dist/auth/microsoft.d.ts.map +1 -0
  6. package/dist/auth/microsoft.js +167 -0
  7. package/dist/auth/microsoft.js.map +1 -0
  8. package/dist/auth/offline.d.ts +20 -0
  9. package/dist/auth/offline.d.ts.map +1 -0
  10. package/dist/auth/offline.js +67 -0
  11. package/dist/auth/offline.js.map +1 -0
  12. package/dist/bot.d.ts +190 -0
  13. package/dist/bot.d.ts.map +1 -0
  14. package/dist/bot.js +624 -0
  15. package/dist/bot.js.map +1 -0
  16. package/dist/entity/entity.d.ts +71 -0
  17. package/dist/entity/entity.d.ts.map +1 -0
  18. package/dist/entity/entity.js +157 -0
  19. package/dist/entity/entity.js.map +1 -0
  20. package/dist/index.d.ts +36 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +73 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/plugins/built-in/chat.d.ts +19 -0
  25. package/dist/plugins/built-in/chat.d.ts.map +1 -0
  26. package/dist/plugins/built-in/chat.js +62 -0
  27. package/dist/plugins/built-in/chat.js.map +1 -0
  28. package/dist/plugins/built-in/combat.d.ts +20 -0
  29. package/dist/plugins/built-in/combat.d.ts.map +1 -0
  30. package/dist/plugins/built-in/combat.js +42 -0
  31. package/dist/plugins/built-in/combat.js.map +1 -0
  32. package/dist/plugins/plugin-manager.d.ts +49 -0
  33. package/dist/plugins/plugin-manager.d.ts.map +1 -0
  34. package/dist/plugins/plugin-manager.js +76 -0
  35. package/dist/plugins/plugin-manager.js.map +1 -0
  36. package/dist/protocol/compression.d.ts +23 -0
  37. package/dist/protocol/compression.d.ts.map +1 -0
  38. package/dist/protocol/compression.js +85 -0
  39. package/dist/protocol/compression.js.map +1 -0
  40. package/dist/protocol/connection.d.ts +73 -0
  41. package/dist/protocol/connection.d.ts.map +1 -0
  42. package/dist/protocol/connection.js +212 -0
  43. package/dist/protocol/connection.js.map +1 -0
  44. package/dist/protocol/encryption.d.ts +29 -0
  45. package/dist/protocol/encryption.d.ts.map +1 -0
  46. package/dist/protocol/encryption.js +116 -0
  47. package/dist/protocol/encryption.js.map +1 -0
  48. package/dist/protocol/packet.d.ts +75 -0
  49. package/dist/protocol/packet.d.ts.map +1 -0
  50. package/dist/protocol/packet.js +140 -0
  51. package/dist/protocol/packet.js.map +1 -0
  52. package/dist/protocol/states/handshake.d.ts +19 -0
  53. package/dist/protocol/states/handshake.d.ts.map +1 -0
  54. package/dist/protocol/states/handshake.js +32 -0
  55. package/dist/protocol/states/handshake.js.map +1 -0
  56. package/dist/protocol/states/login.d.ts +77 -0
  57. package/dist/protocol/states/login.d.ts.map +1 -0
  58. package/dist/protocol/states/login.js +125 -0
  59. package/dist/protocol/states/login.js.map +1 -0
  60. package/dist/protocol/states/play.d.ts +187 -0
  61. package/dist/protocol/states/play.d.ts.map +1 -0
  62. package/dist/protocol/states/play.js +316 -0
  63. package/dist/protocol/states/play.js.map +1 -0
  64. package/dist/protocol/types.d.ts +210 -0
  65. package/dist/protocol/types.d.ts.map +1 -0
  66. package/dist/protocol/types.js +495 -0
  67. package/dist/protocol/types.js.map +1 -0
  68. package/dist/types.d.ts +36 -0
  69. package/dist/types.d.ts.map +1 -0
  70. package/dist/types.js +6 -0
  71. package/dist/types.js.map +1 -0
  72. package/dist/utils/events.d.ts +23 -0
  73. package/dist/utils/events.d.ts.map +1 -0
  74. package/dist/utils/events.js +44 -0
  75. package/dist/utils/events.js.map +1 -0
  76. package/dist/utils/logger.d.ts +19 -0
  77. package/dist/utils/logger.d.ts.map +1 -0
  78. package/dist/utils/logger.js +47 -0
  79. package/dist/utils/logger.js.map +1 -0
  80. package/dist/utils/vec3.d.ts +25 -0
  81. package/dist/utils/vec3.d.ts.map +1 -0
  82. package/dist/utils/vec3.js +66 -0
  83. package/dist/utils/vec3.js.map +1 -0
  84. package/dist/world/block.d.ts +39 -0
  85. package/dist/world/block.d.ts.map +1 -0
  86. package/dist/world/block.js +84 -0
  87. package/dist/world/block.js.map +1 -0
  88. package/dist/world/world.d.ts +55 -0
  89. package/dist/world/world.d.ts.map +1 -0
  90. package/dist/world/world.js +95 -0
  91. package/dist/world/world.js.map +1 -0
  92. package/docs/README.md +29 -0
  93. package/docs/api/auth.md +210 -0
  94. package/docs/api/bot.md +137 -0
  95. package/docs/api/events.md +166 -0
  96. package/docs/api/plugins.md +207 -0
  97. package/docs/api/protocol.md +129 -0
  98. package/docs/api/world.md +138 -0
  99. package/docs/first-bot.md +114 -0
  100. package/docs/getting-started.md +103 -0
  101. package/docs/guides/architecture.md +122 -0
  102. package/docs/guides/custom-plugins.md +211 -0
  103. package/docs/guides/raw-packets.md +80 -0
  104. package/package.json +55 -0
@@ -0,0 +1,210 @@
1
+ # 🔐 Authentication (Kimlik Doğrulama)
2
+
3
+ SpecProtocol iki kimlik doğrulama modu destekler.
4
+
5
+ ## Offline Mod
6
+
7
+ Cracked (lisanssız) sunucular için. UUID, kullanıcı adından üretilir.
8
+
9
+ ```typescript
10
+ const bot = await createBot({
11
+ host: 'localhost',
12
+ username: 'Bot',
13
+ auth: 'offline',
14
+ });
15
+ ```
16
+
17
+ ### offlineUUID Fonksiyonu
18
+
19
+ ```typescript
20
+ import { offlineUUID, createOfflineProfile } from 'specprotocol';
21
+
22
+ // UUID üret (deterministik — aynı isim = aynı UUID)
23
+ const uuid = offlineUUID('Steve');
24
+ // → "abccda02-8f11-3f9b-9e0f-d5336ec6b535"
25
+
26
+ // Tam profil
27
+ const profile = createOfflineProfile('Steve');
28
+ // → { username: 'Steve', uuid: '...' }
29
+ ```
30
+
31
+ ## Microsoft Girişi
32
+
33
+ Online (lisanslı) sunucular için. Device Code Flow kullanır.
34
+
35
+ ```typescript
36
+ const bot = await createBot({
37
+ host: 'online-server.com',
38
+ username: 'Steve', // Gerçek Minecraft adınız ile değiştirilecek
39
+ auth: 'microsoft',
40
+ });
41
+ ```
42
+
43
+ ### Giriş Akışı
44
+
45
+ 1. Bot terminalde bir kod ve URL gösterir
46
+ 2. Tarayıcınızda `https://microsoft.com/link` adresini açarsınız
47
+ 3. Gösterilen kodu girersiniz
48
+ 4. Microsoft hesabınızla giriş yaparsınız
49
+ 5. Bot otomatik olarak bağlanır
50
+
51
+ ```
52
+ ════════════════════════════════════════
53
+ Open this URL: https://microsoft.com/link
54
+ Enter code: ABCD-1234
55
+ ════════════════════════════════════════
56
+ ```
57
+
58
+ ### Kimlik Doğrulama Zinciri
59
+
60
+ ```
61
+ Microsoft OAuth2 (Device Code)
62
+
63
+ Xbox Live Token
64
+
65
+ XSTS Token
66
+
67
+ Minecraft Access Token
68
+
69
+ Minecraft Profile (UUID + username)
70
+
71
+ Session Server Join
72
+ ```
73
+
74
+ ### Gelişmiş Kullanım
75
+
76
+ ```typescript
77
+ import { authenticateMicrosoft, joinServer } from 'specprotocol';
78
+
79
+ // Manuel authentication
80
+ const result = await authenticateMicrosoft((code, uri) => {
81
+ console.log(`Kod: ${code}, URL: ${uri}`);
82
+ });
83
+
84
+ console.log(result.username); // Minecraft kullanıcı adı
85
+ console.log(result.uuid); // Minecraft UUID
86
+ console.log(result.accessToken); // Minecraft access token
87
+
88
+ // Session server'a katılma
89
+ await joinServer(accessToken, uuid, serverHash);
90
+ ```
91
+
92
+ ---
93
+
94
+ # 📐 Vec3 — 3D Vektör
95
+
96
+ Koordinat ve uzaysal hesaplamalar için kullanılır.
97
+
98
+ ```typescript
99
+ import { Vec3 } from 'specprotocol';
100
+ ```
101
+
102
+ ## Oluşturma
103
+
104
+ ```typescript
105
+ const v = new Vec3(10, 64, 20);
106
+ const zero = Vec3.zero(); // (0, 0, 0)
107
+ const fromArr = Vec3.from([1, 2, 3]);
108
+ ```
109
+
110
+ ## Properties
111
+
112
+ ```typescript
113
+ v.x // number
114
+ v.y // number
115
+ v.z // number
116
+ ```
117
+
118
+ ## Aritmetik
119
+
120
+ ```typescript
121
+ const a = new Vec3(1, 2, 3);
122
+ const b = new Vec3(4, 5, 6);
123
+
124
+ a.add(b) // Vec3(5, 7, 9)
125
+ a.subtract(b) // Vec3(-3, -3, -3)
126
+ a.scale(2) // Vec3(2, 4, 6)
127
+ a.dot(b) // number (skaler çarpım)
128
+ a.cross(b) // Vec3 (vektörel çarpım)
129
+ ```
130
+
131
+ ## Uzaklık & Büyüklük
132
+
133
+ ```typescript
134
+ a.length() // Vektör uzunluğu
135
+ a.distanceTo(b) // İki nokta arası mesafe
136
+ a.normalize() // Birim vektör (uzunluk = 1)
137
+ ```
138
+
139
+ ## Dönüşümler
140
+
141
+ ```typescript
142
+ a.floor() // Aşağı yuvarla (blok koordinatı)
143
+ a.clone() // Kopyala
144
+ a.toArray() // [x, y, z]
145
+ a.toString() // "Vec3(1, 2, 3)"
146
+ a.equals(b) // Eşitlik kontrolü
147
+ ```
148
+
149
+ ---
150
+
151
+ # 📝 BufferReader & BufferWriter
152
+
153
+ Paket verisi okuma/yazma için kullanılır.
154
+
155
+ ```typescript
156
+ import { BufferReader, BufferWriter } from 'specprotocol';
157
+ ```
158
+
159
+ ## BufferWriter
160
+
161
+ ```typescript
162
+ const writer = new BufferWriter();
163
+ writer.writeVarInt(42);
164
+ writer.writeString('hello');
165
+ writer.writeBool(true);
166
+ writer.writeFloat(3.14);
167
+ writer.writeDouble(2.718);
168
+ writer.writeLong(123456n);
169
+ writer.writeByte(-1);
170
+ writer.writeUByte(255);
171
+ writer.writeShort(1000);
172
+ writer.writeUShort(65535);
173
+ writer.writeInt(100000);
174
+ writer.writeUUID('550e8400-...');
175
+ writer.writeBytes(Buffer.from([0x01, 0x02]));
176
+
177
+ const buffer = writer.toBuffer();
178
+ ```
179
+
180
+ ## BufferReader
181
+
182
+ ```typescript
183
+ const reader = new BufferReader(buffer);
184
+ const a = reader.readVarInt(); // number
185
+ const b = reader.readString(); // string
186
+ const c = reader.readBool(); // boolean
187
+ const d = reader.readFloat(); // number
188
+ const e = reader.readDouble(); // number
189
+ const f = reader.readLong(); // bigint
190
+ const g = reader.readByte(); // number (-128..127)
191
+ const h = reader.readUByte(); // number (0..255)
192
+ const i = reader.readShort(); // number
193
+ const j = reader.readUShort(); // number
194
+ const k = reader.readInt(); // number
195
+ const l = reader.readUUID(); // string
196
+ const m = reader.readByteArray(); // Buffer
197
+
198
+ reader.offset // Mevcut okuma pozisyonu
199
+ reader.remaining // Kalan byte sayısı
200
+ ```
201
+
202
+ ## Standalone Fonksiyonlar
203
+
204
+ ```typescript
205
+ import { readVarInt, writeVarInt, varIntSize } from 'specprotocol';
206
+
207
+ const buf = writeVarInt(300);
208
+ const { value, bytesRead } = readVarInt(buf);
209
+ const size = varIntSize(300); // 2 byte
210
+ ```
@@ -0,0 +1,137 @@
1
+ # 🤖 Bot API Referansı
2
+
3
+ `Bot` sınıfı, tüm alt sistemleri koordine eden ana orkestratör sınıftır.
4
+
5
+ ## Oluşturma
6
+
7
+ ```typescript
8
+ import { createBot, Bot, type BotOptions } from 'specprotocol';
9
+
10
+ // Factory function (önerilen)
11
+ const bot = await createBot(options);
12
+
13
+ // Manual oluşturma
14
+ const bot = new Bot(options);
15
+ await bot.connect();
16
+ ```
17
+
18
+ ## BotOptions
19
+
20
+ | Parametre | Tip | Varsayılan | Açıklama |
21
+ |-----------|-----|------------|----------|
22
+ | `host` | `string` | **zorunlu** | Sunucu adresi |
23
+ | `port` | `number` | `25565` | Sunucu portu |
24
+ | `username` | `string` | **zorunlu** | Bot kullanıcı adı |
25
+ | `auth` | `'offline' \| 'microsoft'` | `'offline'` | Kimlik doğrulama modu |
26
+ | `version` | `number` | `769` | Protokol versiyonu |
27
+ | `viewDistance` | `number` | `10` | Görüş mesafesi |
28
+ | `logLevel` | `LogLevel` | `INFO` | Log seviyesi |
29
+ | `plugins` | `Plugin[]` | `[]` | Yüklenecek eklentiler |
30
+
31
+ ## Properties (Salt Okunur)
32
+
33
+ ```typescript
34
+ bot.username // string — Bot kullanıcı adı
35
+ bot.uuid // string — Bot UUID'si
36
+ bot.entityId // number — Bot'un entity ID'si
37
+ bot.health // number — Can (0-20)
38
+ bot.food // number — Açlık (0-20)
39
+ bot.saturation // number — Tokluk değeri
40
+ bot.gameMode // number — 0=survival, 1=creative, 2=adventure, 3=spectator
41
+ bot.isAlive // boolean — Hayatta mı?
42
+ bot.position // Vec3 — Mevcut pozisyon
43
+ ```
44
+
45
+ ## Alt Sistemler
46
+
47
+ ```typescript
48
+ bot.world // World — Dünya yöneticisi (bloklar, chunk'lar)
49
+ bot.entities // EntityManager — Varlık takibi
50
+ bot.plugins // PluginManager — Eklenti yönetimi
51
+ bot.entity // Entity — Bot'un kendi entity'si
52
+ ```
53
+
54
+ ## Metodlar
55
+
56
+ ### `chat(message: string): void`
57
+ Chat mesajı gönderir.
58
+
59
+ ```typescript
60
+ bot.chat('Merhaba!');
61
+ bot.chat('/gamemode creative'); // Komut da gönderebilirsiniz
62
+ ```
63
+
64
+ ### `attack(entity: Entity): void`
65
+ Bir varlığa saldırır.
66
+
67
+ ```typescript
68
+ const nearest = bot.entities.getNearestTo(bot.position);
69
+ if (nearest) {
70
+ bot.attack(nearest);
71
+ }
72
+ ```
73
+
74
+ ### `setPosition(x, y, z, onGround?): void`
75
+ Bot'un pozisyonunu günceller ve sunucuya bildirir.
76
+
77
+ ```typescript
78
+ bot.setPosition(100, 64, 200);
79
+ bot.setPosition(100, 64, 200, false); // havada
80
+ ```
81
+
82
+ ### `setPositionAndRotation(x, y, z, yaw, pitch, onGround?): void`
83
+ Pozisyon ve yönü birlikte günceller.
84
+
85
+ ```typescript
86
+ bot.setPositionAndRotation(100, 64, 200, 90, 0);
87
+ ```
88
+
89
+ ### `lookAt(target: Vec3): void`
90
+ Belirtilen koordinata bakar.
91
+
92
+ ```typescript
93
+ import { Vec3 } from 'specprotocol';
94
+ bot.lookAt(new Vec3(100, 65, 200));
95
+ ```
96
+
97
+ ### `dig(x, y, z, face?): void`
98
+ Bir bloğu kırmaya başlar. Creative modda anında kırar.
99
+
100
+ ```typescript
101
+ bot.dig(10, 64, 20); // Üst yüzden
102
+ bot.dig(10, 64, 20, 0); // Alt yüzden (face: 0=bottom, 1=top, 2-5=sides)
103
+ ```
104
+
105
+ ### `setHeldItem(slot: number): void`
106
+ Hotbar slotunu seçer (0-8).
107
+
108
+ ```typescript
109
+ bot.setHeldItem(0); // İlk slot
110
+ bot.setHeldItem(4); // 5. slot
111
+ ```
112
+
113
+ ### `disconnect(): void`
114
+ Sunucudan bağlantıyı keser.
115
+
116
+ ```typescript
117
+ bot.disconnect();
118
+ ```
119
+
120
+ ### `sendPacket(packetId, data): void`
121
+ Sunucuya ham paket gönderir (gelişmiş kullanım).
122
+
123
+ ```typescript
124
+ import { BufferWriter } from 'specprotocol';
125
+ const writer = new BufferWriter();
126
+ writer.writeString('hello');
127
+ bot.sendPacket(0x06, writer.toBuffer());
128
+ ```
129
+
130
+ ### `onPacket(packetId, handler): void`
131
+ Belirli bir paket ID'si için dinleyici ekler (plugin'ler için).
132
+
133
+ ```typescript
134
+ bot.onPacket(0x27, (data) => {
135
+ console.log('Keep-alive paketi alındı');
136
+ });
137
+ ```
@@ -0,0 +1,166 @@
1
+ # 📡 Event (Olay) Sistemi
2
+
3
+ SpecProtocol, tip-güvenli bir event sistemi kullanır. Tüm eventler tam tip desteğiyle gelir.
4
+
5
+ ## Bot Events
6
+
7
+ ### `spawn`
8
+ Bot dünyada doğduğunda tetiklenir.
9
+
10
+ ```typescript
11
+ bot.on('spawn', () => {
12
+ console.log('Dünyaya girdim!');
13
+ });
14
+ ```
15
+
16
+ ### `chat`
17
+ Chat mesajı alındığında tetiklenir.
18
+
19
+ ```typescript
20
+ bot.on('chat', (message: string, isOverlay: boolean) => {
21
+ // message: Mesaj metni (JSON bileşenlerinden çıkarılmış)
22
+ // isOverlay: true ise actionbar mesajı, false ise normal chat
23
+ if (!isOverlay) {
24
+ console.log(`Chat: ${message}`);
25
+ }
26
+ });
27
+ ```
28
+
29
+ ### `health`
30
+ Sağlık değiştiğinde tetiklenir.
31
+
32
+ ```typescript
33
+ bot.on('health', (health: number, food: number, saturation: number) => {
34
+ // health: Can (0-20, float)
35
+ // food: Açlık seviyesi (0-20)
36
+ // saturation: Tokluk değeri (0-20)
37
+ console.log(`❤️ ${health}/20 | 🍖 ${food}/20`);
38
+ });
39
+ ```
40
+
41
+ ### `death`
42
+ Bot öldüğünde tetiklenir (health ≤ 0).
43
+
44
+ ```typescript
45
+ bot.on('death', () => {
46
+ console.log('Öldüm!');
47
+ });
48
+ ```
49
+
50
+ ### `position`
51
+ Sunucu tarafından pozisyon güncellendiğinde tetiklenir (teleport, spawn).
52
+
53
+ ```typescript
54
+ bot.on('position', (position: Vec3) => {
55
+ console.log(`Yeni konum: ${position}`);
56
+ });
57
+ ```
58
+
59
+ ### `kicked`
60
+ Sunucudan atıldığında tetiklenir.
61
+
62
+ ```typescript
63
+ bot.on('kicked', (reason: string) => {
64
+ console.log(`Atıldım: ${reason}`);
65
+ });
66
+ ```
67
+
68
+ ### `entitySpawn`
69
+ Yakında yeni bir varlık doğduğunda tetiklenir.
70
+
71
+ ```typescript
72
+ bot.on('entitySpawn', (entity: Entity) => {
73
+ console.log(`Yeni entity: ${entity.id} (tip: ${entity.type})`);
74
+ });
75
+ ```
76
+
77
+ ### `entityRemove`
78
+ Bir varlık kaldırıldığında tetiklenir.
79
+
80
+ ```typescript
81
+ bot.on('entityRemove', (entityId: number) => {
82
+ console.log(`Entity ${entityId} kaldırıldı`);
83
+ });
84
+ ```
85
+
86
+ ### `blockUpdate`
87
+ Bir blok değiştiğinde tetiklenir.
88
+
89
+ ```typescript
90
+ bot.on('blockUpdate', (x: number, y: number, z: number, stateId: number) => {
91
+ console.log(`Blok değişti: (${x}, ${y}, ${z}) → ${stateId}`);
92
+ });
93
+ ```
94
+
95
+ ### `rawPacket`
96
+ Her ham paket alındığında tetiklenir (gelişmiş kullanım).
97
+
98
+ ```typescript
99
+ bot.on('rawPacket', (packet: RawPacket) => {
100
+ console.log(`Paket 0x${packet.id.toString(16)}: ${packet.data.length} bytes`);
101
+ });
102
+ ```
103
+
104
+ ### `error`
105
+ Bağlantı hatası oluştuğunda tetiklenir.
106
+
107
+ ```typescript
108
+ bot.on('error', (error: Error) => {
109
+ console.error('Hata:', error.message);
110
+ });
111
+ ```
112
+
113
+ ### `connect`
114
+ Sunucuya TCP bağlantısı kurulduğunda tetiklenir.
115
+
116
+ ```typescript
117
+ bot.on('connect', () => {
118
+ console.log('TCP bağlantısı kuruldu');
119
+ });
120
+ ```
121
+
122
+ ### `end`
123
+ Bağlantı kesildiğinde tetiklenir.
124
+
125
+ ```typescript
126
+ bot.on('end', () => {
127
+ console.log('Bağlantı kapandı');
128
+ process.exit(0);
129
+ });
130
+ ```
131
+
132
+ ## TypedEventEmitter
133
+
134
+ SpecProtocol kendi tip-güvenli event emitter'ını kullanır:
135
+
136
+ ```typescript
137
+ import { TypedEventEmitter } from 'specprotocol';
138
+
139
+ interface MyEvents {
140
+ 'ready': () => void;
141
+ 'data': (value: number, label: string) => void;
142
+ }
143
+
144
+ class MyClass extends TypedEventEmitter<MyEvents> {
145
+ start() {
146
+ this.emit('ready');
147
+ this.emit('data', 42, 'answer');
148
+ }
149
+ }
150
+
151
+ const obj = new MyClass();
152
+ obj.on('data', (value, label) => {
153
+ // value: number (otomatik çıkarım)
154
+ // label: string (otomatik çıkarım)
155
+ });
156
+ ```
157
+
158
+ ### Metodlar
159
+
160
+ | Metod | Açıklama |
161
+ |-------|----------|
162
+ | `on(event, listener)` | Dinleyici ekler |
163
+ | `once(event, listener)` | Tek seferlik dinleyici |
164
+ | `off(event, listener)` | Dinleyici kaldırır |
165
+ | `emit(event, ...args)` | Olay tetikler |
166
+ | `removeAllListeners(event?)` | Tüm dinleyicileri kaldırır |
@@ -0,0 +1,207 @@
1
+ # 🧩 Plugin Sistemi
2
+
3
+ SpecProtocol, modüler bir eklenti sistemi sunar. Kendi pluginlerinizi yazarak bot'un işlevselliğini genişletebilirsiniz.
4
+
5
+ ## Dahili Pluginler
6
+
7
+ ### ChatPlugin
8
+ Chat mesajı gönderme ve alma.
9
+
10
+ ```typescript
11
+ // Otomatik yüklenir, doğrudan bot üzerinden kullanabilirsiniz:
12
+ bot.chat('Merhaba!');
13
+ ```
14
+
15
+ ### CombatPlugin
16
+ Saldırı ve item kullanma.
17
+
18
+ ```typescript
19
+ // Otomatik yüklenir:
20
+ bot.attack(entity);
21
+ ```
22
+
23
+ ## Plugin Interface
24
+
25
+ ```typescript
26
+ import { type Plugin, type BotAPI } from 'specprotocol';
27
+
28
+ interface Plugin {
29
+ /** Benzersiz eklenti adı */
30
+ name: string;
31
+
32
+ /** Bot bağlandığında başlatılır */
33
+ initialize(bot: BotAPI): void;
34
+
35
+ /** Eklenti kaldırıldığında çalışır (opsiyonel) */
36
+ destroy?(): void;
37
+ }
38
+ ```
39
+
40
+ ## Kendi Plugininizi Yazma
41
+
42
+ ### Basit Örnek: Geri Sayım Plugin
43
+
44
+ ```typescript
45
+ import { type Plugin, type BotAPI } from 'specprotocol';
46
+
47
+ class CountdownPlugin implements Plugin {
48
+ name = 'countdown';
49
+ private bot!: BotAPI;
50
+
51
+ initialize(bot: BotAPI): void {
52
+ this.bot = bot;
53
+
54
+ bot.on('chat', (message: string) => {
55
+ if (message.includes('!countdown')) {
56
+ this.startCountdown(5);
57
+ }
58
+ });
59
+ }
60
+
61
+ private startCountdown(seconds: number): void {
62
+ let remaining = seconds;
63
+ const interval = setInterval(() => {
64
+ this.bot.chat(`⏰ ${remaining}...`);
65
+ remaining--;
66
+ if (remaining < 0) {
67
+ clearInterval(interval);
68
+ this.bot.chat('💥 BOOM!');
69
+ }
70
+ }, 1000);
71
+ }
72
+ }
73
+
74
+ // Kullanım:
75
+ const bot = await createBot({
76
+ host: 'localhost',
77
+ username: 'Bot',
78
+ plugins: [new CountdownPlugin()],
79
+ });
80
+ ```
81
+
82
+ ### Gelişmiş Örnek: Pozisyon Kayıt Plugin
83
+
84
+ ```typescript
85
+ import { type Plugin, type BotAPI } from 'specprotocol';
86
+ import { Vec3 } from 'specprotocol';
87
+
88
+ class WaypointPlugin implements Plugin {
89
+ name = 'waypoints';
90
+ private bot!: BotAPI;
91
+ private waypoints = new Map<string, Vec3>();
92
+
93
+ initialize(bot: BotAPI): void {
94
+ this.bot = bot;
95
+
96
+ bot.on('chat', (message: string) => {
97
+ const parts = message.split(' ');
98
+
99
+ if (parts[1] === '!save') {
100
+ const name = parts[2];
101
+ if (name) {
102
+ const pos = bot.position;
103
+ this.waypoints.set(name, pos.clone());
104
+ bot.chat(`📍 "${name}" kaydedildi: ${pos}`);
105
+ }
106
+ }
107
+
108
+ if (parts[1] === '!list') {
109
+ if (this.waypoints.size === 0) {
110
+ bot.chat('Kayıtlı waypoint yok');
111
+ return;
112
+ }
113
+ for (const [name, pos] of this.waypoints) {
114
+ bot.chat(`📍 ${name}: ${pos}`);
115
+ }
116
+ }
117
+
118
+ if (parts[1] === '!goto') {
119
+ const name = parts[2];
120
+ const pos = this.waypoints.get(name ?? '');
121
+ if (pos) {
122
+ bot.chat(`🚶 "${name}" konumuna gidiyorum...`);
123
+ bot.setPosition(pos.x, pos.y, pos.z);
124
+ }
125
+ }
126
+ });
127
+ }
128
+
129
+ destroy(): void {
130
+ this.waypoints.clear();
131
+ }
132
+ }
133
+ ```
134
+
135
+ ### Paket Dinleyicili Plugin
136
+
137
+ ```typescript
138
+ import { type Plugin, type BotAPI, PlayClientboundPackets, BufferReader } from 'specprotocol';
139
+
140
+ class BlockSpyPlugin implements Plugin {
141
+ name = 'block-spy';
142
+
143
+ initialize(bot: BotAPI): void {
144
+ // Ham paket dinle
145
+ bot.onPacket(PlayClientboundPackets.BLOCK_UPDATE, (data: Buffer) => {
146
+ const reader = new BufferReader(data);
147
+ const posValue = reader.readLong();
148
+ const blockId = reader.readVarInt();
149
+ console.log(`Blok değişti! ID: ${blockId}`);
150
+ });
151
+ }
152
+ }
153
+ ```
154
+
155
+ ## PluginManager API
156
+
157
+ ```typescript
158
+ // Plugin ekle
159
+ bot.plugins.register(new MyPlugin());
160
+
161
+ // Plugin kaldır
162
+ bot.plugins.unregister('plugin-adi');
163
+
164
+ // Plugin var mı?
165
+ bot.plugins.has('plugin-adi'); // boolean
166
+
167
+ // Plugin al
168
+ const plugin = bot.plugins.get<MyPlugin>('plugin-adi');
169
+
170
+ // Tüm plugin adları
171
+ const names = bot.plugins.getAll(); // string[]
172
+
173
+ // Tüm pluginleri kaldır
174
+ bot.plugins.destroyAll();
175
+ ```
176
+
177
+ ## BotAPI Interface
178
+
179
+ Plugin'lerin gördüğü bot arayüzü:
180
+
181
+ ```typescript
182
+ interface BotAPI {
183
+ // Bilgiler
184
+ readonly username: string;
185
+ readonly uuid: string;
186
+ readonly entityId: number;
187
+ readonly health: number;
188
+ readonly food: number;
189
+ readonly position: Vec3;
190
+ readonly entity: Entity;
191
+ readonly world: World;
192
+ readonly entities: EntityManager;
193
+
194
+ // Aksiyonlar
195
+ sendPacket(packetId: number, data: Buffer): void;
196
+ onPacket(packetId: number, handler: (data: Buffer) => void): void;
197
+ chat(message: string): void;
198
+ attack(entity: Entity): void;
199
+ lookAt(target: Vec3): void;
200
+ disconnect(): void;
201
+
202
+ // Eventler
203
+ on(event: string, listener: (...args: any[]) => void): any;
204
+ once(event: string, listener: (...args: any[]) => void): any;
205
+ emit(event: string, ...args: any[]): boolean;
206
+ }
207
+ ```