Skip to content

Commit

Permalink
internationalized hardcoded messages
Browse files Browse the repository at this point in the history
  • Loading branch information
david committed Jun 15, 2024
1 parent 6d4e72b commit 73dc4ae
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 38 deletions.
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

0 comments on commit 73dc4ae

Please sign in to comment.