Skip to content

Commit 1728af4

Browse files
authored
Refonte de la génération de la dimension des rêves (#1280)
* add DatapackLoader * add omc_dream datapacks * base_camp with campfire not activate * clean resource (remove schem and structure and data/animation * clean old dream dimension world gen (enfin.) * missing new files haha * add on/off campfire when player is enter/leave base camp * remove unused libs and update datapacks * launch fix * fix base camp + rename DIMENSION_WORLD TO DREAM_WORLD * fix getStructureAt, simplify PlayerEnter/ExiStructureListener * fix SEA_LANTERN material in ReplaceBlockListener
1 parent 814da11 commit 1728af4

222 files changed

Lines changed: 3123 additions & 5974 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ dependencies {
5959
compileOnly "de.oliver:FancyNpcs:${fancyNpcsVersion}"
6060
compileOnly "net.dmulloy2:ProtocolLib:${protocolLibVersion}"
6161

62-
implementation "com.flowpowered:flow-nbt:1.0.0"
6362
implementation "org.jetbrains:annotations:${jetbrainsAnnotationsVersion}"
6463
implementation "io.github.revxrsal:lamp.common:${revxrsalLampVersion}"
6564
implementation "io.github.revxrsal:lamp.bukkit:${revxrsalLampVersion}"

src/main/java/fr/openmc/core/OMCBootstrap.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package fr.openmc.core;
22

3+
import fr.openmc.core.bootstrap.integration.DatapackLoader;
34
import fr.openmc.core.bootstrap.integration.OMCLogger;
45
import fr.openmc.core.hooks.itemsadder.ItemsAdderHook;
56
import fr.openmc.core.utils.text.messages.TranslationManager;
67
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
78
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
89
import io.papermc.paper.plugin.bootstrap.PluginProviderContext;
10+
import io.papermc.paper.registry.event.RegistryEvents;
911
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
1012
import org.bukkit.plugin.java.JavaPlugin;
1113
import org.jetbrains.annotations.NotNull;
1214

13-
import java.io.IOException;
14-
import java.net.URI;
15-
import java.net.URISyntaxException;
1615
import java.util.Locale;
17-
import java.util.Objects;
1816

1917
/**
2018
* Bootstrap Paper du plugin OpenMC.
@@ -32,29 +30,15 @@ public class OMCBootstrap implements PluginBootstrap {
3230
public void bootstrap(@NotNull BootstrapContext context) {
3331
OMCLogger.setBootstrapLogger(context.getLogger());
3432

35-
// ** LOAD DATAPACK **
36-
context.getLifecycleManager().registerEventHandler(LifecycleEvents.DATAPACK_DISCOVERY.newHandler(
37-
event -> {
38-
try {
39-
URI uri = Objects.requireNonNull(getClass().getResource("/datapack")).toURI();
40-
41-
event.registrar().discoverPack(uri, "omc");
42-
} catch (URISyntaxException | IOException e) {
43-
throw new RuntimeException(e);
44-
}
45-
}
46-
));
33+
// ** LOAD DATAPACKS **
34+
DatapackLoader.loadAllInResource(context);
4735

4836
// ** LOAD ITEMS ADDER NAMESPACES **
4937
ItemsAdderHook.copyContentsToItemsAdder(context, "contents");
5038

5139
// ** REGISTRY MANAGER **
5240
OMCRegistry.bootstrapAll(context);
5341

54-
// context.getLifecycleManager().registerEventHandler(RegistryEvents.ENCHANTMENT.compose()
55-
// .newHandler(CustomEnchantmentRegistry::loadEnchantmentInBootstrap)
56-
// );
57-
5842
// ** LOAD TRANSLATION **
5943
// this creates resource pack who is needed for item adder
6044
TranslationManager.init(

src/main/java/fr/openmc/core/OMCPlugin.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import fr.openmc.core.features.displays.holograms.HologramLoader;
2525
import fr.openmc.core.features.displays.scoreboards.ScoreboardManager;
2626
import fr.openmc.core.features.dream.DreamManager;
27-
import fr.openmc.core.features.dream.generation.DreamDimensionManager;
2827
import fr.openmc.core.features.economy.BankManager;
2928
import fr.openmc.core.features.economy.EconomyManager;
3029
import fr.openmc.core.features.economy.TransactionsManager;
@@ -201,9 +200,6 @@ public void loadAfterItemsAdder() {
201200
.filter(f -> f instanceof LoadAfterItemsAdder)
202201
.forEachOrdered(Feature::startInit);
203202

204-
// todo: sera supprimé dans https://github.com/ServerOpenMC/PluginV2/pull/1168
205-
DreamDimensionManager.postInit();
206-
207203
if (WorldGuardHook.isEnable()) {
208204
ParticleUtils.spawnParticlesInRegion("spawn", Bukkit.getWorld("world"), Particle.CHERRY_LEAVES, 50, 70, 130);
209205
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package fr.openmc.core.bootstrap.integration;
2+
3+
import fr.openmc.core.utils.FilesUtils;
4+
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
5+
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
6+
7+
import java.io.IOException;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.util.stream.Stream;
11+
12+
@SuppressWarnings("UnstableApiUsage")
13+
public class DatapackLoader {
14+
/**
15+
* Charge tout les datapacks qui sont dans la ressource resources/datapacks
16+
*/
17+
public static void loadAllInResource(BootstrapContext context) {
18+
Path extractedDatapacks = extractDatapacks();
19+
20+
try (Stream<Path> paths = Files.list(extractedDatapacks)){
21+
paths.forEach(pathDir ->
22+
context.getLifecycleManager().registerEventHandler(LifecycleEvents.DATAPACK_DISCOVERY.newHandler(
23+
event -> {
24+
try {
25+
event.registrar().discoverPack(pathDir.toUri(), pathDir.getFileName().toString());
26+
} catch (IOException e) {
27+
throw new RuntimeException(e);
28+
}
29+
})));
30+
} catch (IOException e) {
31+
throw new RuntimeException(e);
32+
}
33+
}
34+
35+
/**
36+
* Extrait tout les datapacks dans un dossier temporaire "omc-datapacks" et retourne le path de ce dossier.
37+
*/
38+
public static Path extractDatapacks() {
39+
try {
40+
Path tempDir = Files.createTempDirectory("omc-datapacks");
41+
42+
FilesUtils.copyResourceFolder("datapacks", tempDir.toFile());
43+
44+
return tempDir;
45+
} catch (IOException e) {
46+
throw new RuntimeException("Failed to extract datapacks", e);
47+
}
48+
}
49+
}

src/main/java/fr/openmc/core/features/animations/AnimationsManager.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import org.bukkit.util.Vector;
2121

2222
import java.io.File;
23-
import java.io.FileReader;
2423
import java.io.IOException;
2524
import java.io.InputStream;
25+
import java.io.InputStreamReader;
2626
import java.nio.charset.StandardCharsets;
2727
import java.nio.file.Files;
2828
import java.util.Map;
@@ -60,16 +60,19 @@ public void save() {
6060
// nothing to save
6161
}
6262

63-
public static JsonObject loadAnimation(OMCPlugin plugin, String ressourcePath) {
64-
File file = new File(plugin.getDataFolder(), ressourcePath);
65-
if (!file.exists()) {
66-
return null;
67-
}
63+
public static JsonObject loadAnimation(OMCPlugin plugin, String resourcePath) {
64+
try (InputStream inputStream = plugin.getResource(resourcePath)) {
65+
if (inputStream == null) {
66+
OMCLogger.error("Animation resource not found: {}", resourcePath);
67+
return null;
68+
}
69+
70+
try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
71+
return JsonParser.parseReader(reader).getAsJsonObject();
72+
}
6873

69-
try (FileReader reader = new FileReader(file, StandardCharsets.UTF_8)) {
70-
return JsonParser.parseReader(reader).getAsJsonObject();
7174
} catch (IOException e) {
72-
OMCLogger.error("Failed to load Animation {}", ressourcePath, e);
75+
OMCLogger.error("Failed to load Animation {}", resourcePath, e);
7376
return null;
7477
}
7578
}
@@ -78,7 +81,7 @@ public static void loadAllAnimations(OMCPlugin plugin) {
7881
for (Animation animation : Animation.values()) {
7982
String animationName = animation.getNameAnimation();
8083

81-
String resourcePath = "data/animations/" + animationName + ".animation.json";
84+
String resourcePath = "contents/omc_animations/" + animationName + ".animation.json";
8285
JsonObject animationJson = loadAnimation(plugin, resourcePath);
8386

8487
JsonObject animations = animationJson.getAsJsonObject("animations");

src/main/java/fr/openmc/core/features/cube/listeners/CubeListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import fr.openmc.core.features.cube.events.ExitCubeZoneEvent;
88
import fr.openmc.core.features.cube.multiblocks.MultiBlock;
99
import fr.openmc.core.features.cube.multiblocks.MultiBlockManager;
10-
import fr.openmc.core.features.dream.generation.DreamDimensionManager;
10+
import fr.openmc.core.features.dream.DreamUtils;
1111
import org.bukkit.Bukkit;
1212
import org.bukkit.Location;
1313
import org.bukkit.attribute.Attribute;
@@ -114,7 +114,7 @@ public void onCubeBubbleStop(CubeDisableBubbleEvent event) {
114114

115115
public void updatePlayerBubbleState(Player player) {
116116
if (!player.getLocation().getWorld().getName().equals("world")
117-
&& !player.getLocation().getWorld().getName().equals(DreamDimensionManager.DIMENSION_NAME)) return;
117+
&& !DreamUtils.isInDreamWorld(player)) return;
118118

119119
UUID uuid = player.getUniqueId();
120120

src/main/java/fr/openmc/core/features/cube/multiblocks/MultiBlockManager.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import fr.openmc.core.features.cube.CubeCommands;
1212
import fr.openmc.core.features.cube.listeners.CubeListener;
1313
import fr.openmc.core.features.cube.listeners.RepulseEffectListener;
14+
import fr.openmc.core.features.dream.DreamDimensionManager;
1415
import fr.openmc.core.features.dream.DreamUtils;
15-
import fr.openmc.core.features.dream.generation.DreamDimensionManager;
1616
import lombok.Getter;
1717
import org.bukkit.Bukkit;
1818
import org.bukkit.Location;
@@ -22,7 +22,6 @@
2222
import org.bukkit.configuration.file.YamlConfiguration;
2323
import org.bukkit.event.Listener;
2424

25-
import javax.annotation.Nullable;
2625
import java.io.File;
2726
import java.io.IOException;
2827
import java.util.*;
@@ -146,13 +145,4 @@ public static void register(MultiBlock multiBlock) {
146145

147146
saveConfig();
148147
}
149-
150-
public static @Nullable MultiBlock getMultiblockAtDimension(String worldName) {
151-
for (MultiBlock multiBlock : multiBlocks) {
152-
if (multiBlock.origin.getWorld().getName().equals(worldName)) {
153-
return multiBlock;
154-
}
155-
}
156-
return null;
157-
}
158148
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package fr.openmc.core.features.dream;
2+
3+
import fr.openmc.core.OMCPlugin;
4+
import fr.openmc.core.bootstrap.integration.OMCLogger;
5+
import org.bukkit.Bukkit;
6+
import org.bukkit.GameRules;
7+
import org.bukkit.World;
8+
import org.bukkit.configuration.file.FileConfiguration;
9+
import org.bukkit.configuration.file.YamlConfiguration;
10+
import org.bukkit.entity.SpawnCategory;
11+
12+
import java.io.File;
13+
import java.io.IOException;
14+
15+
public class DreamDimensionManager {
16+
17+
public static final String DIMENSION_NAME = "world_omc_dream_dream";
18+
public static World DREAM_WORLD;
19+
20+
private static File seedFile;
21+
private static FileConfiguration seedConfig;
22+
private static boolean seedChanged = false;
23+
24+
public static void init() {
25+
seedFile = new File(OMCPlugin.getInstance().getDataFolder() + "/data/dream", "seed.yml");
26+
loadSeed();
27+
DREAM_WORLD = Bukkit.getWorld(DIMENSION_NAME);
28+
29+
setupDimension();
30+
}
31+
32+
public static void save() {
33+
OMCLogger.info("[DreamDimensionManager] Saving seed: {}", DREAM_WORLD.getSeed());
34+
saveSeed(DREAM_WORLD.getSeed());
35+
}
36+
37+
private static void setupDimension() {
38+
if (!DREAM_WORLD.getName().equals(DreamDimensionManager.DIMENSION_NAME)) return;
39+
40+
DreamDimensionManager.checkSeed();
41+
42+
if (DreamDimensionManager.hasSeedChanged()) {
43+
// ** SPAWNING RULES **
44+
DREAM_WORLD.setSpawnLimit(SpawnCategory.MONSTER, 10);
45+
DREAM_WORLD.setSpawnLimit(SpawnCategory.AMBIENT, 10);
46+
DREAM_WORLD.setSpawnLimit(SpawnCategory.ANIMAL, 6);
47+
48+
DREAM_WORLD.setTicksPerSpawns(SpawnCategory.MONSTER, 30);
49+
DREAM_WORLD.setTicksPerSpawns(SpawnCategory.AMBIENT, 15);
50+
DREAM_WORLD.setTicksPerSpawns(SpawnCategory.ANIMAL, 30);
51+
52+
// ** SET GAMERULE FOR THE WORLD **
53+
DREAM_WORLD.setGameRule(GameRules.ADVANCE_TIME, false);
54+
DREAM_WORLD.setGameRule(GameRules.SHOW_ADVANCEMENT_MESSAGES, false);
55+
DREAM_WORLD.setGameRule(GameRules.ADVANCE_WEATHER, false);
56+
DREAM_WORLD.setGameRule(GameRules.RAIDS, true);
57+
DREAM_WORLD.setGameRule(GameRules.SPAWN_PATROLS, false);
58+
DREAM_WORLD.setGameRule(GameRules.SPAWN_WANDERING_TRADERS, false);
59+
DREAM_WORLD.setGameRule(GameRules.NATURAL_HEALTH_REGENERATION, false);
60+
DREAM_WORLD.setGameRule(GameRules.LOCATOR_BAR, false);
61+
DREAM_WORLD.setGameRule(GameRules.ALLOW_ENTERING_NETHER_USING_PORTALS, false);
62+
63+
// ** SET WORLD BORDER AND TIME **
64+
DREAM_WORLD.getWorldBorder().setSize(10000);
65+
DREAM_WORLD.setTime(18000);
66+
}
67+
}
68+
69+
private static void loadSeed() {
70+
if (!seedFile.exists()) {
71+
OMCLogger.info("Fichier seed.yml manquant, il sera créé au saveSeed().");
72+
}
73+
seedConfig = YamlConfiguration.loadConfiguration(seedFile);
74+
}
75+
76+
private static void saveSeed(long seed) {
77+
seedConfig.set("world_seed", seed);
78+
try {
79+
seedConfig.save(seedFile);
80+
} catch (IOException e) {
81+
OMCLogger.error("Cannot save seed dream_world", e);
82+
}
83+
}
84+
85+
public static void checkSeed() {
86+
long saved = seedConfig.getLong("world_seed", -1);
87+
if (DREAM_WORLD == null) return;
88+
89+
long current = DREAM_WORLD.getSeed();
90+
91+
if (saved == -1) {
92+
saveSeed(current);
93+
seedChanged = false;
94+
return;
95+
}
96+
97+
seedChanged = saved != current;
98+
99+
if (seedChanged) {
100+
OMCLogger.info("La seed de la dimension des rêves a changé");
101+
saveSeed(current);
102+
}
103+
}
104+
105+
public static boolean hasSeedChanged() {
106+
return seedChanged;
107+
}
108+
}

0 commit comments

Comments
 (0)