angelo angels

create for me a plugin that can make in fist join teleport the player to a point that admin do /setspawn and if some one die teleport him to spawn and also if do /spawn teleport in spawn point also in first spawn make if some one join launch a firework for creeper and other colored

Kodari AI
KodariYesterday at 7:58 pm 1
FirstJoinSpawnFireworks
A Minecraft Bukkit/Spigot plugin that teleports players to a configurable spawn point on first join, death, and via /spawn command. Admins can set the spawn location using /setspawn. On first join, the plugin launches celebratory fireworks including creeper-colored and other multicolored fireworks to welcome new players. The plugin stores spawn coordinates in a configuration file and provides permission-based command access for players and admins.

Created the spawn plugin:

  • Admins can set the point with /setspawn.

  • /spawn teleports players there, and players return there after death.

  • First-time players teleport there and receive a creeper-shaped firework and a colorful firework.

Set the spawn point before welcoming new players.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
3 129
src/main/java/com/kodari/firstspawn/FirstSpawnPlugin.java
package com.kodari.firstspawn;

import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.plugin.java.JavaPlugin;

public final class FirstSpawnPlugin extends JavaPlugin implements Listener {
    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage(ChatColor.RED + "Only players can use this command.");
            return true;
        }
        Player player = (Player) sender;
        if (command.getName().equalsIgnoreCase("setspawn")) {
            if (!player.hasPermission("firstspawn.setspawn")) {
                player.sendMessage(ChatColor.RED + "You do not have permission to set spawn.");
                return true;
            }
            getConfig().set("spawn", player.getLocation());
            saveConfig();
            player.sendMessage(ChatColor.GREEN + "Spawn point set!");
            return true;
        }
        if (command.getName().equalsIgnoreCase("spawn")) {
            Location spawn = getSpawn();
            if (spawn == null) {
                player.sendMessage(ChatColor.RED + "The spawn point has not been set yet.");
            } else if (player.teleport(spawn)) {
                player.sendMessage(ChatColor.GREEN + "Teleported to spawn!");
            } else {
                player.sendMessage(ChatColor.RED + "Could not teleport you to spawn.");
            }
            return true;
        }
        return false;
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        if (player.hasPlayedBefore()) {
            return;
        }
        getServer().getScheduler().runTask(this, () -> {
            if (!player.isOnline()) {
                return;
            }
            Location spawn = getSpawn();
            if (spawn != null) {
                player.teleport(spawn);
            }
            launchWelcomeFirework(player.getLocation(), FireworkEffect.Type.CREEPER, Color.LIME, Color.GREEN);
            launchWelcomeFirework(player.getLocation(), FireworkEffect.Type.BALL_LARGE, Color.RED, Color.BLUE, Color.YELLOW, Color.PURPLE);
        });
    }

    @EventHandler
    public void onRespawn(PlayerRespawnEvent event) {
        Location spawn = getSpawn();
        if (spawn != null) {
            event.setRespawnLocation(spawn);
        }
    }

    private Location getSpawn() {
        Location spawn = getConfig().getLocation("spawn");
        return spawn != null && spawn.getWorld() != null ? spawn : null;
    }

    private void launchWelcomeFirework(Location location, FireworkEffect.Type type, Color... colors) {
        Firework firework = location.getWorld().spawn(location, Firework.class);
        FireworkMeta meta = firework.getFireworkMeta();
        meta.addEffect(FireworkEffect.builder().with(type).withColor(colors).withTrail().withFlicker().build());
        meta.setPower(1);
        firework.setFireworkMeta(meta);
    }
}