Skip to content

API Reference

API overview

The SofyCoreApi entry point, the synchronous EventBus and the placeholder registry that every integration starts from.

net.sofycore.api

SofyCoreApi

Entry point. Registered in Bukkit's ServicesManager during onEnable; data services appear once storage is ready.

Access: Bukkit.getServicesManager().load(SofyCoreApi.class)

package net.sofycore.api;

public interface SofyCoreApi {
    <T> Optional<T> service(Class<T> type);
    EventBus events();
    PlaceholderRegistry placeholders();
}
  • <T> Optional<T> service(Class<T> type)

    Returns a registered service, or empty if its module is disabled or not ready.

  • EventBus events()

    The core event bus (synchronous, platform-neutral).

  • PlaceholderRegistry placeholders()

    The internal placeholder registry.

net.sofycore.api

EventBus

Synchronous event bus. Events run on the publishing thread; listener exceptions propagate to the publisher.

package net.sofycore.api;

public interface EventBus {
    <T> AutoCloseable subscribe(Class<T> type, Consumer<? super T> listener);
    void publish(Object event);
    default void publishIsolated(Object event, Consumer<Throwable> failure);
}
  • <T> AutoCloseable subscribe(Class<T> type, Consumer<? super T> listener)

    Subscribes a listener. Close the returned handle to unsubscribe.

  • void publish(Object event)

    Publishes an event to its subscribers.

  • default void publishIsolated(Object event, Consumer<Throwable> failure)

    Publishes and reports a listener failure to the callback instead of throwing.

net.sofycore.api

PlaceholderRegistry

Internal placeholder registry, also used by the scoreboard and menus.

package net.sofycore.api;

public interface PlaceholderRegistry {
    void register(String identifier, Function<UUID, String> resolver);
    String resolve(String identifier, UUID playerId);
}
  • void register(String identifier, Function<UUID, String> resolver)

    Registers a resolver for an identifier.

  • String resolve(String identifier, UUID playerId)

    Resolves an identifier for a player.

net.sofycore.api.module

CoreModule

Lifecycle contract of a feature module.

package net.sofycore.api.module;

public interface CoreModule {
    String id();
    void start() throws Exception;
    void stop() throws Exception;
}
  • String id()

    Module identifier.

  • void start() throws Exception

    Starts the module.

  • void stop() throws Exception

    Stops the module and releases its resources.

Event bus semantics

  • Events are synchronous and platform-neutral. They run on the publishing thread.
  • A listener exception propagates to the publisher. sofyCore publishes most events with publishIsolated, so a failing listener does not stop the others.
  • Bukkit calls from a listener must be scheduled on the server thread when the event was not published there.
  • Close the AutoCloseable returned by subscribe in your onDisable.