Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/kotlin/me/fzzyhmstrs/fzzy_config/registry/ClientConfigRegistry.kt
  • Loading branch information
fzzyhmstrs committed Jan 6, 2025
2 parents 46c8351 + a50ab22 commit 5149948
Show file tree
Hide file tree
Showing 231 changed files with 11,881 additions and 4,072 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
* Scheduled `ValidatedEntityAttribute` for removal in **0.6.0**. It is completely unused as far as I can tell with a github-wide search, and quite an unstable concept in general. If needed, a similar validation can be built for your own usage.

### Fixes
* Fixed inaccurate docs in `ValidatedEntityAttribute.Builder` and `EntityAttributeInstanceHolder`
* Fixed inaccurate docs in `ValidatedEntityAttribute.Builder` and `EntityAttributeInstanceHolder`
* Attempt fix on Github/#24, which appears to be caused by concurrent access of some kind. Client scopes are now synchronized.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ org.gradle.warning.mode = all
# Check these on https://fabricmc.net/versions.html
minecraftVersion=1.21.3
yarnMappings=1.21.3+build.2
loaderVersion = 0.16.8
loaderVersion = 0.16.9

# Fabric API
fabricVersion=0.110.0+1.21.3
Expand All @@ -39,4 +39,4 @@ includeExamples = false
# Mod Properties
mavenGroup = me.fzzyhmstrs
archivesBaseName = fzzy_config
modVersion = 0.5.9
modVersion = 0.6.0
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package me.fzzyhmstrs.fzzy_config.annotations
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialInfo
import me.fzzyhmstrs.fzzy_config.annotations.Action.RESTART
import me.fzzyhmstrs.fzzy_config.entry.EntryPermissible
import me.fzzyhmstrs.fzzy_config.fcId
import me.fzzyhmstrs.fzzy_config.util.FcText.command
import me.fzzyhmstrs.fzzy_config.util.FcText.lit
Expand Down Expand Up @@ -70,7 +71,7 @@ annotation class ClientModifiable
* 6. [WithCustomPerms] (Annotating config class itself)
* 7. [WithPerms] (Annotating config class itself)
* 8. [Config.defaultPermLevel][me.fzzyhmstrs.fzzy_config.config.Config.defaultPermLevel]
* @param opLevel the Operator Level required for modification. 1 = moderator, 2 = gamemaster, 3 = admin, 4 = owner
* @param opLevel the Operator Level required for modification. 1 = moderator, 2 = game master, 3 = admin, 4 = owner
* @author fzzyhmstrs
* @since 0.2.0
*/
Expand All @@ -85,6 +86,7 @@ annotation class WithPerms(val opLevel: Int = 3)
* Uses permissions from LuckPerms, or any permissions mod that integrates with `fabric-permissions-api`.
*
* Order of precedence:
* 0. [EntryPermissible] (hardcode bypass pf permission checks)
* 1. [NonSync]
* 2. [ClientModifiable] (Annotating config class itself)
* 3. [ClientModifiable] (specific setting annotation)
Expand All @@ -94,7 +96,7 @@ annotation class WithPerms(val opLevel: Int = 3)
* 7. [WithPerms] (Annotating config class itself)
* 8. [Config.defaultPermLevel][me.fzzyhmstrs.fzzy_config.config.Config.defaultPermLevel]
* @param perms Array<String> - permission groups allowed to access this setting. Groups need to be compatible with LuckPerms or similar.
* @param fallback Int - Default -1 = no custom fallback behavior; it will use the default permissions of the class. If provided, uses vanilla logic: 1 = moderator, 2 = gamemaster, 3 = admin, 4 = owner
* @param fallback Int - Default -1 = no custom fallback behavior; it will use the default permissions of the class. If provided, uses vanilla logic: 1 = moderator, 2 = game master, 3 = admin, 4 = owner
* @author fzzyhmstrs
* @since 0.3.8
*/
Expand All @@ -106,11 +108,11 @@ annotation class WithCustomPerms(val perms: Array<String>, val fallback: Int = -
*
* Admin access will mark that a player can handle access violations (potential cheating of a config update) and other server-level issues, and will be notified in-game if such an error occurs while they are online.
*
* This annotation is outside of the chain of precedence of the others, it is solely responsible for determining admin access.
* This annotation is outside the chain of precedence of the others, it is solely responsible for determining admin access.
*
* If [WithCustomPerms] is used in the config class, this should be paired with it; otherwise the system will consider any server admin or owner (level 3+ perms) as an admin.
* @param perms Array&lt;String&gt; - permission groups allowed to access this setting. Groups need to be compatible with LuckPerms or similar.
* @param fallback Int - Default -1 = no custom fallback behavior; it will check for permission level of 3+. If provided, uses vanilla logic: 1 = moderator, 2 = gamemaster, 3 = admin, 4 = owner
* @param fallback Int - Default -1 = no custom fallback behavior; it will check for permission level of 3+. If provided, uses vanilla logic: 1 = moderator, 2 = game master, 3 = admin, 4 = owner
* @author fzzyhmstrs
* @since 0.4.0
*/
Expand All @@ -137,12 +139,12 @@ annotation class AdminAccess(val perms: Array<String>, val fallback: Int = -1)
* @since 0.2.0
*/
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD)
annotation class NonSync()
annotation class NonSync

/**
* Defines the version of the config file.
*
* Config serialization will prepend a 'version' key with the integer version of a config. defaults to 0, even if a Version annotation is not used. This number is passed to [Config]
* Config serialization will prepend a 'version' key with the integer version of a config. defaults to 0, even if a Version annotation is not used. This number is passed to [Config][me.fzzyhmstrs.fzzy_config.config.Config]
*
* @param version the version number of the config. 0-indexed.
* @author fzzyhmstrs
Expand Down Expand Up @@ -266,7 +268,7 @@ enum class Action(val restartPrompt: Boolean, val sprite: Identifier, val client
"fc.config.reload_resources.warning.config".translate().formatted(Formatting.GOLD));


fun priorityOf(other: Action): Action {
private fun priorityOf(other: Action): Action {
return if (this == other) {
this
} else if(this.ordinal < other.ordinal) {
Expand All @@ -276,7 +278,7 @@ enum class Action(val restartPrompt: Boolean, val sprite: Identifier, val client
}
}

fun isPriority(other: Action): Boolean {
internal fun isPriority(other: Action): Boolean {
return priorityOf(other) == this
}
}
Expand Down Expand Up @@ -325,7 +327,7 @@ annotation class TomlHeaderComment(val text: String)
*
* This is used to define "standard" translations that can be reused regardless of the relative position in a config tree
*
* For example, in a typical config, if you have a repeating element `my_mod.config.element1`, `my_mod.config.element2`, `my_mod.config.element3`, and so on, you would have to write corresponding lang for each subelement of each element. Tedious. With this annotation, you can define a custom prefix for the field or property (or all fields/properties within the annotated class), and all annotated instances will refer to the common translation.
* For example, in a typical config, if you have a repeating element `my_mod.config.element1`, `my_mod.config.element2`, `my_mod.config.element3`, and so on, you would have to write corresponding lang for each sub-element of each element. Tedious. With this annotation, you can define a custom prefix for the field or property (or all fields/properties within the annotated class), and all annotated instances will refer to the common translation.
* - From: `"my_mod.config.element1.subElement1": "Element 1"`, `"my_mod.config.element2.subElement1": "Element 1"` etc.
* - To: `"my_mod.config.prefix.element1": "Element 1"` for all element instances
* @param prefix String - the translation key prefix. Will be appended with `".elementName"`. `"my.prefix"` annotated on a field called `myElement` will yield a translation key `"my.prefix.myElement"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import net.peanuuutz.tomlkt.TomlInteger
*/
@SerialInfo
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY)
public annotation class Comment(val value: String)
annotation class Comment(val value: String)

/**
* Java field-friendly version of [TomlInline](https://peanuuutz.github.io/tomlkt/tomlkt/net.peanuuutz.tomlkt/-toml-inline/index.html)
Expand Down Expand Up @@ -112,7 +112,7 @@ annotation class Inline
*/
@SerialInfo
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY)
public annotation class BlockArray(val itemsPerLine: Int = 1)
annotation class BlockArray(val itemsPerLine: Int = 1)

/**
* Java field-friendly version of [TomlMultilimeString](https://peanuuutz.github.io/tomlkt/tomlkt/net.peanuuutz.tomlkt/-toml-multiline-string/index.html)
Expand Down Expand Up @@ -167,7 +167,7 @@ annotation class MultilineString
*/
@SerialInfo
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY)
public annotation class LiteralString
annotation class LiteralString

/**
* Java field-friendly version of [TomlInteger](https://peanuuutz.github.io/tomlkt/tomlkt/net.peanuuutz.tomlkt/-toml-integer/index.html)
Expand Down Expand Up @@ -199,7 +199,7 @@ public annotation class LiteralString
*/
@SerialInfo
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY)
public annotation class Integer(
annotation class Integer(
val base: TomlInteger.Base = TomlInteger.Base.Dec,
val group: Int = 0
)
32 changes: 31 additions & 1 deletion src/main/kotlin/me/fzzyhmstrs/fzzy_config/api/ConfigApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

package me.fzzyhmstrs.fzzy_config.api

import me.fzzyhmstrs.fzzy_config.annotations.Action
import me.fzzyhmstrs.fzzy_config.annotations.NonSync
import me.fzzyhmstrs.fzzy_config.annotations.TomlHeaderComment
import me.fzzyhmstrs.fzzy_config.annotations.Version
Expand All @@ -32,6 +33,7 @@ import me.fzzyhmstrs.fzzy_config.util.platform.impl.PlatformApiImpl
import net.peanuuutz.tomlkt.*
import org.jetbrains.annotations.ApiStatus
import java.io.File
import java.io.Reader
import java.util.function.Supplier

/**
Expand Down Expand Up @@ -375,6 +377,8 @@ object ConfigApi {

/**
* Whether a config corresponding to the provided scope is registered
* @author fzzyhmstrs
* @since 0.5.3
*/
@JvmStatic
@Deprecated("Only polls synced configs. Use newer overload with RegisterType param")
Expand All @@ -394,6 +398,32 @@ object ConfigApi {
return ConfigApiImpl.isConfigLoaded(scope, type)
}

/**
* Parses a resource reader into a TomlElement for use in Codecs or other things.
* @param reader [Reader] input reader containing a toml file
* @return [TomlElement] parsed from the input reader
* @throws kotlinx.serialization.SerializationException if parsing fails
* @author fzzyhmstrs
* @since 0.6.0
*/
@JvmStatic
fun parseReader(reader: Reader): TomlElement {
return ConfigApiImpl.parseReader(reader)
}

/**
* Returns a set of [Action] annotated onto the provided input
* @param thing Any non-null input for checking
* @return Set&lt;[Action]&gt;
* @see [me.fzzyhmstrs.fzzy_config.entry.EntryParent]
* @author fzzyhmstrs
* @since 0.6.0
*/
@JvmStatic
fun actions(thing: Any): Set<Action> {
return ConfigApiImpl.getActions(thing, ConfigApiImpl.IGNORE_NON_SYNC)
}

/**
* Provides an instance of the [NetworkApi] for usage of the built-in cross-loader networking API
* @author fzzyhmstrs
Expand Down Expand Up @@ -429,7 +459,7 @@ object ConfigApi {
* @since 0.5.3
*/
@JvmStatic
@ApiStatus.Experimental
@ApiStatus.Experimental //TODO fully test for promotion to stable
fun result(): ResultApi {
return ResultApiImpl
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ object ConfigApiJava {
*/
@JvmStatic
@JvmOverloads
@Suppress("DEPRECATION")
@Deprecated("Consider registerAndLoadConfig() instead, to perform automatic loading, registering, and validating in one step.")
fun <T: Config> registerConfig(config: T, configClass: Supplier<T>, registerType: RegisterType = RegisterType.BOTH): T{
return ConfigApi.registerConfig(config, configClass, registerType)
Expand Down Expand Up @@ -98,6 +99,8 @@ object ConfigApiJava {

/**
* Whether a config corresponding to the provided scope is registered
* @author fzzyhmstrs
* @since 0.5.3
*/
@JvmStatic
@Deprecated("Only polls synced configs. Use newer overload with RegisterType param")
Expand Down Expand Up @@ -153,6 +156,7 @@ object ConfigApiJava {
* @since 0.5.3
*/
@JvmStatic
//TODO fully test for promotion to stable
fun result(): ResultApiJava {
return ResultApiJavaImpl
}
Expand Down
25 changes: 24 additions & 1 deletion src/main/kotlin/me/fzzyhmstrs/fzzy_config/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
package me.fzzyhmstrs.fzzy_config.config

import me.fzzyhmstrs.fzzy_config.api.ConfigApi
import me.fzzyhmstrs.fzzy_config.entry.EntryAnchor
import me.fzzyhmstrs.fzzy_config.screen.widget.TextureDeco
import me.fzzyhmstrs.fzzy_config.util.Translatable
import me.fzzyhmstrs.fzzy_config.util.Walkable
import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.util.Identifier
import org.jetbrains.annotations.ApiStatus.Internal

/**
* Base Config class for use with FzzyConfig
Expand All @@ -38,13 +41,15 @@ import net.minecraft.util.Identifier
* @param subfolder String, optional - puts the config into a sub-subfolder inside the subfolder specified in [folder]. Does not affect ID or GUI layout
* @see ConfigApi
* @see ConfigSection
* @see ConfigAction
* @see ConfigGroup
* @see getId
* @see me.fzzyhmstrs.fzzy_config.validation.ValidatedField
* @author fzzyhmstrs
* @since 0.2.0
*/
@Suppress("unused")
open class Config @JvmOverloads constructor(protected val identifier: Identifier, val subfolder: String = "", val folder: String = identifier.namespace, val name: String = identifier.path): Walkable, Translatable {
open class Config @JvmOverloads constructor(protected val identifier: Identifier, val subfolder: String = "", val folder: String = identifier.namespace, val name: String = identifier.path): Walkable, Translatable, EntryAnchor {


/**
Expand Down Expand Up @@ -137,6 +142,24 @@ open class Config @JvmOverloads constructor(protected val identifier: Identifier
*/
open fun onUpdateServer(playerEntity: ServerPlayerEntity){}

/**
* Anchor modifier method for a config. By default, provides a folder icon decoration to the base anchor. You can provide a custom icon if you want a special icon for the config in the goto menu. If your config has a long name, you may also want to create and provide a shortened "summary" name for a goto link.
* @param anchor [EntryAnchor.Anchor] automatically generated input Anchor for modification.
* @return Anchor with any desired modifications. If you still want the folder deco, call super
* @see [TextureDeco] for other built in icons
* @see [me.fzzyhmstrs.fzzy_config.screen.decoration.SpriteDecoration] for a simple class to build your own icon
* @author fzzyhmstrs
* @since 0.6.0
*/
override fun anchorEntry(anchor: EntryAnchor.Anchor): EntryAnchor.Anchor {
return anchor.decoration(TextureDeco.DECO_FOLDER)
}

@Internal
final override fun anchorId(scope: String): String {
return translationKey()
}

/**
* @suppress
*/
Expand Down
Loading

0 comments on commit 5149948

Please sign in to comment.