Write me an minecaft plugin supports 1.13-1.21 creates and island on the other world and…
- User
Write me an minecaft plugin supports 1.13-1.21 creates and island on the other world and deletes with two commands
Assistant
Of course! Here is a complete, self-contained Minecraft plugin that creates and deletes a void island world. This plugin is designed to be highly compatible, supporting versions from 1.13 to 1.21, by using the modern Spigot API.
Features:
- Two simple commands:
/island createand/island delete. - Separate World: Creates the island in a dedicated world named
island_world. - Void World: The world is a complete void, except for the generated platform.
- Safe Deletion: Players are teleported out of the world before it's unloaded and its files are deleted.
- Permissions: Uses permissions to control access to the commands.
- High Compatibility: Uses
api-version: 1.13inplugin.ymlto ensure compatibility across a wide range of modern Minecraft versions.
Step 1:
plugin.ymlFirst, you need to create the
plugin.ymlfile. This file tells your server what your plugin is and how to load it.Place this file in your project's
src/main/resourcesdirectory.plugin.ymlname: IslandCreator version: 1.0.0 main: com.yourname.islandcreator.IslandCreatorPlugin api-version: 1.13 author: YourName description: Creates and deletes a personal island world with simple commands. commands: island: description: Main command to create or delete your island. usage: "/island <create|delete>" aliases: [is] permission: islandcreator.use permissions: islandcreator.use: description: Allows using the /island command. default: op islandcreator.create: description: Allows creating an island. default: op islandcreator.delete: description: Allows deleting the island. default: op
Step 2: Java Code
Now, let's create the Java files. I've broken it down into three clean classes for better organization.
1. Main Plugin Class (
IslandCreatorPlugin.java)This is the entry point of your plugin. Its main job is to register the command handler.
src/main/java/com/yourname/islandcreator/IslandCreatorPlugin.javapackage com.yourname.islandcreator; import org.bukkit.plugin.java.JavaPlugin; public final class IslandCreatorPlugin extends JavaPlugin { @Override public void onEnable() { // Register the command executor this.getCommand("island").setExecutor(new IslandCommand(this)); getLogger().info("IslandCreator has been enabled!"); } @Override public void onDisable() { getLogger().info("IslandCreator has been disabled!"); } }2. Void World Generator (
VoidGenerator.java)This small but crucial class tells Minecraft how to generate chunks for our new world. In this case, it tells it to generate nothing, creating a void.
src/main/java/com/yourname/islandcreator/VoidGenerator.javapackage com.yourname.islandcreator; import org.bukkit.World; import org.bukkit.generator.ChunkGenerator; import java.util.Random; public class VoidGenerator extends ChunkGenerator { /** * This is the new way to generate chunks post 1.16, but for a void world, * it's simple: just return an empty ChunkData object. * This method is also backward compatible with older versions that support custom generators. */ @Override public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) { // Return an empty chunk data, which results in a void chunk return createChunkData(world); } }3. Command Handler (
IslandCommand.java)This class contains all the logic for creating and deleting the island world.
src/main/java/com/yourname/islandcreator/IslandCommand.javapackage com.yourname.islandcreator; import org.bukkit.*; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.util.Comparator; public class IslandCommand implements CommandExecutor { private final IslandCreatorPlugin plugin; private static final String ISLAND_WORLD_NAME = "island_world"; public IslandCommand(IslandCreatorPlugin plugin) { this.plugin = plugin; } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage("This command can only be run by a player."); return true; } Player player = (Player) sender; if (args.length == 0) { player.sendMessage(ChatColor.RED + "Usage: /island <create|delete>"); return true; } String subCommand = args[0].toLowerCase(); switch (subCommand) { case "create": if (!player.hasPermission("islandcreator.create")) { player.sendMessage(ChatColor.RED + "You don't have permission to do that."); return true; } createIsland(player); break; case "delete": if (!player.hasPermission("islandcreator.delete")) { player.sendMessage(ChatColor.RED + "You don't have permission to do that."); return true; } deleteIsland(player); break; default: player.sendMessage(ChatColor.RED + "Unknown command. Usage: /island <create|delete>"); break; } return true; } private void createIsland(Player player) { World islandWorld = Bukkit.getWorld(ISLAND_WORLD_NAME); if (islandWorld != null) { player.sendMessage(ChatColor.YELLOW + "The island world already exists. Teleporting you there..."); teleportToIsland(player, islandWorld); return; } player.sendMessage(ChatColor.GREEN + "Creating your island world... Please wait."); // Use a WorldCreator to define the new world WorldCreator wc = new WorldCreator(ISLAND_WORLD_NAME); wc.environment(World.Environment.NORMAL); wc.type(WorldType.FLAT); // Use our custom VoidGenerator wc.generator(new VoidGenerator()); // Create the world islandWorld = wc.createWorld(); if (islandWorld == null) { player.sendMessage(ChatColor.RED + "An error occurred while creating the world."); return; } // Generate the starting platform generatePlatform(islandWorld); player.sendMessage(ChatColor.GREEN + "Island created! Teleporting you now."); teleportToIsland(player, islandWorld); } private void deleteIsland(Player player) { World islandWorld = Bukkit.getWorld(ISLAND_WORLD_NAME); if (islandWorld == null) { player.sendMessage(ChatColor.RED + "The island world does not exist."); return; } player.sendMessage(ChatColor.YELLOW + "Deleting the island world..."); // Teleport all players from the island world to the main world's spawn World mainWorld = Bukkit.getServer().getWorlds().get(0); // Get the default overworld Location spawnLocation = mainWorld.getSpawnLocation(); for (Player p : islandWorld.getPlayers()) { p.teleport(spawnLocation); p.sendMessage(ChatColor.GOLD + "The island world is being deleted. You have been moved to the main world."); } // Unload the world (false = don't save chunks) File worldFolder = islandWorld.getWorldFolder(); if (!Bukkit.unloadWorld(islandWorld, false)) { player.sendMessage(ChatColor.RED + "Could not unload the world. Is a player still inside?"); return; } // Delete the world folder recursively try { Files.walk(worldFolder.toPath()) .sorted(Comparator.reverseOrder()) .map(java.nio.file.Path::toFile) .forEach(File::delete); player.sendMessage(ChatColor.GREEN + "Island world successfully deleted!"); } catch (IOException e) { player.sendMessage(ChatColor.RED + "Failed to delete world files. Please check the console."); plugin.getLogger().severe("Could not delete world folder: " + worldFolder.getName()); e.printStackTrace(); } } private void generatePlatform(World world) { // Platform centered at 0, 64, 0 Location center = new Location(world, 0, 64, 0); int radius = 5; // Creates an 11x11 platform for (int x = -radius; x <= radius; x++) { for (int z = -radius; z <= radius; z++) { world.getBlockAt(center.getBlockX() + x, center.getBlockY(), center.getBlockZ() + z).setType(Material.GRASS_BLOCK); } } // Add a layer of dirt underneath for (int x = -radius; x <= radius; x++) { for (int z = -radius; z <= radius; z++) { world.getBlockAt(center.getBlockX() + x, center.getBlockY() - 1, center.getBlockZ() + z).setType(Material.DIRT); } } // Place a tree world.generateTree(center.clone().add(0, 1, 0), TreeType.TREE); } private void teleportToIsland(Player player, World islandWorld) { // Teleport player to a safe spot on the platform Location teleportLocation = new Location(islandWorld, 0.5, 66, 0.5, 0, 0); player.teleport(teleportLocation); } }
How to Compile and Install
- Set up a Project: Use a build tool like Maven or Gradle. This is the standard for modern plugin development.
- Add Dependencies: You will need to add the Spigot-API as a dependency. If using Maven, add this to your
pom.xml:<repositories> <repository> <id>spigot-repo</id> <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.spigotmc</groupId> <artifactId>spigot-api</artifactId> <version>1.21-R0.1-SNAPSHOT</version> <!-- Or any version you prefer --> <scope>provided</scope> </dependency> </dependencies> - Build the JAR: Run
mvn clean package(for Maven) or./gradlew build(for Gradle). - Install: A JAR file (e.g.,
IslandCreator-1.0.0.jar) will be created in yourtargetorbuild/libsfolder. Drop this JAR file into your server'spluginsfolder. - Restart/Reload: Restart your server or use a plugin manager to load it. The plugin will now be active.
- Two simple commands:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.