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!");
}
}