From f606d1547ba866d32a2fb2db7537250a3ed8ac3f Mon Sep 17 00:00:00 2001 From: Holly Date: Mon, 8 Jul 2024 09:56:03 +0100 Subject: [PATCH] use funkyarray package --- funkyArray.ts | 77 -------------------------------------- package-lock.json | 40 ++++++++++++++++---- package.json | 1 + server/AABB.ts | 2 +- server/Chunk.ts | 2 +- server/MetadataWriter.ts | 2 +- server/MinecraftServer.ts | 2 +- server/World.ts | 2 +- server/WorldSaveManager.ts | 2 +- 9 files changed, 40 insertions(+), 90 deletions(-) delete mode 100644 funkyArray.ts diff --git a/funkyArray.ts b/funkyArray.ts deleted file mode 100644 index 92c8e56..0000000 --- a/funkyArray.ts +++ /dev/null @@ -1,77 +0,0 @@ -export class FunkyArray { - private items:Map = new Map(); - private itemKeys:Array = new Array(); - - private _getKeys() : Array { - const keyArray = new Array(); - let result:IteratorResult; - const iterator = this.items.keys(); - while (!(result = iterator.next()).done) { - keyArray.push(result.value); - } - return keyArray; - } - - public set(key:T, item:TT, regenerate:boolean = true) : TT { - this.items.set(key, item); - if (regenerate) { - this.itemKeys = this._getKeys(); - } - return item; - } - - public remove(key:T, regenerate:boolean = true) { - const success = this.items.delete(key); - if (regenerate) { - this.itemKeys = this._getKeys(); - } - return success; - } - - public removeFirst(regenerate:boolean = true) { - const success = this.items.delete(this.items.keys().next().value); - if (regenerate) { - this.itemKeys = this._getKeys(); - } - return success; - } - - public first() : TT { - return this.items.values().next().value; - } - - public get length() : number { - return this.items.size; - } - - public get(key:T) : TT | undefined { - return this.items.get(key); - } - - public has(key:T) : boolean { - return this.itemKeys.includes(key); - } - - public get keys() : Array { - return this.itemKeys; - } - - public forEach(callback: (value:TT) => void) { - return new Promise(async (resolve, reject) => { - if (this.items.size === 0) { - return resolve(true); - } - - try { - const iterator = this.items.values(); - let result:IteratorResult; - while (!(result = iterator.next()).done) { - await callback(result.value); - } - resolve(true); - } catch (e) { - reject(e); - } - }); - } -} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 5d24ef6..a1cd8d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "bufferstuff": "^1.4.2", + "funky-array": "^1.0.0", "hsconsole": "^1.0.2" }, "devDependencies": { @@ -512,12 +513,13 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, + "license": "MIT", "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -963,10 +965,11 @@ "peer": true }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, + "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -983,6 +986,21 @@ "is-callable": "^1.1.3" } }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -1016,6 +1034,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/funky-array": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/funky-array/-/funky-array-1.0.0.tgz", + "integrity": "sha512-1oMg2rdLkvQV+RzV6IwaPw0wngQkVb/9bIfr+Twj/MqWKaBVM6KPwkq2IBSjTf0PC3GLeiMZ6weeG3jdhOlIYg==", + "license": "MIT" + }, "node_modules/get-intrinsic": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz", @@ -1351,6 +1375,7 @@ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.12.0" } @@ -2395,6 +2420,7 @@ "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", "dev": true, + "license": "MIT", "dependencies": { "is-number": "^7.0.0" }, diff --git a/package.json b/package.json index dfd6b3b..f997e21 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "homepage": "https://github.com/tgpholly/mc-beta-server#readme", "dependencies": { "bufferstuff": "^1.4.2", + "funky-array": "^1.0.0", "hsconsole": "^1.0.2" }, "devDependencies": { diff --git a/server/AABB.ts b/server/AABB.ts index e7a9ffd..175f6c6 100644 --- a/server/AABB.ts +++ b/server/AABB.ts @@ -1,4 +1,4 @@ -import { FunkyArray } from "../funkyArray"; +import FunkyArray from "funky-array"; import Vec3 from "./Vec3"; // Based on this MDN article: diff --git a/server/Chunk.ts b/server/Chunk.ts index 9c8d9b5..daa6766 100644 --- a/server/Chunk.ts +++ b/server/Chunk.ts @@ -1,4 +1,4 @@ -import { FunkyArray } from "../funkyArray"; +import FunkyArray from "funky-array"; import { NibbleArray } from "../nibbleArray"; import { Block } from "./blocks/Block"; import { Player } from "./entities/Player"; diff --git a/server/MetadataWriter.ts b/server/MetadataWriter.ts index 65a8235..3ba2836 100644 --- a/server/MetadataWriter.ts +++ b/server/MetadataWriter.ts @@ -1,5 +1,5 @@ import { createWriter, Endian } from "bufferstuff"; -import { FunkyArray } from "../funkyArray"; +import FunkyArray from "funky-array"; import { MetadataFieldType } from "./enums/MetadataFieldType"; import Vec3 from "./Vec3"; import { ItemStack } from "./inventories/ItemStack"; diff --git a/server/MinecraftServer.ts b/server/MinecraftServer.ts index 4eaf72a..291c297 100644 --- a/server/MinecraftServer.ts +++ b/server/MinecraftServer.ts @@ -1,7 +1,7 @@ import { Config } from "../config"; import { Console } from "hsconsole"; import { createReader, IReader, Endian } from "bufferstuff"; -import { FunkyArray } from "../funkyArray"; +import FunkyArray from "funky-array"; import { Server, Socket } from "net"; import { MPClient } from "./MPClient"; import { Packet } from "./enums/Packet"; diff --git a/server/World.ts b/server/World.ts index 642a060..0f70f52 100644 --- a/server/World.ts +++ b/server/World.ts @@ -1,5 +1,5 @@ import { Endian, createWriter } from "bufferstuff"; -import { FunkyArray } from "../funkyArray"; +import FunkyArray from "funky-array"; import { Chunk } from "./Chunk"; import { WorldSaveManager } from "./WorldSaveManager"; import { Block } from "./blocks/Block"; diff --git a/server/WorldSaveManager.ts b/server/WorldSaveManager.ts index 25848b9..40467bc 100644 --- a/server/WorldSaveManager.ts +++ b/server/WorldSaveManager.ts @@ -5,7 +5,7 @@ import { Chunk } from "./Chunk"; import { SaveCompressionType } from "./enums/SaveCompressionType"; import { deflate, inflate } from "zlib"; import { World } from "./World"; -import { FunkyArray } from "../funkyArray"; +import FunkyArray from "funky-array"; import { Console } from "hsconsole"; enum FileMagic {