Untitled
Anonymous
plain_text
02/11/2026 10:32 PM
3.7 KB
19
Indexable
package main;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin implements Listener {
private int uniqueCount;
// random spawn stuff
public void onEnable() {
saveDefaultConfig();
uniqueCount = getConfig().getInt("unique-count", 0);
Bukkit.getPluginManager().registerEvents(this, this);
}
public void onDisable() {
getConfig().set("unique-count", uniqueCount);
saveConfig();
}
@EventHandler
public void onFirstJoin(PlayerJoinEvent event) {
if (!event.getPlayer().hasPlayedBefore()) {
uniqueCount++;
event.setJoinMessage(ChatColor.YELLOW + event.getPlayer().getName()
+ " joined the server for the first time. They are the " + uniqueCount + " player to join.");
Player p = event.getPlayer();
World world = p.getWorld();
double radius = 3000;
Location safeLoc = null;
int attempts = 0;
while (attempts < 50) {
double x = (Math.random() * radius * 2) - radius;
double z = (Math.random() * radius * 2) - radius;
int y = world.getHighestBlockYAt((int) x, (int) z);
Location loc = new Location(world, x, y, z);
Block blockAtFeet = world.getBlockAt(loc);
Block blockAtHead = world.getBlockAt(loc.clone().add(0, 1, 0));
Block blockAboveHead = world.getBlockAt(loc.clone().add(0, 2, 0));
// Check for suffocation blocks and liquid blocks
if (isSafeBlock(blockAtFeet) && isSafeBlock(blockAtHead) && isSafeBlock(blockAboveHead)) {
safeLoc = loc.add(0.5, 0, 0.5); // center in block
break;
}
attempts++;
}
// Fallback to world spawn if no safe location found
if (safeLoc == null) {
safeLoc = world.getSpawnLocation();
}
p.teleport(safeLoc);
}
}
private boolean isSafeBlock(Block block) {
Material type = block.getType();
return type.isAir() || type == Material.SNOW;
}
@EventHandler
public void onPlayerDeath(PlayerDeathEvent e) {
e.setDeathMessage(ChatColor.RED + e.getDeathMessage());
for (Player player : Bukkit.getOnlinePlayers()) {
player.playSound(player.getLocation(), Sound.ENTITY_LIGHTNING_BOLT_THUNDER, 1.0f, // volume
1.0f // pitch
);
}
if (e.getEntity() instanceof Player p) { // Java 16+ pattern matching
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ban " + "-s " + p.getName() + " " + e.getDeathMessage());
}
}
}
Editor is loading...
Leave a Comment