Skip to content
/ Lamp Public

A modern annotations-driven commands framework for Java and Kotlin

License

Notifications You must be signed in to change notification settings

Revxrsal/Lamp

Repository files navigation

Lamp

Discord Maven Central License: MIT Build CodeFactor

Documentation

Welcome to Lamp, the versatile and powerful command framework designed for modern Java and Kotlin applications. Whether you're building plugins for Minecraft servers, integrating with Discord, or creating command-line tools, Lamp provides a robust solution with a clean, idiomatic API.

Core Features

  • Multi-Platform Support: Easily integrate with various platforms including Bukkit, BungeeCord, Sponge, Velocity, JDA, Minestom, and more.
  • Command Management:
    • Define commands using simple annotations and manage them effortlessly.
    • Use spaces to define subcommands easily
    • Have multiple variants of the same command
    • Define parameters that come in the middle of the command
  • Advanced Parameter Handling: Support for context-based parameters, custom parameter types, and multiple parameter variants.
  • Optional parameters: Define optional parameters and default values easily with @Optional and @Default
  • Flags and switches:
    • Define Unix-style switches (--switch and -s) and flags (--value <value> or -v <value>)
    • Use shorthand-syntax -s -p -r as -spr
  • Response Handling: Configure how command responses are processed with flexible ResponseHandlers.
  • Dependency Injection: Inject dependencies directly into command classes using a simple builder pattern.
  • Context Resolving: Use context resolvers to handle complex command input scenarios.
  • Command Permissions: Use built-in platform permissions, or define your own permission implementation with custom annotations.
  • Modular Design with Visitors: Extend Lamp’s functionality through modular visitors for dynamic feature additions.
  • Custom annotation support: Lamp allows you to create custom annotations and customize their behaviors.
  • Fool-proof: Lamp has been designed to reduce user error as much as possible. It uses idiomatic APIs, immutability, and builders, to ensure you never run into bugs. Combined with extensive compiler annotations that will help you catch any problems at compile-time

Command Examples

@Command("greet user")
@Description("Sends a greeting message")
public void greet(CommandActor actor, @Optional("World") String name) {
    actor.reply("Hello, " + name + "!");
}

Multiple variants of the same command

@Command("teleport <target> here")
public void teleportHere(Player sender, EntitySelector<LivingEntity> target) {
    for (LivingEntity entity : target)
        entity.teleport(sender);
}

@Command("teleport")
public void teleport(Player sender, double x, double y, double z) {
    sender.teleport(new Location(sender.getWorld(), x, y, z));
}

Easily create aliases of commands

@Command({"gamemode creative", "gmc"})
public void creative(@Default("me") Player sender) {
    sender.setGameMode(GameMode.CREATIVE);
}

@Command({"gamemode adventure", "gma"})
public void adventure(@Default("me") Player sender) {
    sender.setGameMode(GameMode.ADVENTURE);
}

Support for Kotlin's default arguments

@Command("world")
fun teleportToWorld(
    sender: Player,
    @Optional target: Player = sender,
    @Optional world: World = sender.world
) {
}

Integration with Brigadier

Brigadier integration

Custom parameter types

@CommandPermission("quests.command")
@Command("quest")
class QuestCommands {

  @Dependency
  private lateinit var questManager: QuestManager

  @Subcommand("create")
  fun createQuest(sender: CommandSender, name: String, description: String) {
  }

  @Subcommand("<quest> delete")
  fun deleteQuest(sender: CommandSender, quest: Quest) {
  }

  @Subcommand("<quest> start")
  fun startQuest(sender: Player, quest: Quest) {
  }

  @Subcommand("clear")
  fun clearQuests(sender: CommandSender) {
  }
}

Custom permission annotations

@RequiresGroup("admin")
@Command("admin command")
public void adminCommand(BukkitCommandActor actor) {
    actor.reply("You are authorized to use this command!")
}

Supports Discord slash commands

@Command("ban")
@Description("Bans the given user")
@CommandPermission(Permission.BAN_MEMBERS)
public void ban(
        SlashCommandActor actor,
        Member target,
        @Range(min = 1) int days
) {
    actor.replyToInteraction("User **" + target.getEffectiveName() + "** has been banned!").queue();
}

JDA slash commands

Multi-platform support

Lamp supports the following platforms out of the box:

  • Bukkit / Spigot / Paper
  • Brigadier
  • BungeeCord
  • Velocity
  • Sponge
  • Minestom
  • Fabric
  • JDA slash commands
  • Command-line applications

Getting Started

To get started with Lamp, follow the instructions in our setup guide. Whether you're using Gradle or Maven, integrating Lamp into your project is straightforward.

For more detailed documentation on each feature, please refer to our detailed book that outlines all features and APIs in Lamp

Happy coding with Lamp! 🚀

Sponsors

If Lamp has made your life significantly easier or you're feeling particularly generous, consider sponsoring the project! It's a great way to support the many hours I've spent maintaining this library and keeps me motivated. Please don't sponsor if you can't afford it.

Donate with PayPal

Huge thanks to those who donated! 😄

If I missed you, or you would like to remain anonymous, feel free to shoot me a DM on Discord)

  • Demeng ($50)
  • creatorfromhell ($10)
  • Azoraqua ($10)
  • Bed-dev ($6)