Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/main/java/com/shinybunny/intn/INeedTheNight.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import org.bukkit.plugin.java.JavaPlugin;
import revxrsal.commands.bukkit.BukkitCommandHandler;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import java.util.*;

public final class INeedTheNight extends JavaPlugin {
public final Set<Player> needTheNight = new HashSet<>();
private Map<String, String> messages;

@Override
public void onEnable() {
Expand All @@ -20,15 +20,22 @@ public void onEnable() {
Bukkit.getPluginManager().registerEvents(new SleepingListener(this), this);
TimeChecker timeChecker = new TimeChecker(this);
timeChecker.start();

loadMessages();
}

@Override
public void onDisable() {
// Plugin shutdown logic
}

public String getMessage(String key) {
return getConfig().getString(key, "Error: missing message " + key);
/**
* Gets the requested message from the config file. Might return null if key does not exist.
* @param key The Key leading to the message. Sections are seperated with a dot.
* @return The message stored on the given key, or alternatively null if there is no value for the given key.
*/
public @Nullable String getMessage(String key) {
return messages.get(key);
}

public static String combineNames(List<String> items) {
Expand All @@ -53,4 +60,13 @@ public static String combineNames(List<String> items) {
}
return str.toString();
}

private Map<String, String> loadMessages() {
Map<String, String> messages = new HashMap<>();

getConfig().getKeys(true).forEach(key -> messages.put(key, getConfig().getString(key)));

return messages;
}

}