-
Notifications
You must be signed in to change notification settings - Fork 4
API for Developers
Kacper edited this page Sep 6, 2025
·
2 revisions
Welcome, developer! π¨βπ»
The OpenSectors API provides a clean and flexible way to interact with the sector system.
You can use it to listen for events, synchronize data, and extend the project with your own features.
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/fajzu1/OpenSectors</url>
</repository><dependency>
<groupId>net.lightcode</groupId>
<artifactId>sectors-project</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>The main instance of the plugin should only be fetched once, for example:
public class MyPlugin extends JavaPlugin {
private BukkitSectorIntegration integration;
@Override
public void onEnable() {
this.integration = BukkitSectorIntegration.create();
}
}Available methods to get a user:
- BukkitSectorIntegration#findUserByName(String)
- BukkitSectorIntegration#findUserByUUID(UUID)
User user = this.integration.findUserByName("fajzu");
System.out.println(user.name());Available methods to get a sector:
- BukkitSectorIntegration#findSectorByName(String)
- BukkitSectorIntegration#findSectorByLocation(Location)
Sector sector = this.integration.findSectorByName("s1");
System.out.println(sector.id());Available methods for publishing, subscribing class:
- BukkitSectorIntegration#subscribe(String, PacketListener)
- BukkitSectorIntegration#publish(String, Packet)
this.integration.subscribe("test", new MyPacketListener());
this.integration.publish("test", new MyPacket("Hello!"));
public static class MyPacket extends Packet {
private final String message;
public MyPacket() {
this(null); //required for JacksonCodec
}
public MyPacket(String message) {
this.message = message;
}
public String message() {
return this.message;
}
}
public static class MyPacketListener extends PacketListener<MyPacket> {
public MyPacketListener() {
super(MyPacket.class);
}
@Override
public void handle(MyPacket packet) {
System.out.println(packet.message());
}
}Available custom events to use:
- PlayerLoadDataEvent
- PlayerSaveDataEvent
- PlayerSectorChangeEvent
public class PlayerSectorChangeListener implements Listener {
@EventHandler
public void onSectorChange(PlayerSectorChangeEvent event) {
Player player = event.getPlayer();
Sector currentSector = event.currentSector();
Sector newSector = event.newSector();
event.setCancelled(true);
player.sendMessage("Transfer cancelled " + newSector.id());
}
}Registration in onEnable():
@Override
public void onEnable() {
this.getServer().getPluginManager().registerEvents(new PlayerSectorChangeListener(), this);
}OpenSectors 2024 - 2025