Skip to content

Commit

Permalink
Lang rework 23
Browse files Browse the repository at this point in the history
  • Loading branch information
FireInstall committed Feb 15, 2024
1 parent 0fe7f18 commit b8c2b33
Show file tree
Hide file tree
Showing 35 changed files with 223 additions and 188 deletions.
5 changes: 0 additions & 5 deletions Minigames/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@
<version>1.10.0</version>
</dependency>
<!-- part of org.apache.commons -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.15.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void playerInteract(@NotNull PlayerInteractEvent event) {
}
if (mgPlayer.isInMenu() && mgPlayer.getNoClose() && mgPlayer.getManualEntry() != null) {
event.setCancelled(true);
ply.setNoClose(false);
mgPlayer.setNoClose(false);
if (event.getClickedBlock() != null) {
mgPlayer.setNoClose(false);
mgPlayer.getManualEntry().checkValidEntry(event.getClickedBlock().getBlockData().getAsString());
Expand Down
27 changes: 17 additions & 10 deletions Minigames/src/main/java/au/com/mineauz/minigames/PlayerLoadout.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,32 +430,39 @@ public void save(ConfigurationSection section) {
section.set("potions." + eff.getType().getName() + ".dur", eff.getDuration());
}

if (getUsePermissions())
if (getUsePermissions()) {
section.set("usepermissions", true);
}

if (!hasFallDamage())
if (!hasFallDamage()) {
section.set("falldamage", hasFallDamage());
}

if (hasHunger())
if (hasHunger()) {
section.set("hunger", hasHunger());
}

if (getDisplayName() != null)
section.set("displayName", getDisplayName());
section.set("displayName", getDisplayName());

if (isArmourLocked())
if (isArmourLocked()) {
section.set("armourLocked", isArmourLocked());
}

if (isInventoryLocked())
if (isInventoryLocked()) {
section.set("inventoryLocked", isInventoryLocked());
}

if (getTeamColor() != null)
if (getTeamColor() != null) {
section.set("team", getTeamColor().toString());
}

if (!isDisplayedInMenu())
if (!isDisplayedInMenu()) {
section.set("displayInMenu", isDisplayedInMenu());
}

if (!allowOffHand())
if (!allowOffHand()) {
section.set("allowOffhand", allowOffHand());
}

for (Entry<Class<? extends LoadoutAddon>, Object> addonValue : addonValues.entrySet()) {
ConfigurationSection subSection = section.createSection("addons." + addonValue.getKey().getName().replace('.', '-'));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package au.com.mineauz.minigames.backend;

import au.com.mineauz.minigames.stats.StatFormat;
import net.kyori.adventure.text.Component;

import java.util.UUID;

Expand Down Expand Up @@ -35,7 +36,7 @@ public interface BackendImportCallback {
* @param name The username of the player
* @param displayName the display name of the player
*/
void acceptPlayer(UUID playerId, String name, String displayName);
void acceptPlayer(UUID playerId, String name, Component displayName);

/**
* Called to add a minigame to the destination backend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import au.com.mineauz.minigames.backend.*;
import au.com.mineauz.minigames.stats.StatFormat;
import net.kyori.adventure.text.minimessage.MiniMessage;

import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -61,7 +62,8 @@ private void exportPlayers() throws SQLException {
notifyNext("Exporting players...");
try (ResultSet rs = handler.executeQuery(getPlayers)) {
while (rs.next()) {
callback.acceptPlayer(UUID.fromString(rs.getString("player_id")), rs.getString("name"), rs.getString("displayname"));
callback.acceptPlayer(UUID.fromString(rs.getString("player_id")), rs.getString("name"),
MiniMessage.miniMessage().deserialize(rs.getString("displayname")));
++notifyCount;
notifyProgress();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import au.com.mineauz.minigames.backend.ConnectionPool;
import au.com.mineauz.minigames.backend.StatementKey;
import au.com.mineauz.minigames.stats.StatFormat;
import net.kyori.adventure.text.Component;

import java.sql.SQLException;
import java.util.UUID;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void begin() {
}

@Override
public void acceptPlayer(UUID playerId, String name, String displayName) {
public void acceptPlayer(UUID playerId, String name, Component displayName) {
try {
handler.batchUpdate(insertPlayer, playerId.toString(), name, displayName);
++playerBatchCount;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package au.com.mineauz.minigames.backend.mysql;

import au.com.mineauz.minigames.backend.*;
import net.kyori.adventure.text.minimessage.MiniMessage;

import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -86,7 +87,8 @@ private void exportPlayers() throws SQLException {

try (ResultSet rs = handler.executeQuery(selectPlayers)) {
while (rs.next()) {
callback.acceptPlayer(UUID.fromString(rs.getString("UUID")), rs.getString("Player"), rs.getString("Player"));
callback.acceptPlayer(UUID.fromString(rs.getString("UUID")), rs.getString("Player"),
MiniMessage.miniMessage().deserialize(rs.getString("Player")));
++notifyCount;
notifyProgress();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import au.com.mineauz.minigames.stats.StatisticValueField;
import au.com.mineauz.minigames.stats.StoredStat;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
import net.kyori.adventure.text.minimessage.MiniMessage;

import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -109,6 +110,6 @@ private StoredStat loadStat(ResultSet rs) throws SQLException {
String displayName = rs.getString("displayname");
long value = rs.getLong("value");

return new StoredStat(playerId, name, displayName, value);
return new StoredStat(playerId, name, MiniMessage.miniMessage().deserialize(displayName), value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import au.com.mineauz.minigames.backend.Notifier;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.SetMultimap;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.InvalidConfigurationException;
Expand Down Expand Up @@ -81,9 +82,9 @@ private void exportPlayers() {
// Attempt to get information about this player
OfflinePlayer player = Bukkit.getPlayer(playerId);
if (player != null) {
callback.acceptPlayer(playerId, player.getName(), player.getName());
callback.acceptPlayer(playerId, player.getName(), player.getPlayer() != null ? player.getPlayer().displayName() : Component.text(player.getName()));
} else {
callback.acceptPlayer(playerId, "Unknown", "Unknown");
callback.acceptPlayer(playerId, "Unknown", Component.text("Unknown"));
}

++notifyCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import au.com.mineauz.minigames.stats.StatisticValueField;
import au.com.mineauz.minigames.stats.StoredStat;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
import net.kyori.adventure.text.minimessage.MiniMessage;

import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -105,6 +106,6 @@ private StoredStat loadStat(ResultSet rs) throws SQLException {
String displayName = rs.getString("displayname");
long value = rs.getLong("value");

return new StoredStat(playerId, name, displayName, value);
return new StoredStat(playerId, name, MiniMessage.miniMessage().deserialize(displayName), value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public List<StoredStat> loadStats(Minigame minigame, MinigameStat stat, Statisti
List<StoredStat> result = new ArrayList<>();
for (StoredGameStats store : playerGameStats) {
if (store.hasStat(stat) && store.getMinigame().getName().equals(minigame.getName())) {
result.add(new StoredStat(store.getPlayer().getUUID(), store.getPlayer().getName(), store.getPlayer().getDisplayName(true), store.getStat(stat)));
result.add(new StoredStat(store.getPlayer().getUUID(), store.getPlayer().getName(), store.getPlayer().displayName(), store.getStat(stat)));
}
}
if (Objects.requireNonNull(order) == ScoreboardOrder.DESCENDING) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import au.com.mineauz.minigames.managers.language.langkeys.MgCommandLangKey;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import au.com.mineauz.minigames.minigame.Minigame;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -61,7 +59,7 @@ public boolean onCommand(final @NotNull CommandSender sender,
try {
CompletableFuture<Void> future = manager.exportTo(args[1], Minigames.getPlugin().getConfig(), new ExportNotifier(sender));
future.exceptionally(throwable -> {
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_BACKEND_ERROR_INTERNAL,
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_ERROR_INTERNAL,
Placeholder.unparsed(MinigamePlaceHolderKey.TEXT.getKey(), throwable.getMessage()));
Minigames.getCmpnntLogger().error("An internal error occurred while exporting.", throwable);
return null;
Expand All @@ -81,7 +79,7 @@ public boolean onCommand(final @NotNull CommandSender sender,
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.SUCCESS, MgCommandLangKey.COMMAND_BACKEND_SWITCH_SUCCESS);
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.WARNING, MgCommandLangKey.COMMAND_BACKEND_SWITCH_WARNING_TEMP);
} else {
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_BACKEND_ERROR_INTERNAL,
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_ERROR_INTERNAL,
Placeholder.unparsed(MinigamePlaceHolderKey.TEXT.getKey(), throwable.getMessage()));
Minigames.getCmpnntLogger().error("An internal error occurred while exporting.", throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ public boolean onCommand(final @NotNull CommandSender sender, @NotNull String @N
));
for (StoredStat playerStat : result) {
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.NONE, MgCommandLangKey.COMMAND_SCOREBOARD_LIST_PLAYER,
Placeholder.unparsed(MinigamePlaceHolderKey.PLAYER.getKey(), playerStat.getPlayerDisplayName()),
Placeholder.unparsed(MinigamePlaceHolderKey.NUMBER.getKey(), stat.displayValue(playerStat.getValue(), settings)));
Placeholder.component(MinigamePlaceHolderKey.PLAYER.getKey(), playerStat.getPlayerDisplayName()),
Placeholder.component(MinigamePlaceHolderKey.NUMBER.getKey(), stat.displayValue(playerStat.getValue(), settings)));
}
} else {
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_ERROR_INTERNAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import au.com.mineauz.minigames.MinigameUtils;
import au.com.mineauz.minigames.Minigames;
import au.com.mineauz.minigames.managers.MinigameMessageManager;
import au.com.mineauz.minigames.managers.language.MinigameMessageType;
import au.com.mineauz.minigames.managers.language.langkeys.MgCommandLangKey;
import au.com.mineauz.minigames.objects.MinigamePlayer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
Expand All @@ -25,16 +27,12 @@ public boolean canBeConsole() {

@Override
public @NotNull Component getDescription() {
return "select and clear region selections";
return MinigameMessageManager.getMgMessage(MgCommandLangKey.COMMAND_SELECT_DESCRIPTION);
}

@Override
public @NotNull Component getUsage() {
return new String[]{
"/minigame select 1",
"/minigame select 2",
"/minigame select clear"
};
return MinigameMessageManager.getMgMessage(MgCommandLangKey.COMMAND_SELECT_USAGE);
}

@Override
Expand All @@ -50,22 +48,22 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull String @NotNull
if (args.length > 0) {
if (args[0].equalsIgnoreCase("1")) {
mgPlayer.setSelection1(player.getLocation());
mgPlayer.sendInfoMessage(Component.text("Point 1 selected", NamedTextColor.GRAY));
MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgCommandLangKey.COMMAND_SELECT_POINT1);
} else if (args[0].equalsIgnoreCase("2")) {
mgPlayer.setSelection2(player.getLocation());
mgPlayer.sendInfoMessage(Component.text("Point 2 selected", NamedTextColor.GRAY));
MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgCommandLangKey.COMMAND_SELECT_POINT2);

} else if (args[0].equalsIgnoreCase("clear")) {
mgPlayer.clearSelection();
mgPlayer.sendInfoMessage(Component.text("Selection cleared.", NamedTextColor.GRAY));
MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.INFO, MgCommandLangKey.COMMAND_SELECT_CLEAR);
} else { // unknown param
return false;
}
} else { // not enough args
return false;
}
} else {
sender.sendMessage(Component.text("You have to be a player.", NamedTextColor.RED));
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.ERROR, MgCommandLangKey.COMMAND_ERROR_SENDERNOTAPLAYER);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import au.com.mineauz.minigames.minigame.Minigame;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.apache.commons.lang3.BooleanUtils;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -65,15 +64,18 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Minigame miniga
} else if (args[0].equalsIgnoreCase("display") && args.length >= 2){ //todo
if (args[1].equalsIgnoreCase("xpBar")) {
minigame.setTimerDisplayType(MinigameTimer.DisplayType.XP_BAR);
sender.sendMessage(ChatColor.GRAY + minigame.toString() + " will now show the timer in the XP bar.");
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.SUCCESS, MgCommandLangKey.COMMAND_SET_TIMER_XPBAR,
Placeholder.unparsed(MinigamePlaceHolderKey.MINIGAME.getKey(), minigame.getName()));
return true;
} else if (args[1].equalsIgnoreCase("bossBar")) {
minigame.setTimerDisplayType(MinigameTimer.DisplayType.BOSS_BAR);
sender.sendMessage(ChatColor.GRAY + minigame.toString() + " will now show the timer in the boss bar.");
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.SUCCESS, MgCommandLangKey.COMMAND_SET_TIMER_BOSSBAR,
Placeholder.unparsed(MinigamePlaceHolderKey.MINIGAME.getKey(), minigame.getName()));
return true;
} else if (args[1].equalsIgnoreCase("none")) {
minigame.setTimerDisplayType(MinigameTimer.DisplayType.NONE);
sender.sendMessage(ChatColor.GRAY + minigame.toString() + " will no longer show the timer.");
MinigameMessageManager.sendMgMessage(sender, MinigameMessageType.SUCCESS, MgCommandLangKey.COMMAND_SET_TIMER_NONE,
Placeholder.unparsed(MinigamePlaceHolderKey.MINIGAME.getKey(), minigame.getName()));
return true;
} // else here will default to false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public enum MgCommandLangKey implements LangKey {
COMMAND_LIST_LIST("command.list.list"),
COMMAND_LIST_USAGE("command.list.usage"),
COMMAND_LOADOUT_DESCRIPTION("command.loadout.description"),
COMMAND_LOADOUT_USAGE("command.loadout.usage"),
COMMAND_MINIGAMES_AUTHORS("command.minigames.authors"),
COMMAND_MINIGAMES_HELP("command.minigames.help"),
COMMAND_MINIGAMES_VERSION("command.minigames.version"),
Expand Down Expand Up @@ -346,12 +347,13 @@ public enum MgCommandLangKey implements LangKey {
COMMAND_SET_TEAM_REMOVE("command.set.team.remove"),
COMMAND_SET_TEAM_RENAME("command.set.team.rename"),
COMMAND_SET_TEAM_USAGE("command.set.team.usage"),
COMMAND_SET_TIMER_BOSSBAR("command.set.timer.bossBar"),
COMMAND_SET_TIMER_DESCRIPTION("command.set.timer.description"),
COMMAND_SET_TIMER_NONE("command.set.timer.none"),
COMMAND_SET_TIMER_REMOVE("command.set.timer.remove"),
COMMAND_SET_TIMER_SUCCESS("command.set.timer.success"),
COMMAND_SET_TIMER_USAGE("command.set.timer.usage"),
COMMAND_SET_TIMER_XPBAR_REMOVE("command.set.timer.xpBar.remove"),
COMMAND_SET_TIMER_XPBAR_SUCCESS("command.set.timer.xpBar.success"),
COMMAND_SET_TIMER_XPBAR("command.set.timer.xpBar"),
COMMAND_SET_TYPE_DESCRIPTION("command.set.type.description"),
COMMAND_SET_TYPE_ERROR_NOTTYPE("command.set.type.error.notType"),
COMMAND_SET_TYPE_SUCCESS("command.set.type.success"),
Expand Down Expand Up @@ -397,7 +399,11 @@ public enum MgCommandLangKey implements LangKey {
COMMAND_TOOL_SETMODE("command.tool.setMode"),
COMMAND_TOOL_SETTEAM("command.tool.setTeam"),
COMMAND_TOOL_USAGE("command.tool.usage"),
COMMAND_LOADOUT_USAGE("command.loadout.usage");
COMMAND_SELECT_DESCRIPTION("command.select.description"),
COMMAND_SELECT_USAGE("command.select.usage"),
COMMAND_SELECT_POINT1("command.select.point1"),
COMMAND_SELECT_POINT2("command.select.point2"),
COMMAND_SELECT_CLEAR("command.select.clear");

private final @NotNull String path;

Expand Down
Loading

0 comments on commit b8c2b33

Please sign in to comment.