From 73dc4aeb320ee0408100caa00ac5fa2347d7705e Mon Sep 17 00:00:00 2001 From: david Date: Sat, 15 Jun 2024 18:32:09 +0200 Subject: [PATCH] internationalized hardcoded messages --- .../brush/PlayerBrushManager.java | 31 +++++++++------- .../bettergopaint/command/GoPaintCommand.java | 35 ++++++++++--------- .../listeners/InteractListener.java | 4 +-- .../objects/brush/PaintBrush.java | 17 ++++++--- 4 files changed, 49 insertions(+), 38 deletions(-) diff --git a/src/main/java/net/onelitefeather/bettergopaint/brush/PlayerBrushManager.java b/src/main/java/net/onelitefeather/bettergopaint/brush/PlayerBrushManager.java index f08d4e85..a7bd8e9d 100644 --- a/src/main/java/net/onelitefeather/bettergopaint/brush/PlayerBrushManager.java +++ b/src/main/java/net/onelitefeather/bettergopaint/brush/PlayerBrushManager.java @@ -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; @@ -47,19 +48,23 @@ public class PlayerBrushManager { private final @NotNull HashMap playerBrushes = new HashMap<>(); - private final @NotNull List 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 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. diff --git a/src/main/java/net/onelitefeather/bettergopaint/command/GoPaintCommand.java b/src/main/java/net/onelitefeather/bettergopaint/command/GoPaintCommand.java index eb4b1d18..9c5c4102 100644 --- a/src/main/java/net/onelitefeather/bettergopaint/command/GoPaintCommand.java +++ b/src/main/java/net/onelitefeather/bettergopaint/command/GoPaintCommand.java @@ -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; @@ -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 + "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 + "/gp size|toggle|info|reload"); + plugin.bundle().sendMessage(p, "command.gopaint.usage.admin"); return true; } - p.sendRichMessage(prefix + "/gp size|toggle|info"); + plugin.bundle().sendMessage(p, "command.gopaint.usage"); return true; } else if (args.length == 1) { if (args[0].equalsIgnoreCase("size")) { - p.sendRichMessage(prefix + "/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 + "Disabled brush"); + plugin.bundle().sendMessage(p, "command.gopaint.brush.disabled"); } else { pb.toggle(); - p.sendRichMessage(prefix + "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 + "Reloaded"); + plugin.bundle().sendMessage(p, "command.gopaint.reloaded"); return true; } else if (args[0].equalsIgnoreCase("info") || args[0].equalsIgnoreCase("i")) { - p.sendRichMessage(prefix + "Created by: TheMeinerLP"); - p.sendRichMessage(prefix + "Links: Twitter"); + 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 + "/gp size|toggle|info|reload"); + plugin.bundle().sendMessage(p, "command.gopaint.usage.admin"); return true; } - p.sendRichMessage(prefix + "/gp size|toggle|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 + "Size set to: " + 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 + "/gb size [number]"); + plugin.bundle().sendMessage(p, "command.gopaint.usage.size"); return true; } } if (p.hasPermission(BetterGoPaint.ADMIN_PERMISSION)) { - p.sendRichMessage(prefix + "/gp size|toggle|info|reload"); + plugin.bundle().sendMessage(p, "command.gopaint.usage.admin"); return true; } - p.sendRichMessage(prefix + "/gp size|toggle|info"); + plugin.bundle().sendMessage(p, "command.gopaint.usage"); return true; } return false; diff --git a/src/main/java/net/onelitefeather/bettergopaint/listeners/InteractListener.java b/src/main/java/net/onelitefeather/bettergopaint/listeners/InteractListener.java index 950da9f3..7608d1af 100644 --- a/src/main/java/net/onelitefeather/bettergopaint/listeners/InteractListener.java +++ b/src/main/java/net/onelitefeather/bettergopaint/listeners/InteractListener.java @@ -117,9 +117,7 @@ public void onClick(PlayerInteractEvent event) { () -> brushSettings.brush().paint(location, player, brushSettings), false, true ); } else { - player.sendRichMessage( - Settings.settings().GENERIC.PREFIX + "Your brush is disabled, left click to enable the brush." - ); + plugin.bundle().sendMessage(player, "brush.disabled"); } } diff --git a/src/main/java/net/onelitefeather/bettergopaint/objects/brush/PaintBrush.java b/src/main/java/net/onelitefeather/bettergopaint/objects/brush/PaintBrush.java index 5004964a..15e68640 100644 --- a/src/main/java/net/onelitefeather/bettergopaint/objects/brush/PaintBrush.java +++ b/src/main/java/net/onelitefeather/bettergopaint/objects/brush/PaintBrush.java @@ -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; @@ -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> selectedPoints = new HashMap<>(); @@ -53,13 +57,16 @@ public void paint( @NotNull Player player, @NotNull BrushSettings brushSettings ) { - String prefix = Settings.settings().GENERIC.PREFIX; - List 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; }