7fd3fc157c
Default trigger is now player join rather than a timer, with a short delay so the curiosity lands after the join message instead of racing it. Modes entrada/intervalo/ambos/manual select the triggers. Adds a full /curiosidade tree so behaviour is adjustable in-game without editing config.yml: mode, interval, join delay, per-player cooldown, no-repeat history, reaction window, reaction labels, and per-category toggles. Every setter writes through to disk immediately so changes survive a restart. Facts are now tagged with a category so they can be filtered, and a per-player cooldown plus recent-fact history stop repeats when someone relogs. Config changes are gated behind curiosidades.admin; reacting and opting out stay default-true. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ActvLGJApdxEAd2yfKPwqv
125 lines
3.5 KiB
Java
125 lines
3.5 KiB
Java
package dev.marcospaulo.curiosidades;
|
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* Typed view over config.yml.
|
|
*
|
|
* <p>Every setter writes through to disk immediately, so a command that changes
|
|
* behaviour survives a restart without anyone having to remember to save.
|
|
*/
|
|
final class Settings {
|
|
|
|
private final Curiosidades plugin;
|
|
|
|
Settings(Curiosidades plugin) {
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
// --- triggering ---------------------------------------------------------
|
|
|
|
Mode mode() {
|
|
Mode mode = Mode.byKey(plugin.getConfig().getString("modo", "ENTRADA"));
|
|
return mode == null ? Mode.ENTRADA : mode;
|
|
}
|
|
|
|
void mode(Mode mode) {
|
|
set("modo", mode.name());
|
|
}
|
|
|
|
int intervalMinutes() {
|
|
return Math.max(1, plugin.getConfig().getInt("intervalo-minutos", 20));
|
|
}
|
|
|
|
void intervalMinutes(int minutes) {
|
|
set("intervalo-minutos", Math.max(1, minutes));
|
|
}
|
|
|
|
/** Seconds to wait after a join before announcing, so it lands after the join message. */
|
|
int joinDelaySeconds() {
|
|
return Math.max(0, plugin.getConfig().getInt("atraso-entrada-segundos", 6));
|
|
}
|
|
|
|
void joinDelaySeconds(int seconds) {
|
|
set("atraso-entrada-segundos", Math.max(0, seconds));
|
|
}
|
|
|
|
/** Minutes before the same player can be the subject again. */
|
|
int cooldownMinutes() {
|
|
return Math.max(0, plugin.getConfig().getInt("cooldown-minutos", 30));
|
|
}
|
|
|
|
void cooldownMinutes(int minutes) {
|
|
set("cooldown-minutos", Math.max(0, minutes));
|
|
}
|
|
|
|
/** How many recent facts to remember and avoid repeating. */
|
|
int noRepeat() {
|
|
return Math.max(0, plugin.getConfig().getInt("evitar-repetir", 15));
|
|
}
|
|
|
|
void noRepeat(int count) {
|
|
set("evitar-repetir", Math.max(0, count));
|
|
}
|
|
|
|
// --- presentation -------------------------------------------------------
|
|
|
|
boolean reactionsEnabled() {
|
|
return plugin.getConfig().getBoolean("reacoes-ativas", true);
|
|
}
|
|
|
|
void reactionsEnabled(boolean enabled) {
|
|
set("reacoes-ativas", enabled);
|
|
}
|
|
|
|
int reactionWindowSeconds() {
|
|
return Math.max(5, plugin.getConfig().getInt("janela-reacao-segundos", 90));
|
|
}
|
|
|
|
void reactionWindowSeconds(int seconds) {
|
|
set("janela-reacao-segundos", Math.max(5, seconds));
|
|
}
|
|
|
|
Map<String, String> reactions() {
|
|
Map<String, String> reactions = new LinkedHashMap<>();
|
|
ConfigurationSection section = plugin.getConfig().getConfigurationSection("reacoes");
|
|
if (section != null) {
|
|
for (String key : section.getKeys(false)) {
|
|
reactions.put(key, section.getString(key, key));
|
|
}
|
|
}
|
|
if (reactions.isEmpty()) {
|
|
reactions.put("joia", "[+1]");
|
|
}
|
|
return reactions;
|
|
}
|
|
|
|
void reaction(String key, String label) {
|
|
set("reacoes." + key, label);
|
|
}
|
|
|
|
void removeReaction(String key) {
|
|
set("reacoes." + key, null);
|
|
}
|
|
|
|
// --- content ------------------------------------------------------------
|
|
|
|
boolean categoryEnabled(Category category) {
|
|
return plugin.getConfig().getBoolean("categorias." + category.key(), true);
|
|
}
|
|
|
|
void categoryEnabled(Category category, boolean enabled) {
|
|
set("categorias." + category.key(), enabled);
|
|
}
|
|
|
|
// --- plumbing -----------------------------------------------------------
|
|
|
|
private void set(String path, Object value) {
|
|
plugin.getConfig().set(path, value);
|
|
plugin.saveConfig();
|
|
}
|
|
}
|