Creating a Minecraft plugin that supports versions 1.13 to 1.21, creates an island in another world (e.g., the Nether or End), and deletes it with two commands requires careful handling of version compatibility and Bukkit/Spigot API usage. Below is a complete implementation of such a plugin.
Plugin Overview
Command 1: /createisland - Creates an island in the Nether or End.
Command 2: /deleteisland - Deletes the created island.
Supported Versions: 1.13 to 1.21.
World Management: Uses the Nether or End for island creation.
Code Implementation
java
package com.example.islandplugin;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.Map;
public class IslandPlugin extends JavaPlugin {
private final Map<String, Location> playerIslands = new HashMap<>();
@Override
public void onEnable() {
getLogger().info("IslandPlugin has been enabled!");
}
@Override
public void onDisable() {
getLogger().info("IslandPlugin has been disabled!");
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "This command can only be executed by players.");
return true;
}
Player player = (Player) sender;
if (command.getName().equalsIgnoreCase("createisland")) {
createIsland(player);
return true;
}
if (command.getName().equalsIgnoreCase("deleteisland")) {
deleteIsland(player);
return true;
}
return false;
}
private void createIsland(Player player) {
// Check if the player already has an island
if (playerIslands.containsKey(player.getName())) {
player.sendMessage(ChatColor.RED + "You already have an island!");
return;
}
// Get the Nether world
World netherWorld = Bukkit.getWorld("world_nether");
if (netherWorld == null) {
player.sendMessage(ChatColor.RED + "The Nether world could not be found!");
return;
}
// Generate a random location in the Nether
int x = (int) (Math.random() * 1000) - 500; // Random X coordinate
int z = (int) (Math.random() * 1000) - 500; // Random Z coordinate
int y = netherWorld.getHighestBlockYAt(x, z); // Find the highest block at the location
Location islandLocation = new Location(netherWorld, x, y + 1, z);
// Build a simple platform for the island
buildPlatform(islandLocation);
// Store the island location
playerIslands.put(player.getName(), islandLocation);
// Teleport the player to the island
player.teleport(islandLocation);
player.sendMessage(ChatColor.GREEN + "Your island has been created! Welcome to your new home.");
}
private void deleteIsland(Player player) {
// Check if the player has an island
Location islandLocation = playerIslands.remove(player.getName());
if (islandLocation == null) {
player.sendMessage(ChatColor.RED + "You do not have an island to delete!");
return;
}
// Clear the platform
clearPlatform(islandLocation);
player.sendMessage(ChatColor.GREEN + "Your island has been deleted.");
}
private void buildPlatform(Location location) {
World world = location.getWorld();
if (world == null) return;
// Create a 5x5 platform of stone
for (int x = -2; x <= 2; x++) {
for (int z = -2; z <= 2; z++) {
Location blockLocation = location.clone().add(x, -1, z);
world.getBlockAt(blockLocation).setType(Material.STONE);
}
}
// Add a tree on top
if (location.getBlock().getType() == Material.AIR) {
location.getBlock().setType(Material.OAK_SAPLING);
}
}
private void clearPlatform(Location location) {
World world = location.getWorld();
if (world == null) return;
// Clear a 5x5 area
for (int x = -2; x <= 2; x++) {
for (int z = -2; z <= 2; z++) {
Location blockLocation = location.clone().add(x, -1, z);
world.getBlockAt(blockLocation).setType(Material.AIR);
}
}
}
}
Explanation of the Code
Plugin Initialization:
The onEnable and onDisable methods handle plugin lifecycle events.
A HashMap (playerIslands) stores the locations of islands created by players.
Commands:
The /createisland command generates a random location in the Nether, builds a platform, and teleports the player to it.
The /deleteisland command removes the platform and clears the stored location.
Platform Creation:
A 5x5 platform of stone is created at the generated location.
An oak sapling is placed in the center of the platform.
Platform Deletion:
The platform is cleared by setting all blocks in the 5x5 area to air.
Version Compatibility:
The code uses general Bukkit/Spigot APIs compatible with versions 1.13 to 1.21.
Material names (Material.STONE, Material.OAK_SAPLING, etc.) are consistent across these versions.
Plugin Configuration
plugin.yml:
Create a plugin.yml file in the src/main/resources directory:
yaml
name: IslandPlugin
version: 1.0
main: com.example.islandplugin.IslandPlugin
api-version: 1.13
commands:
createisland:
description: Creates an island in the Nether.
usage: /createisland
deleteisland:
description: Deletes your island.
usage: /deleteisland
Building the Plugin:
Use Maven or Gradle to compile the plugin into a .jar file.
Place the .jar file in the plugins folder of your server.
Testing
Ensure the Nether world (world_nether) exists on your server.
Run /createisland to generate an island and teleport to it.
Run /deleteisland to remove the island.
Final Notes
This plugin is designed to be simple and functional across multiple Minecraft versions. You can expand it further by adding features like custom island designs, permissions, or economy integration.