@zardoy/flying-squid 0.0.111 → 0.0.113

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.
@@ -10,6 +10,8 @@ const server = function (serv) {
10
10
  serv.broadcast = (message, { whitelist = serv.players, blacklist = [], system = false } = {}) => {
11
11
  if (whitelist.type === 'player')
12
12
  whitelist = [whitelist];
13
+ // Log the broadcast message
14
+ serv.log(`[${serv.color.blue}SERVER BROADCAST${serv.color.reset}]: ${message}`);
13
15
  whitelist.filter(w => blacklist.indexOf(w) === -1).forEach(player => {
14
16
  if (!system)
15
17
  player.chat(message);
@@ -13,7 +13,7 @@ const server = (serv) => {
13
13
  // Send update to the player if they're online
14
14
  const player = serv.uuidToPlayer[uuid];
15
15
  if (player) {
16
- sendBreakTimeConfig(player, serv);
16
+ player.sendBreakTimeConfig();
17
17
  }
18
18
  };
19
19
  serv.customRemovePlayerBreakTime = (uuid) => {
@@ -21,24 +21,11 @@ const server = (serv) => {
21
21
  // Send empty config to the player if they're online
22
22
  const player = serv.uuidToPlayer[uuid];
23
23
  if (player) {
24
- sendBreakTimeConfig(player, serv);
24
+ player.sendBreakTimeConfig();
25
25
  }
26
26
  };
27
27
  };
28
28
  exports.server = server;
29
- function sendBreakTimeConfig(player, serv) {
30
- if (!serv.customPlayersBreakTime[player.uuid])
31
- return;
32
- const config = serv.customPlayersBreakTime[player.uuid];
33
- const data = {
34
- customBreakTime: config?.blocks ?? {},
35
- customBreakTimeToolAllowance: config?.toolNames ?? [],
36
- ...config?.rawConfig
37
- };
38
- player._client.writeChannel(CHANNEL_NAME, {
39
- newConfiguration: JSON.stringify(data)
40
- });
41
- }
42
29
  const player = async (player, serv) => {
43
30
  player.customGetBreakTime = (block) => {
44
31
  const config = serv.customPlayersBreakTime[player.uuid];
@@ -59,7 +46,20 @@ const player = async (player, serv) => {
59
46
  ]]);
60
47
  // Send initial configuration if it exists
61
48
  player.on('login', () => {
62
- sendBreakTimeConfig(player, serv);
49
+ player.sendBreakTimeConfig();
63
50
  });
51
+ player.sendBreakTimeConfig = () => {
52
+ if (!serv.customPlayersBreakTime[player.uuid])
53
+ return;
54
+ const config = serv.customPlayersBreakTime[player.uuid];
55
+ const data = {
56
+ customBreakTime: config?.blocks ?? {},
57
+ customBreakTimeToolAllowance: config?.toolNames ?? [],
58
+ ...config?.rawConfig
59
+ };
60
+ player._client.writeChannel(CHANNEL_NAME, {
61
+ newConfiguration: JSON.stringify(data)
62
+ });
63
+ };
64
64
  };
65
65
  exports.player = player;
@@ -8,6 +8,7 @@ declare global {
8
8
  }) => Promise<Player | undefined>;
9
9
  }
10
10
  interface Player {
11
+ loadedChunks: Record<string, boolean>;
11
12
  /** The username of the player */
12
13
  username: string;
13
14
  /** Optional display name of the player */
@@ -44,6 +44,7 @@ declare global {
44
44
  * ```
45
45
  */
46
46
  'save': () => Promise<any>;
47
+ "sendChunk": (chunkX: number, chunkZ: number, column: any) => Promise<void>;
47
48
  /** The world object which the player is in (use serv.overworld, serv.netherworld, serv.endworld, or a custom world). Options:
48
49
  *
49
50
  * - gamemode: Gamemode of the world (Default is player gamemode)
@@ -224,7 +224,7 @@ const server = async function (serv, options) {
224
224
  serv.chunksUsed[id] = 0;
225
225
  }
226
226
  serv.chunksUsed[id]++;
227
- player.loadedChunks[id] = 1;
227
+ player.loadedChunks[id] = true;
228
228
  };
229
229
  serv._unloadPlayerChunk = (chunkX, chunkZ, player) => {
230
230
  const id = chunkX + ',' + chunkZ;
@@ -232,7 +232,8 @@ const server = async function (serv, options) {
232
232
  if (serv.chunksUsed[id] > 0) {
233
233
  serv.chunksUsed[id]--;
234
234
  }
235
- if (!serv.chunksUsed[id]) {
235
+ if (!serv.chunksUsed[id] && player.world.storageProvider) {
236
+ // Never delete chunks when we do not have a storage provider! They will be lost
236
237
  player.world.unloadColumn(chunkX, chunkZ);
237
238
  return true;
238
239
  }
@@ -561,7 +562,7 @@ const player = function (player, serv, settings) {
561
562
  return player.world.getColumn(chunkX, chunkZ);
562
563
  })
563
564
  .then((column) => {
564
- if (abortSignal?.aborted)
565
+ if (!column || abortSignal?.aborted)
565
566
  return;
566
567
  return player.sendChunk(chunkX, chunkZ, column);
567
568
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zardoy/flying-squid",
3
3
  "description": "A minecraft server written in TS",
4
- "version": "0.0.111",
4
+ "version": "0.0.113",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "bin": "dist/app.js",