-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInitializable.java
More file actions
50 lines (39 loc) · 1.05 KB
/
Initializable.java
File metadata and controls
50 lines (39 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package dev.amble.lib.api.sync;
public abstract class Initializable<T extends Initializable.Context> {
public static <T extends Initializable.Context> void init(Initializable<T> component, T context) {
component.init(context);
}
protected void init(T context) {
this.onEarlyInit(context);
if (context.deserialized()) {
this.onLoaded();
} else {
this.onCreate();
}
this.onInit(context);
}
/**
* Called first in the initialization sequence.
*/
protected void onEarlyInit(T ctx) {
}
/**
* Called after a {@link #onLoaded()} or {@link #onCreate()} is called.
*/
protected void onInit(T ctx) {
}
/**
* Called when the component is created. Server-side only.
*/
public void onCreate() {
}
/**
* Called when the component is loaded from a file or received on the client.
*/
public void onLoaded() {
}
public interface Context {
boolean created();
boolean deserialized();
}
}