Fix & Optimize
This commit is contained in:
parent
0ceb38e7a3
commit
97c703a45c
5
gradle/libs.versions.toml
Normal file
5
gradle/libs.versions.toml
Normal file
@ -0,0 +1,5 @@
|
||||
[versions]
|
||||
guava = "33.2.1-jre"
|
||||
|
||||
[libraries]
|
||||
guava = { module = "com.google.guava:guava", version.ref = "guava" }
|
||||
@ -20,8 +20,12 @@ subprojects {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Modules
|
||||
implementation(project(":project:module-common"))
|
||||
implementation(project(":project:module-util"))
|
||||
implementation(project(":project:module-logger"))
|
||||
implementation(project(":project:module-configuration"))
|
||||
implementation(project(":project:module-message"))
|
||||
// Spigot API, https://www.spigotmc.org/
|
||||
compileOnly("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT")
|
||||
// Java Libraries
|
||||
@ -118,7 +122,9 @@ subprojects {
|
||||
archiveClassifier.set("")
|
||||
archiveBaseName.set("AuthMe")
|
||||
destinationDirectory.set(file("$rootDir/outs"))
|
||||
// Libraries Relocate
|
||||
// Kotlin
|
||||
relocate("kotlin.", "kolin200.")
|
||||
// Others
|
||||
relocate("org.apache.http", "fr.xephi.authme.libs.org.apache.http")
|
||||
relocate("org.apache.commons", "fr.xephi.authme.libs.org.apache.commons")
|
||||
relocate("waffle", "fr.xephi.authme.libs.waffle")
|
||||
|
||||
@ -26,7 +26,7 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public final class ConsoleLogger {
|
||||
|
||||
private static final String NEW_LINE = System.getProperty("line.separator");
|
||||
private static final String NEW_LINE = System.lineSeparator();
|
||||
/** Formatter which formats dates to something like "[08-16 21:18:46]" for any given LocalDateTime. */
|
||||
private static final DateTimeFormatter DATE_FORMAT = new DateTimeFormatterBuilder()
|
||||
.appendLiteral('[')
|
||||
|
||||
@ -2,6 +2,7 @@ package fr.xephi.authme.message;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.configruation.Configuration;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
@ -9,8 +10,6 @@ import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.util.FileUtils;
|
||||
import fr.xephi.authme.util.message.I18NUtils;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
@ -35,8 +34,8 @@ public abstract class AbstractMessageFileHandler implements Reloadable {
|
||||
private Settings settings;
|
||||
|
||||
private String filename;
|
||||
private FileConfiguration configuration;
|
||||
private Map<String, FileConfiguration> i18nConfiguration;
|
||||
private Configuration configuration;
|
||||
private Map<String, Configuration> i18nConfiguration;
|
||||
private final String defaultFile;
|
||||
|
||||
protected AbstractMessageFileHandler() {
|
||||
@ -49,7 +48,7 @@ public abstract class AbstractMessageFileHandler implements Reloadable {
|
||||
String language = settings.getProperty(PluginSettings.MESSAGES_LANGUAGE);
|
||||
filename = createFilePath(language);
|
||||
File messagesFile = initializeFile(filename);
|
||||
configuration = YamlConfiguration.loadConfiguration(messagesFile);
|
||||
configuration = Configuration.loadFromFile(messagesFile);
|
||||
i18nConfiguration = null;
|
||||
}
|
||||
|
||||
@ -117,7 +116,7 @@ public abstract class AbstractMessageFileHandler implements Reloadable {
|
||||
return configuration.getString(key);
|
||||
}
|
||||
|
||||
public FileConfiguration getI18nConfiguration(String locale) {
|
||||
public Configuration getI18nConfiguration(String locale) {
|
||||
if (i18nConfiguration == null) {
|
||||
i18nConfiguration = new ConcurrentHashMap<>();
|
||||
}
|
||||
@ -130,7 +129,7 @@ public abstract class AbstractMessageFileHandler implements Reloadable {
|
||||
// Sync with reload();
|
||||
String i18nFilename = createFilePath(locale);
|
||||
File i18nMessagesFile = initializeFile(i18nFilename);
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(i18nMessagesFile);
|
||||
Configuration config = Configuration.loadFromFile(i18nMessagesFile);
|
||||
|
||||
i18nConfiguration.put(locale, config);
|
||||
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
package fr.xephi.authme.message;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.configruation.Configuration;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.util.FileUtils;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.InputStream;
|
||||
@ -19,9 +18,10 @@ public class HelpMessagesFileHandler extends AbstractMessageFileHandler {
|
||||
|
||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(HelpMessagesFileHandler.class);
|
||||
|
||||
private FileConfiguration defaultConfiguration;
|
||||
private Configuration defaultConfiguration;
|
||||
|
||||
@Inject // Trigger injection in the superclass
|
||||
@Inject
|
||||
// Trigger injection in the superclass
|
||||
HelpMessagesFileHandler() {
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ public class HelpMessagesFileHandler extends AbstractMessageFileHandler {
|
||||
|
||||
if (message == null) {
|
||||
logger.warning("Error getting message with key '" + key + "'. "
|
||||
+ "Please update your config file '" + getFilename() + "' or run /authme messages help");
|
||||
+ "Please update your config file '" + getFilename() + "' or run /authme messages help");
|
||||
return getDefault(key);
|
||||
}
|
||||
return message;
|
||||
@ -52,12 +52,12 @@ public class HelpMessagesFileHandler extends AbstractMessageFileHandler {
|
||||
private String getDefault(String key) {
|
||||
if (defaultConfiguration == null) {
|
||||
InputStream stream = FileUtils.getResourceFromJar(createFilePath(DEFAULT_LANGUAGE));
|
||||
defaultConfiguration = YamlConfiguration.loadConfiguration(new InputStreamReader(stream));
|
||||
defaultConfiguration = Configuration.loadFromReader(new InputStreamReader(stream));
|
||||
}
|
||||
String message = defaultConfiguration.getString(key);
|
||||
return message == null
|
||||
? "Error retrieving message '" + key + "'"
|
||||
: message;
|
||||
? "Error retrieving message '" + key + "'"
|
||||
: message;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -7,12 +7,14 @@ import org.apache.logging.log4j.core.Logger;
|
||||
import org.apache.logging.log4j.core.filter.AbstractFilter;
|
||||
import org.apache.logging.log4j.message.Message;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Implements a filter for Log4j to skip sensitive AuthMe commands.
|
||||
*
|
||||
* @author Xephi59
|
||||
*/
|
||||
public class Log4JFilter extends AbstractFilter {
|
||||
public class Log4JFilter extends AbstractFilter implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -5594073755007974254L;
|
||||
|
||||
|
||||
@ -1,5 +1 @@
|
||||
repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
}
|
||||
dependencies {}
|
||||
1
project/module-common/build.gradle.kts
Normal file
1
project/module-common/build.gradle.kts
Normal file
@ -0,0 +1 @@
|
||||
dependencies {}
|
||||
@ -3,12 +3,8 @@ package fr.xephi.authme.configruation
|
||||
import com.electronwill.nightconfig.core.CommentedConfig
|
||||
import com.electronwill.nightconfig.core.Config
|
||||
import com.electronwill.nightconfig.core.EnumGetMethod
|
||||
import org.tabooproject.reflex.Reflex.Companion.setProperty
|
||||
import taboolib.common.util.decodeUnicode
|
||||
import taboolib.common5.Coerce
|
||||
import taboolib.library.configuration.ConfigurationSection
|
||||
import taboolib.module.configuration.util.Commented
|
||||
import taboolib.module.configuration.util.CommentedList
|
||||
import fr.xephi.authme.util.Coerce
|
||||
import fr.xephi.authme.util.StringUtil
|
||||
|
||||
/**
|
||||
* ConfigSection
|
||||
@ -16,7 +12,11 @@ import taboolib.module.configuration.util.CommentedList
|
||||
* @author Taboolib
|
||||
* @since 2024/7/10 19:33
|
||||
*/
|
||||
open class ConfigSection(var root: Config, override val name: String = "", override val parent: ConfigurationSection? = null) : ConfigurationSection {
|
||||
open class ConfigSection(
|
||||
var root: Config,
|
||||
override val name: String = "",
|
||||
override val parent: ConfigurationSection? = null
|
||||
) : ConfigurationSection {
|
||||
|
||||
private val configType = Type.getType(root.configFormat())
|
||||
|
||||
@ -71,9 +71,12 @@ open class ConfigSection(var root: Config, override val name: String = "", overr
|
||||
// 因为在 set 方法中 Map 会被转换为 Config 类型
|
||||
is Map<*, *> -> {
|
||||
val subConfig = root.createSubConfig()
|
||||
subConfig.setProperty("map", value)
|
||||
val field = subConfig::class.java.getField("map")
|
||||
field.isAccessible = true
|
||||
field.set(subConfig, value)
|
||||
ConfigSection(subConfig, name, parent)
|
||||
}
|
||||
|
||||
else -> unwrap(value)
|
||||
}
|
||||
}
|
||||
@ -84,15 +87,17 @@ open class ConfigSection(var root: Config, override val name: String = "", overr
|
||||
value is List<*> -> root.set<Any>(path, unwrap(value, this))
|
||||
value is Collection<*> && value !is List<*> -> set(path, value.toList())
|
||||
value is ConfigurationSection -> set(path, value.getConfig())
|
||||
value is Map<*, *> -> set(path, value.toConfig(this))
|
||||
value is Map<*, *> -> set(path, value.asConfig(this))
|
||||
value is Commented -> {
|
||||
set(path, value.value)
|
||||
setComment(path, value.comment)
|
||||
}
|
||||
|
||||
value is CommentedList -> {
|
||||
set(path, value.value)
|
||||
setComments(path, value.comment)
|
||||
}
|
||||
|
||||
else -> root.set<Any>(path, value)
|
||||
}
|
||||
}
|
||||
@ -111,11 +116,11 @@ open class ConfigSection(var root: Config, override val name: String = "", overr
|
||||
}
|
||||
|
||||
override fun getInt(path: String): Int {
|
||||
return Coerce.toInteger(get(path))
|
||||
return Coerce.asInteger(get(path)).get()
|
||||
}
|
||||
|
||||
override fun getInt(path: String, def: Int): Int {
|
||||
return Coerce.toInteger(get(path) ?: def)
|
||||
return Coerce.asInteger(get(path) ?: def).get()
|
||||
}
|
||||
|
||||
override fun isInt(path: String): Boolean {
|
||||
@ -124,11 +129,11 @@ open class ConfigSection(var root: Config, override val name: String = "", overr
|
||||
}
|
||||
|
||||
override fun getBoolean(path: String): Boolean {
|
||||
return Coerce.toBoolean(get(path))
|
||||
return Coerce.asBoolean(get(path)).get()
|
||||
}
|
||||
|
||||
override fun getBoolean(path: String, def: Boolean): Boolean {
|
||||
return Coerce.toBoolean(get(path) ?: def)
|
||||
return Coerce.asBoolean(get(path) ?: def).get()
|
||||
}
|
||||
|
||||
override fun isBoolean(path: String): Boolean {
|
||||
@ -136,11 +141,11 @@ open class ConfigSection(var root: Config, override val name: String = "", overr
|
||||
}
|
||||
|
||||
override fun getDouble(path: String): Double {
|
||||
return Coerce.toDouble(get(path))
|
||||
return Coerce.asDouble(get(path)).get()
|
||||
}
|
||||
|
||||
override fun getDouble(path: String, def: Double): Double {
|
||||
return Coerce.toDouble(get(path) ?: def)
|
||||
return Coerce.asDouble(get(path) ?: def).get()
|
||||
}
|
||||
|
||||
override fun isDouble(path: String): Boolean {
|
||||
@ -148,11 +153,11 @@ open class ConfigSection(var root: Config, override val name: String = "", overr
|
||||
}
|
||||
|
||||
override fun getLong(path: String): Long {
|
||||
return Coerce.toLong(get(path))
|
||||
return Coerce.asLong(get(path)).get()
|
||||
}
|
||||
|
||||
override fun getLong(path: String, def: Long): Long {
|
||||
return Coerce.toLong(get(path) ?: def)
|
||||
return Coerce.asLong(get(path) ?: def).get()
|
||||
}
|
||||
|
||||
override fun isLong(path: String): Boolean {
|
||||
@ -176,35 +181,35 @@ open class ConfigSection(var root: Config, override val name: String = "", overr
|
||||
}
|
||||
|
||||
override fun getIntegerList(path: String): List<Int> {
|
||||
return getList(path)?.map { Coerce.toInteger(it) }?.toList() ?: ArrayList()
|
||||
return getList(path)?.map { Coerce.asInteger(it).get() }?.toList() ?: ArrayList()
|
||||
}
|
||||
|
||||
override fun getBooleanList(path: String): List<Boolean> {
|
||||
return getList(path)?.map { Coerce.toBoolean(it) }?.toList() ?: ArrayList()
|
||||
return getList(path)?.map { Coerce.asBoolean(it).get() }?.toList() ?: ArrayList()
|
||||
}
|
||||
|
||||
override fun getDoubleList(path: String): List<Double> {
|
||||
return getList(path)?.map { Coerce.toDouble(it) }?.toList() ?: ArrayList()
|
||||
return getList(path)?.map { Coerce.asDouble(it).get() }?.toList() ?: ArrayList()
|
||||
}
|
||||
|
||||
override fun getFloatList(path: String): List<Float> {
|
||||
return getList(path)?.map { Coerce.toFloat(it) }?.toList() ?: ArrayList()
|
||||
return getList(path)?.map { Coerce.asFloat(it).get() }?.toList() ?: ArrayList()
|
||||
}
|
||||
|
||||
override fun getLongList(path: String): List<Long> {
|
||||
return getList(path)?.map { Coerce.toLong(it) }?.toList() ?: ArrayList()
|
||||
return getList(path)?.map { Coerce.asLong(it).get() }?.toList() ?: ArrayList()
|
||||
}
|
||||
|
||||
override fun getByteList(path: String): List<Byte> {
|
||||
return getList(path)?.map { Coerce.toByte(it) }?.toList() ?: ArrayList()
|
||||
return getList(path)?.map { Coerce.asByte(it).get() }?.toList() ?: ArrayList()
|
||||
}
|
||||
|
||||
override fun getCharacterList(path: String): List<Char> {
|
||||
return getList(path)?.map { Coerce.toChar(it) }?.toList() ?: ArrayList()
|
||||
return getList(path)?.map { Coerce.asChar(it).get() }?.toList() ?: ArrayList()
|
||||
}
|
||||
|
||||
override fun getShortList(path: String): List<Short> {
|
||||
return getList(path)?.map { Coerce.toShort(it) }?.toList() ?: ArrayList()
|
||||
return getList(path)?.map { Coerce.asShort(it).get() }?.toList() ?: ArrayList()
|
||||
}
|
||||
|
||||
override fun getMapList(path: String): List<Map<*, *>> {
|
||||
@ -289,7 +294,7 @@ open class ConfigSection(var root: Config, override val name: String = "", overr
|
||||
return if (this is ConfigSection) root else error("Not supported")
|
||||
}
|
||||
|
||||
private fun Map<*, *>.toConfig(parent: ConfigSection): Config {
|
||||
private fun Map<*, *>.asConfig(parent: ConfigSection): Config {
|
||||
val section = ConfigSection(parent.root.createSubConfig())
|
||||
forEach { (k, v) -> section[k.toString()] = v }
|
||||
return section.root
|
||||
@ -321,7 +326,7 @@ open class ConfigSection(var root: Config, override val name: String = "", overr
|
||||
value is List<*> -> unwrap(value, parent)
|
||||
value is Collection<*> && value !is List<*> -> value.toList()
|
||||
value is ConfigurationSection -> value.getConfig()
|
||||
value is Map<*, *> -> value.toConfig(parent)
|
||||
value is Map<*, *> -> value.asConfig(parent)
|
||||
else -> value
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,6 +81,8 @@ interface Configuration : ConfigurationSection {
|
||||
/**
|
||||
* 识别可能的 [ConfigurationSection] 类型
|
||||
*/
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun parse(any: Any, type: Type = Type.YAML, concurrent: Boolean = true): ConfigurationSection {
|
||||
val unwrapped = ConfigSection.unwrap(any)
|
||||
if (unwrapped is Map<*, *>) {
|
||||
@ -96,6 +98,8 @@ interface Configuration : ConfigurationSection {
|
||||
* @param concurrent 是否支持并发
|
||||
* @return [Configuration]
|
||||
*/
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun empty(type: Type = Type.YAML, concurrent: Boolean = true): Configuration {
|
||||
return ConfigFile(
|
||||
if (concurrent) type.newFormat().createConcurrentConfig() else type.newFormat()
|
||||
@ -110,6 +114,8 @@ interface Configuration : ConfigurationSection {
|
||||
* @param concurrent 是否支持并发
|
||||
* @return [Configuration]
|
||||
*/
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun loadFromFile(file: File, type: Type? = null, concurrent: Boolean = true): Configuration {
|
||||
val format = (type ?: getTypeFromFile(file)).newFormat()
|
||||
val configFile =
|
||||
@ -126,6 +132,8 @@ interface Configuration : ConfigurationSection {
|
||||
* @param concurrent 是否支持并发
|
||||
* @return [Configuration]
|
||||
*/
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun loadFromReader(reader: Reader, type: Type = Type.YAML, concurrent: Boolean = true): Configuration {
|
||||
val format = type.newFormat()
|
||||
val configFile =
|
||||
@ -142,6 +150,8 @@ interface Configuration : ConfigurationSection {
|
||||
* @param concurrent 是否支持并发
|
||||
* @return [Configuration]
|
||||
*/
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun loadFromString(contents: String, type: Type = Type.YAML, concurrent: Boolean = true): Configuration {
|
||||
val format = type.newFormat()
|
||||
val configFile =
|
||||
@ -158,6 +168,8 @@ interface Configuration : ConfigurationSection {
|
||||
* @param concurrent 是否支持并发
|
||||
* @return [Configuration]
|
||||
*/
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun loadFromInputStream(
|
||||
inputStream: InputStream,
|
||||
type: Type = Type.YAML,
|
||||
@ -178,6 +190,8 @@ interface Configuration : ConfigurationSection {
|
||||
* @param concurrent 是否支持并发
|
||||
* @return [ConfigurationSection]
|
||||
*/
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun fromMap(map: Map<*, *>, type: Type = Type.YAML, concurrent: Boolean = true): ConfigurationSection {
|
||||
val empty = empty(type, concurrent)
|
||||
map.forEach { (k, v) -> empty[k.toString()] = v }
|
||||
@ -191,6 +205,8 @@ interface Configuration : ConfigurationSection {
|
||||
* @param def 默认类型
|
||||
* @return [Type]
|
||||
*/
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun getTypeFromFile(file: File, def: Type = Type.YAML): Type {
|
||||
return getTypeFromExtension(file.extension, def)
|
||||
}
|
||||
@ -202,6 +218,8 @@ interface Configuration : ConfigurationSection {
|
||||
* @param def 默认类型
|
||||
* @return [Type]
|
||||
*/
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun getTypeFromExtension(extension: String, def: Type = Type.YAML): Type {
|
||||
return when (extension) {
|
||||
"yaml", "yml" -> Type.YAML
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
package fr.xephi.authme.configruation
|
||||
|
||||
import com.electronwill.nightconfig.core.Config
|
||||
import com.electronwill.nightconfig.core.ConfigFormat
|
||||
import com.electronwill.nightconfig.yaml.YamlFormat
|
||||
|
||||
/**
|
||||
* Type
|
||||
*
|
||||
@ -8,7 +12,7 @@ package fr.xephi.authme.configruation
|
||||
*/
|
||||
enum class Type(private val format: () -> ConfigFormat<out Config>) {
|
||||
|
||||
YAML({ YamlFormat.INSTANCE });
|
||||
YAML({ YamlFormat.defaultInstance() });
|
||||
|
||||
// TOML({ TomlFormat.instance() }),
|
||||
//
|
||||
@ -25,7 +29,7 @@ enum class Type(private val format: () -> ConfigFormat<out Config>) {
|
||||
companion object {
|
||||
|
||||
fun getType(format: ConfigFormat<*>): Type {
|
||||
return values().first { it.newFormat().javaClass == format.javaClass }
|
||||
return entries.first { it.newFormat().javaClass == format.javaClass }
|
||||
}
|
||||
}
|
||||
}
|
||||
3
project/module-logger/build.gradle.kts
Normal file
3
project/module-logger/build.gradle.kts
Normal file
@ -0,0 +1,3 @@
|
||||
dependencies {
|
||||
compileOnly(libs.guava)
|
||||
}
|
||||
1
project/module-message/build.gradle.kts
Normal file
1
project/module-message/build.gradle.kts
Normal file
@ -0,0 +1 @@
|
||||
dependencies {}
|
||||
@ -1,3 +1,3 @@
|
||||
dependencies {
|
||||
compileOnly("com.google.guava:guava:33.2.1-jre")
|
||||
compileOnly(libs.guava)
|
||||
}
|
||||
@ -22,7 +22,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.common.data.builder;
|
||||
package fr.xephi.authme.util;
|
||||
|
||||
import com.google.common.primitives.Doubles;
|
||||
import com.google.common.primitives.Ints;
|
||||
@ -44,7 +44,8 @@ public final class Coerce {
|
||||
/**
|
||||
* No subclasses for you.
|
||||
*/
|
||||
private Coerce() {}
|
||||
private Coerce() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the given object as a {@link String}.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user