-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'quiltmc/master' into quiltmc-master
- Loading branch information
Showing
9 changed files
with
447 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/org/quiltmc/config/api/annotations/ChangeWarning.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2024 QuiltMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.quiltmc.config.api.annotations; | ||
|
||
import org.quiltmc.config.api.Config; | ||
import org.quiltmc.config.api.metadata.MetadataType; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Used to tell config screen libraries that a warning should be displayed before applying changes. Can be applied to configs, sections and fields. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.FIELD, ElementType.TYPE}) | ||
public @interface ChangeWarning { | ||
/** | ||
* A {@link MetadataType} to supply to {@link Config.Builder#metadata} | ||
*/ | ||
MetadataType<org.quiltmc.config.api.metadata.ChangeWarning, ChangeWarning.Builder> TYPE = MetadataType.create(Optional::empty, ChangeWarning.Builder::new, true); | ||
|
||
/** | ||
* The {@link org.quiltmc.config.api.metadata.ChangeWarning.Type ChangeWarning.Type} of the change warning | ||
*/ | ||
org.quiltmc.config.api.metadata.ChangeWarning.Type value(); | ||
|
||
/** | ||
* The message to display if the type is {@link org.quiltmc.config.api.metadata.ChangeWarning.Type#Custom ChangeWarning.Type.Custom}. In that case, Metadata processors (like config screens) may define translation keys that take precedence, else the translation key if it is {@link org.quiltmc.config.api.metadata.ChangeWarning.Type#CustomTranslatable ChangeWarning.Type.CustomTranslatable}. | ||
*/ | ||
String customMessage() default ""; | ||
|
||
final class Builder implements MetadataType.Builder<org.quiltmc.config.api.metadata.ChangeWarning> { | ||
private String message; | ||
private org.quiltmc.config.api.metadata.ChangeWarning.Type type; | ||
|
||
public Builder() { | ||
} | ||
|
||
/** | ||
* Utility for updating the type and the message | ||
*/ | ||
public void setMessage(String message) { | ||
this.setType(org.quiltmc.config.api.metadata.ChangeWarning.Type.Custom); | ||
this.message = message; | ||
} | ||
|
||
public void setType(org.quiltmc.config.api.metadata.ChangeWarning.Type type) { | ||
this.type = type; | ||
} | ||
|
||
/** | ||
* Utility for updating the type and the message | ||
*/ | ||
public void setTranslatableMessage(String translationKey) { | ||
this.setType(org.quiltmc.config.api.metadata.ChangeWarning.Type.CustomTranslatable); | ||
this.setMessage(translationKey); | ||
} | ||
|
||
@Override | ||
public org.quiltmc.config.api.metadata.ChangeWarning build() { | ||
return new org.quiltmc.config.api.metadata.ChangeWarning(this.message, this.type); | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/org/quiltmc/config/api/annotations/DisplayName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2024 QuiltMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.quiltmc.config.api.annotations; | ||
|
||
import org.quiltmc.config.api.Config; | ||
import org.quiltmc.config.api.metadata.MetadataType; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Used to tell config screen libraries what name should be used for the annotated element when displaying it. Can be applied to configs, sections and fields. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.FIELD, ElementType.TYPE}) | ||
public @interface DisplayName { | ||
/** | ||
* A {@link MetadataType} to supply to {@link Config.Builder#metadata} | ||
*/ | ||
MetadataType<org.quiltmc.config.api.metadata.DisplayName, DisplayName.Builder> TYPE = MetadataType.create( | ||
Optional::empty, | ||
DisplayName.Builder::new | ||
); | ||
|
||
/** | ||
* The name for the config screen to use if {@link #translatable} is false. A translation key pointing to the name to be used otherwise. Metadata processors (like config screens) may define generated translation keys taking precedence if it isn't translatable. | ||
*/ | ||
String value(); | ||
|
||
/** | ||
* If true, {@link #value()} contains a translation key | ||
*/ | ||
boolean translatable() default false; | ||
|
||
final class Builder implements MetadataType.Builder<org.quiltmc.config.api.metadata.DisplayName> { | ||
private String name; | ||
private boolean translatable; | ||
|
||
public Builder() { | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public void setTranslatable(boolean translatable) { | ||
this.translatable = translatable; | ||
} | ||
|
||
@Override | ||
public org.quiltmc.config.api.metadata.DisplayName build() { | ||
return new org.quiltmc.config.api.metadata.DisplayName(this.name, this.translatable); | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/org/quiltmc/config/api/annotations/DisplayNameConvention.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2024 QuiltMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.quiltmc.config.api.annotations; | ||
|
||
import org.quiltmc.config.api.Config; | ||
import org.quiltmc.config.api.metadata.MetadataType; | ||
import org.quiltmc.config.api.metadata.NamingScheme; | ||
import org.quiltmc.config.api.metadata.NamingSchemes; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Used to tell config screen libraries how properties should be formatted when displaying them. Metadata processors (like config screens) may define generated translation keys taking precedence. Can be applied to configs, sections and properties. {@link DisplayName} must always take priority. | ||
* @see org.quiltmc.config.api.annotations.DisplayName | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.FIELD, ElementType.TYPE}) | ||
public @interface DisplayNameConvention { | ||
/** | ||
* A {@link MetadataType} to supply to {@link Config.Builder#metadata} | ||
*/ | ||
MetadataType<NamingScheme, DisplayNameConvention.Builder> TYPE = MetadataType.create(Optional::empty, DisplayNameConvention.Builder::new, true); | ||
|
||
/** | ||
* One of the included {@link NamingSchemes}. {@link DisplayNameConvention#custom()} takes priority when not empty | ||
* @see NamingSchemes | ||
*/ | ||
NamingSchemes value() default NamingSchemes.PASSTHROUGH; | ||
|
||
/** | ||
* A fully qualified name of a class implementing the {@link NamingScheme}. Ignored when empty, takes precedence over {@link DisplayNameConvention#value()} otherwise. | ||
*/ | ||
String custom() default ""; | ||
|
||
final class Builder implements MetadataType.Builder<NamingScheme> { | ||
private NamingScheme scheme; | ||
|
||
public Builder() { | ||
this.scheme = NamingSchemes.PASSTHROUGH; | ||
} | ||
|
||
public void set(NamingScheme scheme) { | ||
this.scheme = scheme; | ||
} | ||
|
||
@Override | ||
public NamingScheme build() { | ||
return this.scheme; | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/org/quiltmc/config/api/metadata/ChangeWarning.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2024 QuiltMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.quiltmc.config.api.metadata; | ||
|
||
import java.util.Objects; | ||
|
||
public class ChangeWarning { | ||
private final String customMessage; | ||
private final Type type; | ||
|
||
public ChangeWarning(String customMessage, Type type) { | ||
this.customMessage = customMessage; | ||
this.type = type; | ||
} | ||
|
||
public String getCustomMessage() { | ||
return this.customMessage; | ||
} | ||
|
||
public Type getType() { | ||
return this.type; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
|
||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
ChangeWarning that = (ChangeWarning) o; | ||
return Objects.equals(this.customMessage, that.customMessage) && this.type == that.type; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.customMessage, this.type); | ||
} | ||
|
||
public enum Type { | ||
/** | ||
* indicates that the changed setting requires a restart to apply | ||
*/ | ||
RequiresRestart, | ||
/** | ||
* indicates that stuff may or will go wrong, and that that is intentional | ||
*/ | ||
Unsafe, | ||
/** | ||
* indicates that stuff may or will go wrong, because the setting is not mature enough | ||
*/ | ||
Experimental, | ||
/** | ||
* the message parameter contains the raw message to be displayed | ||
*/ | ||
CustomTranslatable, | ||
/** | ||
* the message parameter contains the translation key to be displayed | ||
*/ | ||
Custom | ||
} | ||
} |
Oops, something went wrong.