Skip to main content

๐ŸŽฏ ObjectiveService

ObjectiveService lets addons read information about registered objective types.

Use it when you want to build:

admin dashboards
setup tools
debug commands
addon compatibility checks
event builders
developer utilities

Getting the service

ObjectiveService objectiveService = EventForgeAPI.getObjectiveService();

Always check the API is available first:

if (!EventForgeAPI.isAvailable()) {
return;
}

Registered objective count

int count = objectiveService.getRegisteredObjectiveCount();

Example:

getLogger().info("Registered EventForge objectives: "
+ objectiveService.getRegisteredObjectiveCount());

Registered objective IDs

Set<String> objectiveIds = objectiveService.getRegisteredObjectiveIds();

Example:

for (String objectiveId : objectiveService.getRegisteredObjectiveIds()) {
getLogger().info("Objective: " + objectiveId);
}

Built-in objective types may include:

MINE_BLOCKS
KILL_MOBS
FISH_ITEMS
COLLECT_ITEMS
MOB_INVASION

Custom addons can register more.


Check if an objective exists

boolean registered = objectiveService.isObjectiveRegistered("MINE_BLOCKS");

Example:

if (!objectiveService.isObjectiveRegistered("RELIC_HUNT")) {
sender.sendMessage("The RELIC_HUNT addon is not installed or not loaded.");
}

ObjectiveRegistry vs ObjectiveService

Use ObjectiveService to read registered objective information.

Use ObjectiveRegistry to register or unregister objective handlers.

ObjectiveService objectiveService = EventForgeAPI.getObjectiveService();
ObjectiveRegistry objectiveRegistry = EventForgeAPI.getObjectiveRegistry();

Read:

objectiveService.getRegisteredObjectiveIds();

Register:

objectiveRegistry.register(new MyObjectiveHandler());

Unregister:

objectiveRegistry.unregister("MY_OBJECTIVE");

Registering a custom objective

@Override
public void onEnable() {
if (!EventForgeAPI.isAvailable()) {
getLogger().severe("EventForgeAPI is not available.");
getServer().getPluginManager().disablePlugin(this);
return;
}

boolean registered = EventForgeAPI
.getObjectiveRegistry()
.register(new RelicHuntObjectiveHandler(this));

if (registered) {
getLogger().info("Registered RELIC_HUNT objective.");
}
}

Unregistering a custom objective

@Override
public void onDisable() {
if (EventForgeAPI.isAvailable()) {
EventForgeAPI.getObjectiveRegistry().unregister("RELIC_HUNT");
}
}

This keeps the registry clean if your addon is disabled or reloaded.


Checking addon compatibility

You can use ObjectiveService to check whether another objective addon is present.

boolean hasRelicHunt = EventForgeAPI
.getObjectiveService()
.isObjectiveRegistered("RELIC_HUNT");

if (hasRelicHunt) {
getLogger().info("Relic Hunt support is available.");
}

Event objective info

v1.0.1 added objective information to EventInfo.

This is separate from ObjectiveService.

ObjectiveService tells you which objective types are registered.

EventInfo#getObjectives() tells you which objectives a specific event uses.

Example:

EventForgeAPI.getEventService()
.getEventInfo("survival_rush")
.ifPresent(eventInfo -> {
eventInfo.getObjectives().forEach(objective -> {
getLogger().info(objective.getId()
+ " | type=" + objective.getType()
+ " | weight=" + objective.getWeight());
});
});

EventObjectiveInfo

EventObjectiveInfo is useful for event browsers, GUIs, dashboards, and setup tools.

Common methods:

getId();
getType();
getDisplayName();
getWeight();
isPrimary();

Example:

for (EventObjectiveInfo objective : eventInfo.getObjectives()) {
String id = objective.getId();
String type = objective.getType();
String displayName = objective.getDisplayName();
double weight = objective.getWeight();
boolean primary = objective.isPrimary();
}

Showing objective multipliers

weight is the API/config term.

For player-facing displays, show it as a multiplier.

Good:

Multiplier: x1.5

Avoid:

Weight: 1.5

Example formatter:

private String formatMultiplier(double multiplier) {
if (multiplier == (long) multiplier) {
return "x" + (long) multiplier;
}

String formatted = String.format(java.util.Locale.US, "%.2f", multiplier);

while (formatted.contains(".") && formatted.endsWith("0")) {
formatted = formatted.substring(0, formatted.length() - 1);
}

if (formatted.endsWith(".")) {
formatted = formatted.substring(0, formatted.length() - 1);
}

return "x" + formatted;
}

Usage:

sender.sendMessage("Multiplier: " + formatMultiplier(objective.getWeight()));

Example objective browser command

public void sendObjectiveTypes(CommandSender sender) {
ObjectiveService objectiveService = EventForgeAPI.getObjectiveService();

sender.sendMessage("Registered objective types:");

for (String objectiveId : objectiveService.getRegisteredObjectiveIds()) {
sender.sendMessage("- " + objectiveId);
}
}

Example event objective command

public void sendEventObjectives(CommandSender sender, String eventId) {
EventForgeAPI.getEventService()
.getEventInfo(eventId)
.ifPresentOrElse(eventInfo -> {
sender.sendMessage("Objectives for " + eventInfo.getDisplayName() + ":");

for (EventObjectiveInfo objective : eventInfo.getObjectives()) {
sender.sendMessage("- "
+ objective.getId()
+ " | type=" + objective.getType()
+ " | multiplier=" + formatMultiplier(objective.getWeight()));
}
}, () -> sender.sendMessage("Unknown event: " + eventId));
}

Common use cases

showing registered objective types in admin tools
checking whether custom objective addons are installed
building event setup GUIs
debugging missing custom objectives
listing objectives used by an event
showing objective multipliers in player menus

Common mistakes

Confusing objective type with objective IDโ€‹

In this config:

objectives:
mining:
type: MINE_BLOCKS

mining is the objective ID inside that event.

MINE_BLOCKS is the registered objective type.


Checking only built-in objectivesโ€‹

Custom addons can register more objective types.

Always read from:

objectiveService.getRegisteredObjectiveIds();

instead of hardcoding a list.


Showing weight directly to playersโ€‹

Avoid showing this:

Weight: 1.5

Use:

Multiplier: x1.5