Skip to content
Flint
Dokumentation
Going further

Java access

Using any method of the server API and any Java class from a script.

When a value has no Flint property or method of a name, the server’s own Java API is tried, with names written in snake_case:

on server.ping:
    event.motd("<gold>My server")          # ServerListPingEvent.motd(Component)
    event.set_max_players(100)             # setMaxPlayers(int)

on player.join:
    print(player.client_brand_name)        # getClientBrandName()
In a script Calls
value.name getName(), isName(), hasName() or name()
value.name = x setName(x) or name(x)
value.do_thing(a, b) doThing(a, b)

Arguments are converted to what the Java method expects: numbers to int, long, float…; text to enums ("creative" for GameMode.CREATIVE) and to formatted text where a Component is wanted; lists to arrays. Return values come back as Flint values.

The java module

import java

Bukkit = java.type("org.bukkit.Bukkit")
print(Bukkit.get_motd())

runtime = java.type("java.lang.Runtime").get_runtime()
print("Free memory: {runtime.free_memory() / 1048576} MB")

builder = java.type("java.lang.StringBuilder").new("abc")
print(java.members(builder))           # what can be called on it
  • java.type(name) gives a class: call its static methods, read its constants, or create objects with .new(...).
  • java.class_of(value) tells you the Java class of any value.
  • java.members(value) lists the method names you can call.

Any event

Together with on event "ClassName": (see Events) this means a script can use anything a plugin could.

Turning it off

Java access gives scripts the same power as a plugin. On a server where people you do not fully trust write scripts, set this in plugins/Flint/config.properties:

java-access=false