Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internationalize chat message #21

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ val supportedMinecraftVersions = listOf(

repositories {
mavenCentral()
maven("https://repo.thenextlvl.net/releases")
maven("https://papermc.io/repo/repository/maven-public/")
}

Expand All @@ -60,6 +61,8 @@ dependencies {
implementation(libs.paperlib)
// Stats
implementation(libs.bstats)
// Internationalization
implementation(libs.core.internationalization)
// Commands
implementation(libs.cloud.annotations)
implementation(libs.cloud.minecraft.extras)
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ intellectualsites = "1.27"
bstats = "3.0.2"
cloud-minecraft = "2.0.0-beta.8"
cloud-annotations = "2.0.0-rc.2"
core-i18n = "1.0.18"

[libraries]
paper = { group = "io.papermc.paper", name = "paper-api", version.ref = "minecraft" }
Expand All @@ -15,6 +16,7 @@ bstats = { group = "org.bstats", name = "bstats-bukkit", version.ref = "bstats"
cloud-annotations = { group = "org.incendo", name = "cloud-annotations", version.ref = "cloud-annotations" }
cloud-minecraft-extras = { group = "org.incendo", name = "cloud-minecraft-extras", version.ref = "cloud-minecraft" }
cloud-paper = { group = "org.incendo", name = "cloud-paper", version.ref = "cloud-minecraft" }
core-internationalization = { group = "net.thenextlvl.core", name = "i18n", version.ref = "core-i18n" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use pure Adventure, for i18n we will not rely on unpopular 3Party lib


[plugins]
spotless = { id = "com.diffplug.spotless", version = "6.18.0" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
package net.onelitefeather.bettergopaint;

import com.fastasyncworldedit.core.Fawe;
import core.i18n.file.ComponentBundle;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.onelitefeather.bettergopaint.brush.PlayerBrushManager;
import net.onelitefeather.bettergopaint.command.GoPaintCommand;
import net.onelitefeather.bettergopaint.command.ReloadCommand;
Expand All @@ -32,6 +35,7 @@
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -44,6 +48,7 @@
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.Locale;
import java.util.Objects;
import java.util.logging.Level;

Expand All @@ -56,7 +61,17 @@ public class BetterGoPaint extends JavaPlugin implements Listener {
public static final @NotNull String RELOAD_PERMISSION = "bettergopaint.command.admin.reload";
public static final @NotNull String WORLD_BYPASS_PERMISSION = "bettergopaint.world.bypass";

private final @NotNull PlayerBrushManager brushManager = new PlayerBrushManager();
private final @NotNull File translations = new File(getDataFolder(), "translations");
private final @NotNull ComponentBundle bundle = new ComponentBundle(translations, audience ->
audience instanceof Player player ? player.locale() : Locale.US)
.register("messages", Locale.US)
.register("messages_german", Locale.GERMANY)
.miniMessage(bundle -> MiniMessage.builder().tags(TagResolver.resolver(
TagResolver.standard(),
Placeholder.component("prefix", bundle.component(Locale.US, "prefix"))
)).build());

private final @NotNull PlayerBrushManager brushManager = new PlayerBrushManager(bundle);
private final @NotNull Metrics metrics = new Metrics(this, 18734);

@Override
Expand Down Expand Up @@ -151,4 +166,8 @@ private boolean hasOriginalGoPaint() {
return brushManager;
}

public ComponentBundle bundle() {
return bundle;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package net.onelitefeather.bettergopaint.brush;

import com.google.common.collect.ImmutableList;
import core.i18n.file.ComponentBundle;
import net.onelitefeather.bettergopaint.objects.brush.AngleBrush;
import net.onelitefeather.bettergopaint.objects.brush.Brush;
import net.onelitefeather.bettergopaint.objects.brush.BucketBrush;
Expand Down Expand Up @@ -47,19 +48,23 @@
public class PlayerBrushManager {

private final @NotNull HashMap<UUID, PlayerBrush> playerBrushes = new HashMap<>();
private final @NotNull List<Brush> brushes = ImmutableList.of(
new SphereBrush(),
new SprayBrush(),
new SplatterBrush(),
new DiscBrush(),
new BucketBrush(),
new AngleBrush(),
new OverlayBrush(),
new UnderlayBrush(),
new FractureBrush(),
new GradientBrush(),
new PaintBrush()
);
private final @NotNull List<Brush> brushes;

public PlayerBrushManager(ComponentBundle bundle) {
brushes = ImmutableList.of(
new SphereBrush(),
new SprayBrush(),
new SplatterBrush(),
new DiscBrush(),
new BucketBrush(),
new AngleBrush(),
new OverlayBrush(),
new UnderlayBrush(),
new FractureBrush(),
new GradientBrush(),
new PaintBrush(bundle)
);
}

/**
* Retrieves the brush for the given player.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package net.onelitefeather.bettergopaint.command;

import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.onelitefeather.bettergopaint.BetterGoPaint;
import net.onelitefeather.bettergopaint.objects.other.Settings;
import net.onelitefeather.bettergopaint.brush.PlayerBrush;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -49,64 +49,65 @@ public boolean execute(
return false;
}
PlayerBrush pb = plugin.getBrushManager().getBrush(p);
String prefix = Settings.settings().GENERIC.PREFIX;
if (!p.hasPermission(BetterGoPaint.USE_PERMISSION)) {
p.sendRichMessage(prefix + "<red>You are lacking the permission bettergopaint.use");
plugin.bundle().sendMessage(p, "command.gopaint.permission");
return true;
}
if (args.length == 0) {
if (p.hasPermission(BetterGoPaint.ADMIN_PERMISSION)) {
p.sendRichMessage(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info<gray>|<red>reload");
plugin.bundle().sendMessage(p, "command.gopaint.usage.admin");
return true;
}
p.sendRichMessage(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info<gray>");
plugin.bundle().sendMessage(p, "command.gopaint.usage");
return true;
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("size")) {
p.sendRichMessage(prefix + "<red>/gp size [number]");
plugin.bundle().sendMessage(p, "command.gopaint.usage.size");
return true;
} else if (args[0].equalsIgnoreCase("toggle")) {
if (pb.enabled()) {
pb.toggle();
p.sendRichMessage(prefix + "<red>Disabled brush");
plugin.bundle().sendMessage(p, "command.gopaint.brush.disabled");
} else {
pb.toggle();
p.sendRichMessage(prefix + "<green>Enabled brush");
plugin.bundle().sendMessage(p, "command.gopaint.brush.enabled");
}
return true;
} else if ((args[0].equalsIgnoreCase("reload") || args[0].equalsIgnoreCase("r")) && p.hasPermission(
BetterGoPaint.ADMIN_PERMISSION)) {
plugin.reloadConfig();
p.sendRichMessage(prefix + "<green>Reloaded");
plugin.bundle().sendMessage(p, "command.gopaint.reloaded");
return true;
} else if (args[0].equalsIgnoreCase("info") || args[0].equalsIgnoreCase("i")) {
p.sendRichMessage(prefix + "<aqua>Created by: <gold>TheMeinerLP");
p.sendRichMessage(prefix + "<aqua>Links: <gold><click:open_url:https://twitter.com/themeinerlp'><u>Twitter</u></click>");
plugin.bundle().sendMessage(p, "command.gopaint.info.creator");
plugin.bundle().sendMessage(p, "command.gopaint.info.link");
return true;
}
if (p.hasPermission(BetterGoPaint.ADMIN_PERMISSION)) {
p.sendRichMessage(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info<gray>|<red>reload");
plugin.bundle().sendMessage(p, "command.gopaint.usage.admin");
return true;
}
p.sendRichMessage(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info");
plugin.bundle().sendMessage(p, "command.gopaint.usage");
return true;
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("size") || args[0].equalsIgnoreCase("s")) {
try {
int sizeAmount = Integer.parseInt(args[1]);
pb.setSize(sizeAmount);
p.sendRichMessage(prefix + "<gold>Size set to: <yellow>" + pb.size());
plugin.bundle().sendMessage(p, "command.gopaint.brush.size",
Placeholder.parsed("size", String.valueOf(pb.size()))
);
return true;
} catch (Exception e) {
p.sendRichMessage(prefix + "<red>/gb size [number]");
plugin.bundle().sendMessage(p, "command.gopaint.usage.size");
return true;
}
}
if (p.hasPermission(BetterGoPaint.ADMIN_PERMISSION)) {
p.sendRichMessage(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info<gray>|<red>reload");
plugin.bundle().sendMessage(p, "command.gopaint.usage.admin");
return true;
}
p.sendRichMessage(prefix + "<red>/gp size<gray>|<red>toggle<gray>|<red>info<gray>");
plugin.bundle().sendMessage(p, "command.gopaint.usage");
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ public void onClick(PlayerInteractEvent event) {
() -> brushSettings.brush().paint(location, player, brushSettings), false, true
);
} else {
player.sendRichMessage(
Settings.settings().GENERIC.PREFIX + "<red>Your brush is disabled, left click to enable the brush."
);
plugin.bundle().sendMessage(player, "brush.disabled");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
*/
package net.onelitefeather.bettergopaint.objects.brush;

import core.i18n.file.ComponentBundle;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.onelitefeather.bettergopaint.brush.BrushSettings;
import net.onelitefeather.bettergopaint.objects.other.Settings;
import net.onelitefeather.bettergopaint.utils.Height;
import net.onelitefeather.bettergopaint.utils.Sphere;
import net.onelitefeather.bettergopaint.utils.curve.BezierSpline;
Expand All @@ -41,8 +42,11 @@ public class PaintBrush extends Brush {
private static final @NotNull String HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODBiM2E5ZGZhYmVmYmRkOTQ5YjIxN2JiZDRmYTlhNDg2YmQwYzNmMGNhYjBkMGI5ZGZhMjRjMzMyZGQzZTM0MiJ9fX0=";
private static final @NotNull String NAME = "Paint Brush";

public PaintBrush() {
private final @NotNull ComponentBundle bundle;

public PaintBrush(@NotNull ComponentBundle bundle) {
super(NAME, DESCRIPTION, HEAD);
this.bundle = bundle;
}

private static final HashMap<UUID, List<Location>> selectedPoints = new HashMap<>();
Expand All @@ -53,13 +57,16 @@ public void paint(
@NotNull Player player,
@NotNull BrushSettings brushSettings
) {
String prefix = Settings.settings().GENERIC.PREFIX;

List<Location> locations = selectedPoints.computeIfAbsent(player.getUniqueId(), ignored -> new ArrayList<>());
locations.add(target);

if (!player.isSneaking()) {
player.sendRichMessage(prefix + " Paint brush point #" + locations.size() + " set.");
bundle.sendMessage(player, "brush.paint.point.set",
Placeholder.parsed("x", String.valueOf(target.getBlockX())),
Placeholder.parsed("y", String.valueOf(target.getBlockY())),
Placeholder.parsed("z", String.valueOf(target.getBlockZ())),
Placeholder.parsed("point", String.valueOf(locations.size()))
);
return;
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
prefix=<aqua>BetterGoPaint ><reset>
command.gopaint.permission=<prefix> <red>You are lacking the permission bettergopaint.use
command.gopaint.usage=<prefix> <red>/gp size<gray>|<red>toggle<gray>|<red>info
command.gopaint.usage.admin=<prefix> <red>/gp size<gray>|<red>toggle<gray>|<red>info<gray>|<red>reload
command.gopaint.usage.size=<prefix> <red>/gp size [number]
command.gopaint.brush.disabled=<prefix> <red>Disabled brush
command.gopaint.brush.enabled=<prefix> <green>Enabled brush
command.gopaint.brush.size=<prefix> <gold>Brush size set to: <yellow><size>
command.gopaint.reloaded=<prefix> <green>Reloaded
command.gopaint.info.creator=<prefix> <aqua>Created by: <gold>TheMeinerLP
command.gopaint.info.link=<prefix> <aqua>Links: <gold><click:open_url:https://twitter.com/themeinerlp'><u>Twitter</u></click>
brush.disabled=<prefix> <red>Your brush is disabled, left click to enable the brush.
brush.paint.point.set=<prefix> <white>Paint brush point #<point> set.
9 changes: 9 additions & 0 deletions src/main/resources/messages_german.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
command.gopaint.permission=<prefix> <red>Dir fehlt die Berechtigung bettergopaint.use
command.gopaint.brush.disabled=<prefix> <red>Der Pinsel wurde deaktiviert
command.gopaint.brush.enabled=<prefix> <green>Der Pinsel wurde aktiviert
command.gopaint.brush.size=<prefix> <gold>Die Pinselgröße wurde geändert: <yellow><size>
command.gopaint.reloaded=<prefix> <green>Die Konfiguration wurde neu geladen
command.gopaint.info.creator=<prefix> <aqua>Erstellt von: <gold>TheMeinerLP
command.gopaint.info.link=<prefix> <aqua>Links: <gold><click:open_url:https://twitter.com/themeinerlp'><u>Twitter</u></click>
brush.disabled=<prefix> <red>Dein Pinsel ist deaktiviert, linksklick um den Pinsel zu aktivieren.
brush.paint.point.set=<prefix> <white>Der Pinselstrich #<point> wurde gesetzt.
Loading