package ru.baronessdev.shitexample;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
private final String command = "твоя команда";
@Override
public void onEnable() {
getCommand(command).setExecutor((sender, cmd, label, args) -> {
if (sender instanceof Player) {
sender.sendMessage("Введите " + cmd + " ещё раз");
Bukkit.getPluginManager().registerEvents(new Handler((Player) sender), this);
}
return true;
});
}
public static void unregisterEvent(Listener l) {
HandlerList.unregisterAll(l);
}
class Handler implements Listener {
private final Player player;
Handler(Player player) {
this.player = player;
}
@EventHandler
private void onCommand(PlayerCommandPreprocessEvent e) {
if (!e.getMessage().equals(command)) return;
if (!e.getPlayer().equals(player)) return;
player.sendMessage("Ура, вы ввели ее снова!");
e.setCancelled(true);
Main.unregisterEvent(this);
}
@EventHandler
private void onQuit(PlayerQuitEvent e) {
if (e.getPlayer().equals(player))
Main.unregisterEvent(this);
}
}
}