@block_factory/lib 0.0.8 → 0.0.9

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.
@@ -2,7 +2,7 @@ import { Player, EntityInventoryComponent, PlayAnimationOptions, system, world,
2
2
  import { IContainer, Inventory } from "./_Container";
3
3
  import { iSystem } from "../ISystem";
4
4
  import { Ctor, PropertyRecord } from "../Globals";
5
- import { WrapperCore } from "./_Common";
5
+ import { CLASS_I_UUID, WrapperCore } from "./_Common";
6
6
 
7
7
  export type IPlayer<T extends ICustomPlayer> = T & Player;
8
8
 
@@ -41,6 +41,7 @@ export abstract class ICustomPlayer {
41
41
  public data?(): PropertyRecord;
42
42
  public onReady?(): void;
43
43
  public interval?(): void;
44
+ public onLeave?(): void;
44
45
  }
45
46
 
46
47
  const cache = new Map<string, Map<Function, any>>();
@@ -59,6 +60,17 @@ class PlayerWrapper {
59
60
  }
60
61
  }
61
62
 
63
+ world.beforeEvents.playerLeave.subscribe((event) => {
64
+ const classId = event.player.getDynamicProperty(CLASS_I_UUID) as string | undefined;
65
+ system.run(() => {
66
+ if (!classId) return;
67
+ const Ctor = iSystem.iClassRegistry.get(classId);
68
+ if (!Ctor) return;
69
+ const wrapped = ICustomPlayer.wrap(event.player, Ctor);
70
+ wrapped.onLeave?.();
71
+ })
72
+ });
73
+
62
74
  //Delete from cache on remove
63
75
  world.afterEvents.playerLeave.subscribe(({ playerId }) => {
64
76
  if (!cache.has(playerId)) return;
@@ -28,7 +28,6 @@ export class WrapperCore {
28
28
 
29
29
  const existing = byCtor.get(Ctor) as W | undefined;
30
30
  if (existing) return existing;
31
-
32
31
  const inst = new (Ctor as any)(source);
33
32
  const proxied = iSystem.ProxyConstructor(inst, source) as W;
34
33
 
@@ -36,7 +35,9 @@ export class WrapperCore {
36
35
  proxied.onReady?.();
37
36
 
38
37
  byCtor.set(Ctor, proxied);
39
- source.setDynamicProperty(CLASS_I_UUID, Ctor.name);
38
+ try {
39
+ source.setDynamicProperty(CLASS_I_UUID, Ctor.name);
40
+ } catch (error) {/*Stops void players from throwing errors on logout*/}
40
41
 
41
42
  return proxied;
42
43
  }
@@ -54,7 +55,6 @@ export class WrapperCore {
54
55
 
55
56
  const Ctor = registry.get(classId);
56
57
  if (!Ctor) return;
57
-
58
58
  wrapFn(source as any, Ctor);
59
59
  }
60
60
 
@@ -100,7 +100,6 @@ export class WrapperCore {
100
100
 
101
101
  public static loadDynData(target: DynStore): void {
102
102
  if (!target.data) return;
103
-
104
103
  const schema = target.data() as Record<string, unknown>;
105
104
  for (const key of Object.keys(schema)) {
106
105
  const v = target.getDynamicProperty(key);
@@ -110,7 +109,6 @@ export class WrapperCore {
110
109
 
111
110
  public static saveDynData(target: DynStore): void {
112
111
  if (!target.isValid || !target.data) return;
113
-
114
112
  const saveData = target.data() as Record<string, unknown>;
115
113
  for (const [key, value] of Object.entries(saveData)) {
116
114
  target.setDynamicProperty(key, value as PropertyValue);
package/index.js CHANGED
@@ -160,7 +160,10 @@ var WrapperCore = class {
160
160
  proxied.loadData();
161
161
  proxied.onReady?.();
162
162
  byCtor.set(Ctor, proxied);
163
- source.setDynamicProperty(CLASS_I_UUID, Ctor.name);
163
+ try {
164
+ source.setDynamicProperty(CLASS_I_UUID, Ctor.name);
165
+ } catch (error) {
166
+ }
164
167
  return proxied;
165
168
  }
166
169
  static repopulate(cache3, source, registry, wrapFn) {
@@ -273,6 +276,16 @@ var PlayerWrapper = class {
273
276
  return WrapperCore.iterateByCtor(cache, Ctor);
274
277
  }
275
278
  };
279
+ world.beforeEvents.playerLeave.subscribe((event) => {
280
+ const classId = event.player.getDynamicProperty(CLASS_I_UUID);
281
+ system4.run(() => {
282
+ if (!classId) return;
283
+ const Ctor = iSystem.iClassRegistry.get(classId);
284
+ if (!Ctor) return;
285
+ const wrapped = ICustomPlayer.wrap(event.player, Ctor);
286
+ wrapped.onLeave?.();
287
+ });
288
+ });
276
289
  world.afterEvents.playerLeave.subscribe(({ playerId }) => {
277
290
  if (!cache.has(playerId)) return;
278
291
  cache.delete(playerId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@block_factory/lib",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "description": "Typescript Library for Minecraft Bedrock Edition",