Skip to content
Larrox edited this page Aug 29, 2025 · 1 revision

The User class in LarroxUtilsAPI is a powerful wrapper around Bukkit’s CommandSender. It allows you to easily interact with players and the console through one unified API. It supports messaging (via ChatUtil), permission checks, player management (teleport, kick, health, food), and more.


Note

Don’t forget to import:

import dev.larrox.user.User;

🚀 Features

  • Wraps CommandSender (works with both Players and Console).
  • Simple checks: isPlayer(), isConsole(), isOnline().
  • Send messages, titles, subtitles, and action bars (uses ChatUtil).
  • Perform permission checks with hasPermission().
  • Manage players: teleport, kick, set health/food level, get location.
  • Execute commands directly as the sender.

🛠️ Examples

Create a User from CommandSender

public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    User user = new User(sender);

    if (user.isConsole()) {
        user.sendMessage("&cThis command is only for players!");
        return true;
    }

    user.sendMessage("&aHello " + user.getName() + "!");
    return true;
}

Send messages and titles

user.sendMessage("&eWelcome back!");
user.sendTitle("&6Welcome!", "&7Enjoy your stay!", 10, 70, 20);
user.sendActionBar("&bYou gained 5 XP!");

Check permissions

if (!user.hasPermission("myplugin.use")) {
    user.sendMessage("&cYou don’t have permission!");
    return true;
}

Teleport, Kick, and Manage Player State

user.teleport(new Location(Bukkit.getWorld("world"), 100, 64, 100));
user.kick("&cYou have been kicked!");
user.setHealth(20.0);
user.setFoodLevel(20);

Execute a command as the User

user.executeCommand("say Hello from User!");

✅ Best Practices

  • Always use isPlayer() before performing player-only actions like teleport or health changes.
  • Use sendMessage, sendTitle, and sendActionBar via User instead of calling ChatUtil directly — it makes code cleaner.
  • isConsole() is useful for restricting commands to players only.
  • Use hasPermission() to enforce permission checks before actions.
  • Treat User as the universal access point for all sender/player interactions in your plugin.

Clone this wiki locally