Skip to content

Commit

Permalink
Fix Fr messages
Browse files Browse the repository at this point in the history
load neutral / capture sign text from translation files
Fix wrongly saved trigger amount
  • Loading branch information
FireInstall committed Mar 11, 2024
1 parent 59725e6 commit cdcaef8
Show file tree
Hide file tree
Showing 21 changed files with 301 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
import au.com.mineauz.minigames.stats.MinigameStatistics;
import au.com.mineauz.minigames.stats.StatisticValueField;
import au.com.mineauz.minigames.stats.StoredGameStats;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
import net.milkbowl.vault.economy.Economy;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.CustomChart;
import org.bstats.charts.MultiLineChart;
import org.bstats.charts.SimpleBarChart;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.ConfigurationSection;
Expand Down Expand Up @@ -339,7 +340,7 @@ private void setupMinigames() {
game.loadMinigame();
this.minigameManager.addMinigame(game);
} catch (final Exception e) {
this.getLogger().severe(ChatColor.RED + "Failed to load \"" + minigame + "\"! The configuration file may be corrupt or missing!");
this.getComponentLogger().error(Component.text("Failed to load \"" + minigame + "\"! The configuration file may be corrupt or missing!", NamedTextColor.RED));
getCmpnntLogger().error("", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void loadValue(@NotNull Configuration config, @NotNull String path) {
result = new Location(world, x, y, z, yaw, pitch);
} else {
Minigames.getCmpnntLogger().warn("Could not load legacy location flag at '" + path + configSeparator + getName() +
"' because World '" + worldName + "' is not a valid name! Throwing error so the config don't get overwritten.");
"' because World '" + worldName + "' is not a valid name! Throwing exception so the config don't get overwritten.");
throw new RuntimeException("invalid worldName at '" + path + configSeparator + getName() + "'");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void loadValue(@NotNull Configuration config, @NotNull String path) {
result = new MgRegion(world, name, Position.fine(x1, y1, z1), Position.fine(x2, y2, z2));
} else {
Minigames.getCmpnntLogger().warn("Could not load Region because world '" + worldName + "' was invalid. " +
"Throwing error so the config don't get overwritten.");
"Throwing exception so the config don't get overwritten.");
throw new RuntimeException("invalid worldName at '" + path + configSeparator + getName() + "'");
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void loadValue(@NotNull Configuration config, @NotNull String path) {
result = new Location(world, x, y, z);
} else {
Minigames.getCmpnntLogger().warn("Could not simple location flag at '" + path + configSeparator + getName() +
"' because World '" + worldName + "' is not a valid name! Throwing error so the config don't get overwritten.");
"' because World '" + worldName + "' is not a valid name! Throwing exception so the config don't get overwritten.");
throw new RuntimeException("invalid worldName at '" + path + configSeparator + getName() + "'");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public enum MgSignLangKey implements MinigameLangKey {
TYPE_BET("sign.type.bet"),
TYPE_CHECKPOINT("sign.type.checkpoint"),
TYPE_CTFFLAG("sign.type.flag"),
SUBTYPE_CAPTURE("sign.subtype.capture"),
TEAM_NEUTRAL("sign.team.neutral"),
TYPE_FINISH("sign.type.finish"),
TYPE_TELEPORT("sign.type.teleport"),
TYPE_JOIN("sign.type.join"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Sign;
Expand Down Expand Up @@ -64,7 +63,7 @@ public String getMechanicName() {
}

@Override
public EnumSet<MinigameType> validTypes() {
public @NotNull EnumSet<@NotNull MinigameType> validTypes() {
return EnumSet.of(MinigameType.MULTIPLAYER);
}

Expand Down Expand Up @@ -137,7 +136,7 @@ private void takeFlag(@NotNull PlayerInteractEvent event) { //todo better system
@Nullable TeamColor colorOnLine2 = TeamColor.matchColor(plainTextSerializer.serialize(signFrontSide.line(2)));
if (colorOnLine2 == team.getColor() &&
mgm.hasDroppedFlag(sloc) &&
!(sloc.equals(MinigameUtils.createLocationID(mgm.getDroppedFlag(sloc).getSpawnLocation())))) {
!(sloc.equals(MinigameUtils.createLocationID(mgm.getDroppedFlag(sloc).getSpawnLocation())))) { //todo this whole if/else needs a reordering
if (CTFModule.getMinigameModule(mgm).getBringFlagBackManual()) {
CTFFlag flag = mgm.getDroppedFlag(sloc);
flag.stopTimer();
Expand All @@ -149,14 +148,12 @@ private void takeFlag(@NotNull PlayerInteractEvent event) { //todo better system
MinigameMessageManager.sendMinigameMessage(mgm, MinigameMessageManager.getMgMessage(MgMiscLangKey.MINIGAME_FLAG_RETURNEDTEAM,
Placeholder.component(MinigamePlaceHolderKey.TEAM.getKey(), Component.text(team.getDisplayName(), team.getTextColor()))), MinigameMessageType.INFO);
}
} else if ((colorOnLine2 != team.getColor() &&
!signFrontSide.getLine(2).equalsIgnoreCase(ChatColor.GREEN + "Capture")) ||
signFrontSide.getLine(2).equalsIgnoreCase(ChatColor.GRAY + "Neutral")) {
} else if ((colorOnLine2 != team.getColor() && !CTFFlagSign.isCapture(signFrontSide.line(2))) ||
CTFFlagSign.isNeutral(signFrontSide.line(2))) {
if (mgm.getCarriedFlag(mgPlayer) == null) {
TakeCTFFlagEvent ev = null;
if (!mgm.hasDroppedFlag(sloc) &&
(TeamsModule.getMinigameModule(mgm).hasTeam(colorOnLine2) ||
signFrontSide.getLine(2).equalsIgnoreCase(ChatColor.GRAY + "Neutral"))) {
(TeamsModule.getMinigameModule(mgm).hasTeam(colorOnLine2) || CTFFlagSign.isNeutral(signFrontSide.line(2)))) {
Team oTeam = TeamsModule.getMinigameModule(mgm).getTeam(colorOnLine2);
CTFFlag flag = new CTFFlag(sign, oTeam, mgm);
ev = new TakeCTFFlagEvent(mgm, mgPlayer, flag);
Expand Down Expand Up @@ -197,9 +194,8 @@ private void takeFlag(@NotNull PlayerInteractEvent event) { //todo better system

} else if (team == TeamsModule.getMinigameModule(mgm).getTeam(colorOnLine2) && CTFModule.getMinigameModule(mgm).getUseFlagAsCapturePoint() ||
(team == TeamsModule.getMinigameModule(mgm).getTeam(TeamColor.matchColor(plainTextSerializer.serialize(signFrontSide.line(3)))) &&
signFrontSide.getLine(2).equalsIgnoreCase(ChatColor.GREEN + "Capture")) ||
(signFrontSide.getLine(2).equalsIgnoreCase(ChatColor.GREEN + "Capture") &&
signFrontSide.getLine(3).equalsIgnoreCase(ChatColor.GRAY + "Neutral"))) {
CTFFlagSign.isCapture(signFrontSide.line(2))) ||
(CTFFlagSign.isCapture(signFrontSide.line(2)) && CTFFlagSign.isNeutral(signFrontSide.line(3)))) {

String clickID = MinigameUtils.createLocationID(event.getClickedBlock().getLocation());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public String getMechanicName() {
}

@Override
public EnumSet<MinigameType> validTypes() {
public @NotNull EnumSet<@NotNull MinigameType> validTypes() {
return EnumSet.of(MinigameType.MULTIPLAYER, MinigameType.SINGLEPLAYER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public GameMechanicBase() {
*
* @return All valid game types.
*/
public abstract EnumSet<MinigameType> validTypes();
public abstract @NotNull EnumSet<@NotNull MinigameType> validTypes();

/**
* Checks if a mechanic is allowed to start with the current settings. Caller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String getMechanicName() {
}

@Override
public EnumSet<MinigameType> validTypes() {
public @NotNull EnumSet<@NotNull MinigameType> validTypes() {
return EnumSet.of(MinigameType.MULTIPLAYER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public String getMechanicName() {
}

@Override
public EnumSet<MinigameType> validTypes() {
public @NotNull EnumSet<@NotNull MinigameType> validTypes() {
return EnumSet.of(MinigameType.MULTIPLAYER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public String getMechanicName() {
}

@Override
public EnumSet<MinigameType> validTypes() {
public @NotNull EnumSet<@NotNull MinigameType> validTypes() {
return EnumSet.of(MinigameType.MULTIPLAYER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public String getMechanicName() {
}

@Override
public EnumSet<MinigameType> validTypes() {
public @NotNull EnumSet<@NotNull MinigameType> validTypes() {
return EnumSet.of(MinigameType.MULTIPLAYER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public String getMechanicName() {
}

@Override
public EnumSet<MinigameType> validTypes() {
public @NotNull EnumSet<@NotNull MinigameType> validTypes() {
return EnumSet.of(MinigameType.GLOBAL);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package au.com.mineauz.minigames.signs;

import au.com.mineauz.minigames.Minigames;
import au.com.mineauz.minigames.managers.language.MinigameMessageManager;
import au.com.mineauz.minigames.managers.language.langkeys.MgSignLangKey;
import au.com.mineauz.minigames.minigame.Minigame;
import au.com.mineauz.minigames.objects.MinigamePlayer;
import net.kyori.adventure.text.Component;
Expand Down Expand Up @@ -28,6 +30,10 @@ public boolean isType(@NotNull String signLine) { // but this is the best way fo
return PlainTextComponentSerializer.plainText().serialize(getName()).equalsIgnoreCase(signLine);
}

public static boolean isNeutral(@NotNull Component signLine) {
return PlainTextComponentSerializer.plainText().serialize(signLine).equalsIgnoreCase(MinigameMessageManager.getStrippedMgMessage(MgSignLangKey.TEAM_NEUTRAL));
}

public abstract @Nullable String getCreatePermission();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import au.com.mineauz.minigames.managers.language.MinigameMessageManager;
import au.com.mineauz.minigames.managers.language.MinigameMessageType;
import au.com.mineauz.minigames.managers.language.MinigamePlaceHolderKey;
import au.com.mineauz.minigames.managers.language.langkeys.MgMiscLangKey;
import au.com.mineauz.minigames.managers.language.langkeys.MgSignLangKey;
import au.com.mineauz.minigames.mechanics.CTFMechanic;
import au.com.mineauz.minigames.minigame.TeamColor;
import au.com.mineauz.minigames.objects.MinigamePlayer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.apache.commons.text.WordUtils;
import org.bukkit.Material;
Expand All @@ -34,6 +35,10 @@ public String getUsePermission() {
return null;
}

public static boolean isCapture(@NotNull Component signLine) {
return PlainTextComponentSerializer.plainText().serialize(signLine).equalsIgnoreCase(MinigameMessageManager.getStrippedMgMessage(MgSignLangKey.SUBTYPE_CAPTURE));
}

@Override
public boolean signCreate(@NotNull SignChangeEvent event) {
PlainTextComponentSerializer plainSerializer = PlainTextComponentSerializer.plainText();
Expand All @@ -43,20 +48,20 @@ public boolean signCreate(@NotNull SignChangeEvent event) {

if (col != null) {
event.line(2, Component.text(WordUtils.capitalizeFully(col.toString()), col.getColor()));
} else if (plainSerializer.serialize(event.line(2)).equalsIgnoreCase("neutral")) {
event.line(2, Component.text("Neutral", NamedTextColor.GRAY));
} else if (plainSerializer.serialize(event.line(2)).equalsIgnoreCase("capture") &&
!plainSerializer.serialize(event.line(3)).isEmpty()) {
event.line(2, Component.text("Capture", NamedTextColor.GREEN));
} else if (isNeutral(event.line(2))) {
event.line(2, MinigameMessageManager.getMgMessage(MgSignLangKey.TEAM_NEUTRAL));
} else if (isCapture(event.line(2)) && !plainSerializer.serialize(event.line(3)).isEmpty()) {
event.line(2, MinigameMessageManager.getMgMessage(MgSignLangKey.SUBTYPE_CAPTURE));

col = TeamColor.matchColor(plainSerializer.serialize(event.line(3)));
if (col != null) {
event.line(3, Component.text(WordUtils.capitalizeFully(col.toString()), col.getColor()));
} else if (plainSerializer.serialize(event.line(3)).equalsIgnoreCase("neutral")) {
event.line(3, Component.text("Neutral", NamedTextColor.GRAY));
} else if (isNeutral(event.line(3))) {
event.line(3, MinigameMessageManager.getMgMessage(MgSignLangKey.TEAM_NEUTRAL));
} else {
event.getBlock().breakNaturally();
MinigameMessageManager.sendMgMessage(event.getPlayer(), MinigameMessageType.ERROR, MgMiscLangKey.SIGN_ERROR_TEAM_INVALIDFORMAT);
MinigameMessageManager.sendMgMessage(event.getPlayer(), MinigameMessageType.ERROR, MgMiscLangKey.SIGN_ERROR_TEAM_INVALIDFORMAT,
Placeholder.component(MinigamePlaceHolderKey.TEXT.getKey(), MinigameMessageManager.getMgMessage(MgSignLangKey.TEAM_NEUTRAL)));
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import au.com.mineauz.minigames.minigame.modules.TeamsModule;
import au.com.mineauz.minigames.objects.MinigamePlayer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
Expand Down Expand Up @@ -45,8 +44,8 @@ public boolean signCreate(@NotNull SignChangeEvent event) {
event.line(1, getName());
PlainTextComponentSerializer plainSerializer = PlainTextComponentSerializer.plainText();

if (plainSerializer.serialize(event.line(2)).equalsIgnoreCase("neutral")) { // todo
event.line(2, Component.text("Neutral", NamedTextColor.GRAY));
if (isNeutral(event.line(2))) {
event.line(2, MinigameMessageManager.getMgMessage(MgSignLangKey.TEAM_NEUTRAL));
return true;
} else {
TeamColor color = TeamColor.matchColor(plainSerializer.serialize(event.line(2)));
Expand All @@ -56,7 +55,8 @@ public boolean signCreate(@NotNull SignChangeEvent event) {
}
}

MinigameMessageManager.sendMgMessage(event.getPlayer(), MinigameMessageType.ERROR, MgMiscLangKey.SIGN_ERROR_TEAM_INVALIDFORMAT);
MinigameMessageManager.sendMgMessage(event.getPlayer(), MinigameMessageType.ERROR, MgMiscLangKey.SIGN_ERROR_TEAM_INVALIDFORMAT,
Placeholder.component(MinigamePlaceHolderKey.TEXT.getKey(), MinigameMessageManager.getMgMessage(MgSignLangKey.TEAM_NEUTRAL)));
return false;
}

Expand All @@ -69,7 +69,7 @@ public boolean signUse(@NotNull Sign sign, @NotNull MinigamePlayer mgPlayer) {
PlainTextComponentSerializer plainSerializer = PlainTextComponentSerializer.plainText();

if (mgPlayer.getTeam() != matchTeam(mgm, frontSide.line(2))) {
if (!mgm.isWaitingForPlayers() && !plainSerializer.serialize(frontSide.line(2)).equalsIgnoreCase("Neutral")) {
if (!mgm.isWaitingForPlayers() && !isNeutral(frontSide.line(2))) {
Team sm = null;
Team nt = matchTeam(mgm, frontSide.line(2));
if (nt != null) {
Expand All @@ -96,7 +96,7 @@ public boolean signUse(@NotNull Sign sign, @NotNull MinigamePlayer mgPlayer) {
MinigameMessageManager.sendMgMessage(mgPlayer, MinigameMessageType.ERROR, MgMiscLangKey.PLAYER_TEAM_ASSIGN_ERROR_FULL);
}
}
} else if (plainSerializer.serialize(frontSide.line(2)).equalsIgnoreCase("Neutral") || matchTeam(mgm, frontSide.line(2)) != mgPlayer.getTeam()) {
} else if (isNeutral(frontSide.line(2)) || matchTeam(mgm, frontSide.line(2)) != mgPlayer.getTeam()) {
Team currentTeam = mgPlayer.getTeam();
Team nt = matchTeam(mgm, sign.getSide(Side.FRONT).line(2));
if (currentTeam != null) {
Expand Down
4 changes: 3 additions & 1 deletion Minigames/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ sign.error.backside=You can't use the backside of a sign for minigames signs!
sign.error.emptyHand=Your hand must be empty to use this sign.
sign.error.fullInv=Your inventory must be empty to use this sign.
sign.error.invalid=Invalid Minigames sign!
sign.error.team.invalidFormat=Line 3 must be a color or "neutral"!
sign.error.team.invalidFormat=Line 3 must be a color or "<text>"!
sign.finish.requireFlags=You still require the following flags: <text>
sign.flag.broken.support=You broke the support block of a flag! It won't be able to respawn!
sign.join.invalidMoney=Invalid money amount!
Expand All @@ -871,6 +871,8 @@ sign.team.error.unbalance=You cannot unbalance the teams!
sign.teleport.invalid=Invalid teleport sign!
sign.type.bet=<green>Bet<green>
sign.type.checkpoint=<green>Checkpoint</green>
sign.subtype.capture=<green>Capture</green>
sign.team.neutral=<gray>Neutral</gray>
sign.type.finish=<green>Finish</green>
sign.type.flag=<green>flag</green>
sign.type.join=<green>Join</green>
Expand Down
2 changes: 1 addition & 1 deletion Minigames/src/main/resources/messages_en_AU.properties
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ sign.error.backside=You can't use the backside of a sign for minigames signs!
sign.error.emptyHand=Your hand must be empty to use this sign.
sign.error.fullInv=Your inventory must be empty to use this sign.
sign.error.invalid=Invalid Minigames sign!
sign.error.team.invalidFormat=Line 3 must be a color or "neutral"!
sign.error.team.invalidFormat=Line 3 must be a color or "<text>"!
sign.finish.requireFlags=You still require the following flags: <text>
sign.join.invalidMoney=Invalid money amount!
sign.minigame=[<blue>Minigame</blue>]
Expand Down
2 changes: 1 addition & 1 deletion Minigames/src/main/resources/messages_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ sign.error.backside=You can't use the backside of a sign for minigames signs!
sign.error.emptyHand=Your hand must be empty to use this sign.
sign.error.fullInv=Your inventory must be empty to use this sign.
sign.error.invalid=Invalid Minigames sign!
sign.error.team.invalidFormat=Line 3 must be a color or "neutral"!
sign.error.team.invalidFormat=Line 3 must be a color or "<text>"!
sign.finish.requireFlags=You still require the following flags: <text>
sign.join.invalidMoney=Invalid money amount!
sign.minigame=[<blue>Minigame</blue>]
Expand Down
Loading

0 comments on commit cdcaef8

Please sign in to comment.