Skip to content

PlayerUtil

Larrox edited this page Aug 29, 2025 · 1 revision

The PlayerUtil class in LarroxUtilsAPI is a small utility designed to simplify player checks in your commands and plugin logic.
It helps determine whether a CommandSender is a Player or not.


Note

Don’t forget to import:

import dev.larrox.PlayerUtil;

🚀 Features

  • Check if a CommandSender is a Player.
  • Useful for command validation or player-only actions.

🛠️ Examples

Check if a sender is a player

if (!PlayerUtil.isPlayer(sender)) {
    sender.sendMessage("§cYou must be a player to use this command!");
    return true;
}

Player player = (Player) sender;
player.sendMessage("§aHello, player!");

✅ Best Practices

  • Use PlayerUtil.isPlayer(sender) before casting a CommandSender to Player.
  • Always handle the case when the sender is not a player (e.g., console commands).
  • Combine with your own messaging utility for consistent plugin feedback.

Clone this wiki locally