Skip to content

Commit

Permalink
Adding WaterWorldGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev7ex committed Dec 7, 2024
1 parent b64406a commit 3cd91d0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
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;
import com.dev7ex.multiworld.translation.DefaultTranslationProvider;
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;
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 3cd91d0

Please sign in to comment.