karen
📎 1 file 1,896 chars
📄
pasted-code-1794923495216.txt
txt 59 lines
▶
package me.example.lplugin;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.title.Title;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import java.time.Duration;

public class LPlugin extends JavaPlugin implements CommandExecutor {

    @Override
    public void onEnable() {
        getCommand("l").setExecutor(this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (args.length < 1) {
            sender.sendMessage(Component.text("Usage: /L ", NamedTextColor.RED));
            return true;
        }

        Player target = Bukkit.getPlayerExact(args[0]);
        if (target == null) {
            sender.sendMessage(Component.text("Player not found.", NamedTextColor.RED));
            return true;
        }

        Title title = Title.title(
                Component.text("L", NamedTextColor.RED),
                Component.text("NOOB", NamedTextColor.RED),
                Title.Times.times(Duration.ZERO, Duration.ofMillis(700), Duration.ZERO)
        );

        new BukkitRunnable() {
            int ticks = 0;

            @Override
            public void run() {
                if (!target.isOnline() || ticks >= 2400) { // 2400 tick = 2 دقیقه
                    target.clearTitle();
                    cancel();
                    return;
                }
                target.showTitle(title);
                ticks += 10;
            }
        }.runTaskTimer(this, 0L, 10L); // هر ۰.۵ ثانیه تکرار

        return true;
    }
}
Kodari AI
KodariTue at 1:51 pm 1
LNoobTitlePlugin
A Minecraft plugin that displays a persistent "L NOOB" title to a targeted player for two minutes. The plugin registers a command "/L" that accepts a player name, validates the player is online, and then repeatedly shows a red title with "L" as the main text and "NOOB" as the subtitle every half second. The title display continues for 2400 ticks (2 minutes) or until the target player goes offline, at which point the title is cleared and the task is cancelled. Uses Adventure API for modern text components and titles, with a scheduled BukkitRunnable for periodic updates.
  • Create the Paper plugin around the supplied /l <player> command.

  • Add command registration and build configuration.

Created the Paper plugin from your code. /l <player> displays the title for two minutes.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 86
src/main/java/me/example/lplugin/LPlugin.java
package me.example.lplugin;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.title.Title;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import java.time.Duration;

public class LPlugin extends JavaPlugin implements CommandExecutor {
    @Override
    public void onEnable() {
        getCommand("l").setExecutor(this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (args.length < 1) {
            sender.sendMessage(Component.text("Usage: /L <player>", NamedTextColor.RED));
            return true;
        }

        Player target = Bukkit.getPlayerExact(args[0]);
        if (target == null) {
            sender.sendMessage(Component.text("Player not found.", NamedTextColor.RED));
            return true;
        }

        Title title = Title.title(
                Component.text("L", NamedTextColor.RED),
                Component.text("NOOB", NamedTextColor.RED),
                Title.Times.times(Duration.ZERO, Duration.ofMillis(700), Duration.ZERO)
        );

        new BukkitRunnable() {
            int ticks = 0;

            @Override
            public void run() {
                if (!target.isOnline() || ticks >= 2400) {
                    target.clearTitle();
                    cancel();
                    return;
                }
                target.showTitle(title);
                ticks += 10;
            }
        }.runTaskTimer(this, 0L, 10L);

        return true;
    }
}