Skip to content

Commit

Permalink
progress on 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CubBossa committed Dec 25, 2023
1 parent 4162d83 commit 4c194f1
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 64 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,37 +77,37 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.14.0</version>
<version>4.15.0</version>
</dependency>

<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.3.1</version>
<version>4.3.2</version>
</dependency>

<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.14.0</version>
<version>4.15.0</version>
</dependency>

<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-legacy</artifactId>
<version>4.14.0</version>
<version>4.15.0</version>
</dependency>

<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-gson</artifactId>
<version>4.14.0</version>
<version>4.15.0</version>
</dependency>

<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-plain</artifactId>
<version>4.14.0</version>
<version>4.15.0</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public boolean remove(Object key, Object value) {

this.defaultResolvers = TagResolver.resolver(
DefaultResolvers.darken("darker"),
DefaultResolvers.lighten("lighter"),
DefaultResolvers.lighten("brighter"),
DefaultResolvers.repeat("repeat"),
DefaultResolvers.reverse("reverse"),
DefaultResolvers.upper("upper"),
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/de/cubbossa/translations/GlobalMessages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.cubbossa.translations;

public class GlobalMessages {

public static final Message BRAND = new MessageBuilder("brand")
.withDefault("<gradient:#ff2200:#ffff00:#ff2200>My Server Name</gradient>")
.build();

public static final Message PREFIX = new MessageBuilder("prefix")
.withDefault("")
.withComment("Empty placeholder to make global messages work without application to set prefix message")
.build();

public static final Message NO_PERM = new MessageBuilder("missing_permissions")
.withDefault("<prefix_negative>You don't have enough permission to perform this action!</prefix_negative>")
.build();
public static final Message NO_PERM_SPECIFIED = new MessageBuilder("missing_permission")
.withDefault("<prefix_negative>You don't have the required permission!</prefix_negative> <text_d>(<text>{permission}</text>)</text_d>")
.withPlaceholder("permission", "The required node")
.build();
public static final Message NO_PERM_CMD = new MessageBuilder("command.missing_permissions")
.withDefault("<prefix_negative>You don't have enough permission to perform this command!</prefix_negative>")
.build();

public static final Message ARROW_RIGHT = new MessageBuilder("symbols.arrow_right")
.withDefault("🠖")
.build();
public static final Message ARROW_LEFT = new MessageBuilder("symbols.arrow_left")
.withDefault("🠔")
.build();

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.LinkedList;
import java.util.List;

public enum NamedGlobalStyles {
public enum GlobalStyles {

PRIMARY("primary"),
PRIMARY_LIGHT("primary_l", "primary_light"),
Expand All @@ -16,7 +16,6 @@ public enum NamedGlobalStyles {
ACCENT_DARK("accent_d", "accent_dark"),

NOTIFY("notify"),
INFO("info"),
NEGATIVE("negative"),
POSITIVE("positive"),
WARNING("warning"),
Expand All @@ -31,14 +30,15 @@ public enum NamedGlobalStyles {
BACKGROUND_DARK("bg_d", "background_dark"),

PREFIX("prefix"),
PREFIXED("prefixed"),
PREFIX_WARNING("prefix_warning"),
PREFIX_NEGATIVE("prefix_negative"),

SEPARATOR("separator"),
BUTTON("button"),
BUTTON_ACCEPT("button_accept"),
BUTTON_DECLINE("button_decline"),

LIST_ELEMENT("list_el", "list_element"),
PREVIOUS_PAGE("prev_page_symbol"),
NEXT_PAGE("next_page_symbol"),

URL("url"),

Expand All @@ -51,7 +51,7 @@ public enum NamedGlobalStyles {

private final List<String> keys = new LinkedList<>();

NamedGlobalStyles(String key, String... alias) {
GlobalStyles(String key, String... alias) {
keys.add(key);
keys.addAll(List.of(alias));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ protected GlobalTranslations(File dir) {
if (createStartFiles) {
writeResourceIfNotExists(globalLangDir, "README.txt");
writeResourceIfNotExists(globalLangDir, "global_styles.properties");
writeResourceIfNotExists(globalLangDir, "en.properties");
}

setMessageStorage(new PropertiesMessageStorage(globalLangDir));
setStyleStorage(new PropertiesStyleStorage(new File(globalLangDir, "global_styles.properties")));

addMessages(TranslationsFramework.messageFieldsFromClass(GlobalMessages.class));
saveLocale(Locale.ENGLISH);

writeMissingDefaultStyles();
}

Expand Down
Binary file added src/main/resources/Kirche1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 29 additions & 20 deletions src/main/resources/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#=================================#

The "lang" directory within your plugin directory appeared, because one of
the installed plugins uses the Translations library.
the installed plugins uses the Translations Framework dependency.

More information on the library can be found here: https://github.com/CubBossa/Translations
More information on the framework can be found here: https://github.com/CubBossa/Translations

The library comes with support for
- Plain Text Messages
Expand All @@ -16,26 +16,26 @@ The library comes with support for
- JSON (NBT) Messages
(Read on to learn more)

Every Message can be cross-referenced with <msg:[key]>, so
Every Message can be cross-referenced with {msg:key}, so

my_message.a = "hello"
my_message.b = "<msg:my_message.a> world!"
my_message.b = "{msg:my_message.a} world!"

is fully valid. We mostly use this to insert the plugins prefix.
is fully valid. We could use this to insert the plugins prefix.

You can also cross-reference messages from the global directory, which is why this directory exists.
A very common use case would be, that you place your server name in this directory, like so:

brand = "<gradient:#ffa200:#fffbc9:#ffa200>Hypixel</gradient>"
brand = "<gradient:#ffa200:#fffbc9:#ffa200>My Server Name</gradient>"

Then you can use <msg:brand> in all your plugin translations that support this library.
Then you can use {msg:brand} in all your plugin translations that support this library.
You only have to change a translation in one place to make an effect on all translations.

Plugin translations are always preferred to global translations, so if both your plugins en.properties and
the global en.properties contain a message with "no_perm", the plugin translation will be preferred.
If you want to explicitly call a global translation, use <msg:[path]:[key]>, like <msg:global:no_perm>
If you want to explicitly call a global translation, use {msg:[path]:[key]}, like {msg:global:no_perm}
This works not only for the global translations but for all registered translations instances.
If there are two plugins A and B, you can use a translation from B in A with <msg:global.B:no_perm>, even though
If there are two plugins A and B, you can use a translation from B in A with {msg:global.B:no_perm}, even though
it is not recommended to use translations that are not from direct or indirect parent translations.

global
Expand Down Expand Up @@ -64,14 +64,30 @@ Use:
- Hover texts with <hover:[action]:[data]>Text</hover>
Example: <hover:show_text:"<green>Oh hey<green>">Hover me</hover>

- <repeat:[times]></repeat> To repeat the given content for any amount of times.

- <darker></darker> or <brighter></brighter> To make the content darker or brighter.
Important: <red><darker>Hi</darker><red> does not provide a darker shade of red. Only explicit colors in the content
are being darkened

- <lower></lower> makes the content lower case

- <upper></upper> makes the content upper case

- <reverse></reverse>Will render the content backwards. Keep in mind that
<gradient:green:red><reverse>Helloworld</reverse></gradient> is NOT
<gradient:red:green>dlrowolleH</gradient>, but
<gradient:green:red>dlrowolleH</gradient>
Outer styles are not applied.

And many more (https://docs.advntr.dev/minimessage/format.html)


Other Formats
-------------

Other formats than MiniMessage are supported, but not advised.
To encode a message in a different format, use the following prefax:
To encode a message in a different format, use the following syntax:

example_message = <legacy>&cA legacy ampersand text</legacy>
example_message = <legacy:'&'>&cA legacy ampersand text</legacy>
Expand All @@ -88,20 +104,13 @@ Instead of explicitly using styles in your language file, you can use style plac
<primary> for your primary color or <bg> for background colors.

Use them for your messages like so:
buy.success: = "<text>Successfully bought plot!</text>"
buy.success = "<text>Successfully bought plot!</text>"
buy.no_perms = "<negative>No permission!</negative>"

And style them from within your style files:
text = "<light_gray>"
negative = "<red><bold>"
text = "<light_gray>{slot}</light_gray>"
negative = "<red><bold>{}</bold></red>"

Application styles override global styles, so if you put a style "negative" in global and one with
the exact same key in your applications styles.properties, the application style will be used.

The style format is a combination of opening tags that render has an effect on an ongoing text.
"<red><ul><click:...:...>" -> valid
"<red>hehe</red><click:...:...>" -> invalid
"<red></red>" -> invalid
"" -> valid but stupid


5 changes: 4 additions & 1 deletion src/main/resources/en.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
brand="<gradient:#ff2200:#ffff00:#ff2200>My Server Name</gradient>"
no_perm="<negative>You don't have enough permission!</negative>"
no_perm="<negative>You don't have enough permission!</negative>"

symbols.arrow_right="🠖"
symbols.arrow_left="🠔"
Loading

0 comments on commit 4c194f1

Please sign in to comment.