@zardoy/flying-squid 0.0.104 → 0.0.106
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.
- package/dist/index.js +6 -5
- package/dist/lib/behavior.d.ts +1 -1
- package/dist/lib/behavior.js +9 -3
- package/dist/lib/modules/digging.js +1 -1
- package/package.json +1 -2
package/dist/index.js
CHANGED
|
@@ -56,7 +56,6 @@ if (typeof process !== 'undefined' && !process.browser && process.platform !== '
|
|
|
56
56
|
console.error(`[\x1b[31mCRITICAL\x1b[0m] Your current Node.JS version is: ${process.versions.node}`);
|
|
57
57
|
process.exit(1);
|
|
58
58
|
}
|
|
59
|
-
require('emit-then').register();
|
|
60
59
|
if (process.env.NODE_ENV === 'dev') {
|
|
61
60
|
|
|
62
61
|
}
|
|
@@ -108,16 +107,16 @@ class MCServer extends events_1.EventEmitter {
|
|
|
108
107
|
server._server = oldServer?._server ?? (0, minecraft_protocol_1.createServer)({
|
|
109
108
|
...options,
|
|
110
109
|
});
|
|
110
|
+
const connPendingUsernames = new Set();
|
|
111
111
|
server._server.on('connection', (client) => {
|
|
112
112
|
const loginOld = client['_events'].login_start;
|
|
113
|
-
const pendingUsernames = new Set();
|
|
114
113
|
if (typeof loginOld === 'function') {
|
|
115
114
|
client['_events'].login_start = async (packet) => {
|
|
116
115
|
const packetUsername = packet.username.toLowerCase();
|
|
117
|
-
if (
|
|
116
|
+
if (connPendingUsernames.has(packetUsername)) {
|
|
118
117
|
client.end('A player with this username is already connecting');
|
|
119
118
|
}
|
|
120
|
-
|
|
119
|
+
connPendingUsernames.add(packetUsername);
|
|
121
120
|
try {
|
|
122
121
|
const username = (await server.customGetUsername?.(packet, client)) ?? packetUsername;
|
|
123
122
|
if (client.ended)
|
|
@@ -132,9 +131,11 @@ class MCServer extends events_1.EventEmitter {
|
|
|
132
131
|
}
|
|
133
132
|
}
|
|
134
133
|
catch (err) {
|
|
135
|
-
pendingUsernames.delete(packetUsername);
|
|
136
134
|
client.end('An error occurred while connecting to the server');
|
|
137
135
|
}
|
|
136
|
+
finally {
|
|
137
|
+
connPendingUsernames.delete(packetUsername);
|
|
138
|
+
}
|
|
138
139
|
};
|
|
139
140
|
}
|
|
140
141
|
});
|
package/dist/lib/behavior.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type CustomEventEmitter = {
|
|
2
|
+
listeners(event: string): Function[];
|
|
2
3
|
emit(event: string, ...args: any[]): boolean;
|
|
3
|
-
emitThen(event: string, ...args: any[]): Promise<void>;
|
|
4
4
|
};
|
|
5
5
|
export type CancelFunction = (defaultCancel?: boolean, hidden?: boolean) => void;
|
|
6
6
|
export type BehaviorFunction<T = any, R = any> = (data: T) => R | Promise<R>;
|
package/dist/lib/behavior.js
CHANGED
|
@@ -35,14 +35,18 @@ exports.default = (obj) => {
|
|
|
35
35
|
// Handle each event emission separately to allow pipeline to continue
|
|
36
36
|
// PRE EVENT
|
|
37
37
|
try {
|
|
38
|
-
|
|
38
|
+
for (const listener of obj.listeners(eventName + '_cancel')) {
|
|
39
|
+
await listener(data, cancel);
|
|
40
|
+
}
|
|
39
41
|
}
|
|
40
42
|
catch (err) {
|
|
41
43
|
handleError(err, eventName + '_cancel', false);
|
|
42
44
|
}
|
|
43
45
|
// MAIN EVENT
|
|
44
46
|
try {
|
|
45
|
-
|
|
47
|
+
for (const listener of obj.listeners(eventName)) {
|
|
48
|
+
await listener(data, cancelled, cancelCount);
|
|
49
|
+
}
|
|
46
50
|
}
|
|
47
51
|
catch (err) {
|
|
48
52
|
handleError(err, eventName, false);
|
|
@@ -79,7 +83,9 @@ exports.default = (obj) => {
|
|
|
79
83
|
}
|
|
80
84
|
// POST EVENT
|
|
81
85
|
try {
|
|
82
|
-
|
|
86
|
+
for (const listener of obj.listeners(eventName + '_done')) {
|
|
87
|
+
await listener(data, resp, cancelled);
|
|
88
|
+
}
|
|
83
89
|
}
|
|
84
90
|
catch (err) {
|
|
85
91
|
handleError(err, eventName + '_done', true);
|
|
@@ -89,7 +89,7 @@ const player = function (player, serv, { version }) {
|
|
|
89
89
|
const customBreakTime = player.customGetBreakTime(currentlyDugBlock);
|
|
90
90
|
if (customBreakTime !== undefined)
|
|
91
91
|
return customBreakTime * 1000;
|
|
92
|
-
return currentlyDugBlock.digTime(null, false, false, false);
|
|
92
|
+
return currentlyDugBlock.digTime(player.inventory.slots[36 + player.heldItemSlot]?.type ?? null, false, false, false);
|
|
93
93
|
}
|
|
94
94
|
let currentlyDugBlock;
|
|
95
95
|
let startDiggingTime;
|
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.
|
|
4
|
+
"version": "0.0.106",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"bin": "dist/app.js",
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"chalk": "^5.3.0",
|
|
26
26
|
"change-case": "^4.1.2",
|
|
27
27
|
"diamond-square": "github:zardoy/diamond-square",
|
|
28
|
-
"emit-then": "^2.0.0",
|
|
29
28
|
"exit-hook": "^2.2.1",
|
|
30
29
|
"flatmap": "^0.0.3",
|
|
31
30
|
"long": "^5.1.0",
|