Skip to content

Commit 715ac02

Browse files
committed
Added translations and error messages
Publishing to hangar is now done by Jenkins
1 parent c08d550 commit 715ac02

File tree

13 files changed

+178
-68
lines changed

13 files changed

+178
-68
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,4 @@ jobs:
3535
SONATYPE_USERNAME: ${{ secrets.OSSRH_USERNAME }}
3636
SONATYPE_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
3737
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }}
38-
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}
39-
- name: Publish to Hangar
40-
run: ./gradlew build publishAllPublicationsToHangar --stacktrace
41-
env:
42-
HANGAR_API_TOKEN: ${{ secrets.HANGAR_API_TOKEN }}
38+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}

necrify-api/src/main/java/de/jvstvshd/necrify/api/message/MessageProvider.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package de.jvstvshd.necrify.api.message;
2626

2727
import net.kyori.adventure.text.Component;
28+
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
2829
import org.jetbrains.annotations.NotNull;
2930
import org.jetbrains.annotations.Nullable;
3031

@@ -88,14 +89,34 @@ public interface MessageProvider {
8889
@NotNull
8990
Component prefix();
9091

92+
/**
93+
* Provides a message to the user with the given key in the default locale. This yields the same result content-wise
94+
* as calling {@link #provide(String, Locale, Component...)}, but as String instead of a Component.
95+
*
96+
* @param key an unique key identifying the message to provide.
97+
* @param locale the locale in whose language the message should be provided. If locale is null, the system's {@link #defaultLocale() default Locale}
98+
* @param args additional components that fill in placeholders in the message.
99+
* @return the translated and formatted message as a string.
100+
*/
101+
@NotNull
102+
default String provideString(@NotNull String key, @Nullable Locale locale, Component... args) {
103+
return PlainTextComponentSerializer.plainText().serialize(provide(key, locale, args));
104+
}
105+
91106
/**
92107
* Prefixes the provided components into one component.
108+
*
93109
* @param args the components to prefix.
94110
* @return one prefixed component.
95111
*/
96112
@NotNull
97113
default Component prefixed(Component... args) {
98-
var comp = prefix();
114+
Component comp;
115+
if (autoPrefixed()) {
116+
comp = prefix();
117+
} else {
118+
comp = Component.empty();
119+
}
99120
for (Component arg : args) {
100121
comp = comp.append(arg);
101122
}
@@ -127,4 +148,13 @@ default Locale defaultLocale() {
127148
default void autoPrefixed(boolean autoPrefixed) {
128149
throw new UnsupportedOperationException("This message provider does not support changing the auto-prefixing behavior.");
129150
}
151+
152+
/**
153+
* Returns a new message provider that does not prefix messages.
154+
*
155+
* @return a new message provider that does not prefix messages.
156+
*/
157+
default MessageProvider unprefixedProvider() {
158+
throw new UnsupportedOperationException("This message provider does not support changing the auto-prefixing behavior.");
159+
}
130160
}

necrify-api/src/main/java/de/jvstvshd/necrify/api/user/NecrifyUser.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ default Optional<Punishment> getPunishment(@NotNull UUID punishmentUuid) {
189189
return getPunishments().stream().filter(punishment -> punishment.getPunishmentUuid().equals(punishmentUuid)).findFirst();
190190
}
191191

192+
/**
193+
* Gets this player's current locale. This locale is used to provide messages in the user's language. If the locale
194+
* is not set, the default locale is used. Note: The locale may be provided from the language the user has set in
195+
* their Minecraft client. This information is only sent after the client connected to the server, so calls to this
196+
* during the connection process usually return the default locale.
197+
* @return the locale of the user.
198+
*/
199+
@NotNull
192200
Locale getLocale();
193201

194202
/* *//**

necrify-common/src/main/java/de/jvstvshd/necrify/common/AbstractNecrifyPlugin.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ public final void registerCommands(CommandManager<NecrifyUser> manager, boolean
100100
});
101101
}
102102

103+
manager.exceptionController()
104+
.registerHandler(ArgumentParseException.class, context -> {
105+
var component = getMessageProvider().prefixed(Component.text(context.exception().getCause().getMessage()).color(NamedTextColor.DARK_RED));
106+
context.context().sender().sendMessage(component);
107+
});
103108
manager.exceptionController()
104109
.registerHandler(ArgumentParseException.class, ExceptionHandler.unwrappingHandler(UserNotFoundParseException.class))
105110
.registerHandler(UserNotFoundParseException.class, context -> {
@@ -115,19 +120,20 @@ public final void registerCommands(CommandManager<NecrifyUser> manager, boolean
115120
var component = getMessageProvider().provide(context.exception().getMessage(), replacements).color(NamedTextColor.RED);
116121
context.context().sender().sendMessage(component);
117122
});
118-
/*manager.exceptionController()//.registerHandler(ArgumentParseException.class, ExceptionHandler.unwrappingHandler(ArgumentParseException.class))
119-
.registerHandler(ArgumentParseException.class, context -> {
120-
context.context().sender().sendMessage("commands.general.invalid-argument");
121-
System.out.println(context.exception().getCause());
122-
});*/
123+
manager.exceptionController()
124+
.registerHandler(ArgumentParseException.class, ExceptionHandler.unwrappingHandler(PunishmentDuration.Parser.ParseException.class))
125+
.registerHandler(PunishmentDuration.Parser.ParseException.class, context -> {
126+
var component = getMessageProvider().provide("command.punishment.duration.invalid", Component.text(context.exception().getMessage(), NamedTextColor.YELLOW)).color(NamedTextColor.RED);
127+
context.context().sender().sendMessage(component);
128+
});
123129
manager.captionRegistry().registerProvider((caption, user) -> {
124130
var component = getMessageProvider().provide(caption.key(), user.getLocale());
125131
return PlainTextComponentSerializer.plainText().serialize(component);
126132
});
127133
var parserRegistry = manager.parserRegistry();
128134
parserRegistry.registerParser(ParserDescriptor.of(new NecrifyUserParser(this.getUserManager()), NecrifyUser.class));
129135
parserRegistry.registerParser(ComponentParser.componentParser(MiniMessage.miniMessage(), StringParser.StringMode.GREEDY));
130-
parserRegistry.registerParser(ParserDescriptor.of(new PunishmentDurationParser(), PunishmentDuration.class));
136+
parserRegistry.registerParser(ParserDescriptor.of(new PunishmentDurationParser(getMessageProvider()), PunishmentDuration.class));
131137
parserRegistry.registerParser(ParserDescriptor.of(new PunishmentParser(this), Punishment.class));
132138
var commands = new NecrifyCommand(this);
133139
parser.parse(commands);

necrify-common/src/main/java/de/jvstvshd/necrify/common/commands/NecrifyCommand.java

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public void unbanCommand(
206206
) {
207207
var punishments = target.getPunishments(StandardPunishmentType.TEMPORARY_BAN, StandardPunishmentType.PERMANENT_BAN);
208208
try {
209-
removePunishments(sender, "unban", punishments);
209+
removePunishments(sender, punishments, "unban", "ban", "banned");
210210
} catch (Exception e) {
211211
logException(e);
212212
}
@@ -220,10 +220,11 @@ public void unmuteCommand(
220220
@Argument(value = "target", description = "Player to unmute", suggestions = "suggestOnlinePlayers") NecrifyUser target
221221
) {
222222
var punishments = target.getPunishments(StandardPunishmentType.TEMPORARY_MUTE, StandardPunishmentType.PERMANENT_MUTE);
223-
System.out.println(punishments);
224-
removePunishments(sender, "unmute", punishments);
223+
removePunishments(sender, punishments, "unmute", "mute", "muted");
225224
}
226225

226+
//Informational/other
227+
227228
@Command("necrify punishment <punishmentId> [option]")
228229
@Permission(value = {"necrify.command.punishment", "necrify.admin"}, mode = Permission.Mode.ANY_OF)
229230
public void punishmentCommand(
@@ -240,7 +241,7 @@ public void punishmentCommand(
240241
logException(sender, th);
241242
return;
242243
}
243-
sender.sendMessage("command.punishment.cancel.success");
244+
sender.sendMessage(provider.provide("command.punishment.cancel.success").color(NamedTextColor.GREEN));
244245
}, plugin.getService());
245246
}
246247
case "change" -> {
@@ -286,16 +287,19 @@ public List<? extends Suggestion> suggestNames(CommandContext<NecrifyUser> conte
286287
.getOnlinePlayers()
287288
.stream()
288289
.filter(pair -> pair.first().toLowerCase(Locale.ROOT).startsWith(input.peekString().toLowerCase(Locale.ROOT)))
289-
.map(pair -> ComponentTooltipSuggestion.suggestion(pair.first(),
290-
miniMessage("<red>The player <yellow>(<name>/<uuid>)</yellow> you want to select.</red><yellow>",
291-
Placeholder.parsed("name", pair.first()),
292-
Placeholder.parsed("uuid", pair.second().toString()))
293-
)).toList();
290+
.map(pair -> {
291+
var select = provider.unprefixedProvider().provide("suggestion.select-player", context.sender().getLocale(), miniMessage(
292+
"<yellow>(<name>/<uuid>)</yellow>",
293+
Placeholder.parsed("name", pair.first()),
294+
Placeholder.parsed("uuid", pair.second().toString()))).color(NamedTextColor.RED);
295+
return ComponentTooltipSuggestion.suggestion(pair.first(), select);
296+
}).toList();
294297
}
295298

296299
@Suggestions("suggestMiniMessage")
297300
public List<? extends Suggestion> suggestMiniMessage(CommandContext<NecrifyUser> context, CommandInput input) {
298-
return Collections.singletonList(ComponentTooltipSuggestion.suggestion(input.remainingInput() + " (hover for preview)",
301+
return Collections.singletonList(ComponentTooltipSuggestion.suggestion(input.remainingInput()
302+
+ " (" + provider.unprefixedProvider() .provideString("suggestion.hover-over-me", context.sender().getLocale()) + ")",
299303
miniMessage(input.remainingInput())));
300304
}
301305

@@ -319,14 +323,22 @@ public List<? extends Suggestion> suggestUserCommandOptions(CommandContext<Necri
319323

320324
//HELPER METHODS
321325

322-
private void removePunishments(NecrifyUser source, String commandName, List<Punishment> punishments) {
323-
var type = commandName.substring(2);
326+
/**
327+
* This will execute the punishment removal process for the given punishments. If more than one punishment is found,
328+
* the user will be informed about it and can then decide which punishment to remove.
329+
*
330+
* @param source the user who executed the command.
331+
* @param punishments the list of punishments the target has.
332+
* @param values some strings for the message provider. Format: [0] = command name, [1] = punishment type, [2] = past
333+
* of the verb form to indicate the process of punishing the target; for example: "unban", "ban", "banned"
334+
*/
335+
private void removePunishments(NecrifyUser source, List<Punishment> punishments, String... values) {
324336
if (punishments.isEmpty()) {
325-
source.sendMessage(plugin.getMessageProvider().provide("command.punishment.not-" + type).color(NamedTextColor.RED));
337+
source.sendMessage(plugin.getMessageProvider().provide("command.punishment.not-" + values[2]).color(NamedTextColor.RED));
326338
return;
327339
}
328340
if (punishments.size() > 1) {
329-
source.sendMessage(plugin.getMessageProvider().provide("command." + commandName + ".multiple-" + type + "s").color(NamedTextColor.YELLOW));
341+
source.sendMessage(plugin.getMessageProvider().provide("command." + values[0] + ".multiple-" + values[1] + "s").color(NamedTextColor.YELLOW));
330342
for (Punishment punishment : punishments) {
331343
source.sendMessage(buildComponent(PunishmentHelper.buildPunishmentData(punishment, plugin.getMessageProvider()), punishment));
332344
}
@@ -340,7 +352,7 @@ private void removePunishments(NecrifyUser source, String commandName, List<Puni
340352
source.sendMessage(plugin.getMessageProvider().internalError());
341353
return;
342354
}
343-
source.sendMessage(plugin.getMessageProvider().provide("command." + commandName + ".success").color(NamedTextColor.GREEN));
355+
source.sendMessage(plugin.getMessageProvider().provide("command." + values[0] + ".success").color(NamedTextColor.GREEN));
344356
}, plugin.getService());
345357
} catch (Exception e) {
346358
logException(source, e);

necrify-common/src/main/java/de/jvstvshd/necrify/common/commands/PunishmentDurationParser.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.mojang.brigadier.LiteralMessage;
2828
import de.jvstvshd.necrify.api.duration.PunishmentDuration;
29+
import de.jvstvshd.necrify.api.message.MessageProvider;
2930
import de.jvstvshd.necrify.api.user.NecrifyUser;
3031
import net.kyori.adventure.text.minimessage.MiniMessage;
3132
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -43,6 +44,12 @@
4344

4445
public class PunishmentDurationParser implements ArgumentParser<NecrifyUser, PunishmentDuration> {
4546

47+
private final MessageProvider provider;
48+
49+
public PunishmentDurationParser(MessageProvider provider) {
50+
this.provider = provider;
51+
}
52+
4653
@Override
4754
public @NonNull ArgumentParseResult<@NonNull PunishmentDuration> parse(@NonNull CommandContext<@NonNull NecrifyUser> commandContext, @NonNull CommandInput commandInput) {
4855
var input = commandInput.peekString();
@@ -58,15 +65,21 @@ public class PunishmentDurationParser implements ArgumentParser<NecrifyUser, Pun
5865
}
5966
@Override
6067
public @NonNull SuggestionProvider<NecrifyUser> suggestionProvider() {
68+
var unprefixedProvider = this.provider.unprefixedProvider();
6169
return (context, input) -> {
6270
var string = input.peekString();
6371
ComponentTooltipSuggestion suggestion;
72+
var hoverOverMe = " (" + unprefixedProvider.provideString("suggestion.hover-over-me", context.sender().getLocale()).trim() + ")";// (hover over me)
6473
try {
6574
var duration = PunishmentDuration.parse(string);
6675
var expiration = duration.expirationAsString();
67-
suggestion = ComponentTooltipSuggestion.suggestion(string + " | correct (hover over me)", MiniMessage.miniMessage().deserialize("<green>until " + expiration));
76+
var correct = unprefixedProvider.provideString("suggestion.correct", context.sender().getLocale());
77+
var until = unprefixedProvider.provideString("suggestion.until", context.sender().getLocale()) + " ";
78+
suggestion = ComponentTooltipSuggestion.suggestion(string + " | " + correct + hoverOverMe, MiniMessage.miniMessage().deserialize("<green>" + until + expiration));
6879
} catch (PunishmentDuration.Parser.ParseException e) {
69-
suggestion = ComponentTooltipSuggestion.suggestion(string + " | incorrect (hover over me)", MiniMessage.miniMessage().deserialize("<red>Invalid duration format: " + e.getMessage()));
80+
var incorrect = unprefixedProvider.provideString("suggestion.incorrect", context.sender().getLocale());
81+
var invalidDuration = unprefixedProvider.provideString("suggestion.invalid-duration", context.sender().getLocale()) + " ";
82+
suggestion = ComponentTooltipSuggestion.suggestion(string + " | " + incorrect + hoverOverMe, MiniMessage.miniMessage().deserialize("<red>" + invalidDuration + e.getMessage()));
7083
}
7184
return CompletableFuture.completedFuture(List.of(suggestion));
7285
};

necrify-common/src/main/java/de/jvstvshd/necrify/common/user/AbstractConsoleUser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public boolean hasPermission(@NotNull String permission) {
128128
}
129129

130130
@Override
131-
public Locale getLocale() {
131+
public @NotNull Locale getLocale() {
132132
return locale;
133133
}
134134

necrify-common/src/main/resources/translations/de.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ command.punishment.not-banned=Dieser Spieler ist derzeit nicht gebannt.
1515
command.punishment.not-muted=Dieser Spieler ist derzeit nicht gemutet.
1616
command.punishment.cancel.success=Die Strafe wurde erfolgreich abgebrochen.
1717
command.punishment.click-to-remove=Zum Entfernen klicken
18+
command.punishment.duration.invalid=Die angegeben Dauer ist ungültig bzw. konnte nicht verarbeitet werden: {0}
1819
command.punishment.punishments=Dieser Spieler hat derzeit {0} laufende Bestrafungen.
1920
command.punishment.uuid-parse-error={0} ist keine valide UUID.
2021
command.punishment.unknown-option=Unbekannte Option: {0}
@@ -41,6 +42,12 @@ helper.type=Typ:
4142
helper.reason=Grund:
4243
helper.temporal.duration=Dauer:
4344
helper.temporal.end=Ende:
45+
suggestion.correct=Korrekte
46+
suggestion.incorrect=Fehlerhaft
47+
suggestion.invalid-duration=Ungültige Dauer:
48+
suggestion.hover-over-me=mit der Maus über mich fahren
49+
suggestion.select-player=Der Spieler {0}, der als Ziel ausgewählt werden soll.
50+
suggestion.until=bis
4451
punishment.remove=Die Strafe wurde entfernt.
4552
punishment.ban.permanent.full-reason=Du wurdest permanent vom Server verbannt.\n\nGrund:\n{0}
4653
punishment.ban.temp.full-reason=Du wurdest für {0} gebannt.\n\nGrund:\n{1}\n\nEnde des Banns: {2}

necrify-common/src/main/resources/translations/en.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ command.punishment.not-banned=This player is not banned at the moment.
1414
command.punishment.not-muted=This player is not muted at the moment.
1515
command.punishment.cancel.success=The punishment has been successfully cancelled.
1616
command.punishment.click-to-remove=Click to remove
17+
command.punishment.duration.invalid=The specified duration is invalid or could not be processed: {0}
1718
command.punishment.punishments=This player has {0} punishments.
1819
command.punishment.uuid-parse-error=Could not parse string {0} as uuid.
1920
command.punishment.unknown-option=Unknown option: {0}
@@ -40,6 +41,12 @@ helper.type=Type:
4041
helper.reason=reason:
4142
helper.temporal.duration=duration:
4243
helper.temporal.end=end of punishment:
44+
suggestion.correct=correct
45+
suggestion.incorrect=incorrect
46+
suggestion.invalid-duration=Invalid duration:
47+
suggestion.hover-over-me=hover over me
48+
suggestion.select-player=Select the player {0} as target.
49+
suggestion.until=until
4350
punishment.remove=The punishment has been successfully removed.
4451
punishment.ban.permanent.full-reason=You have been permanently banned from this server.\n\nReason:\n{0}
4552
punishment.ban.temp.full-reason=You are banned for {0}.\n\nReason:\n{1}\n\nEnd of punishment: {2}

necrify-paper/build.gradle.kts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,22 @@ fun latestCommitMessage(): String {
6464
val versionString: String = version as String
6565
val isRelease: Boolean = !versionString.contains('-')
6666

67-
val suffixedVersion: String = if (isRelease) {
68-
"$versionString-paper"
67+
val suffixedVersion: String = "$versionString-Paper" + if (project.hasProperty("buildnumber")) {
68+
"-" + project.property("buildnumber") as String
6969
} else {
70-
// Give the version a unique name by using the GitHub Actions run number
71-
versionString + "-paper-" + System.getenv("GITHUB_RUN_NUMBER")
70+
val githubRunNumber = System.getenv("GITHUB_RUN_NUMBER")
71+
versionString + if (githubRunNumber != null) "-$githubRunNumber" else ""
7272
}
7373

7474
val changelogContent: String = latestCommitMessage()
7575

7676
hangarPublish {
7777
publications.register("necrify-paper") {
78-
val pluginVersion = project.version as String
78+
project.version as String
7979
version.set(suffixedVersion)
80-
channel.set(if (!isRelease) "Snapshot" else "Release")
80+
if (!isRelease) {
81+
changelog.set(changelogContent)
82+
}
8183
id.set("necrify")
8284
apiKey.set(System.getenv("HANGAR_API_TOKEN"))
8385
changelog.set(changelogContent)

necrify-velocity/build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,14 @@ val suffixedVersion: String = if (isRelease) {
101101
val changelogContent: String = latestCommitMessage()
102102

103103
hangarPublish {
104-
publications.register("necrify-paper") {
104+
publications.register("necrify-velocity") {
105105
version.set(suffixedVersion)
106106
channel.set(if (!isRelease) "Snapshot" else "Release")
107107
id.set("necrify")
108108
apiKey.set(System.getenv("HANGAR_API_TOKEN"))
109-
changelog.set(changelogContent)
109+
if (!isRelease) {
110+
changelog.set(changelogContent)
111+
}
110112
platforms {
111113
register(Platforms.VELOCITY) {
112114
jar.set(tasks.jar.flatMap { it.archiveFile })

0 commit comments

Comments
 (0)