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

Per-player localization #101

Merged
merged 6 commits into from
Jan 30, 2024
Merged
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
2 changes: 1 addition & 1 deletion bukkit/src/main/java/org/popcraft/bolt/BoltPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void onDisable() {

public void reload() {
reloadConfig();
Translator.load(getDataPath(), getConfig().getString("language", "en"));
Translator.loadAllTranslations(getDataPath(), getConfig().getString("language", "en"), getConfig().getBoolean("per-player-locale", true));
this.useActionBar = getConfig().getBoolean("settings.use-action-bar", false);
this.doors = getConfig().getConfigurationSection("doors") != null;
this.doorsOpenIron = getConfig().getBoolean("doors.open-iron", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ private void runPage(final CommandSender sender, final Profile playerProfile, fi
BoltComponents.sendMessage(
sender,
Translation.FIND_RESULT,
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(blockProtection)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(blockProtection)),
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(blockProtection, sender)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(blockProtection, sender)),
Placeholder.component(Translation.Placeholder.PLAYER, Component.text(playerProfile.name())),
Placeholder.component(Translation.Placeholder.TIME, Component.text(time)),
Placeholder.component(Translation.Placeholder.WORLD, Component.text(blockProtection.getWorld())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void execute(CommandSender sender, Arguments arguments) {
player,
Translation.CLICK_ACTION,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.ACTION, BoltComponents.resolveTranslation(Translation.EDIT))
Placeholder.component(Translation.Placeholder.ACTION, BoltComponents.resolveTranslation(Translation.EDIT, player))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void execute(CommandSender sender, Arguments arguments) {
player,
Translation.CLICK_ACTION,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.ACTION, BoltComponents.resolveTranslation(Translation.LOCK))
Placeholder.component(Translation.Placeholder.ACTION, BoltComponents.resolveTranslation(Translation.LOCK, player))
);
} else {
BoltComponents.sendMessage(sender, Translation.COMMAND_PLAYER_ONLY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void execute(CommandSender sender, Arguments arguments) {
BoltComponents.sendMessage(
player,
hasMode ? Translation.MODE_ENABLED : Translation.MODE_DISABLED,
Placeholder.component(Translation.Placeholder.MODE, BoltComponents.resolveTranslation("mode_%s".formatted(mode.name().toLowerCase())))
Placeholder.component(Translation.Placeholder.MODE, BoltComponents.resolveTranslation("mode_%s".formatted(mode.name().toLowerCase()), player))
);
final UUID uuid = player.getUniqueId();
CompletableFuture.runAsync(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void execute(CommandSender sender, Arguments arguments) {
player,
Translation.CLICK_ACTION,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.ACTION, BoltComponents.resolveTranslation(Translation.EDIT))
Placeholder.component(Translation.Placeholder.ACTION, BoltComponents.resolveTranslation(Translation.EDIT, player))
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void execute(CommandSender sender, Arguments arguments) {
player,
Translation.CLICK_ACTION,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.ACTION, BoltComponents.resolveTranslation(Translation.UNLOCK))
Placeholder.component(Translation.Placeholder.ACTION, BoltComponents.resolveTranslation(Translation.UNLOCK, player))
);
} else {
BoltComponents.sendMessage(sender, Translation.COMMAND_PLAYER_ONLY);
Expand Down
61 changes: 31 additions & 30 deletions bukkit/src/main/java/org/popcraft/bolt/listeners/BlockListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
import java.util.Optional;
import java.util.UUID;

import static org.popcraft.bolt.lang.Translator.translate;
import static org.popcraft.bolt.util.BoltComponents.resolveTranslation;
import static org.popcraft.bolt.util.BoltComponents.translateRaw;
import static org.popcraft.bolt.util.Profiles.NIL_UUID;

public final class BlockListener implements Listener {
Expand Down Expand Up @@ -123,7 +124,7 @@ public void onPlayerInteract(final PlayerInteractEvent e) {
player,
Translation.LOCKED,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection))
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection, player))
);
}
}
Expand All @@ -137,7 +138,7 @@ public void onPlayerInteract(final PlayerInteractEvent e) {
return;
}
final boolean isYou = player.getUniqueId().equals(protection.getOwner());
final String owner = isYou ? translate(Translation.YOU) : profile.name();
final String owner = isYou ? translateRaw(Translation.YOU, player) : profile.name();
if (owner == null) {
SchedulerUtil.schedule(plugin, player, () -> {
if (!plugin.isProtected(clicked)) {
Expand All @@ -147,8 +148,8 @@ public void onPlayerInteract(final PlayerInteractEvent e) {
player,
Translation.PROTECTION_NOTIFY_GENERIC,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection))
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection, player)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection, player))
);
});
} else if (!isYou || player.hasPermission("bolt.protection.notify.self")) {
Expand All @@ -160,8 +161,8 @@ public void onPlayerInteract(final PlayerInteractEvent e) {
player,
Translation.PROTECTION_NOTIFY,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection)),
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection, player)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection, player)),
Placeholder.component(Translation.Placeholder.PLAYER, Component.text(owner))
);
});
Expand Down Expand Up @@ -224,14 +225,14 @@ private boolean triggerActions(final Player player, final Protection protection,
player,
Translation.CLICK_LOCKED_CHANGED,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection))
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection, player))
);
} else {
BoltComponents.sendMessage(
player,
Translation.CLICK_LOCKED_ALREADY,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection))
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection, player))
);
}
} else if (plugin.isProtectable(block) && (!lockPermission || player.hasPermission("bolt.protection.lock.%s".formatted(block.getType().name().toLowerCase())))) {
Expand All @@ -242,15 +243,15 @@ private boolean triggerActions(final Player player, final Protection protection,
player,
Translation.CLICK_LOCKED,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(newProtection)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block))
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(newProtection, player)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block, player))
);
} else {
BoltComponents.sendMessage(
player,
Translation.CLICK_NOT_LOCKABLE,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block))
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block, player))
);
}
}
Expand All @@ -262,8 +263,8 @@ private boolean triggerActions(final Player player, final Protection protection,
player,
Translation.CLICK_UNLOCKED,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection))
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection, player)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection, player))
);
} else {
BoltComponents.sendMessage(
Expand All @@ -277,7 +278,7 @@ private boolean triggerActions(final Player player, final Protection protection,
player,
Translation.CLICK_NOT_LOCKED,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block))
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block, player))
);
}
}
Expand All @@ -287,9 +288,9 @@ private boolean triggerActions(final Player player, final Protection protection,
.thenAccept(profile -> SchedulerUtil.schedule(plugin, player, () -> BoltComponents.sendMessage(
player,
protection.getAccess().size() > 0 && (protection.getOwner().equals(player.getUniqueId()) || player.hasPermission("bolt.command.info.full")) ? Translation.INFO_FULL : Translation.INFO,
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection)),
Placeholder.component(Translation.Placeholder.PLAYER, Component.text(Optional.ofNullable(profile.name()).orElse(translate(Translation.UNKNOWN)))),
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection, player)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection, player)),
Placeholder.component(Translation.Placeholder.PLAYER, Optional.ofNullable(profile.name()).<Component>map(Component::text).orElse(resolveTranslation(Translation.UNKNOWN, player))),
Placeholder.component(Translation.Placeholder.ACCESS_LIST_SIZE, Component.text(protection.getAccess().size())),
Placeholder.component(Translation.Placeholder.ACCESS_LIST, Component.text(Protections.accessList(protection.getAccess())))
)));
Expand All @@ -298,7 +299,7 @@ private boolean triggerActions(final Player player, final Protection protection,
player,
Translation.CLICK_NOT_LOCKED,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block))
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block, player))
);
}
}
Expand All @@ -317,8 +318,8 @@ private boolean triggerActions(final Player player, final Protection protection,
player,
Translation.CLICK_EDITED,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection))
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection, player)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection, player))
);
} else {
BoltComponents.sendMessage(
Expand All @@ -332,7 +333,7 @@ private boolean triggerActions(final Player player, final Protection protection,
player,
Translation.CLICK_NOT_LOCKED,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block))
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block, player))
);
}
}
Expand All @@ -351,9 +352,9 @@ private boolean triggerActions(final Player player, final Protection protection,
player,
Translation.CLICK_TRANSFER_CONFIRM,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection)),
Placeholder.component(Translation.Placeholder.PLAYER, Component.text(Optional.ofNullable(profile.name()).orElse(translate(Translation.UNKNOWN))))
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection, player)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection, player)),
Placeholder.component(Translation.Placeholder.PLAYER, Optional.ofNullable(profile.name()).<Component>map(Component::text).orElse(resolveTranslation(Translation.UNKNOWN, player)))
)));
} else {
BoltComponents.sendMessage(player, Translation.CLICK_EDITED_NO_OWNER, plugin.isUseActionBar());
Expand All @@ -363,7 +364,7 @@ private boolean triggerActions(final Player player, final Protection protection,
player,
Translation.CLICK_NOT_LOCKED,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block))
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block, player))
);
}
}
Expand Down Expand Up @@ -406,8 +407,8 @@ public void onBlockPlace(final BlockPlaceEvent e) {
player,
Translation.CLICK_LOCKED,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(newProtection)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block))
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(newProtection, player)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(block, player))
);
}
}
Expand Down Expand Up @@ -443,8 +444,8 @@ public void onBlockBreak(final BlockBreakEvent e) {
player,
Translation.CLICK_UNLOCKED,
plugin.isUseActionBar(),
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection))
Placeholder.component(Translation.Placeholder.PROTECTION_TYPE, Protections.protectionType(protection, player)),
Placeholder.component(Translation.Placeholder.PROTECTION, Protections.displayType(protection, player))
);
}
}
Expand Down
Loading
Loading