Skip to content

Commit 44ae577

Browse files
committed
allow user facing messages to be translated
1 parent 510f04e commit 44ae577

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

spigot/src/main/java/com/guflimc/treasurechests/spigot/TreasureChests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.guflimc.treasurechests.spigot;
22

33
import com.guflimc.brick.gui.spigot.SpigotBrickGUI;
4+
import com.guflimc.brick.i18n.spigot.api.SpigotTranslator;
45
import com.guflimc.brick.placeholders.spigot.api.manager.SpigotPlaceholderManager;
56
import com.guflimc.treasurechests.spigot.data.DatabaseContext;
67
import com.guflimc.treasurechests.spigot.listeners.PlayerChestListener;
@@ -12,19 +13,26 @@
1213
import org.bukkit.plugin.PluginManager;
1314
import org.bukkit.plugin.java.JavaPlugin;
1415

16+
import java.util.Locale;
17+
1518
public class TreasureChests extends JavaPlugin {
1619

1720
private DatabaseContext databaseContext;
1821
private TreasureChestManager manager;
1922
private ParticleJobManager particleJobManager;
2023

24+
private SpigotTranslator translator;
2125
//
2226

2327
@Override
2428
public void onEnable() {
2529
// LOAD CONFIG
2630
TreasureChestsConfig config = new TreasureChestsConfig();
2731

32+
// translations
33+
translator = new SpigotTranslator(this, Locale.ENGLISH);
34+
translator.importTranslations(this);
35+
2836
// INIT DATABASE
2937
databaseContext = new DatabaseContext(config.database);
3038

@@ -44,7 +52,7 @@ public void onEnable() {
4452
// events
4553
PluginManager pm = getServer().getPluginManager();
4654
pm.registerEvents(new PlayerConnectionListener(manager), this);
47-
pm.registerEvents(new PlayerChestListener(manager), this);
55+
pm.registerEvents(new PlayerChestListener(manager, translator), this);
4856
pm.registerEvents(new PlayerChestSetupListener(manager, particleJobManager), this);
4957
pm.registerEvents(new WorldListener(particleJobManager), this);
5058

spigot/src/main/java/com/guflimc/treasurechests/spigot/listeners/PlayerChestListener.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.guflimc.treasurechests.spigot.listeners;
22

33
import com.guflimc.brick.i18n.api.time.DurationFormatter;
4+
import com.guflimc.brick.i18n.spigot.api.SpigotTranslator;
45
import com.guflimc.treasurechests.spigot.TreasureChestManager;
56
import org.bukkit.ChatColor;
67
import org.bukkit.block.Block;
@@ -18,9 +19,11 @@
1819
public class PlayerChestListener implements Listener {
1920

2021
private final TreasureChestManager manager;
22+
private final SpigotTranslator translator;
2123

22-
public PlayerChestListener(TreasureChestManager manager) {
24+
public PlayerChestListener(TreasureChestManager manager, SpigotTranslator translator) {
2325
this.manager = manager;
26+
this.translator = translator;
2427
}
2528

2629
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
@@ -44,12 +47,12 @@ public void onClick(PlayerInteractEvent event) {
4447
if ( inv.isEmpty() ) {
4548
Duration duration = manager.respawnIn(block, player);
4649
if ( duration == null ) {
47-
player.sendMessage(ChatColor.RED + "This chest has already been looted.");
50+
translator.send(player, "chest.looted");
4851
return;
4952
}
5053

5154
String formatted = DurationFormatter.COMPACT.format(duration);
52-
player.sendMessage(ChatColor.RED + "This chest has already been looted. It will refill in " + ChatColor.GOLD + formatted + ChatColor.RED + ".");
55+
translator.send(player, "chest.looted.duration", formatted);
5356
return;
5457
}
5558

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"chest.looted": "<red>This chest has already been looted.",
3+
"chest.looted.duration": "<red>This chest has already been looted. It will refill in <gold>{0}<red>."
4+
}

0 commit comments

Comments
 (0)