Это задание по какому-то курсу типо?
package com.example.randomnicksplugin;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
public class RandomNicksPlugin extends JavaPlugin implements Listener {
private final Set players = Collections.newSetFromMap(new ConcurrentHashMap<>());
private final AtomicBoolean cooldownActive = new AtomicBoolean(false);
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
scheduleRandomNickDisplayTask();
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
players.add(event.getPlayer());
}
private void scheduleRandomNickDisplayTask() {
new BukkitRunnable() {
@Override
public void run() {
if (!cooldownActive.get()) {
displayRandomNicks();
cooldownActive.set(true);
new BukkitRunnable() {
@Override
public void run() {
cooldownActive.set(false);
}
}.runTaskLater(RandomNicksPlugin.this, 20 * 30); // 30 seconds
}
}
}.runTaskTimer(this, 20, 20); // Runs every second
}
private void displayRandomNicks() {
if (players.size() < 2) {
return;
}
List shuffledPlayers = new ArrayList<>(players);
Collections.shuffle(shuffledPlayers);
Player player1 = shuffledPlayers.get(0);
Player player2 = shuffledPlayers.get(1);
broadcastRandomNickMessage(player1.getName(), player2.getName());
}
private void broadcastRandomNickMessage(String nick1, String nick2) {
Bukkit.broadcastMessage("Случайные ники: " + nick1 + " и " + nick2);
}
}