Skip to content

Commit 6fcd2e1

Browse files
committed
Add Chunky to load spawn chunks
1 parent 69e94b5 commit 6fcd2e1

File tree

6 files changed

+48
-24
lines changed

6 files changed

+48
-24
lines changed

Common/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies {
2626
}
2727
compileOnly("net.luckperms:api:5.5")
2828
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1")
29+
compileOnly("org.popcraft:chunky-common:1.4.40")
2930

3031
api("net.kyori:adventure-platform-bukkit:4.4.1")
3132
api("net.kyori:adventure-api:$adventureVersion")

Common/src/main/java/systems/kscott/randomspawnplus/config/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private ConfigLocale getConfigLocale() {
208208
return locale;
209209
}
210210

211-
enum ConfigLocale {
211+
private enum ConfigLocale {
212212
ENGLISH,
213213
CHINESE,
214214
RUSSIAN

Common/src/main/java/systems/kscott/randomspawnplus/hooks/HookInstance.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import net.luckperms.api.LuckPerms;
55
import net.milkbowl.vault.economy.Economy;
66
import org.bstats.bukkit.Metrics;
7+
import org.popcraft.chunky.api.ChunkyAPI;
78
import systems.kscott.randomspawnplus.RandomSpawnPlus;
9+
import org.bukkit.Bukkit;
810
import org.bukkit.plugin.Plugin;
911
import org.bukkit.plugin.RegisteredServiceProvider;
1012

@@ -14,7 +16,8 @@ public class HookInstance {
1416

1517
private IEssentials essentials;
1618
private LuckPerms luckPerms;
17-
private static Economy economy;
19+
private Economy economy;
20+
private ChunkyAPI chunky;
1821

1922
public HookInstance(RandomSpawnPlus pluginInstance) {
2023
instance = pluginInstance;
@@ -32,43 +35,37 @@ private void registerHooks() {
3235
}
3336

3437
if (instance.getServer().getPluginManager().getPlugin("LuckPerms") != null) {
35-
try {
36-
setupPermissions();
37-
} catch (Exception e) {
38-
e.printStackTrace();
39-
}
38+
setupPermissions();
4039
} else {
4140
RandomSpawnPlus.LOGGER.warn("The LuckPerms API is not detected, so the 'remove-permission-on-first-use' config option will not be enabled.");
4241
}
4342

4443
if (instance.getServer().getPluginManager().getPlugin("Vault") != null) {
45-
try {
46-
setupEconomy();
47-
} catch (Exception e) {
48-
e.printStackTrace();
49-
}
44+
setupEconomy();
5045
} else {
5146
RandomSpawnPlus.LOGGER.warn("The Vault API is not detected, so /wild cost will not be enabled.");
5247
}
48+
49+
if (instance.getServer().getPluginManager().getPlugin("Chunky") != null) {
50+
chunky = Bukkit.getServer().getServicesManager().load(ChunkyAPI.class);
51+
} else {
52+
RandomSpawnPlus.LOGGER.warn("You need to have Chunky installed to use RandomSpawnPlus.");
53+
RandomSpawnPlus.getInstance().getPluginLoader().disablePlugin(instance);
54+
}
5355
}
5456

5557
private void setupPermissions() {
5658
RegisteredServiceProvider<LuckPerms> rsp = instance.getServer().getServicesManager().getRegistration(LuckPerms.class);
5759
if (rsp != null) {
5860
luckPerms = rsp.getProvider();
59-
} else {
60-
luckPerms = null;
6161
}
6262
}
6363

64-
private boolean setupEconomy() {
64+
private void setupEconomy() {
6565
RegisteredServiceProvider<Economy> rsp = instance.getServer().getServicesManager().getRegistration(Economy.class);
66-
67-
if (rsp == null) return false;
68-
69-
economy = rsp.getProvider();
70-
71-
return economy != null;
66+
if (rsp != null) {
67+
economy = rsp.getProvider();
68+
}
7269
}
7370

7471
public HookInstance getInstance() {
@@ -86,4 +83,8 @@ public LuckPerms getLuckPerms() {
8683
public Economy getEconomy() {
8784
return economy;
8885
}
86+
87+
public ChunkyAPI getChunky() {
88+
return chunky;
89+
}
8990
}

Common/src/main/java/systems/kscott/randomspawnplus/spawn/SpawnGenerator.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package systems.kscott.randomspawnplus.spawn;
22

33
import it.unimi.dsi.fastutil.longs.LongArrayList;
4+
import org.popcraft.chunky.api.ChunkyAPI;
45
import systems.kscott.randomspawnplus.RandomSpawnPlus;
56
import systems.kscott.randomspawnplus.config.Config;
7+
import systems.kscott.randomspawnplus.hooks.HookInstance;
68
import systems.kscott.randomspawnplus.util.Locations;
79
import systems.kscott.randomspawnplus.util.PlatformUtil;
810
import org.bukkit.Bukkit;
11+
import org.bukkit.Chunk;
912
import org.bukkit.Location;
1013
import org.bukkit.Material;
1114
import org.bukkit.World;
@@ -47,11 +50,23 @@ private static void initSpawnChunks() {
4750
long start = System.currentTimeMillis();
4851
CompletableFuture<LongArrayList> prepareChunksTask = PlatformUtil.getPlatform().collectNonGeneratedChunksAsync(spawnLevel, minX, minZ, maxX, maxZ);
4952

50-
prepareChunksTask.thenAccept($ -> {
51-
initSpawnPoints();
52-
// TODO: change to logger or remove
53+
prepareChunksTask.thenAccept(chunks -> {
54+
if (chunks.isEmpty()) return;
55+
56+
System.out.println("Found non-generated chunks: " + chunks.size());
5357
System.out.println("Prepare chunks took " + (System.currentTimeMillis() - start) + "ms");
58+
59+
generateSpawnChunks(worldStr, minX, minZ, maxX, maxZ);
60+
});
61+
}
62+
63+
private static void generateSpawnChunks(String spawnLevel, int minX, int minZ, int maxX, int maxZ) {
64+
ChunkyAPI chunky = RandomSpawnPlus.getHooks().getChunky();
65+
chunky.startTask(spawnLevel, "square", minX, minZ, maxX, maxZ, "concentric");
66+
chunky.onGenerationComplete(event -> {
67+
RandomSpawnPlus.LOGGER.info("Generation completed for {}", event.world());
5468
SpawnData.finalizeSpawnChunksGeneration();
69+
initSpawnPoints();
5570
});
5671
}
5772

Common/src/main/resources/plugin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ softdepend:
77
- Essentials
88
- Vault
99
- LuckPerms
10+
- Chunky
1011
authors:
1112
- 89apt89
1213
- Dreeam-qwq

build-logic/src/main/kotlin/cn.dreeam.rsp.wrapper.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ repositories {
2727
url = uri("https://repo.bsdevelopment.org/releases")
2828
}
2929

30+
// Chunky
31+
maven {
32+
name = "CodeMC-repo"
33+
url = uri("https://repo.codemc.io/repository/maven-public")
34+
}
35+
3036
// JitPack
3137
maven {
3238
name = "jitpack.io"

0 commit comments

Comments
 (0)