Skip to content

Script API

Jesse McKee edited this page Sep 28, 2023 · 4 revisions

Events made available

INTERACTION

  • onBlockLeftClick
  • onBlockRightClick
  • onEntityLeftClick
  • onEntityRightClick

MOVE

  • onEntityMove
  • onPlayerMove

BLOCKS

  • onBlockChange

ENTITIES

  • onEntitySpawn
  • onEntityDamage
  • onEntityRemove
  • onEntityDeath

PLAYERS

  • onPlayerLogin
  • onPlayerJoin
  • onPlayerLeave
  • onPlayerDamage
  • onPlayerDeath

SERVER

  • onServerStarting
  • onServerStarted
  • onServerStopping
  • onServerStopped

Using Events

To use events all you need is a closure {} Events provide their methods from Sponge as well

ServerStartedEvent

onServerStarted {
  //You can call cause(),context(),etc.. here
}

Managers

val | Type | Equivalent method call

SpongeServer | Server | Sponge#Server
SpongePluginManager | PluginManager | Sponge#pluginManager
SpongeCommandManager | CommandManager (Sponge) | Sponge#server#commandManager
SpongeEventManager | EventManager | Sponge#eventManager
SpongeServerServiceManager | ServiceProvider.ServerScoped | Sponge#server#serviceProvider
SpongeGameServiceManager | ServiceProvider.GameScoped | Sponge#serviceProvider
SpongeScheduler | Scheduler | Sponge#server#scheduler
SpongeAsyncSchedluer | Scheduler | Sponge#asnycScheduler
Container | PluginContainer | API#container
Logger | Logger | API#logger
ScriptCommandManager | CommandManager (me.zodd) | CommandManager

Using Managers

Managers is really a misnomer, they're really just a wrapper to make scripting a little easier.

Most of these "Managers" are calls to Sponge methods. to use them just call them!

Logger.info("Using Logger Manager!")

onServerStarted {
    val seconds = Duration.ofSeconds(5)

    val task = Task.builder()
        .execute { ->
            Logger.info("Executes after 5 seconds!")
        }
        .delay(seconds)
        .plugin(Container)
        .build()

    //Register the task
    SpongeScheduler.submit(task)
}
Clone this wiki locally