Repository navigation
API
Mantice edited this page Sep 2, 2025
·
2 revisions
static @NotNull MythBoardAPI getApi() {
final MythBoardAPI api = Bukkit.getServicesManager().load(MythBoardAPI.class);
if (api == null) {
throw new IllegalStateException("MythBoardAPI is not registered. Please ensure the plugin is enabled!");
}
return api;
}
/**
* Get MythBoard's implementation of the {@link CriteriaManager}
* @return {@link CriteriaManager}
*/
@Nullable CriteriaManager getCriteriaManager(); /**
* Register a criteria
* @param criteria Your implementation of {@link CriteriaType}
*/
void register(final @NotNull CriteriaType criteria);
/**
* Checks if a {@link CriteriaType} with this ID exists in the registry
* @param id {@link String} ID of the {@link CriteriaType}
* @return <code>true</code> if a {@link CriteriaType} exists in the registry, <code>false</code> if otherwise
*/
boolean exists(final @NotNull String id);
/**
* Get a {@link CriteriaType} from the registry by its ID
* @param id {@link String} ID for the {@link CriteriaType}
* @return {@link CriteriaType} or <code>null</code> if it does not exist within the registry
*/
@Nullable CriteriaType getCriteria(final @Nullable String id); /**
* Get the ID for this {@link CriteriaType}
* @return {@link String}
*/
@NotNull String getId();
/**
* Create an {@link CriteriaInstance} of this {@link CriteriaType}
* @param options {@link Map}<{@link String}, {@link Object}>
* @return {@link CriteriaInstance}
*/
@NotNull CriteriaInstance create(final @NotNull Map<String, Object> options); /**
* Check if a {@link Player} meets this criteria
* @param player {@link Player}
* @return <code>true</code> if the {@link Player} meets the criteria, <code>false</code> otherwise
*/
boolean meets(final @NotNull Player player);You can create your own custom criteria using the API!
More specifically, you'll be implementing your own criteria type.
public class ExampleCriteriaType implements CriteriaType {
@Override
public @NotNull String getId() {
// Your criteria ID
// Must be unique
// Not case sensitive
return "EXAMPLE"
}
@Override
public @NotNull CriteriaInstance create(@NotNull Map<String, Object> options) {
// The options map are the options in the scoreboard's config for this criteria!
// It's important to practice safe casting and null checks
String balanceString = (String) options.getOrDefault("balance", "0");
double balance;
try {
balance = Double.parseDouble(balanceString);
}
catch (NumberFormatExecption exception) {
// Handle exception
balance = 0.0d;
}
// Return the conditions you want the player to meet
// player is the player being checked against
// You're actually returning a CriteriaInstance here
return player -> {
double playerBalance = ...; // Get player's balance
return playerBalance >= balance; // Return true if their balance is >= the required balance
};
}
}Now it just comes down to registering your new criteria!
To achieve this, utilize the API's CriteriaManager.
public class YourMainClass extends JavaPlugin {
@Override
public void onEnable() {
// Get the API
MythBoardAPI api = MythBoardAPI.getApi();
// null check
if (api != null) {
CriteriaManager manager = api.getCriteriaManager(); // Get the CriteriaManager
manager.register(new ExampleCriteriaType()); // Register your CriteriaType
}
}
}