From 3cd91d0d04cab19c3c47435452fc64cada106c98 Mon Sep 17 00:00:00 2001 From: Dev7ex <46531389+Dev7ex@users.noreply.github.com> Date: Sat, 7 Dec 2024 13:45:21 +0100 Subject: [PATCH] Adding WaterWorldGenerator --- .../multiworld/world/DefaultWorldManager.java | 25 ++++++++++++++++--- .../DefaultWorldGeneratorProvider.java | 2 ++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/multiworld-bukkit/src/main/java/com/dev7ex/multiworld/world/DefaultWorldManager.java b/multiworld-bukkit/src/main/java/com/dev7ex/multiworld/world/DefaultWorldManager.java index 9dfc14f..8e8190a 100644 --- a/multiworld-bukkit/src/main/java/com/dev7ex/multiworld/world/DefaultWorldManager.java +++ b/multiworld-bukkit/src/main/java/com/dev7ex/multiworld/world/DefaultWorldManager.java @@ -14,6 +14,7 @@ import com.dev7ex.multiworld.api.bukkit.world.BukkitWorldProvider; import com.dev7ex.multiworld.api.bukkit.world.generator.defaults.FlatWorldGenerator; import com.dev7ex.multiworld.api.bukkit.world.generator.defaults.VoidWorldGenerator; +import com.dev7ex.multiworld.api.bukkit.world.generator.defaults.WaterWorldGenerator; import com.dev7ex.multiworld.api.world.WorldDefaultProperty; import com.dev7ex.multiworld.api.world.WorldEnvironment; import com.dev7ex.multiworld.api.world.WorldType; @@ -21,6 +22,7 @@ import lombok.AccessLevel; import lombok.Getter; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.SerializationUtils; import org.bukkit.*; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -33,6 +35,7 @@ import java.util.Calendar; import java.util.Collections; import java.util.Objects; +import java.util.logging.Level; /** * Manages world creation, deletion, cloning, and backup operations. @@ -74,7 +77,8 @@ public void cloneWorld(@NotNull final String creatorName, @NotNull final String final File sourceFolder = new File(Bukkit.getWorldContainer(), name); final File destinationFolder = new File(Bukkit.getWorldContainer(), clonedName); final CommandSender commandSender = BukkitCommon.getCommandSender(creatorName); - final BukkitWorldHolder worldHolder = this.getProvider().getWorldHolder(name).orElseThrow(); + final BukkitWorldHolder worldHolder = this.getProvider().getWorldHolder(name) + .orElseThrow(); final WorldCloneEvent event = new WorldCloneEvent(worldHolder, commandSender, clonedName, sourceFolder, destinationFolder); Bukkit.getPluginManager().callEvent(event); @@ -103,13 +107,22 @@ public void cloneWorld(@NotNull final String creatorName, @NotNull final String } file.delete(); } + + final BukkitWorldHolder clonedWorldHolder = worldHolder.clone(); + clonedWorldHolder.setName(clonedName); + clonedWorldHolder.setCreationTimeStamp(System.currentTimeMillis()); + + this.configuration.add(clonedWorldHolder); + this.getProvider().register(clonedWorldHolder); + commandSender.sendMessage(this.translationProvider.getMessage(commandSender, "commands.world.clone.finished") .replaceAll("%prefix%", this.pluginConfiguration.getPrefix()) - .replaceAll("%world_name%", name)); + .replaceAll("%world_name%", name) + .replaceAll("%cloned_world_name%", clonedName)); } catch (final IOException exception) { commandSender.sendMessage("§cAn error has occurred. View the logs"); - exception.printStackTrace(); + MultiWorldPlugin.getInstance().getLogger().log(Level.SEVERE, "§cAn error has occurred. View the logs", exception); } } @@ -153,7 +166,7 @@ public void createBackup(@NotNull final String creatorName, @NotNull final Strin } catch (final IOException exception) { commandSender.sendMessage("§cAn error has occurred. View the logs"); - exception.printStackTrace(); + MultiWorldPlugin.getInstance().getLogger().log(Level.SEVERE, "§cAn error has occurred. View the logs", exception); } } @@ -314,6 +327,10 @@ public void createWorld(@NotNull final String creatorName, @NotNull final String worldCreator.generator(new VoidWorldGenerator(MultiWorldPlugin.getInstance())); break; + case "WaterWorldGenerator": + worldCreator.generator(new WaterWorldGenerator(MultiWorldPlugin.getInstance())); + break; + default: worldCreator.generator(generator); break; diff --git a/multiworld-bukkit/src/main/java/com/dev7ex/multiworld/world/generator/DefaultWorldGeneratorProvider.java b/multiworld-bukkit/src/main/java/com/dev7ex/multiworld/world/generator/DefaultWorldGeneratorProvider.java index a3c616c..b9342b8 100644 --- a/multiworld-bukkit/src/main/java/com/dev7ex/multiworld/world/generator/DefaultWorldGeneratorProvider.java +++ b/multiworld-bukkit/src/main/java/com/dev7ex/multiworld/world/generator/DefaultWorldGeneratorProvider.java @@ -7,6 +7,7 @@ import com.dev7ex.multiworld.api.bukkit.world.generator.BukkitWorldGeneratorProvider; import com.dev7ex.multiworld.api.bukkit.world.generator.defaults.FlatWorldGenerator; import com.dev7ex.multiworld.api.bukkit.world.generator.defaults.VoidWorldGenerator; +import com.dev7ex.multiworld.api.bukkit.world.generator.defaults.WaterWorldGenerator; import com.dev7ex.multiworld.api.world.generator.WorldGenerator; import lombok.AccessLevel; import lombok.Getter; @@ -55,6 +56,7 @@ public void onEnable() { } this.defaultGenerators.add(new FlatWorldGenerator(MultiWorldPlugin.getInstance())); this.defaultGenerators.add(new VoidWorldGenerator(MultiWorldPlugin.getInstance())); + this.defaultGenerators.add(new WaterWorldGenerator(MultiWorldPlugin.getInstance())); MultiWorldPlugin.getInstance().getLogger().info("Found: [" + this.customGenerators.values().size() + "] World Generator"); }