Skip to content

Commit 446f038

Browse files
committed
Fix load issues
1 parent ed64bf1 commit 446f038

5 files changed

Lines changed: 51 additions & 8 deletions

File tree

realty-paper-plan-extension/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies {
1010
compileOnly("com.github.plan-player-analytics:Plan:5.7.3306")
1111
compileOnly("org.jetbrains:annotations:26.0.2-1")
1212

13+
testImplementation(project(":realty-common"))
1314
testImplementation(platform("org.junit:junit-bom:5.11.4"))
1415
testImplementation("org.junit.jupiter:junit-jupiter")
1516
testImplementation("com.github.plan-player-analytics:Plan:5.7.3306")
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package io.github.md5sha256.realty.plan;
2+
3+
import com.djrapitops.plan.capability.CapabilityService;
4+
import com.djrapitops.plan.extension.ExtensionService;
5+
import io.github.md5sha256.realty.api.RealtyApi;
6+
7+
final class PlanRegistration {
8+
9+
private final RealtyDataExtension extension;
10+
11+
PlanRegistration(RealtyApi realtyApi) {
12+
this.extension = new RealtyDataExtension(realtyApi);
13+
}
14+
15+
void register() {
16+
CapabilityService.getInstance().registerEnableListener(isPlanEnabled -> {
17+
if (isPlanEnabled) {
18+
registerExtension();
19+
}
20+
});
21+
registerExtension();
22+
}
23+
24+
void unregister() {
25+
try {
26+
ExtensionService.getInstance().unregister(extension);
27+
} catch (IllegalStateException ignored) {
28+
// ExtensionService not initialized, nothing to unregister
29+
}
30+
}
31+
32+
private void registerExtension() {
33+
if (!CapabilityService.getInstance().hasCapability("DATA_EXTENSION_VALUES")) {
34+
return;
35+
}
36+
ExtensionService.getInstance().register(extension);
37+
}
38+
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package io.github.md5sha256.realty.plan;
22

3-
import com.djrapitops.plan.extension.DataExtension;
4-
import com.djrapitops.plan.extension.ExtensionService;
53
import io.github.md5sha256.realty.api.RealtyApi;
64
import org.bukkit.plugin.java.JavaPlugin;
75

86
public final class RealtyPaperPlanExtensionPlugin extends JavaPlugin {
97

10-
private DataExtension dataExtension;
8+
private PlanRegistration registration;
119

1210
@Override
1311
public void onEnable() {
@@ -17,13 +15,14 @@ public void onEnable() {
1715
getServer().getPluginManager().disablePlugin(this);
1816
return;
1917
}
20-
var api = provider.getProvider();
21-
this.dataExtension = new RealtyDataExtension(api);
22-
ExtensionService.getInstance().register(dataExtension);
18+
this.registration = new PlanRegistration(provider.getProvider());
19+
this.registration.register();
2320
}
2421

2522
@Override
2623
public void onDisable() {
27-
ExtensionService.getInstance().unregister(dataExtension);
24+
if (registration != null) {
25+
registration.unregister();
26+
}
2827
}
2928
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
name: Realty-Plan-Extension
1+
name: Realty Plan Extension
22
version: "${version}"
33
main: io.github.md5sha256.realty.plan.RealtyPaperPlanExtensionPlugin
44
api-version: "1.21.8"
55
authors: [ md5sha256 ]
66
dependencies:
77
server:
88
Realty:
9+
load: BEFORE
910
join-classpath: true
1011
required: true
1112
Plan:
13+
load: BEFORE
1214
join-classpath: true
1315
required: true

realty-paper/src/main/resources/paper-plugin.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ authors: [ md5sha256 ]
66
dependencies:
77
server:
88
Vault:
9+
load: BEFORE
910
join-classpath: true
1011
required: true
1112
WorldGuard:
13+
load: BEFORE
1214
join-classpath: true
1315
required: true
1416
Essentials:
17+
load: BEFORE
1518
join-classpath: true
1619
required: false
1720
permissions:

0 commit comments

Comments
 (0)