From c03e4586048c236a5bd852948eef350e4bce0350 Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 1 Feb 2024 12:38:41 +0100 Subject: [PATCH] Dev. progress for v3.8 --- .../betterstats/util/stats/SASConfig.java | 6 +- .../util/stats/StatAnnouncementSystem.java | 92 ++++++++++++++----- .../assets/betterstats/lang/en_us.json | 3 +- .../betterstats/util/stats/SASConfig.java | 6 +- .../util/stats/StatAnnouncementSystem.java | 92 ++++++++++++++----- .../assets/betterstats/lang/en_us.json | 3 +- .../betterstats/util/stats/SASConfig.java | 6 +- .../util/stats/StatAnnouncementSystem.java | 92 ++++++++++++++----- .../assets/betterstats/lang/en_us.json | 3 +- 9 files changed, 219 insertions(+), 84 deletions(-) diff --git a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/util/stats/SASConfig.java b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/util/stats/SASConfig.java index 6e954e6b..434e5aa7 100644 --- a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/util/stats/SASConfig.java +++ b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/util/stats/SASConfig.java @@ -10,18 +10,18 @@ public class SASConfig implements ACJsonHandler // ================================================== public String[] firstMinedBlocks = new String[] { "diamond_ore", "deepslate_diamond_ore", "ancient_debris", "deepslate_coal_ore", "dragon_egg", "sculk_sensor", "reinforced_deepslate" }; public String[] firstCraftedItems = new String[] { "wooden_pickaxe", "diamond_pickaxe", "beacon", "netherite_block", "ender_eye" }; - public boolean announceFirstDeaths = true; public String[] firstKilledEntities = new String[] { "zombie", "blaze", "enderman", "ender_dragon", "warden", "wither", "player" }; public String[] firstKilledByEntities = new String[] { "ender_dragon", "warden", "wither", "player" }; + public String[] firstCustomStats = new String[] { "deaths" }; // ================================================== public final @Override JsonObject saveToJson() { final var json = new JsonObject(); json.add("firstMinedBlocks", stringArrayToJsonArray(this.firstMinedBlocks)); json.add("firstCraftedItems", stringArrayToJsonArray(this.firstCraftedItems)); - json.addProperty("announceFirstDeaths", this.announceFirstDeaths); json.add("firstKilledEntities", stringArrayToJsonArray(this.firstKilledEntities)); json.add("firstKilledByEntities", stringArrayToJsonArray(this.firstKilledByEntities)); + json.add("firstCustomStats", stringArrayToJsonArray(this.firstCustomStats)); return json; } // -------------------------------------------------- @@ -32,9 +32,9 @@ public class SASConfig implements ACJsonHandler { if(json.has("firstMinedBlocks")) this.firstMinedBlocks = jsonArrayToStringArray(json.getAsJsonArray("firstMinedBlocks")); if(json.has("firstCraftedItems")) this.firstCraftedItems = jsonArrayToStringArray(json.getAsJsonArray("firstCraftedItems")); - if(json.has("announceFirstDeaths")) this.announceFirstDeaths = json.getAsJsonPrimitive("announceFirstDeaths").getAsBoolean(); if(json.has("firstKilledEntities")) this.firstKilledEntities = jsonArrayToStringArray(json.getAsJsonArray("firstKilledEntities")); if(json.has("firstKilledByEntities")) this.firstKilledByEntities = jsonArrayToStringArray(json.getAsJsonArray("firstKilledByEntities")); + if(json.has("firstCustomStats")) this.firstCustomStats = jsonArrayToStringArray(json.getAsJsonArray("firstCustomStats")); return true; } catch(Exception e) { return false; } diff --git a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/util/stats/StatAnnouncementSystem.java b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/util/stats/StatAnnouncementSystem.java index 9c04ba24..db0caa5f 100644 --- a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/util/stats/StatAnnouncementSystem.java +++ b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/util/stats/StatAnnouncementSystem.java @@ -30,6 +30,7 @@ import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.util.InvalidIdentifierException; +import static io.github.thecsdev.betterstats.api.util.stats.SUGeneralStat.getGeneralStatText; /** * A {@link Class} that handles announcing players doing @@ -47,15 +48,17 @@ public static final String TXT_FIRST_DEATH_HC1 = P + "first_death.hc1"; public static final String TXT_FIRST_KILLED = P + "first_kill"; public static final String TXT_FIRST_KILLED_BY = P + "first_death_to"; + public static final String TXT_CUSTOM = P + "custom"; // private static final Text WATERMARK; private static final BetterStatsConfig BSSC; private static final SASConfig SASC; // -------------------------------------------------- - public static final HashSet FIRST_MINED_BLOCKS; - public static final HashSet FIRST_CRAFTED_ITEMS; + public static final HashSet FIRST_MINED_BLOCKS; + public static final HashSet FIRST_CRAFTED_ITEMS; public static final HashSet> FIRST_KILLED_ENTITIES; public static final HashSet> FIRST_KILLED_BY_ENTITIES; + public static final HashSet FIRST_CUSTOM_STATS; //aka "general stats" // -------------------------------------------------- private StatAnnouncementSystem() {} static @@ -89,6 +92,7 @@ private StatAnnouncementSystem() {} FIRST_CRAFTED_ITEMS = new HashSet(); FIRST_KILLED_ENTITIES = new HashSet>(); FIRST_KILLED_BY_ENTITIES = new HashSet>(); + FIRST_CUSTOM_STATS = new HashSet(); //initialize set entries for(final var fmbId : SASC.firstMinedBlocks) @@ -130,6 +134,16 @@ private StatAnnouncementSystem() {} FIRST_KILLED_BY_ENTITIES.add(fkbe); } catch(InvalidIdentifierException e) { continue; } + + for(final var fcsId : SASC.firstCustomStats) + try + { + final var id = new Identifier(fcsId); + final @Nullable var fcs = Registries.CUSTOM_STAT.getOrEmpty(id).orElse(null); + if(fcs == null) continue; + FIRST_CUSTOM_STATS.add(fcs); + } + catch(InvalidIdentifierException e) { continue; } } // ================================================== /** @@ -168,10 +182,6 @@ else if(oldValue == 0 && newValue > 0) else if(stat.getType() == Stats.CRAFTED && FIRST_CRAFTED_ITEMS.contains(stat.getValue())) broadcastFirstCraft(player, (Item)stat.getValue()); - //handle "first death" - else if(stat.getType() == Stats.CUSTOM && Objects.equals(stat.getValue(), Stats.DEATHS) && SASC.announceFirstDeaths) - broadcastFirstDeath(player); - //handle first "killed" else if(stat.getType() == Stats.KILLED && FIRST_KILLED_ENTITIES.contains(stat.getValue())) broadcastFirstKilled(player, (EntityType)stat.getValue()); @@ -179,6 +189,20 @@ else if(stat.getType() == Stats.KILLED && FIRST_KILLED_ENTITIES.contains(stat.ge //handle first "killed by" else if(stat.getType() == Stats.KILLED_BY && FIRST_KILLED_BY_ENTITIES.contains(stat.getValue())) broadcastFirstKilledBy(player, (EntityType)stat.getValue()); + + //handle "first death" + else if(stat.getType() == Stats.CUSTOM && + Objects.equals(stat.getValue(), Stats.DEATHS) && + FIRST_CUSTOM_STATS.contains(stat.getValue())) + broadcastFirstDeath(player); + + //handle custom stats + else if(stat.getType() == Stats.CUSTOM && FIRST_CUSTOM_STATS.contains(stat.getValue())) + { + @SuppressWarnings("unchecked") + final var cStat = (Stat)stat; + broadcastFirstCustomStat(player, cStat, stat.format(newValue)); + } } } // -------------------------------------------------- @@ -273,24 +297,6 @@ public static final void broadcastFirstCraft(ServerPlayerEntity player, Item cra .append(pText).append(" just crafted their first ").append(iText).append(".")); } - /** - * Broadcasts a "first death" event to all players in the server. - * @param player A {@link ServerPlayerEntity} that died for their first time. - * @throws NullPointerException If an argument is {@code null}. - */ - public static final void broadcastFirstDeath(ServerPlayerEntity player) - { - final var hardcore = player.getServer().isHardcore(); - final var key = hardcore ? TXT_FIRST_DEATH_HC1 : TXT_FIRST_DEATH; - final var literalBrightSide = hardcore ? " On the bright side, it likely won't happen again." : ""; - - final var pText = formatPlayerText(player); - broadcastBssMessage(player.getServer(), - literal("").append(WATERMARK).append(" ").append(translatable(key, pText)), - literal("").append(WATERMARK).append(" ") - .append(pText).append(" died for their first time." + literalBrightSide)); - } - /** * Broadcasts a "first killed" event to all players in the server. * @param player A {@link ServerPlayerEntity} that killed an {@link EntityType} for their first time. @@ -322,6 +328,44 @@ public static final void broadcastFirstKilledBy(ServerPlayerEntity player, Entit literal("").append(WATERMARK).append(" ").append(pText) .append(" just died to a ").append(etText).append(" for their first time.")); } + + /** + * Broadcasts a "first death" event to all players in the server. + * @param player A {@link ServerPlayerEntity} that died for their first time. + * @throws NullPointerException If an argument is {@code null}. + */ + public static final void broadcastFirstDeath(ServerPlayerEntity player) + { + final var hardcore = player.getServer().isHardcore(); + final var key = hardcore ? TXT_FIRST_DEATH_HC1 : TXT_FIRST_DEATH; + final var literalBrightSide = hardcore ? " On the bright side, it likely won't happen again." : ""; + + final var pText = formatPlayerText(player); + broadcastBssMessage(player.getServer(), + literal("").append(WATERMARK).append(" ").append(translatable(key, pText)), + literal("").append(WATERMARK).append(" ") + .append(pText).append(" died for their first time." + literalBrightSide)); + } + + /** + * Broadcasts a player increasing the value of a "custom stat" for their first time. + * @param player The {@link ServerPlayerEntity} whose general/custom stat increased. + * @param stat The general/custom {@link Stat} in question. + * @param statValue The new {@link Stat} value. + * @throws NullPointerException If an argument is {@code null}. + */ + public static final void broadcastFirstCustomStat( + ServerPlayerEntity player, Stat stat, String statValue) throws NullPointerException + { + final var pText = formatPlayerText(player); + final var sText = literal("").append(getGeneralStatText(stat)).formatted(Formatting.GRAY); + final var vText = literal(statValue).formatted(Formatting.GREEN); + broadcastBssMessage(player.getServer(), + literal("").append(WATERMARK).append(" ").append(translatable(TXT_CUSTOM, pText, sText, vText)), + literal("").append(WATERMARK).append(" ").append(pText) + .append(" just increased their ").append(sText).append(" stat value to ") + .append(vText).append(".")); + } // -------------------------------------------------- /** * Broadcasts a stat announcement to all users in the server.

diff --git a/betterstats-3-fabric-1.20.1/src/main/resources/assets/betterstats/lang/en_us.json b/betterstats-3-fabric-1.20.1/src/main/resources/assets/betterstats/lang/en_us.json index c5d4c5bf..cbaf619f 100644 --- a/betterstats-3-fabric-1.20.1/src/main/resources/assets/betterstats/lang/en_us.json +++ b/betterstats-3-fabric-1.20.1/src/main/resources/assets/betterstats/lang/en_us.json @@ -76,5 +76,6 @@ "betterstats.util.stats.statannouncementsystem.first_death": "%s just died for their first time.", "betterstats.util.stats.statannouncementsystem.first_death.hc1": "%s just died for their first time. On the bright side, it likely won't happen again.", "betterstats.util.stats.statannouncementsystem.first_kill": "%s just killed a %s for their first time.", - "betterstats.util.stats.statannouncementsystem.first_death_to": "%s just died to a %s for their first time." + "betterstats.util.stats.statannouncementsystem.first_death_to": "%s just died to a %s for their first time.", + "betterstats.util.stats.statannouncementsystem.custom": "%s just increased their '%s' stat value to %s." } \ No newline at end of file diff --git a/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/util/stats/SASConfig.java b/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/util/stats/SASConfig.java index 6e954e6b..434e5aa7 100644 --- a/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/util/stats/SASConfig.java +++ b/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/util/stats/SASConfig.java @@ -10,18 +10,18 @@ public class SASConfig implements ACJsonHandler // ================================================== public String[] firstMinedBlocks = new String[] { "diamond_ore", "deepslate_diamond_ore", "ancient_debris", "deepslate_coal_ore", "dragon_egg", "sculk_sensor", "reinforced_deepslate" }; public String[] firstCraftedItems = new String[] { "wooden_pickaxe", "diamond_pickaxe", "beacon", "netherite_block", "ender_eye" }; - public boolean announceFirstDeaths = true; public String[] firstKilledEntities = new String[] { "zombie", "blaze", "enderman", "ender_dragon", "warden", "wither", "player" }; public String[] firstKilledByEntities = new String[] { "ender_dragon", "warden", "wither", "player" }; + public String[] firstCustomStats = new String[] { "deaths" }; // ================================================== public final @Override JsonObject saveToJson() { final var json = new JsonObject(); json.add("firstMinedBlocks", stringArrayToJsonArray(this.firstMinedBlocks)); json.add("firstCraftedItems", stringArrayToJsonArray(this.firstCraftedItems)); - json.addProperty("announceFirstDeaths", this.announceFirstDeaths); json.add("firstKilledEntities", stringArrayToJsonArray(this.firstKilledEntities)); json.add("firstKilledByEntities", stringArrayToJsonArray(this.firstKilledByEntities)); + json.add("firstCustomStats", stringArrayToJsonArray(this.firstCustomStats)); return json; } // -------------------------------------------------- @@ -32,9 +32,9 @@ public class SASConfig implements ACJsonHandler { if(json.has("firstMinedBlocks")) this.firstMinedBlocks = jsonArrayToStringArray(json.getAsJsonArray("firstMinedBlocks")); if(json.has("firstCraftedItems")) this.firstCraftedItems = jsonArrayToStringArray(json.getAsJsonArray("firstCraftedItems")); - if(json.has("announceFirstDeaths")) this.announceFirstDeaths = json.getAsJsonPrimitive("announceFirstDeaths").getAsBoolean(); if(json.has("firstKilledEntities")) this.firstKilledEntities = jsonArrayToStringArray(json.getAsJsonArray("firstKilledEntities")); if(json.has("firstKilledByEntities")) this.firstKilledByEntities = jsonArrayToStringArray(json.getAsJsonArray("firstKilledByEntities")); + if(json.has("firstCustomStats")) this.firstCustomStats = jsonArrayToStringArray(json.getAsJsonArray("firstCustomStats")); return true; } catch(Exception e) { return false; } diff --git a/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/util/stats/StatAnnouncementSystem.java b/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/util/stats/StatAnnouncementSystem.java index 9c04ba24..db0caa5f 100644 --- a/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/util/stats/StatAnnouncementSystem.java +++ b/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/util/stats/StatAnnouncementSystem.java @@ -30,6 +30,7 @@ import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.util.InvalidIdentifierException; +import static io.github.thecsdev.betterstats.api.util.stats.SUGeneralStat.getGeneralStatText; /** * A {@link Class} that handles announcing players doing @@ -47,15 +48,17 @@ public static final String TXT_FIRST_DEATH_HC1 = P + "first_death.hc1"; public static final String TXT_FIRST_KILLED = P + "first_kill"; public static final String TXT_FIRST_KILLED_BY = P + "first_death_to"; + public static final String TXT_CUSTOM = P + "custom"; // private static final Text WATERMARK; private static final BetterStatsConfig BSSC; private static final SASConfig SASC; // -------------------------------------------------- - public static final HashSet FIRST_MINED_BLOCKS; - public static final HashSet FIRST_CRAFTED_ITEMS; + public static final HashSet FIRST_MINED_BLOCKS; + public static final HashSet FIRST_CRAFTED_ITEMS; public static final HashSet> FIRST_KILLED_ENTITIES; public static final HashSet> FIRST_KILLED_BY_ENTITIES; + public static final HashSet FIRST_CUSTOM_STATS; //aka "general stats" // -------------------------------------------------- private StatAnnouncementSystem() {} static @@ -89,6 +92,7 @@ private StatAnnouncementSystem() {} FIRST_CRAFTED_ITEMS = new HashSet(); FIRST_KILLED_ENTITIES = new HashSet>(); FIRST_KILLED_BY_ENTITIES = new HashSet>(); + FIRST_CUSTOM_STATS = new HashSet(); //initialize set entries for(final var fmbId : SASC.firstMinedBlocks) @@ -130,6 +134,16 @@ private StatAnnouncementSystem() {} FIRST_KILLED_BY_ENTITIES.add(fkbe); } catch(InvalidIdentifierException e) { continue; } + + for(final var fcsId : SASC.firstCustomStats) + try + { + final var id = new Identifier(fcsId); + final @Nullable var fcs = Registries.CUSTOM_STAT.getOrEmpty(id).orElse(null); + if(fcs == null) continue; + FIRST_CUSTOM_STATS.add(fcs); + } + catch(InvalidIdentifierException e) { continue; } } // ================================================== /** @@ -168,10 +182,6 @@ else if(oldValue == 0 && newValue > 0) else if(stat.getType() == Stats.CRAFTED && FIRST_CRAFTED_ITEMS.contains(stat.getValue())) broadcastFirstCraft(player, (Item)stat.getValue()); - //handle "first death" - else if(stat.getType() == Stats.CUSTOM && Objects.equals(stat.getValue(), Stats.DEATHS) && SASC.announceFirstDeaths) - broadcastFirstDeath(player); - //handle first "killed" else if(stat.getType() == Stats.KILLED && FIRST_KILLED_ENTITIES.contains(stat.getValue())) broadcastFirstKilled(player, (EntityType)stat.getValue()); @@ -179,6 +189,20 @@ else if(stat.getType() == Stats.KILLED && FIRST_KILLED_ENTITIES.contains(stat.ge //handle first "killed by" else if(stat.getType() == Stats.KILLED_BY && FIRST_KILLED_BY_ENTITIES.contains(stat.getValue())) broadcastFirstKilledBy(player, (EntityType)stat.getValue()); + + //handle "first death" + else if(stat.getType() == Stats.CUSTOM && + Objects.equals(stat.getValue(), Stats.DEATHS) && + FIRST_CUSTOM_STATS.contains(stat.getValue())) + broadcastFirstDeath(player); + + //handle custom stats + else if(stat.getType() == Stats.CUSTOM && FIRST_CUSTOM_STATS.contains(stat.getValue())) + { + @SuppressWarnings("unchecked") + final var cStat = (Stat)stat; + broadcastFirstCustomStat(player, cStat, stat.format(newValue)); + } } } // -------------------------------------------------- @@ -273,24 +297,6 @@ public static final void broadcastFirstCraft(ServerPlayerEntity player, Item cra .append(pText).append(" just crafted their first ").append(iText).append(".")); } - /** - * Broadcasts a "first death" event to all players in the server. - * @param player A {@link ServerPlayerEntity} that died for their first time. - * @throws NullPointerException If an argument is {@code null}. - */ - public static final void broadcastFirstDeath(ServerPlayerEntity player) - { - final var hardcore = player.getServer().isHardcore(); - final var key = hardcore ? TXT_FIRST_DEATH_HC1 : TXT_FIRST_DEATH; - final var literalBrightSide = hardcore ? " On the bright side, it likely won't happen again." : ""; - - final var pText = formatPlayerText(player); - broadcastBssMessage(player.getServer(), - literal("").append(WATERMARK).append(" ").append(translatable(key, pText)), - literal("").append(WATERMARK).append(" ") - .append(pText).append(" died for their first time." + literalBrightSide)); - } - /** * Broadcasts a "first killed" event to all players in the server. * @param player A {@link ServerPlayerEntity} that killed an {@link EntityType} for their first time. @@ -322,6 +328,44 @@ public static final void broadcastFirstKilledBy(ServerPlayerEntity player, Entit literal("").append(WATERMARK).append(" ").append(pText) .append(" just died to a ").append(etText).append(" for their first time.")); } + + /** + * Broadcasts a "first death" event to all players in the server. + * @param player A {@link ServerPlayerEntity} that died for their first time. + * @throws NullPointerException If an argument is {@code null}. + */ + public static final void broadcastFirstDeath(ServerPlayerEntity player) + { + final var hardcore = player.getServer().isHardcore(); + final var key = hardcore ? TXT_FIRST_DEATH_HC1 : TXT_FIRST_DEATH; + final var literalBrightSide = hardcore ? " On the bright side, it likely won't happen again." : ""; + + final var pText = formatPlayerText(player); + broadcastBssMessage(player.getServer(), + literal("").append(WATERMARK).append(" ").append(translatable(key, pText)), + literal("").append(WATERMARK).append(" ") + .append(pText).append(" died for their first time." + literalBrightSide)); + } + + /** + * Broadcasts a player increasing the value of a "custom stat" for their first time. + * @param player The {@link ServerPlayerEntity} whose general/custom stat increased. + * @param stat The general/custom {@link Stat} in question. + * @param statValue The new {@link Stat} value. + * @throws NullPointerException If an argument is {@code null}. + */ + public static final void broadcastFirstCustomStat( + ServerPlayerEntity player, Stat stat, String statValue) throws NullPointerException + { + final var pText = formatPlayerText(player); + final var sText = literal("").append(getGeneralStatText(stat)).formatted(Formatting.GRAY); + final var vText = literal(statValue).formatted(Formatting.GREEN); + broadcastBssMessage(player.getServer(), + literal("").append(WATERMARK).append(" ").append(translatable(TXT_CUSTOM, pText, sText, vText)), + literal("").append(WATERMARK).append(" ").append(pText) + .append(" just increased their ").append(sText).append(" stat value to ") + .append(vText).append(".")); + } // -------------------------------------------------- /** * Broadcasts a stat announcement to all users in the server.

diff --git a/betterstats-3-fabric-1.20.2/src/main/resources/assets/betterstats/lang/en_us.json b/betterstats-3-fabric-1.20.2/src/main/resources/assets/betterstats/lang/en_us.json index c5d4c5bf..cbaf619f 100644 --- a/betterstats-3-fabric-1.20.2/src/main/resources/assets/betterstats/lang/en_us.json +++ b/betterstats-3-fabric-1.20.2/src/main/resources/assets/betterstats/lang/en_us.json @@ -76,5 +76,6 @@ "betterstats.util.stats.statannouncementsystem.first_death": "%s just died for their first time.", "betterstats.util.stats.statannouncementsystem.first_death.hc1": "%s just died for their first time. On the bright side, it likely won't happen again.", "betterstats.util.stats.statannouncementsystem.first_kill": "%s just killed a %s for their first time.", - "betterstats.util.stats.statannouncementsystem.first_death_to": "%s just died to a %s for their first time." + "betterstats.util.stats.statannouncementsystem.first_death_to": "%s just died to a %s for their first time.", + "betterstats.util.stats.statannouncementsystem.custom": "%s just increased their '%s' stat value to %s." } \ No newline at end of file diff --git a/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/util/stats/SASConfig.java b/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/util/stats/SASConfig.java index 6e954e6b..434e5aa7 100644 --- a/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/util/stats/SASConfig.java +++ b/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/util/stats/SASConfig.java @@ -10,18 +10,18 @@ public class SASConfig implements ACJsonHandler // ================================================== public String[] firstMinedBlocks = new String[] { "diamond_ore", "deepslate_diamond_ore", "ancient_debris", "deepslate_coal_ore", "dragon_egg", "sculk_sensor", "reinforced_deepslate" }; public String[] firstCraftedItems = new String[] { "wooden_pickaxe", "diamond_pickaxe", "beacon", "netherite_block", "ender_eye" }; - public boolean announceFirstDeaths = true; public String[] firstKilledEntities = new String[] { "zombie", "blaze", "enderman", "ender_dragon", "warden", "wither", "player" }; public String[] firstKilledByEntities = new String[] { "ender_dragon", "warden", "wither", "player" }; + public String[] firstCustomStats = new String[] { "deaths" }; // ================================================== public final @Override JsonObject saveToJson() { final var json = new JsonObject(); json.add("firstMinedBlocks", stringArrayToJsonArray(this.firstMinedBlocks)); json.add("firstCraftedItems", stringArrayToJsonArray(this.firstCraftedItems)); - json.addProperty("announceFirstDeaths", this.announceFirstDeaths); json.add("firstKilledEntities", stringArrayToJsonArray(this.firstKilledEntities)); json.add("firstKilledByEntities", stringArrayToJsonArray(this.firstKilledByEntities)); + json.add("firstCustomStats", stringArrayToJsonArray(this.firstCustomStats)); return json; } // -------------------------------------------------- @@ -32,9 +32,9 @@ public class SASConfig implements ACJsonHandler { if(json.has("firstMinedBlocks")) this.firstMinedBlocks = jsonArrayToStringArray(json.getAsJsonArray("firstMinedBlocks")); if(json.has("firstCraftedItems")) this.firstCraftedItems = jsonArrayToStringArray(json.getAsJsonArray("firstCraftedItems")); - if(json.has("announceFirstDeaths")) this.announceFirstDeaths = json.getAsJsonPrimitive("announceFirstDeaths").getAsBoolean(); if(json.has("firstKilledEntities")) this.firstKilledEntities = jsonArrayToStringArray(json.getAsJsonArray("firstKilledEntities")); if(json.has("firstKilledByEntities")) this.firstKilledByEntities = jsonArrayToStringArray(json.getAsJsonArray("firstKilledByEntities")); + if(json.has("firstCustomStats")) this.firstCustomStats = jsonArrayToStringArray(json.getAsJsonArray("firstCustomStats")); return true; } catch(Exception e) { return false; } diff --git a/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/util/stats/StatAnnouncementSystem.java b/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/util/stats/StatAnnouncementSystem.java index 9c04ba24..db0caa5f 100644 --- a/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/util/stats/StatAnnouncementSystem.java +++ b/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/util/stats/StatAnnouncementSystem.java @@ -30,6 +30,7 @@ import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.util.InvalidIdentifierException; +import static io.github.thecsdev.betterstats.api.util.stats.SUGeneralStat.getGeneralStatText; /** * A {@link Class} that handles announcing players doing @@ -47,15 +48,17 @@ public static final String TXT_FIRST_DEATH_HC1 = P + "first_death.hc1"; public static final String TXT_FIRST_KILLED = P + "first_kill"; public static final String TXT_FIRST_KILLED_BY = P + "first_death_to"; + public static final String TXT_CUSTOM = P + "custom"; // private static final Text WATERMARK; private static final BetterStatsConfig BSSC; private static final SASConfig SASC; // -------------------------------------------------- - public static final HashSet FIRST_MINED_BLOCKS; - public static final HashSet FIRST_CRAFTED_ITEMS; + public static final HashSet FIRST_MINED_BLOCKS; + public static final HashSet FIRST_CRAFTED_ITEMS; public static final HashSet> FIRST_KILLED_ENTITIES; public static final HashSet> FIRST_KILLED_BY_ENTITIES; + public static final HashSet FIRST_CUSTOM_STATS; //aka "general stats" // -------------------------------------------------- private StatAnnouncementSystem() {} static @@ -89,6 +92,7 @@ private StatAnnouncementSystem() {} FIRST_CRAFTED_ITEMS = new HashSet(); FIRST_KILLED_ENTITIES = new HashSet>(); FIRST_KILLED_BY_ENTITIES = new HashSet>(); + FIRST_CUSTOM_STATS = new HashSet(); //initialize set entries for(final var fmbId : SASC.firstMinedBlocks) @@ -130,6 +134,16 @@ private StatAnnouncementSystem() {} FIRST_KILLED_BY_ENTITIES.add(fkbe); } catch(InvalidIdentifierException e) { continue; } + + for(final var fcsId : SASC.firstCustomStats) + try + { + final var id = new Identifier(fcsId); + final @Nullable var fcs = Registries.CUSTOM_STAT.getOrEmpty(id).orElse(null); + if(fcs == null) continue; + FIRST_CUSTOM_STATS.add(fcs); + } + catch(InvalidIdentifierException e) { continue; } } // ================================================== /** @@ -168,10 +182,6 @@ else if(oldValue == 0 && newValue > 0) else if(stat.getType() == Stats.CRAFTED && FIRST_CRAFTED_ITEMS.contains(stat.getValue())) broadcastFirstCraft(player, (Item)stat.getValue()); - //handle "first death" - else if(stat.getType() == Stats.CUSTOM && Objects.equals(stat.getValue(), Stats.DEATHS) && SASC.announceFirstDeaths) - broadcastFirstDeath(player); - //handle first "killed" else if(stat.getType() == Stats.KILLED && FIRST_KILLED_ENTITIES.contains(stat.getValue())) broadcastFirstKilled(player, (EntityType)stat.getValue()); @@ -179,6 +189,20 @@ else if(stat.getType() == Stats.KILLED && FIRST_KILLED_ENTITIES.contains(stat.ge //handle first "killed by" else if(stat.getType() == Stats.KILLED_BY && FIRST_KILLED_BY_ENTITIES.contains(stat.getValue())) broadcastFirstKilledBy(player, (EntityType)stat.getValue()); + + //handle "first death" + else if(stat.getType() == Stats.CUSTOM && + Objects.equals(stat.getValue(), Stats.DEATHS) && + FIRST_CUSTOM_STATS.contains(stat.getValue())) + broadcastFirstDeath(player); + + //handle custom stats + else if(stat.getType() == Stats.CUSTOM && FIRST_CUSTOM_STATS.contains(stat.getValue())) + { + @SuppressWarnings("unchecked") + final var cStat = (Stat)stat; + broadcastFirstCustomStat(player, cStat, stat.format(newValue)); + } } } // -------------------------------------------------- @@ -273,24 +297,6 @@ public static final void broadcastFirstCraft(ServerPlayerEntity player, Item cra .append(pText).append(" just crafted their first ").append(iText).append(".")); } - /** - * Broadcasts a "first death" event to all players in the server. - * @param player A {@link ServerPlayerEntity} that died for their first time. - * @throws NullPointerException If an argument is {@code null}. - */ - public static final void broadcastFirstDeath(ServerPlayerEntity player) - { - final var hardcore = player.getServer().isHardcore(); - final var key = hardcore ? TXT_FIRST_DEATH_HC1 : TXT_FIRST_DEATH; - final var literalBrightSide = hardcore ? " On the bright side, it likely won't happen again." : ""; - - final var pText = formatPlayerText(player); - broadcastBssMessage(player.getServer(), - literal("").append(WATERMARK).append(" ").append(translatable(key, pText)), - literal("").append(WATERMARK).append(" ") - .append(pText).append(" died for their first time." + literalBrightSide)); - } - /** * Broadcasts a "first killed" event to all players in the server. * @param player A {@link ServerPlayerEntity} that killed an {@link EntityType} for their first time. @@ -322,6 +328,44 @@ public static final void broadcastFirstKilledBy(ServerPlayerEntity player, Entit literal("").append(WATERMARK).append(" ").append(pText) .append(" just died to a ").append(etText).append(" for their first time.")); } + + /** + * Broadcasts a "first death" event to all players in the server. + * @param player A {@link ServerPlayerEntity} that died for their first time. + * @throws NullPointerException If an argument is {@code null}. + */ + public static final void broadcastFirstDeath(ServerPlayerEntity player) + { + final var hardcore = player.getServer().isHardcore(); + final var key = hardcore ? TXT_FIRST_DEATH_HC1 : TXT_FIRST_DEATH; + final var literalBrightSide = hardcore ? " On the bright side, it likely won't happen again." : ""; + + final var pText = formatPlayerText(player); + broadcastBssMessage(player.getServer(), + literal("").append(WATERMARK).append(" ").append(translatable(key, pText)), + literal("").append(WATERMARK).append(" ") + .append(pText).append(" died for their first time." + literalBrightSide)); + } + + /** + * Broadcasts a player increasing the value of a "custom stat" for their first time. + * @param player The {@link ServerPlayerEntity} whose general/custom stat increased. + * @param stat The general/custom {@link Stat} in question. + * @param statValue The new {@link Stat} value. + * @throws NullPointerException If an argument is {@code null}. + */ + public static final void broadcastFirstCustomStat( + ServerPlayerEntity player, Stat stat, String statValue) throws NullPointerException + { + final var pText = formatPlayerText(player); + final var sText = literal("").append(getGeneralStatText(stat)).formatted(Formatting.GRAY); + final var vText = literal(statValue).formatted(Formatting.GREEN); + broadcastBssMessage(player.getServer(), + literal("").append(WATERMARK).append(" ").append(translatable(TXT_CUSTOM, pText, sText, vText)), + literal("").append(WATERMARK).append(" ").append(pText) + .append(" just increased their ").append(sText).append(" stat value to ") + .append(vText).append(".")); + } // -------------------------------------------------- /** * Broadcasts a stat announcement to all users in the server.

diff --git a/betterstats-3-fabric-1.20.4/src/main/resources/assets/betterstats/lang/en_us.json b/betterstats-3-fabric-1.20.4/src/main/resources/assets/betterstats/lang/en_us.json index c5d4c5bf..cbaf619f 100644 --- a/betterstats-3-fabric-1.20.4/src/main/resources/assets/betterstats/lang/en_us.json +++ b/betterstats-3-fabric-1.20.4/src/main/resources/assets/betterstats/lang/en_us.json @@ -76,5 +76,6 @@ "betterstats.util.stats.statannouncementsystem.first_death": "%s just died for their first time.", "betterstats.util.stats.statannouncementsystem.first_death.hc1": "%s just died for their first time. On the bright side, it likely won't happen again.", "betterstats.util.stats.statannouncementsystem.first_kill": "%s just killed a %s for their first time.", - "betterstats.util.stats.statannouncementsystem.first_death_to": "%s just died to a %s for their first time." + "betterstats.util.stats.statannouncementsystem.first_death_to": "%s just died to a %s for their first time.", + "betterstats.util.stats.statannouncementsystem.custom": "%s just increased their '%s' stat value to %s." } \ No newline at end of file