54 lines
1.7 KiB
Java
54 lines
1.7 KiB
Java
package nl.sbdeveloper.themeparkplus.util;
|
|
|
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.command.ConsoleCommandSender;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
public class ConfigUtil {
|
|
@NotNull
|
|
public static String makecolored(String str) {
|
|
return ChatColor.translateAlternateColorCodes('&', str);
|
|
}
|
|
|
|
@NotNull
|
|
public static List<String> getLore(String path, Map<String, String> vars) {
|
|
ArrayList<String> response = new ArrayList<>();
|
|
for (String str : ThemeParkPlus.getSConfig().getFile().getStringList(path)) {
|
|
for (Map.Entry<String, String> entry : vars.entrySet()) {
|
|
str = str.replaceAll(entry.getKey(), entry.getValue());
|
|
}
|
|
response.add(makecolored(str));
|
|
}
|
|
return response;
|
|
}
|
|
|
|
@NotNull
|
|
public static String getMessage(String path) {
|
|
return getMessage(path, new HashMap<>());
|
|
}
|
|
|
|
@NotNull
|
|
public static String getMessage(String path, Map<String, String> vars) {
|
|
String message = ThemeParkPlus.getMessages().getFile().getString(path);
|
|
if (message == null) return "";
|
|
for (Map.Entry<String, String> entry : vars.entrySet()) {
|
|
message = message.replaceAll(entry.getKey(), entry.getValue());
|
|
}
|
|
return makecolored(message);
|
|
}
|
|
|
|
public static boolean sendConsole(CommandSender sender) {
|
|
if (sender instanceof ConsoleCommandSender) {
|
|
return ThemeParkPlus.getSConfig().getFile().getBoolean("MessageInConsole");
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
}
|