@zardoy/flying-squid 0.0.80 → 0.0.82
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/lib/modules/customBlockBreakTime.js +3 -1
- package/dist/lib/modules/customWaypoints.d.ts +19 -0
- package/dist/lib/modules/customWaypoints.js +73 -0
- package/dist/lib/modules/errorHandler.d.ts +0 -2
- package/dist/lib/modules/errorHandler.js +2 -2
- package/dist/lib/modules/index.js +1 -0
- package/dist/lib/modules/log.d.ts +1 -1
- package/dist/lib/modules/log.js +19 -20
- package/dist/lib/modules/login.js +1 -0
- package/dist/modules.d.ts +1 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const server: (serv: Server) => {
|
|
2
|
+
customWaypoints: Record<string, Waypoint>;
|
|
3
|
+
customAddWaypoint: (id: string, waypoint: Waypoint) => void;
|
|
4
|
+
customRemoveWaypoint: (id: string) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare const player: (player: Player, serv: Server) => Promise<void>;
|
|
7
|
+
export type Waypoint = {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
z: number;
|
|
11
|
+
minDistance?: number;
|
|
12
|
+
label?: string;
|
|
13
|
+
color?: number;
|
|
14
|
+
};
|
|
15
|
+
declare global {
|
|
16
|
+
interface Server {
|
|
17
|
+
customWaypoints: ReturnType<typeof server>;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.player = exports.server = void 0;
|
|
4
|
+
const ADD_CHANNEL = 'minecraft-web-client:waypoint-add';
|
|
5
|
+
const DELETE_CHANNEL = 'minecraft-web-client:waypoint-delete';
|
|
6
|
+
const server = (serv) => {
|
|
7
|
+
const module = {
|
|
8
|
+
customWaypoints: {},
|
|
9
|
+
customAddWaypoint: (id, waypoint) => {
|
|
10
|
+
serv.customWaypoints.customWaypoints[id] = waypoint;
|
|
11
|
+
// Broadcast add/update to all online players
|
|
12
|
+
for (const player of serv.players ?? []) {
|
|
13
|
+
sendAddWaypoint(player, id, waypoint);
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
customRemoveWaypoint: (id) => {
|
|
17
|
+
delete serv.customWaypoints.customWaypoints[id];
|
|
18
|
+
// Broadcast delete to all online players
|
|
19
|
+
for (const player of serv.players ?? []) {
|
|
20
|
+
sendDeleteWaypoint(player, id);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
serv.customWaypoints = module;
|
|
25
|
+
return module;
|
|
26
|
+
};
|
|
27
|
+
exports.server = server;
|
|
28
|
+
function sendAddWaypoint(player, id, waypoint) {
|
|
29
|
+
player._client.writeChannel(ADD_CHANNEL, {
|
|
30
|
+
id,
|
|
31
|
+
x: waypoint.x,
|
|
32
|
+
y: waypoint.y,
|
|
33
|
+
z: waypoint.z,
|
|
34
|
+
minDistance: waypoint.minDistance ?? 0,
|
|
35
|
+
label: waypoint.label ?? '',
|
|
36
|
+
color: waypoint.color ?? 0
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function sendDeleteWaypoint(player, id) {
|
|
40
|
+
player._client.writeChannel(DELETE_CHANNEL, { id });
|
|
41
|
+
}
|
|
42
|
+
function sendAllWaypoints(player, serv) {
|
|
43
|
+
const entries = Object.entries(serv.customWaypoints.customWaypoints ?? {});
|
|
44
|
+
for (const [id, waypoint] of entries) {
|
|
45
|
+
sendAddWaypoint(player, id, waypoint);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const player = async (player, serv) => {
|
|
49
|
+
// Register channels expected by the client
|
|
50
|
+
player._client.registerChannel(ADD_CHANNEL, ['container', [
|
|
51
|
+
{ name: 'id', type: ['pstring', { countType: 'i16' }] },
|
|
52
|
+
{ name: 'x', type: 'f32' },
|
|
53
|
+
{ name: 'y', type: 'f32' },
|
|
54
|
+
{ name: 'z', type: 'f32' },
|
|
55
|
+
{ name: 'minDistance', type: 'i32' },
|
|
56
|
+
{
|
|
57
|
+
name: 'label',
|
|
58
|
+
type: ['pstring', { countType: 'i16' }]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'color',
|
|
62
|
+
type: 'i32'
|
|
63
|
+
}
|
|
64
|
+
]]);
|
|
65
|
+
player._client.registerChannel(DELETE_CHANNEL, ['container', [
|
|
66
|
+
{ name: 'id', type: ['pstring', { countType: 'i16' }] },
|
|
67
|
+
]]);
|
|
68
|
+
// Send current server waypoints on join
|
|
69
|
+
player.on('login', () => {
|
|
70
|
+
sendAllWaypoints(player, serv);
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
exports.player = player;
|
|
@@ -6,7 +6,7 @@ const player = async function (player, serv) {
|
|
|
6
6
|
serv.warn('-------------------------------');
|
|
7
7
|
serv.warn('Please report this flying-squid! This is bug (mabye)');
|
|
8
8
|
serv.warn('Unhandled rejection warning!');
|
|
9
|
-
serv.warn('Error: ' + promise);
|
|
9
|
+
serv.warn('Error: ' + (promise.stack ?? promise));
|
|
10
10
|
serv.warn('Report this error here: https://github.com/PrismarineJS/flying-squid/issues');
|
|
11
11
|
serv.warn('-------------------------------');
|
|
12
12
|
serv.emit('unhandledRejectionWarning');
|
|
@@ -15,7 +15,7 @@ const player = async function (player, serv) {
|
|
|
15
15
|
serv.err('-------------------------------');
|
|
16
16
|
serv.err('Please report this flying-squid! This is bug (mabye)');
|
|
17
17
|
serv.err('Something went wrong!');
|
|
18
|
-
serv.err('Error: ' + err.stack);
|
|
18
|
+
serv.err('Error: ' + (err.stack ?? err));
|
|
19
19
|
serv.err('Report this error here: https://github.com/PrismarineJS/flying-squid/issues');
|
|
20
20
|
serv.err('-------------------------------');
|
|
21
21
|
serv.emit('crash');
|
|
@@ -15,6 +15,7 @@ module.exports = {
|
|
|
15
15
|
'communication': require('./communication'),
|
|
16
16
|
'crafting': require('./crafting'),
|
|
17
17
|
'customBlockBreakTime': require('./customBlockBreakTime'),
|
|
18
|
+
'customWaypoints': require('./customWaypoints'),
|
|
18
19
|
'database': require('./database'),
|
|
19
20
|
'daycycle': require('./daycycle'),
|
|
20
21
|
'digging': require('./digging'),
|
|
@@ -5,7 +5,7 @@ declare global {
|
|
|
5
5
|
/** You can override this function so you can process the message before sending it to the console. */
|
|
6
6
|
formatMessage(message: any): any;
|
|
7
7
|
/** Logs a `message` */
|
|
8
|
-
"log": (message: any) => void;
|
|
8
|
+
"log": (message: any, isError?: boolean) => void;
|
|
9
9
|
/** Logs a `message` as info */
|
|
10
10
|
"info": (message: any) => void;
|
|
11
11
|
/** Logs a `message` as error */
|
package/dist/lib/modules/log.js
CHANGED
|
@@ -85,46 +85,45 @@ const server = function (serv, settings) {
|
|
|
85
85
|
serv.on('banned', (banner, bannedUsername, reason) => serv.info(banner.username + ' banned ' + bannedUsername + (reason ? ' (' + reason + ')' : '')));
|
|
86
86
|
serv.on('seed', (seed) => serv.info('World seed: ' + seed));
|
|
87
87
|
const logFile = path_1.default.join('logs', timeStarted + '.log');
|
|
88
|
-
serv.log = message => {
|
|
88
|
+
serv.log = (message, isError = false) => {
|
|
89
89
|
readline?.cursorTo(process.stdout, 0);
|
|
90
90
|
let date = new Date();
|
|
91
91
|
let formattedDate = `${date.toLocaleString('default', { month: 'long' })} ${date.getDate()} ${date.getFullYear()}, ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}:${date.getSeconds().toString().padStart(2, '0')}`;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
// Prefix timestamp first
|
|
93
|
+
let fullMessage = formattedDate + ' ' + message; // todo use intl
|
|
94
|
+
// Allow user-defined formatting to modify the full line
|
|
95
|
+
fullMessage = serv.formatMessage?.(fullMessage) ?? fullMessage;
|
|
96
|
+
if (!fullMessage)
|
|
95
97
|
return;
|
|
98
|
+
// Push to buffers (plain text, with timestamp)
|
|
99
|
+
const plain = fullMessage.replace(/\x1B\[[0-9;]*m/g, '');
|
|
100
|
+
serv._logBuffer.push(plain);
|
|
101
|
+
if (serv._logBuffer.length > MAX_BUFFER_LINES)
|
|
102
|
+
serv._logBuffer.shift();
|
|
103
|
+
if (isError) {
|
|
104
|
+
serv._errorBuffer.push(plain);
|
|
105
|
+
if (serv._errorBuffer.length > MAX_BUFFER_LINES)
|
|
106
|
+
serv._errorBuffer.shift();
|
|
107
|
+
}
|
|
96
108
|
if (!settings.noConsoleOutput)
|
|
97
|
-
console.log(
|
|
109
|
+
console.log(fullMessage);
|
|
98
110
|
if (!settings.logging)
|
|
99
111
|
return;
|
|
100
|
-
fs_1.default.appendFile(logFile,
|
|
112
|
+
fs_1.default.appendFile(logFile, plain + '\n', (err) => {
|
|
101
113
|
if (err)
|
|
102
114
|
console.log(err);
|
|
103
115
|
});
|
|
104
116
|
};
|
|
105
117
|
serv.info = message => {
|
|
106
118
|
const line = '[' + chalk_1.default.green('INFO') + ']: ' + message;
|
|
107
|
-
serv._logBuffer.push(line.replace(/\x1B\[[0-9;]*m/g, ''));
|
|
108
|
-
if (serv._logBuffer.length > MAX_BUFFER_LINES)
|
|
109
|
-
serv._logBuffer.shift();
|
|
110
119
|
serv.log(line);
|
|
111
120
|
};
|
|
112
121
|
serv.err = message => {
|
|
113
122
|
const line = '[' + chalk_1.default.red('ERROR') + ']: ' + message;
|
|
114
|
-
|
|
115
|
-
serv._logBuffer.push(plain);
|
|
116
|
-
serv._errorBuffer.push(plain);
|
|
117
|
-
if (serv._logBuffer.length > MAX_BUFFER_LINES)
|
|
118
|
-
serv._logBuffer.shift();
|
|
119
|
-
if (serv._errorBuffer.length > MAX_BUFFER_LINES)
|
|
120
|
-
serv._errorBuffer.shift();
|
|
121
|
-
serv.log(line);
|
|
123
|
+
serv.log(line, true);
|
|
122
124
|
};
|
|
123
125
|
serv.warn = message => {
|
|
124
126
|
const line = '[' + chalk_1.default.yellow('WARN') + ']: ' + message;
|
|
125
|
-
serv._logBuffer.push(line.replace(/\x1B\[[0-9;]*m/g, ''));
|
|
126
|
-
if (serv._logBuffer.length > MAX_BUFFER_LINES)
|
|
127
|
-
serv._logBuffer.shift();
|
|
128
127
|
serv.log(line);
|
|
129
128
|
};
|
|
130
129
|
if (isInNode) {
|
|
@@ -241,6 +241,7 @@ const player = async function (player, serv, settings) {
|
|
|
241
241
|
isDebug: false,
|
|
242
242
|
isFlat: settings.generation?.name === 'superflat'
|
|
243
243
|
});
|
|
244
|
+
player.emit('login');
|
|
244
245
|
if (serv.supportFeature('difficultySentSeparately')) {
|
|
245
246
|
player._client.write('difficulty', {
|
|
246
247
|
difficulty: serv.difficulty,
|
package/dist/modules.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ declare global {
|
|
|
17
17
|
/** Emitted when the player's data is loaded from playerdata folder and can be patched if needed (but will be saved back to playerdata folder if patched) */
|
|
18
18
|
dataLoaded: () => void;
|
|
19
19
|
databaseLoaded: () => void;
|
|
20
|
+
login: () => void;
|
|
20
21
|
}
|
|
21
22
|
interface ServerEvents {
|
|
22
23
|
error: (error: Error, pluginName?: string) => void;
|
package/dist/types.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import "./lib/modules/commands.d.ts"
|
|
|
12
12
|
import "./lib/modules/communication.d.ts"
|
|
13
13
|
import "./lib/modules/crafting.d.ts"
|
|
14
14
|
import "./lib/modules/customBlockBreakTime.d.ts"
|
|
15
|
+
import "./lib/modules/customWaypoints.d.ts"
|
|
15
16
|
import "./lib/modules/database.d.ts"
|
|
16
17
|
import "./lib/modules/daycycle.d.ts"
|
|
17
18
|
import "./lib/modules/digging.d.ts"
|