-
Notifications
You must be signed in to change notification settings - Fork 0
User
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;- 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.
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;
}user.sendMessage("&eWelcome back!");
user.sendTitle("&6Welcome!", "&7Enjoy your stay!", 10, 70, 20);
user.sendActionBar("&bYou gained 5 XP!");if (!user.hasPermission("myplugin.use")) {
user.sendMessage("&cYou don’t have permission!");
return true;
}user.teleport(new Location(Bukkit.getWorld("world"), 100, 64, 100));
user.kick("&cYou have been kicked!");
user.setHealth(20.0);
user.setFoodLevel(20);user.executeCommand("say Hello from User!");- Always use
isPlayer()before performing player-only actions like teleport or health changes. - Use
sendMessage,sendTitle, andsendActionBarviaUserinstead of callingChatUtildirectly — it makes code cleaner. -
isConsole()is useful for restricting commands to players only. - Use
hasPermission()to enforce permission checks before actions. - Treat
Useras the universal access point for all sender/player interactions in your plugin.