📘 RedeemX Template API
This guide explains how to use the RedeemTemplateServiceAPI
to manage templates in RedeemCodeX.
📄 Overview
Templates in RedeemCodeX define reusable settings for generating redeem codes.
Access the template API via:
Example
val templateService = RedeemXAPI.template
🆕 Creating a Template
To create a new template (or update if it exists):
Example
val template = templateService.generateTemplate("VIP")
You can then modify its properties and upsert it.
✏️ Modifying a Template
Like codes, templates are just data classes. You can directly modify their fields:
Example
template.duration = "3d"
template.cooldown = "1h"
template.permission = "event.redeem"
After modification, remember to save it:
Example
templateService.upsertTemplate(template)
Tip
Upserting ensures the template is saved in the template.yml
.
🗑️ Deleting a Template
To delete a template:
Example
val success = templateService.deleteTemplate("VIP")
Warning
If the template is in use by codes, deleting it may affect them.
📦 Getting Placeholders
To get a placeholder object from a template:
Example
val placeholders = templateService.getRCXPlaceHolder(template)
Useful for GUI or Discord messages.
📚 Fetching Templates
🔹 Get One Template
Example
val template = templateService.getTemplate("VIP")
🔹 Get All Template Names
Example
val names = templateService.getTemplates()
🛠 Full Example
Creating and Saving a Template
val template = templateService.generateTemplate("VIP")
template.redemption = 3
template.cooldown = "5m"
template.commands += listOf("say Welcome VIP")
templateService.upsertTemplate(template)
✅ Recommendation
Recommended
- Define templates for all common code types (e.g., VIP).
- Always use
upsertTemplate
after modifications. - Avoid deleting templates that are actively referenced by codes.