Skip to content

Custom settings

David Rodriguez edited this page Mar 13, 2024 · 6 revisions

Configuration

To create a custom setting using the configuration, you will need to define two sections named after your custom setting

settings.yml

In the first section, we will define the properties of the setting we want to create

# AuthMeReloaded https://www.spigotmc.org/resources/authmereloaded.6269/
premium-setting:
  enabled: true
  name: "&dPremium"
  default: 0
  triggers: []
  onEnable:
    - "SUDO premium %player%"
  onDisable:
    - "SUDO cracked %player%"

items.yml

Next, we define the properties of the item that will display the setting on the menu

premium-setting:
  page: 1
  slot: 34
  name: '&dPremium'
  material: JUKEBOX
  amount: 1
  lore:
    - '&7Toggle your account as authenticated and skip the login step!'
    - ''
    - '&f&lClick &7to toggle'

After both sections are defined, run the /settings reload command, and your custom setting should appear inside the settings menu

You can learn more about the format and options available for these configurations here

API

Creating a setting using the API is a fairly simple task using the builder class provided by the plugin.

If you haven't added the PlayerSettings API to your project's dependencies, please do so before continuing with the guide. You can find a guide here on how to add the API to your dependencies.

The following steps will show you how to create an example setting and register it using the SettingsContainer service

Defining an example setting using the setting builder class provided by the API:

Setting exampleSetting = ImmutableSetting.builder()
    .item(ImmutableMenuItem.of(itemStack, page, slot))
    .name("example-setting")
    .displayName("&6Example")
    .defaultValue(0)
    .maxValue(1)
    .triggers("join", "respawn")
    .addCallback(
        (setting, player, value) -> player.sendMessage(setting.getName() + " - " + value))
    .build();

After defining our setting, all we need to do is register it like so:

SettingsContainer container = Bukkit.getServicesManager().load(SettingsContainer.class);
container.registerSetting(exampleSetting);

Great! Your custom setting is now registered and should now appear inside the settings menu 🎉

Clone this wiki locally