GlacierStaff / Develop

1 min readMarkdown

Developer API

Add GlacierStaff as a dependency, use its 18 feature APIs and listen to its 9 events.

The API is part of the GlacierStaff plugin JAR. Only dev.glacierlabs.glacierstaff.api and its subpackages are supported for external use; everything else is internal and can change between releases.

Add the dependency

<dependency>
    <groupId>dev.glacierlabs</groupId>
    <artifactId>GlacierStaff</artifactId>
    <version>3.0.0</version>
    <scope>provided</scope>
</dependency>

Never shade GlacierStaff into your plugin. Bukkit’s service lookup relies on both plugins using the API classes from GlacierStaff’s classloader.

depend: [GlacierStaff]

For an optional integration, use softdepend: [GlacierStaff] and keep the imports in a class you only load after checking:

if (getServer().getPluginManager().isPluginEnabled("GlacierStaff")) {
    glacierStaffIntegration = new GlacierStaffIntegration();
}

The API classes don’t exist when GlacierStaff isn’t installed, and an Optional can’t stop the JVM from loading a class that references them.

Get the API

private GlacierStaffApi glacierStaff;

@Override
public void onEnable() {
    glacierStaff = GlacierStaffProvider.get();
}

Inside an integration class, GlacierStaffProvider.getIfPresent() handles the short window where the plugin exists but its service isn’t registered.

Feature getters are empty while their module is disabled:

glacierStaff.getFreezeApi().ifPresent(freeze -> {
    if (freeze.isFrozen(player)) {
        event.setCancelled(true);
    }
});

If you keep a handle, check isAvailable() before using it again. A disabled feature returns false and rejects calls with FeatureUnavailableException.

Feature APIs

Module Getter Methods
vanish getVanishApi() isVanished, getVanishLevel, canSeeLevel(Player, int)
staffmode getStaffModeApi() isInStaffMode(Player)
freeze getFreezeApi() isFrozen(Player), getTimeLeft(Player)
chatcontrol getChatControlApi() isChatMuted(), getMuteRemainingMillis()
cps getCpsApi() getCurrentCps, getMaxCps, getAverageCps
inventory getInventoryApi() getSnapshotCount(UUID), getPlayersWithSaves()
invsee getInvseeApi() canView, canEdit, canViewEnder, canEditEnder, openInventory, openEnderChest
logs getLogsApi() getTotalLogs, getLatestMessage, getLatestTimestamp
modmail getModMailApi() openInbox(Player), sendMail(Player, String)
punish getPunishApi() openMenu(Player staff, Player target)
randomtp getRandomTPApi() teleport(Player)
staff getStaffApi() openMenu(Player)
staffchat getStaffChatApi() isInStaffChat, getActiveChannel, sendMessage
reports getReportsApi() getOpenReportCount()
socialspy getSocialSpyApi() isEnabled(UUID)
notes getNotesApi() getNoteCount(UUID), isWatchlisted(UUID)
staffactivity getStaffActivityApi() getOnDutyMillis(UUID), getPunishmentsIssued(UUID)
altdetect getAltDetectApi() getKnownAlts(UUID)

core, replays, mining, staffauth, discord and staffutils have no feature API and only appear in module info.

Hiding vanished staff from your own features

List<Player> visibleTo(Player viewer) {
    return glacierStaff.getVanishApi()
        .map(vanish -> Bukkit.getOnlinePlayers().stream()
            .filter(p -> !vanish.isVanished(p) || vanish.canSeeLevel(viewer, vanish.getVanishLevel(p)))
            .collect(Collectors.<Player>toList()))
        .orElseGet(() -> new ArrayList<>(Bukkit.getOnlinePlayers()));
}

Module info

getModules() and getModule(String) return immutable snapshots, so ask again when you need the current state. Module IDs are constants in ModuleIds. The API doesn’t expose enable/disable controls, managers, listeners or config files.

Events

All events are synchronous.

Event Fired when Getters
GlacierStaffModuleEnabledEvent A module is turned on at runtime getModule()
GlacierStaffModuleDisabledEvent A module is turned off at runtime getModule()
StaffModeToggledEvent Someone enters or leaves staff mode getPlayer(), isActive()
StaffFreezeChangedEvent A freeze is applied, removed or expires getTargetId(), getTargetName(), getTarget(), getStaffId(), getReason(), getFrozen()
StaffPunishActionEvent A punishment is issued, from the menu or as a native case getStaff(), getCommand()
StaffReportSubmittedEvent A report is accepted getReportId(), getReporterId(), getTargetId(), getTargetName(), getTarget(), getReason()
StaffReportResolvedEvent A report is resolved or dismissed getReportId(), getTargetName(), getStaff(), isResolved()
StaffNoteAddedEvent A note is added to a player getTargetId(), getTargetName(), getAuthorId(), getAuthorName(), getText()
PlayerFlaggedAsAltEvent A joining player shares an IP with known accounts getPlayer(), getKnownAlts()

getTarget() on the freeze and report events can be null when the player is offline. Use the ID and name.

@EventHandler
public void onStaffMode(StaffModeToggledEvent event) {
    if (event.isActive()) {
        getLogger().info(event.getPlayer().getName() + " is now on duty");
    }
}

Module events aren’t fired for modules loaded at startup or stopped at shutdown.

Versioning

Read the versions with getPluginVersion() and getApiVersion(). API majors change when integrations need source changes, minors add backward-compatible methods, patches fix documentation or behaviour.

Changes in 3.0.0

  • The API moved to dev.glacierlabs.glacierstaff.api.
  • PluginApi is now GlacierStaffApi, and PluginApiProvider is GlacierStaffProvider.
  • The module events are now GlacierStaffModuleEnabledEvent and GlacierStaffModuleDisabledEvent.

Javadocs

mvn clean javadoc:javadoc

Open target/site/apidocs/index.html. Only the supported API packages are included.