jssyro.

A spawn gaurd plugin protecting a 500 x 500 radius of spawn meaning it cannot be destroyed by creepers tnt or eeven if ur in survival

Kodari AI
KodariJul 4 at 1:42 pm 1

I’ll create a spawn protection plugin.

SpawnGuard
A lightweight spawn area protection plugin that prevents griefing within a configurable radius of the world spawn. Blocks block destruction from creepers, TNT explosions, and survival-mode player interactions. Features a bypass permission for trusted players, configurable protection radius, and per-world targeting. Simple and performance-focused with no external dependencies.</project_description<project_name>SpawnGuard</project_name>
A lightweight spawn protection plugin that safeguards a 500x500 block radius around spawn. Prevents creepers and TNT from destroying blocks in the protected zone, and stops survival/adventure mode players from breaking blocks. Fully configurable center and radius, with bypass permission for staff. Supports all Minecraft versions from 1.8 to latest.
Kodari can make mistakes. Review important code before using.
Files
src
Code
4 111
src/main/java/com/spawnguard/SpawnGuard.java
package com.spawnguard;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;

public class SpawnGuard extends JavaPlugin {

    private static SpawnGuard instance;
    private Location spawnCenter;
    private int radius;

    @Override
    public void onEnable() {
        instance = this;
        saveDefaultConfig();
        loadConfig();
        getServer().getPluginManager().registerEvents(new SpawnGuardListener(), this);
        getLogger().info("SpawnGuard enabled - protecting " + radius + " block radius around spawn");
    }

    @Override
    public void onDisable() {
        getLogger().info("SpawnGuard disabled");
    }

    public void reload() {
        loadConfig();
    }

    private void loadConfig() {
        reloadConfig();
        World world = Bukkit.getWorld(getConfig().getString("center.world", "world"));
        double x = getConfig().getDouble("center.x", 0);
        double z = getConfig().getDouble("center.z", 0);
        radius = getConfig().getInt("radius", 500);
        spawnCenter = (world != null) ? new Location(world, x, 0, z) : null;
    }

    public boolean isInProtectedRegion(Location location) {
        if (spawnCenter == null || location == null) return false;
        if (!location.getWorld().equals(spawnCenter.getWorld())) return false;
        double dx = location.getX() - spawnCenter.getX();
        double dz = location.getZ() - spawnCenter.getZ();
        return (dx * dx + dz * dz) <= (double) radius * radius;
    }

    public static SpawnGuard getInstance() {
        return instance;
    }

    public String getMessage(String path) {
        return getConfig().getString("messages." + path, "&cYou cannot do that in the spawn area!");
    }
}