Skip to content

BetterChairs API

Christian Koop edited this page Jun 15, 2021 · 4 revisions
Content
Use Maven
BetterChair Events
BetterChairs API

Use Maven

You have to add my maven repository to your pom.xml:

<repository>
    <id>sprax-repo</id>
    <url>https://repo.sprax2013.de/repository/maven-public/</url>
</repository>

Now you can add the BetterChairs-API as dependency (Replace VERSION with the current plugin version):

<dependency>
    <groupId>de.sprax2013</groupId>
    <artifactId>betterchairs-api</artifactId>
    <version>VERSION</version>
    <scope>provided</scope>
</dependency>

Do not forget to add BetterChairs to your plugin.yml:

depend: [ BetterChairs ]

BetterChair Events

When using the API, you'll most likely only use the events it provides. You can use them like the events provided by Bukkit/Spigot.

Both events provide you with a Player and an Chair.

PlayerEnterChairEvent

This event is called when a player wants to sit and BetterChairs has prepared everything for it.

You can cancel the event to prevent players from sitting on all or an specific chair.

PlayerLeaveChairEvent

This event is called when a player is leaving its chair. This can (for example) be voluntarily (sneaking), another Plugin using the API (ChairManager) or the player leaving the server.

You cannot cancel this event. If you really want to force the player, take a look at ChairManager.

BetterChairs API

BetterChairs exposes its API via the ChairManager class. You can use ChairManager.getInstance() to access it (may be null if BetterChairs hasn't been enabled).

Take a look at the JavaDocs for a full list or API methods (+ explanation).

Here's an example:

Player player = ...;
Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);

ChairManager.getInstance().create(player, block);   // Create the chair and make the player sit