🛖
Fox Hut
  • Introduction
    • Setting up
    • CommandActor, @Command and @Subcommand
    • Creating your first command
    • Improving our greet command
  • Platforms
    • Bukkit / Spigot / Paper
    • BungeeCord
    • Velocity
    • Sponge
    • Fabric
    • Brigadier
    • Minestom
    • JDA
    • Command line
  • How-to
    • Creating variants of /teleport
    • Custom parameter types
    • Suggestions and auto-completion
    • Context parameters
    • Command permissions
    • Parameter validators
    • Command conditions
    • Response handlers
    • Cooldowns
    • Help commands
    • Annotation replacers
    • Orphan command
    • Exception handling
    • Hooks
    • Dependency injection
    • Visitors
    • Customizing the dispatcher and failure behavior
Powered by GitBook
On this page
  • Setting up
  • Adding Lamp dependency
  • Velocity-specific annotations
  • @CommandPermission
  • Supported Velocity types
  • Example

Was this helpful?

Edit on GitHub
  1. Platforms

Velocity

This page describes how to integrate Lamp with Velocity 3+, as well as what to expect out of it.

Setting up

Adding Lamp dependency

To add Lamp to your project, add the following (depending on your project structure):

<dependencies>
  <!-- Required for all platforms -->
  <dependency>
      <groupId>io.github.revxrsal</groupId>
      <artifactId>lamp.common</artifactId> 
      <version>[VERSION]</version>
  </dependency>

  <!-- Velocity module -->
  <dependency>
      <groupId>io.github.revxrsal</groupId>
      <artifactId>lamp.velocity</artifactId>
      <version>[VERSION]</version>
  </dependency>  
  
  <!-- Optional: Brigadier module -->
  <dependency>
      <groupId>io.github.revxrsal</groupId>
      <artifactId>lamp.brigadier</artifactId>
      <version>[VERSION]</version>
  </dependency>
</dependencies>
dependencies {
   // Required for all platforms
   implementation 'io.github.revxrsal:lamp.common:[VERSION]'
   
   // Velocity module
   implementation 'io.github.revxrsal:lamp.velocity:[VERSION]'
   
   // Optional: Brigadier module
   implementation 'io.github.revxrsal:lamp.brigadier:[VERSION]'
}
dependencies {
    // Required for all platforms
    implementation("io.github.revxrsal:lamp.common:[VERSION]")
    
    // Velocity module
    implementation("io.github.revxrsal:lamp.velocity:[VERSION]")
    
    // Optional: Brigadier module
    implementation("io.github.revxrsal:lamp.brigadier:[VERSION]")
}

Optional: Preserve parameter names

Lamp identifies parameters by their names and uses them to generate relevant command metadata. By default, Java does not preserve parameter names reflectively. You need to add the following to your project:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
      <compilerArgs>
        <!-- Preserves parameter names -->
        <arg>-parameters</arg>
      </compilerArgs>
    </configuration>
  </plugin>
</plugins>
compileJava { 
    // Preserve parameter names in the bytecode
    options.compilerArgs += ["-parameters"]
}

// optional: if you're using Kotlin
compileKotlin {
    kotlinOptions.javaParameters = true
}
tasks.withType<JavaCompile> {
    // Preserve parameter names in the bytecode
    options.compilerArgs.add("-parameters")
}

// optional: if you're using Kotlin
tasks.withType<KotlinJvmCompile> {
    compilerOptions {
        javaParameters = true
    }
}

Velocity-specific annotations

@CommandPermission

Adds a command permission for the given command

Supported Velocity types

  • com.velocitypowered.api.command.CommandSource and its subclasses in place of CommandActor

  • com.velocitypowered.api.proxy.Player

Example

@Plugin(
    id = "myplugin",
    name = "MyPlugin",
    version = "1.0",
    description = "A simple Velocity plugin",
    authors = {"YourName"}
)
public class MyPlugin {

    private final ProxyServer server;
    private final Lamp<VelocityCommandActor> lamp;

    @Inject
    public MyPlugin(ProxyServer server, @DataDirectory Path dataDirectory) {
        this.server = server;
        this.lamp = VelocityLamp.builder(this, server).build();
        lamp.register(new MyCommand());
        // register all your commands here
        lamp.register(...);

        // IMPORTANT: You MUST call this to register your commands to Velocity
        lamp.accept(brigadier(server)); 
    }

    public static class MyCommand {

        @Command("hello")
        @CommandPermission("myplugin.hello")
        public void hello(VelocityCommandActor actor) {
            ...
        }
    }
}
@Plugin(
    id = "myplugin",
    name = "MyPlugin",
    version = "1.0",
    description = "A simple Velocity plugin",
    authors = ["YourName"]
)
class MyPlugin @Inject constructor(
    private val server: ProxyServer,
    @DataDirectory private val dataDirectory: Path
) {

    private val lamp = VelocityLamp.builder(this, server).build()

    init {
        lamp.register(MyCommand())
        // register all your commands here
        lamp.register(...)

        // IMPORTANT: You MUST call this to register your commands to Velocity
        lamp.accept(brigadier(server)) 
    }

    class MyCommand {

        @Command("hello")
        @CommandPermission("myplugin.hello")
        fun hello(actor: VelocityCommandActor) {
            ...
        }
    }
}
PreviousBungeeCordNextSponge

Last updated 4 months ago

Was this helpful?

Latest version: