Skip to content

Commit

Permalink
feat: add misc.yml config
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
HappyAreaBean committed Apr 15, 2024
1 parent 97314fd commit 70f27fb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/cc/happyareabean/sjm/SimpleJoinMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cc.happyareabean.sjm.commands.SJMCommand;
import cc.happyareabean.sjm.config.SJMConfig;
import cc.happyareabean.sjm.config.SJMMisc;
import cc.happyareabean.sjm.listener.PlayerJoinListener;
import cc.happyareabean.sjm.listener.UpdateNotifyListener;
import cc.happyareabean.sjm.utils.AdventureWebEditorAPI;
Expand Down Expand Up @@ -38,6 +39,7 @@ public class SimpleJoinMessage extends JavaPlugin {
@Getter private AdventureWebEditorAPI adventureWebEditorAPI;
@Getter private BukkitCommandHandler commandHandler;
@Getter private SJMConfig SJMConfig;
@Getter private SJMMisc miscConfig;

@Override
public void onEnable() {
Expand All @@ -46,6 +48,7 @@ public void onEnable() {

getLogger().info("Loading settings...");
SJMConfig = new SJMConfig(new File(getDataFolder(), "settings.yml").toPath());
miscConfig = new SJMMisc(new File(getDataFolder(), "misc.yml").toPath());

getLogger().info("Registering listener...");
getServer().getPluginManager().registerEvents(new PlayerJoinListener(), this);
Expand Down Expand Up @@ -78,7 +81,7 @@ public void onEnable() {

getLogger().info("SimpleJoinMessage version " + getDescription().getVersion() + " has been successfully enabled!");

checkUpdate();
if (miscConfig.isUpdateChecker()) checkUpdate();
}

public void checkUpdate() {
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/cc/happyareabean/sjm/config/SJMMisc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package cc.happyareabean.sjm.config;

import de.exlll.configlib.annotation.Comment;
import de.exlll.configlib.configs.yaml.YamlConfiguration;
import de.exlll.configlib.format.FieldNameFormatters;
import lombok.Getter;
import lombok.Setter;

import java.nio.file.Path;
import java.util.Arrays;

@Getter @Setter
@SuppressWarnings("FieldMayBeFinal")
public class SJMMisc extends YamlConfiguration {

public final Path path;

@Comment({
"Enable updater checker?",
" ",
"Depends on your need, but we generally recommend to keep it enable.",
"So you won't miss any update! :)"
})
private boolean updateChecker = true;

public SJMMisc(Path path) {
super(path, YamlProperties.builder()
.setFormatter(FieldNameFormatters.IDENTITY)
.setPrependedComments(Arrays.asList(
"------------------------------------------------------------------------",
" ",
" _____ _ _ _ _ __ __ ",
" / ____(_) | | | | (_) | \\/ | ",
" | (___ _ _ __ ___ _ __ | | ___ | | ___ _ _ __ | \\ / | ___ ___ ___ __ _ __ _ ___ ",
" \\___ \\| | '_ ` _ \\| '_ \\| |/ _ \\_ | |/ _ \\| | '_ \\| |\\/| |/ _ \\/ __/ __|/ _` |/ _` |/ _ \\",
" ____) | | | | | | | |_) | | __/ |__| | (_) | | | | | | | | __/\\__ \\__ \\ (_| | (_| | __/",
" |_____/|_|_| |_| |_| .__/|_|\\___|\\____/ \\___/|_|_| |_|_| |_|\\___||___/___/\\__,_|\\__, |\\___|",
" | | __/ | ",
" |_| |___/ ",
" ",
" SimpleJoinMessage misc configuration - misc.yml",
" ",
"------------------------------------------------------------------------",
" ",
"https://go.happyareabean.cc/sjm",
" ",
"------------------------------------------------------------------------"
)).build());
this.path = path;

this.loadAndSave();
}

public void reloadAndSave() {
load();
save();
}
}

0 comments on commit 70f27fb

Please sign in to comment.