@zardoy/flying-squid 0.0.91 → 0.0.93
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/config/default-settings.json +11 -9
- package/dist/lib/behavior.d.ts +21 -1
- package/dist/lib/behavior.js +29 -17
- package/dist/lib/modules/animations.d.ts +5 -0
- package/dist/lib/modules/animations.js +7 -5
- package/dist/lib/modules/behavior.d.ts +6 -1
- package/dist/lib/modules/blockUpdates.js +3 -1
- package/dist/lib/modules/blocks.d.ts +15 -0
- package/dist/lib/modules/chat.d.ts +74 -29
- package/dist/lib/modules/chat.js +87 -13
- package/dist/lib/modules/chest.js +1 -1
- package/dist/lib/modules/crafting.js +1 -1
- package/dist/lib/modules/customBlockBreakTime.d.ts +1 -0
- package/dist/lib/modules/customBlockBreakTime.js +1 -1
- package/dist/lib/modules/database.js +0 -4
- package/dist/lib/modules/digging.d.ts +42 -0
- package/dist/lib/modules/digging.js +26 -17
- package/dist/lib/modules/effects.d.ts +1 -1
- package/dist/lib/modules/effects.js +7 -5
- package/dist/lib/modules/header.js +9 -5
- package/dist/lib/modules/inventory.d.ts +18 -3
- package/dist/lib/modules/inventory.js +6 -1
- package/dist/lib/modules/logout.js +2 -1
- package/dist/lib/modules/particle.js +7 -1
- package/dist/lib/modules/placeBlock.d.ts +27 -1
- package/dist/lib/modules/placeBlock.js +30 -2
- package/dist/lib/modules/playerLogin.js +37 -24
- package/dist/lib/modules/pvp.d.ts +13 -0
- package/dist/lib/modules/pvp.js +4 -0
- package/dist/lib/modules/respawn.d.ts +8 -0
- package/dist/lib/modules/safeZones.d.ts +2 -2
- package/dist/lib/modules/safeZones.js +129 -50
- package/dist/lib/modules/sound.js +35 -13
- package/dist/lib/modules/spawn.js +25 -48
- package/dist/lib/modules/updatePositions.d.ts +18 -0
- package/dist/lib/modules/updatePositions.js +22 -7
- package/dist/lib/modules/useItem.js +2 -2
- package/dist/lib/modules/world.d.ts +10 -1
- package/dist/lib/modules/world.js +1 -0
- package/dist/modules.d.ts +5 -1
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ const player = function (player, serv, { version }) {
|
|
|
7
7
|
function cancelDig({ position, block }) {
|
|
8
8
|
player.sendBlock(position, block.type);
|
|
9
9
|
}
|
|
10
|
-
player._client.on('block_dig', ({ location, status, face }) => {
|
|
10
|
+
player._client.on('block_dig', ({ location, status, face, sequence }) => {
|
|
11
11
|
if (status === 3 || status === 4) {
|
|
12
12
|
const heldItem = player.inventory.slots[36 + player.heldItemSlot];
|
|
13
13
|
if (!heldItem || heldItem.type === -1)
|
|
@@ -53,14 +53,14 @@ const player = function (player, serv, { version }) {
|
|
|
53
53
|
console.warn(`[Digging] Column not loaded for player ${player.username} at ${pos}`);
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
-
const facedBlock = columnFaced.getBlock(new vec3_1.Vec3(facedPos.x & 15,
|
|
56
|
+
const facedBlock = columnFaced.getBlock(new vec3_1.Vec3(facedPos.x & 15, facedPos.y, facedPos.z & 15));
|
|
57
57
|
let block;
|
|
58
58
|
if (facedBlock.name === 'fire') {
|
|
59
59
|
block = facedBlock;
|
|
60
60
|
pos = facedPos;
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
|
-
block = columnBlock.getBlock(new vec3_1.Vec3(pos.x & 15,
|
|
63
|
+
block = columnBlock.getBlock(new vec3_1.Vec3(pos.x & 15, pos.y, pos.z & 15));
|
|
64
64
|
}
|
|
65
65
|
currentlyDugBlock = block;
|
|
66
66
|
if (currentlyDugBlock.type === 0)
|
|
@@ -70,14 +70,14 @@ const player = function (player, serv, { version }) {
|
|
|
70
70
|
creativeDigging(pos);
|
|
71
71
|
}
|
|
72
72
|
else {
|
|
73
|
-
startDigging(pos);
|
|
73
|
+
startDigging(pos, sequence);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
else if (status === 1 || player.gameMode >= 2) {
|
|
77
|
-
cancelDigging(pos);
|
|
77
|
+
cancelDigging(pos, sequence);
|
|
78
78
|
}
|
|
79
79
|
else if (status === 2) {
|
|
80
|
-
completeDigging(pos, directionVector);
|
|
80
|
+
completeDigging(pos, directionVector, sequence);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
});
|
|
@@ -94,7 +94,7 @@ const player = function (player, serv, { version }) {
|
|
|
94
94
|
let expectedDiggingTime;
|
|
95
95
|
let lastDestroyState;
|
|
96
96
|
let currentAnimationId;
|
|
97
|
-
function startDigging(location) {
|
|
97
|
+
function startDigging(location, sequenceId) {
|
|
98
98
|
serv.entityMaxId++;
|
|
99
99
|
currentAnimationId = serv.entityMaxId;
|
|
100
100
|
expectedDiggingTime = diggingTime();
|
|
@@ -125,6 +125,7 @@ const player = function (player, serv, { version }) {
|
|
|
125
125
|
}
|
|
126
126
|
if (serv.supportFeature('acknowledgePlayerDigging')) {
|
|
127
127
|
player._client.write('acknowledge_player_digging', {
|
|
128
|
+
sequenceId, // 1.19
|
|
128
129
|
location,
|
|
129
130
|
block: currentlyDugBlock.stateId,
|
|
130
131
|
status: 0,
|
|
@@ -132,7 +133,7 @@ const player = function (player, serv, { version }) {
|
|
|
132
133
|
});
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
|
-
function cancelDigging(location) {
|
|
136
|
+
function cancelDigging(location, sequenceId) {
|
|
136
137
|
clearInterval(animationInterval);
|
|
137
138
|
player._writeOthersNearby('block_break_animation', {
|
|
138
139
|
entityId: currentAnimationId,
|
|
@@ -141,6 +142,7 @@ const player = function (player, serv, { version }) {
|
|
|
141
142
|
});
|
|
142
143
|
if (serv.supportFeature('acknowledgePlayerDigging')) {
|
|
143
144
|
player._client.write('acknowledge_player_digging', {
|
|
145
|
+
sequenceId, // 1.19
|
|
144
146
|
location,
|
|
145
147
|
block: currentlyDugBlock.stateId,
|
|
146
148
|
status: 1,
|
|
@@ -149,19 +151,23 @@ const player = function (player, serv, { version }) {
|
|
|
149
151
|
}
|
|
150
152
|
}
|
|
151
153
|
const blockDropVelocity = new vec3_1.Vec3(Math.random() * 4 - 2, Math.random() * 2 + 2, Math.random() * 4 - 2);
|
|
152
|
-
async function completeDigging(location, directionVector) {
|
|
154
|
+
async function completeDigging(location, directionVector, sequenceId) {
|
|
153
155
|
clearInterval(animationInterval);
|
|
154
156
|
const diggingTime = Date.now() - startDiggingTime;
|
|
155
157
|
let stop = false;
|
|
156
158
|
// const MAX_DIG_DISTANCE = 7
|
|
157
159
|
const MAX_DIG_DISTANCE = 8;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
160
|
+
const tooFast = expectedDiggingTime - diggingTime > 50;
|
|
161
|
+
const tooFar = player.position.distanceTo(location) > MAX_DIG_DISTANCE;
|
|
162
|
+
if (tooFast || tooFar) {
|
|
163
|
+
stop = true;
|
|
164
|
+
await player.behavior('suspiciousDigStopped', {
|
|
165
|
+
tooFast,
|
|
166
|
+
tooFar,
|
|
167
|
+
location
|
|
168
|
+
}, () => { }, () => {
|
|
169
|
+
stop = false;
|
|
170
|
+
});
|
|
165
171
|
}
|
|
166
172
|
if (!stop) {
|
|
167
173
|
const drops = [];
|
|
@@ -214,6 +220,7 @@ const player = function (player, serv, { version }) {
|
|
|
214
220
|
}
|
|
215
221
|
if (serv.supportFeature('acknowledgePlayerDigging')) {
|
|
216
222
|
player._client.write('acknowledge_player_digging', {
|
|
223
|
+
sequenceId, // 1.19
|
|
217
224
|
location,
|
|
218
225
|
block: 0,
|
|
219
226
|
status: 2,
|
|
@@ -225,10 +232,11 @@ const player = function (player, serv, { version }) {
|
|
|
225
232
|
else {
|
|
226
233
|
player._client.write('block_change', {
|
|
227
234
|
location,
|
|
228
|
-
type: currentlyDugBlock.
|
|
235
|
+
type: currentlyDugBlock.stateId
|
|
229
236
|
});
|
|
230
237
|
if (serv.supportFeature('acknowledgePlayerDigging')) {
|
|
231
238
|
player.writePacket('acknowledge_player_digging', {
|
|
239
|
+
sequenceId, // 1.19
|
|
232
240
|
location,
|
|
233
241
|
block: currentlyDugBlock.stateId,
|
|
234
242
|
status: 2,
|
|
@@ -252,6 +260,7 @@ const player = function (player, serv, { version }) {
|
|
|
252
260
|
position: location,
|
|
253
261
|
block: currentlyDugBlock,
|
|
254
262
|
dropBlock: false,
|
|
263
|
+
blockDropCount: 0,
|
|
255
264
|
blockDropPosition: location.offset(0.5, 0.5, 0.5),
|
|
256
265
|
blockDropWorld: player.world,
|
|
257
266
|
blockDropVelocity: blockDropVelocity,
|
|
@@ -44,20 +44,22 @@ const entity = function (entity, serv) {
|
|
|
44
44
|
duration: opt.duration || 30 * 20,
|
|
45
45
|
particles: opt.particles || true,
|
|
46
46
|
end: Date.now() + (opt.duration || 30 * 20) * 1000 / 20, // 1000/20 === convert from ticks to milliseconds,
|
|
47
|
-
timeout: setTimeout(() => entity.removeEffect(effectId, {}), (opt.duration || 30 * 20) * 1000 / 20)
|
|
47
|
+
timeout: opt.duration === -1 ? undefined : setTimeout(() => entity.removeEffect(effectId, {}), (opt.duration || 30 * 20) * 1000 / 20)
|
|
48
48
|
};
|
|
49
|
-
entity.sendEffect(effectId, opt);
|
|
49
|
+
entity.sendEffect(effectId, { ...opt, whitelist: [entity] });
|
|
50
50
|
return true;
|
|
51
51
|
}
|
|
52
52
|
else
|
|
53
53
|
return false;
|
|
54
54
|
};
|
|
55
55
|
entity.removeEffect = (effectId, opt) => {
|
|
56
|
-
|
|
56
|
+
const effect = entity.effects[effectId];
|
|
57
|
+
if (!effect)
|
|
57
58
|
return;
|
|
58
|
-
|
|
59
|
+
if (effect.timeout)
|
|
60
|
+
clearTimeout(effect.timeout);
|
|
59
61
|
entity.effects[effectId] = null;
|
|
60
|
-
entity.sendRemoveEffect(effectId, opt);
|
|
62
|
+
entity.sendRemoveEffect(effectId, { ...opt, whitelist: [entity] });
|
|
61
63
|
};
|
|
62
64
|
};
|
|
63
65
|
exports.entity = entity;
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.player = void 0;
|
|
4
4
|
const player = function (player, serv, settings) {
|
|
5
|
-
player.playerlistUpdateText = (header, footer)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
player.playerlistUpdateText = function (header, footer) {
|
|
6
|
+
player._client.write('playerlist_header', {
|
|
7
|
+
header: serv._createChatComponent(header).toNetworkFormat(),
|
|
8
|
+
footer: serv._createChatComponent(footer).toNetworkFormat()
|
|
9
|
+
});
|
|
10
|
+
};
|
|
9
11
|
if (settings['player-list-text']) {
|
|
10
|
-
|
|
12
|
+
const header = settings['player-list-text'].header || '';
|
|
13
|
+
const footer = settings['player-list-text'].footer || '';
|
|
14
|
+
player.playerlistUpdateText(header, footer);
|
|
11
15
|
}
|
|
12
16
|
};
|
|
13
17
|
exports.player = player;
|
|
@@ -2,9 +2,24 @@ import { Item } from 'prismarine-item';
|
|
|
2
2
|
import { Window } from 'prismarine-windows';
|
|
3
3
|
export declare const player: (player: Player, serv: Server, { version }: Options) => void;
|
|
4
4
|
declare global {
|
|
5
|
+
interface Entity {
|
|
6
|
+
setEquipment: (slot: number, item: any) => void;
|
|
7
|
+
}
|
|
5
8
|
interface Player {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
heldItemSlot: number;
|
|
10
|
+
heldItem: Item;
|
|
11
|
+
inventory: Window;
|
|
12
|
+
customWindow: Window | undefined;
|
|
13
|
+
"collect": (collectEntity: Entity & {
|
|
14
|
+
itemId: number;
|
|
15
|
+
damage: number;
|
|
16
|
+
}) => void;
|
|
17
|
+
}
|
|
18
|
+
interface PlayerBehaviorInputMap {
|
|
19
|
+
'changeHeldItemSlot': {
|
|
20
|
+
_input: {
|
|
21
|
+
slot: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
9
24
|
}
|
|
10
25
|
}
|
|
@@ -13,7 +13,12 @@ const player = function (player, serv, { version }) {
|
|
|
13
13
|
player.heldItemSlot = 0;
|
|
14
14
|
// player.heldItem = new Item(256, 1)
|
|
15
15
|
player.inventory = windows.createWindow(1, 'minecraft:inventory', 'inv', 36);
|
|
16
|
-
player._client.on('held_item_slot', ({ slotId } = {}) => {
|
|
16
|
+
player._client.on('held_item_slot', async ({ slotId } = {}) => {
|
|
17
|
+
const { cancelled } = await player.behavior('changeHeldItemSlot', { slot: slotId, item: player.inventory.slots[36 + slotId] });
|
|
18
|
+
if (cancelled) {
|
|
19
|
+
player.writePacket('held_item_slot', { slotId: player.heldItemSlot });
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
17
22
|
player.heldItemSlot = slotId;
|
|
18
23
|
player.setEquipment(0, player.inventory.slots[36 + player.heldItemSlot]);
|
|
19
24
|
if (serv.supportFeature('allEntityEquipmentInOne')) {
|
|
@@ -22,7 +22,7 @@ const player = function (player, serv, { worldFolder }) {
|
|
|
22
22
|
entityIds: entities.map(e => e.id)
|
|
23
23
|
});
|
|
24
24
|
player._client.on('end', async (endReason) => {
|
|
25
|
-
if (player) {
|
|
25
|
+
if (!player.disconnected) {
|
|
26
26
|
player._unloadAllChunks?.();
|
|
27
27
|
if (player.username) {
|
|
28
28
|
serv.broadcast(serv.chatColor.yellow + player.username + ' left the game.');
|
|
@@ -43,6 +43,7 @@ const player = function (player, serv, { worldFolder }) {
|
|
|
43
43
|
serv.players.splice(index, 1);
|
|
44
44
|
}
|
|
45
45
|
delete serv.uuidToPlayer[player.uuid];
|
|
46
|
+
player.disconnected = true;
|
|
46
47
|
}
|
|
47
48
|
player.save?.();
|
|
48
49
|
});
|
|
@@ -22,7 +22,13 @@ const server = function (serv) {
|
|
|
22
22
|
offsetZ: size.z,
|
|
23
23
|
particleData: 1.0,
|
|
24
24
|
particles: count,
|
|
25
|
-
|
|
25
|
+
amount: count, // 1.20.5+
|
|
26
|
+
data: [],
|
|
27
|
+
velocityOffset: 0, // 1.20.5+
|
|
28
|
+
particle: {
|
|
29
|
+
type: 'bubble',
|
|
30
|
+
data: null
|
|
31
|
+
}
|
|
26
32
|
}, players.filter(p => blacklist.indexOf(p) === -1));
|
|
27
33
|
};
|
|
28
34
|
serv.commands.add({
|
|
@@ -1,13 +1,38 @@
|
|
|
1
1
|
import { Block } from 'prismarine-block';
|
|
2
|
+
import { Vec3 } from 'vec3';
|
|
3
|
+
import { Item } from 'prismarine-item';
|
|
2
4
|
export declare const server: (serv: Server, { version }: Options) => void;
|
|
3
5
|
export declare const player: (player: Player, serv: Server, { version }: Options) => void;
|
|
6
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
4
7
|
declare global {
|
|
5
8
|
interface Server {
|
|
6
9
|
/** Register a handler that will be called when an item of type `name` is called to place a block.
|
|
7
10
|
*
|
|
8
11
|
* The argument given to the handler is an object containing the held item that triggered the event, the direction (face) on which the player clicked, the angle of the player around the placed block. It should return an object containing the id and data of the block to place.
|
|
9
12
|
*/
|
|
10
|
-
'onItemPlace': (name:
|
|
13
|
+
'onItemPlace': (name: string, handler: (data: {
|
|
14
|
+
item: Item;
|
|
15
|
+
direction: number;
|
|
16
|
+
angle: number;
|
|
17
|
+
player: Player;
|
|
18
|
+
referencePosition: Vec3;
|
|
19
|
+
placedPosition: Vec3;
|
|
20
|
+
directionVector: Vec3;
|
|
21
|
+
properties: any;
|
|
22
|
+
}) => MaybePromise<{
|
|
23
|
+
id: number;
|
|
24
|
+
data: number;
|
|
25
|
+
} | void>, warn?: boolean) => void;
|
|
26
|
+
'onItemUse': (name: string, handler: (data: {
|
|
27
|
+
item: Item;
|
|
28
|
+
slot: number;
|
|
29
|
+
player: Player;
|
|
30
|
+
}) => void) => void;
|
|
31
|
+
itemUseHandlers: Map<number, (data: {
|
|
32
|
+
item: Item;
|
|
33
|
+
slot: number;
|
|
34
|
+
player: Player;
|
|
35
|
+
}) => void>;
|
|
11
36
|
/** Register a handler that will be called when a player interact with a block of type `name`.
|
|
12
37
|
*
|
|
13
38
|
* The argument given to the handler is an object containing the clicked block and the player. It should return true if the block interaction occurred and the block placement should be cancelled.
|
|
@@ -18,3 +43,4 @@ declare global {
|
|
|
18
43
|
}) => boolean | Promise<boolean>) => void;
|
|
19
44
|
}
|
|
20
45
|
}
|
|
46
|
+
export {};
|
|
@@ -35,6 +35,15 @@ const server = (serv, { version }) => {
|
|
|
35
35
|
}
|
|
36
36
|
itemPlaceHandlers.set(item.id, handler);
|
|
37
37
|
};
|
|
38
|
+
serv.itemUseHandlers = new Map();
|
|
39
|
+
serv.onItemUse = (name, handler) => {
|
|
40
|
+
const item = mcData.itemsByName[name] ?? mcData.blocksByName[name];
|
|
41
|
+
if (!item) {
|
|
42
|
+
serv.warn(`[onItemUse] Unknown item or block ${name}`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
serv.itemUseHandlers.set(item.id, handler);
|
|
46
|
+
};
|
|
38
47
|
if (serv.supportFeature('theFlattening')) {
|
|
39
48
|
const parseValue = (value, state) => {
|
|
40
49
|
if (state.type === 'enum') {
|
|
@@ -140,7 +149,13 @@ exports.server = server;
|
|
|
140
149
|
const player = function (player, serv, { version }) {
|
|
141
150
|
const mcData = serv.mcData;
|
|
142
151
|
const blocks = mcData.blocks;
|
|
143
|
-
|
|
152
|
+
let lastPlace = 0;
|
|
153
|
+
player._client.on('block_place', async ({ direction, location, cursorY, hand = 0 }) => {
|
|
154
|
+
if (hand !== 0)
|
|
155
|
+
return; // todo-low implement offhand
|
|
156
|
+
if (Date.now() - lastPlace < 15)
|
|
157
|
+
return;
|
|
158
|
+
lastPlace = Date.now();
|
|
144
159
|
const referencePosition = new vec3_1.Vec3(location.x, location.y, location.z);
|
|
145
160
|
const block = await player.world.getBlock(referencePosition);
|
|
146
161
|
block.position = referencePosition;
|
|
@@ -192,7 +207,7 @@ const player = function (player, serv, { version }) {
|
|
|
192
207
|
half,
|
|
193
208
|
waterlogged: (await player.world.getBlock(placedPosition)).type === mcData.blocksByName.water.id
|
|
194
209
|
}
|
|
195
|
-
});
|
|
210
|
+
}) ?? {};
|
|
196
211
|
if (!blocks[id])
|
|
197
212
|
return;
|
|
198
213
|
player.emit('blockPlaced', blocks[id]);
|
|
@@ -212,6 +227,19 @@ const player = function (player, serv, { version }) {
|
|
|
212
227
|
const stateId = serv.supportFeature('theFlattening') ? (blocks[id].minStateId + data) : (id << 4 | data);
|
|
213
228
|
player.setBlock(placedPosition, stateId);
|
|
214
229
|
});
|
|
230
|
+
let lastItemUse = 0;
|
|
231
|
+
player._client.on('use_item', async ({ hand = 0 }) => {
|
|
232
|
+
if (Date.now() - lastItemUse < 15)
|
|
233
|
+
return;
|
|
234
|
+
lastItemUse = Date.now();
|
|
235
|
+
const heldItem = player.inventory.slots[hand === 0 ? 36 + player.heldItemSlot : 45];
|
|
236
|
+
if (!heldItem || heldItem.type === -1)
|
|
237
|
+
return;
|
|
238
|
+
const handler = serv.itemUseHandlers.get(heldItem.type);
|
|
239
|
+
if (handler) {
|
|
240
|
+
handler({ item: heldItem, slot: hand === 0 ? player.heldItemSlot : 45, player });
|
|
241
|
+
}
|
|
242
|
+
});
|
|
215
243
|
};
|
|
216
244
|
exports.player = player;
|
|
217
245
|
const directionToVector = [new vec3_1.Vec3(0, -1, 0), new vec3_1.Vec3(0, 1, 0), new vec3_1.Vec3(0, 0, -1), new vec3_1.Vec3(0, 0, 1), new vec3_1.Vec3(-1, 0, 0), new vec3_1.Vec3(1, 0, 0)];
|
|
@@ -66,6 +66,12 @@ const server = function (serv, options) {
|
|
|
66
66
|
client.on('error', error => {
|
|
67
67
|
serv.emit('clientError', client, error);
|
|
68
68
|
});
|
|
69
|
+
client.on('state', (now) => {
|
|
70
|
+
if (now === 'configuration') {
|
|
71
|
+
client.write('feature_flags', { features: ['minecraft:vanilla'] });
|
|
72
|
+
client.write('select_known_packs', { packs: [] });
|
|
73
|
+
}
|
|
74
|
+
});
|
|
69
75
|
});
|
|
70
76
|
const patchClient = (client, player) => {
|
|
71
77
|
client.oldAddListener ??= client.on.bind(client);
|
|
@@ -106,6 +112,9 @@ const server = function (serv, options) {
|
|
|
106
112
|
plugin.player?.(player, serv, options);
|
|
107
113
|
serv.emit('newPlayer', player);
|
|
108
114
|
player.emit('asap');
|
|
115
|
+
player.on('move', () => {
|
|
116
|
+
player.sendChunkWhenMove();
|
|
117
|
+
});
|
|
109
118
|
};
|
|
110
119
|
// #region hot reload
|
|
111
120
|
serv.on('pluginsReady', () => {
|
|
@@ -113,7 +122,6 @@ const server = function (serv, options) {
|
|
|
113
122
|
for (const player of serv.players ?? []) {
|
|
114
123
|
addPlayerShared(player);
|
|
115
124
|
player.world = serv.overworld;
|
|
116
|
-
player.sendChunkWhenMove();
|
|
117
125
|
player._unloadAllChunks();
|
|
118
126
|
player.sendRestMap();
|
|
119
127
|
}
|
|
@@ -199,7 +207,10 @@ const player = async function (player, serv, settings) {
|
|
|
199
207
|
// Set world based on saved dimension data, fallback to overworld
|
|
200
208
|
const savedDimension = (playerData?.player?.Dimension?.value ?? 'overworld').replace('minecraft:', '');
|
|
201
209
|
player.world = (savedDimension === 'the_nether' || savedDimension === 'nether') ? serv.netherworld : (serv.worlds[savedDimension] ?? serv.overworld);
|
|
202
|
-
|
|
210
|
+
if (!player.disconnected) {
|
|
211
|
+
// it's possible player gets kicked during login process ; don't add them to the server
|
|
212
|
+
serv.players.push(player);
|
|
213
|
+
}
|
|
203
214
|
serv.uuidToPlayer[player.uuid] = player;
|
|
204
215
|
player.loadedChunks = {};
|
|
205
216
|
player.setLoadingStatus(null);
|
|
@@ -272,7 +283,8 @@ const player = async function (player, serv, settings) {
|
|
|
272
283
|
maxPlayers: Math.min(255, serv._server.maxPlayers),
|
|
273
284
|
enableRespawnScreen: true,
|
|
274
285
|
isDebug: false,
|
|
275
|
-
isFlat: settings.generation?.name === 'superflat'
|
|
286
|
+
isFlat: settings.generation?.name === 'superflat',
|
|
287
|
+
enforcesSecureChat: serv._server.options?.enforcesSecureChat
|
|
276
288
|
});
|
|
277
289
|
player.emit('login');
|
|
278
290
|
if (serv.supportFeature('difficultySentSeparately')) {
|
|
@@ -286,26 +298,28 @@ const player = async function (player, serv, settings) {
|
|
|
286
298
|
return new vec3_1.Vec3(pos.x, 0, pos.z);
|
|
287
299
|
};
|
|
288
300
|
player.sendChunkWhenMove = () => {
|
|
289
|
-
player.
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
301
|
+
if (player.stopChunkUpdates) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (!player.lastPositionChunkUpdated) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (getXYPos(player.position).distanceTo(getXYPos(player.lastPositionChunkUpdated)) > 16) {
|
|
308
|
+
player.sendRestMap();
|
|
309
|
+
}
|
|
310
|
+
if (!serv.supportFeature('updateViewPosition')) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const chunkX = Math.floor(player.position.x / 16);
|
|
314
|
+
const chunkZ = Math.floor(player.position.z / 16);
|
|
315
|
+
const lastChunkX = Math.floor(player.lastPositionPlayersUpdated.x / 16);
|
|
316
|
+
const lastChunkZ = Math.floor(player.lastPositionPlayersUpdated.z / 16);
|
|
317
|
+
if (chunkX !== lastChunkX || chunkZ !== lastChunkZ) {
|
|
318
|
+
player._client.write('update_view_position', {
|
|
319
|
+
chunkX,
|
|
320
|
+
chunkZ
|
|
321
|
+
});
|
|
322
|
+
}
|
|
309
323
|
};
|
|
310
324
|
function updateTime() {
|
|
311
325
|
player._client.write('update_time', {
|
|
@@ -471,7 +485,6 @@ const player = async function (player, serv, settings) {
|
|
|
471
485
|
await player.waitPlayerLogin();
|
|
472
486
|
}
|
|
473
487
|
player.sendRestMap();
|
|
474
|
-
player.sendChunkWhenMove();
|
|
475
488
|
if (playerData.new) { // otherwise we skip unnecessary fs operation
|
|
476
489
|
player.save();
|
|
477
490
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { Vec3 } from 'vec3';
|
|
1
2
|
export declare const player: (player: Player, serv: Server) => void;
|
|
2
3
|
export declare const entity: (entity: Entity, serv: Server) => void;
|
|
3
4
|
export declare const server: (serv: Server) => void;
|
|
4
5
|
declare global {
|
|
6
|
+
interface Player {
|
|
7
|
+
/** Timestamp of last damage taken, used for movement anti-cheat */
|
|
8
|
+
lastDamageTime?: number;
|
|
9
|
+
}
|
|
5
10
|
interface Entity {
|
|
6
11
|
/** Whether the entity is invincible to all damage */
|
|
7
12
|
invincible: boolean;
|
|
@@ -21,4 +26,12 @@ declare global {
|
|
|
21
26
|
animation?: boolean | undefined;
|
|
22
27
|
}) => void;
|
|
23
28
|
}
|
|
29
|
+
interface PlayerBehaviorInputMap {
|
|
30
|
+
'attack': {
|
|
31
|
+
_input: {
|
|
32
|
+
attackedEntity: Entity;
|
|
33
|
+
velocity: Vec3;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
}
|
|
24
37
|
}
|
package/dist/lib/modules/pvp.js
CHANGED
|
@@ -61,6 +61,10 @@ const entity = function (entity, serv) {
|
|
|
61
61
|
return;
|
|
62
62
|
entity.updateHealth(entity.health - damage);
|
|
63
63
|
serv.playSound(sound, entity.world, entity.position);
|
|
64
|
+
// Track last damage time for anti-cheat movement checks
|
|
65
|
+
if (entity.type === 'player') {
|
|
66
|
+
entity.lastDamageTime = Date.now();
|
|
67
|
+
}
|
|
64
68
|
entity.sendVelocity(velocity, maxVelocity);
|
|
65
69
|
if (entity.health <= 0) {
|
|
66
70
|
if (animation) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Vec3 } from 'vec3';
|
|
2
2
|
export declare const server: (serv: Server) => void;
|
|
3
|
-
export declare const player: (player: Player, serv: Server, { basePositionAntiCheat,
|
|
3
|
+
export declare const player: (player: Player, serv: Server, { basePositionAntiCheat, positionAntiCheatNotifyPlayer }: Options) => void;
|
|
4
4
|
export type AABB = {
|
|
5
5
|
min: Vec3;
|
|
6
6
|
max: Vec3;
|
|
@@ -8,7 +8,7 @@ export type AABB = {
|
|
|
8
8
|
declare global {
|
|
9
9
|
interface Options {
|
|
10
10
|
basePositionAntiCheat?: boolean;
|
|
11
|
-
|
|
11
|
+
positionAntiCheatNotifyPlayer?: boolean;
|
|
12
12
|
}
|
|
13
13
|
interface Server {
|
|
14
14
|
safeZones: AABB[];
|