-
Notifications
You must be signed in to change notification settings - Fork 0
Script API
Jesse McKee edited this page Sep 28, 2023
·
4 revisions
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
To use events all you need is a closure {}
Events provide their methods from Sponge as well
onServerStarted {
//You can call cause(),context(),etc.. here
}
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
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)
}