Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ dependencies {
compileOnly "de.oliver:FancyNpcs:${fancyNpcsVersion}"
compileOnly "net.dmulloy2:ProtocolLib:${protocolLibVersion}"

implementation "com.flowpowered:flow-nbt:1.0.0"
implementation "org.jetbrains:annotations:${jetbrainsAnnotationsVersion}"
implementation "io.github.revxrsal:lamp.common:${revxrsalLampVersion}"
implementation "io.github.revxrsal:lamp.bukkit:${revxrsalLampVersion}"
Expand Down
24 changes: 4 additions & 20 deletions src/main/java/fr/openmc/core/OMCBootstrap.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package fr.openmc.core;

import fr.openmc.core.bootstrap.integration.DatapackLoader;
import fr.openmc.core.bootstrap.integration.OMCLogger;
import fr.openmc.core.hooks.itemsadder.ItemsAdderHook;
import fr.openmc.core.utils.text.messages.TranslationManager;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
import io.papermc.paper.plugin.bootstrap.PluginProviderContext;
import io.papermc.paper.registry.event.RegistryEvents;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Locale;
import java.util.Objects;

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

// ** LOAD DATAPACK **
context.getLifecycleManager().registerEventHandler(LifecycleEvents.DATAPACK_DISCOVERY.newHandler(
event -> {
try {
URI uri = Objects.requireNonNull(getClass().getResource("/datapack")).toURI();

event.registrar().discoverPack(uri, "omc");
} catch (URISyntaxException | IOException e) {
throw new RuntimeException(e);
}
}
));
// ** LOAD DATAPACKS **
DatapackLoader.loadAllInResource(context);

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

// ** REGISTRY MANAGER **
OMCRegistry.bootstrapAll(context);

// context.getLifecycleManager().registerEventHandler(RegistryEvents.ENCHANTMENT.compose()
// .newHandler(CustomEnchantmentRegistry::loadEnchantmentInBootstrap)
// );

// ** LOAD TRANSLATION **
// this creates resource pack who is needed for item adder
TranslationManager.init(
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/fr/openmc/core/OMCPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import fr.openmc.core.features.displays.holograms.HologramLoader;
import fr.openmc.core.features.displays.scoreboards.ScoreboardManager;
import fr.openmc.core.features.dream.DreamManager;
import fr.openmc.core.features.dream.generation.DreamDimensionManager;
import fr.openmc.core.features.economy.BankManager;
import fr.openmc.core.features.economy.EconomyManager;
import fr.openmc.core.features.economy.TransactionsManager;
Expand Down Expand Up @@ -201,9 +200,6 @@ public void loadAfterItemsAdder() {
.filter(f -> f instanceof LoadAfterItemsAdder)
.forEachOrdered(Feature::startInit);

// todo: sera supprimé dans https://github.com/ServerOpenMC/PluginV2/pull/1168
DreamDimensionManager.postInit();

if (WorldGuardHook.isEnable()) {
ParticleUtils.spawnParticlesInRegion("spawn", Bukkit.getWorld("world"), Particle.CHERRY_LEAVES, 50, 70, 130);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package fr.openmc.core.bootstrap.integration;

import fr.openmc.core.utils.FilesUtils;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;

@SuppressWarnings("UnstableApiUsage")
public class DatapackLoader {
/**
* Charge tout les datapacks qui sont dans la ressource resources/datapacks
*/
public static void loadAllInResource(BootstrapContext context) {
Path extractedDatapacks = extractDatapacks();

try (Stream<Path> paths = Files.list(extractedDatapacks)){
paths.forEach(pathDir ->
context.getLifecycleManager().registerEventHandler(LifecycleEvents.DATAPACK_DISCOVERY.newHandler(
event -> {
try {
event.registrar().discoverPack(pathDir.toUri(), pathDir.getFileName().toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
})));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

/**
* Extrait tout les datapacks dans un dossier temporaire "omc-datapacks" et retourne le path de ce dossier.
*/
public static Path extractDatapacks() {
try {
Path tempDir = Files.createTempDirectory("omc-datapacks");

FilesUtils.copyResourceFolder("datapacks", tempDir.toFile());

return tempDir;
} catch (IOException e) {
throw new RuntimeException("Failed to extract datapacks", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import org.bukkit.util.Vector;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Map;
Expand Down Expand Up @@ -60,16 +60,19 @@ public void save() {
// nothing to save
}

public static JsonObject loadAnimation(OMCPlugin plugin, String ressourcePath) {
File file = new File(plugin.getDataFolder(), ressourcePath);
if (!file.exists()) {
return null;
}
public static JsonObject loadAnimation(OMCPlugin plugin, String resourcePath) {
try (InputStream inputStream = plugin.getResource(resourcePath)) {
if (inputStream == null) {
OMCLogger.error("Animation resource not found: {}", resourcePath);
return null;
}

try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
return JsonParser.parseReader(reader).getAsJsonObject();
}

try (FileReader reader = new FileReader(file, StandardCharsets.UTF_8)) {
return JsonParser.parseReader(reader).getAsJsonObject();
} catch (IOException e) {
OMCLogger.error("Failed to load Animation {}", ressourcePath, e);
OMCLogger.error("Failed to load Animation {}", resourcePath, e);
return null;
}
}
Expand All @@ -78,7 +81,7 @@ public static void loadAllAnimations(OMCPlugin plugin) {
for (Animation animation : Animation.values()) {
String animationName = animation.getNameAnimation();

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

JsonObject animations = animationJson.getAsJsonObject("animations");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import fr.openmc.core.features.cube.events.ExitCubeZoneEvent;
import fr.openmc.core.features.cube.multiblocks.MultiBlock;
import fr.openmc.core.features.cube.multiblocks.MultiBlockManager;
import fr.openmc.core.features.dream.generation.DreamDimensionManager;
import fr.openmc.core.features.dream.DreamUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.attribute.Attribute;
Expand Down Expand Up @@ -114,7 +114,7 @@ public void onCubeBubbleStop(CubeDisableBubbleEvent event) {

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

UUID uuid = player.getUniqueId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import fr.openmc.core.features.cube.CubeCommands;
import fr.openmc.core.features.cube.listeners.CubeListener;
import fr.openmc.core.features.cube.listeners.RepulseEffectListener;
import fr.openmc.core.features.dream.DreamDimensionManager;
import fr.openmc.core.features.dream.DreamUtils;
import fr.openmc.core.features.dream.generation.DreamDimensionManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand All @@ -22,7 +22,6 @@
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.Listener;

import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.*;
Expand Down Expand Up @@ -146,13 +145,4 @@ public static void register(MultiBlock multiBlock) {

saveConfig();
}

public static @Nullable MultiBlock getMultiblockAtDimension(String worldName) {
for (MultiBlock multiBlock : multiBlocks) {
if (multiBlock.origin.getWorld().getName().equals(worldName)) {
return multiBlock;
}
}
return null;
}
}
108 changes: 108 additions & 0 deletions src/main/java/fr/openmc/core/features/dream/DreamDimensionManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package fr.openmc.core.features.dream;

import fr.openmc.core.OMCPlugin;
import fr.openmc.core.bootstrap.integration.OMCLogger;
import org.bukkit.Bukkit;
import org.bukkit.GameRules;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.SpawnCategory;

import java.io.File;
import java.io.IOException;

public class DreamDimensionManager {

public static final String DIMENSION_NAME = "world_omc_dream_dream";
public static World DREAM_WORLD;

private static File seedFile;
private static FileConfiguration seedConfig;
private static boolean seedChanged = false;

public static void init() {
seedFile = new File(OMCPlugin.getInstance().getDataFolder() + "/data/dream", "seed.yml");
loadSeed();
DREAM_WORLD = Bukkit.getWorld(DIMENSION_NAME);

setupDimension();
}

public static void save() {
OMCLogger.info("[DreamDimensionManager] Saving seed: {}", DREAM_WORLD.getSeed());
saveSeed(DREAM_WORLD.getSeed());
}

private static void setupDimension() {
if (!DREAM_WORLD.getName().equals(DreamDimensionManager.DIMENSION_NAME)) return;

DreamDimensionManager.checkSeed();

if (DreamDimensionManager.hasSeedChanged()) {
// ** SPAWNING RULES **
DREAM_WORLD.setSpawnLimit(SpawnCategory.MONSTER, 10);
DREAM_WORLD.setSpawnLimit(SpawnCategory.AMBIENT, 10);
DREAM_WORLD.setSpawnLimit(SpawnCategory.ANIMAL, 6);

DREAM_WORLD.setTicksPerSpawns(SpawnCategory.MONSTER, 30);
DREAM_WORLD.setTicksPerSpawns(SpawnCategory.AMBIENT, 15);
DREAM_WORLD.setTicksPerSpawns(SpawnCategory.ANIMAL, 30);

// ** SET GAMERULE FOR THE WORLD **
DREAM_WORLD.setGameRule(GameRules.ADVANCE_TIME, false);
DREAM_WORLD.setGameRule(GameRules.SHOW_ADVANCEMENT_MESSAGES, false);
DREAM_WORLD.setGameRule(GameRules.ADVANCE_WEATHER, false);
DREAM_WORLD.setGameRule(GameRules.RAIDS, true);
DREAM_WORLD.setGameRule(GameRules.SPAWN_PATROLS, false);
DREAM_WORLD.setGameRule(GameRules.SPAWN_WANDERING_TRADERS, false);
DREAM_WORLD.setGameRule(GameRules.NATURAL_HEALTH_REGENERATION, false);
DREAM_WORLD.setGameRule(GameRules.LOCATOR_BAR, false);
DREAM_WORLD.setGameRule(GameRules.ALLOW_ENTERING_NETHER_USING_PORTALS, false);

// ** SET WORLD BORDER AND TIME **
DREAM_WORLD.getWorldBorder().setSize(10000);
DREAM_WORLD.setTime(18000);
}
}

private static void loadSeed() {
if (!seedFile.exists()) {
OMCLogger.info("Fichier seed.yml manquant, il sera créé au saveSeed().");
}
seedConfig = YamlConfiguration.loadConfiguration(seedFile);
}

private static void saveSeed(long seed) {
seedConfig.set("world_seed", seed);
try {
seedConfig.save(seedFile);
} catch (IOException e) {
OMCLogger.error("Cannot save seed dream_world", e);
}
}

public static void checkSeed() {
long saved = seedConfig.getLong("world_seed", -1);
if (DREAM_WORLD == null) return;

long current = DREAM_WORLD.getSeed();

if (saved == -1) {
saveSeed(current);
seedChanged = false;
return;
}

seedChanged = saved != current;

if (seedChanged) {
OMCLogger.info("La seed de la dimension des rêves a changé");
saveSeed(current);
}
}

public static boolean hasSeedChanged() {
return seedChanged;
}
}
Loading
Loading