diff --git a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/BetterStatsConfig.java b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/BetterStatsConfig.java index 34b65a12..046a596f 100644 --- a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/BetterStatsConfig.java +++ b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/BetterStatsConfig.java @@ -1,5 +1,7 @@ package io.github.thecsdev.betterstats; +import java.util.Locale; + import io.github.thecsdev.betterstats.util.stats.SASConfig; import io.github.thecsdev.tcdcommons.api.config.AutoConfig; import io.github.thecsdev.tcdcommons.api.config.annotation.NonSerialized; @@ -17,6 +19,13 @@ public class BetterStatsConfig extends AutoConfig * MUST NOT AND SHALL NOT BE DONE WITHOUT THE USER'S CONSENT! */ public static @NonSerialized boolean CLIENT_NET_CONSENT = false; + + /** + * Defines whether or not certain features are available for + * a given user, such as specific API endpoints, and the + * user being shown certain links in GUI interfaces. + */ + public static final @NonSerialized boolean RESTRICTED_MODE; // -------------------------------------------------- public @SerializedAs("client-guiMobsFollowCursor") boolean guiMobsFollowCursor = true; public @SerializedAs("client-trustAllServersBssNet") boolean trustAllServersBssNet = true; @@ -25,5 +34,12 @@ public class BetterStatsConfig extends AutoConfig public @SerializedAs("server-sasConfig") SASConfig sasConfig = new SASConfig(); // ================================================== public BetterStatsConfig(String name) { super(name); } + static + { + //define RESTRICTED_MODE value + final var lc = Locale.getDefault().getCountry().toLowerCase(); + final var rc = "cn".equals(lc); + RESTRICTED_MODE = rc; //TODO - How do I check if the client is authenticated with Mojang? + } // ================================================== } \ No newline at end of file diff --git a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/api/registry/BSRegistries.java b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/api/registry/BSRegistries.java index 960c698a..54c9f5a2 100644 --- a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/api/registry/BSRegistries.java +++ b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/api/registry/BSRegistries.java @@ -1,5 +1,6 @@ package io.github.thecsdev.betterstats.api.registry; +import static io.github.thecsdev.tcdcommons.api.util.TextUtils.literal; import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable; import java.util.HashMap; import java.util.Map; @@ -15,6 +16,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.item.Item; +import net.minecraft.registry.Registries; import net.minecraft.stat.StatType; import net.minecraft.stat.Stats; import net.minecraft.text.Text; @@ -62,6 +64,15 @@ private BSRegistries() {} * @apiNote The {@link Function} must not return {@code null}! */ public static final Map>, Function> ENTITY_STAT_TEXT_FORMATTER; + + /** + * A {@link Map} of {@link Text}s representing "phrases" for each entity stat type.
+ * For example:
+ * - {@link Stats#KILLED} becomes "Kills"
+ * - {@link Stats#KILLED_BY} becomes "Died to"
+ * - and so on... + */ + public static final Map>, Text> ENTITY_STAT_PHRASE; // -------------------------------------------------- static { @@ -69,6 +80,7 @@ private BSRegistries() {} ITEM_WIKIS = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); MOB_WIKIS = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); ENTITY_STAT_TEXT_FORMATTER = new HashMap<>(); + ENTITY_STAT_PHRASE = new HashMap<>(); //the default Wiki for 'minecraft' is now 'minecraft.wiki' final String mc = new Identifier("air").getNamespace(); @@ -90,6 +102,9 @@ private BSRegistries() {} translatable("stat_type.minecraft.killed_by.none", entityName) : translatable("stat_type.minecraft.killed_by", entityName, Integer.toString(stat.deaths)); }); + + ENTITY_STAT_PHRASE.put(Stats.KILLED, translatable("betterstats.api.client.gui.stats.widget.mobstatwidget.kills")); + ENTITY_STAT_PHRASE.put(Stats.KILLED_BY, translatable("betterstats.api.client.gui.stats.widget.mobstatwidget.deaths")); } // ================================================== /** @@ -98,7 +113,7 @@ private BSRegistries() {} * @return {@code null} if the URL is not found. * @throws NullPointerException If the argument is null. */ - public static @Nullable String getItemWikiURL(Identifier itemId) throws NullPointerException + public static final @Nullable String getItemWikiURL(Identifier itemId) throws NullPointerException { Objects.requireNonNull(itemId); var supplier = ITEM_WIKIS.get(itemId.getNamespace()); @@ -112,12 +127,23 @@ private BSRegistries() {} * @return {@code null} if the URL is not found. * @throws NullPointerException If the argument is null. */ - public static @Nullable String getMobWikiURL(Identifier entityId) throws NullPointerException + public static final @Nullable String getMobWikiURL(Identifier entityId) throws NullPointerException { Objects.requireNonNull(entityId); var supplier = MOB_WIKIS.get(entityId.getNamespace()); if(supplier == null) return null; else return supplier.apply(entityId); } + + /** + * Obtains the {@link Text} representing the "phrase" for a given entity {@link StatType}. + * @param statType The {@link StatType}. + */ + public static final Text getEntityStatTypePhrase(StatType> statType) + { + final @Nullable var p = ENTITY_STAT_PHRASE.get(statType); + if(p != null) return p; + else return literal(Objects.toString(Registries.STAT_TYPE.getId(statType))); + } // ================================================== } \ No newline at end of file diff --git a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/hud/entry/StatsHudMobEntry.java b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/hud/entry/StatsHudMobEntry.java index f99f347b..4423d8ac 100644 --- a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/hud/entry/StatsHudMobEntry.java +++ b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/hud/entry/StatsHudMobEntry.java @@ -1,5 +1,6 @@ package io.github.thecsdev.betterstats.client.gui.screen.hud.entry; +import static io.github.thecsdev.betterstats.api.registry.BSRegistries.getEntityStatTypePhrase; import static io.github.thecsdev.tcdcommons.api.util.TextUtils.literal; import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable; @@ -11,7 +12,6 @@ import io.github.thecsdev.betterstats.api.client.gui.stats.widget.ItemStatWidget; import io.github.thecsdev.betterstats.api.client.gui.stats.widget.MobStatWidget; import io.github.thecsdev.betterstats.api.client.util.io.LocalPlayerStatsProvider; -import io.github.thecsdev.betterstats.api.util.enumerations.MobStatType; import io.github.thecsdev.betterstats.api.util.io.IStatsProvider; import io.github.thecsdev.betterstats.api.util.stats.SUMobStat; import io.github.thecsdev.tcdcommons.api.client.gui.TElement; @@ -19,6 +19,9 @@ import io.github.thecsdev.tcdcommons.api.client.gui.screen.TWidgetHudScreen; import io.github.thecsdev.tcdcommons.api.client.gui.util.TDrawContext; import net.minecraft.entity.EntityType; +import net.minecraft.registry.Registries; +import net.minecraft.stat.StatType; +import net.minecraft.stat.Stats; import net.minecraft.text.Text; public final class StatsHudMobEntry extends TWidgetHudScreen.WidgetEntry @@ -28,7 +31,7 @@ public final class StatsHudMobEntry extends TWidgetHudScreen.WidgetEntry entityType; - protected MobStatType mode = MobStatType.KILLED; + protected StatType> mode = Stats.KILLED; // ================================================== public StatsHudMobEntry(SUMobStat stat) throws NullPointerException { this(stat.getStatsProvider(), stat.getEntityType()); } public StatsHudMobEntry(IStatsProvider statsProvider, EntityType entityType) throws NullPointerException @@ -48,11 +51,18 @@ public StatsHudMobEntry(IStatsProvider statsProvider, EntityType entityType) final var el = new Element(); el.eContextMenu.register((__, cMenu) -> { - for(final var ist : MobStatType.values()) + //entity stat type entries + for(final var statType : Registries.STAT_TYPE) { - cMenu.addButton(ist.getText(), ___ -> + //check the stat type and if it's compatible + if(statType.getRegistry() != Registries.ENTITY_TYPE) + continue; + final @SuppressWarnings("unchecked") var statTypeE = (StatType>)statType; + + //create a button that will switch to the given stat type, and refresh + cMenu.addButton(getEntityStatTypePhrase(statTypeE), ___ -> { - this.mode = ist; + this.mode = statTypeE; refreshEntry(); }); } @@ -64,12 +74,13 @@ public StatsHudMobEntry(IStatsProvider statsProvider, EntityType entityType) // -------------------------------------------------- private final CustomStatElement createCustomStatElement(SUMobStat stat) { - //collect info - final int i = ItemStatWidget.SIZE; - @Nullable Text left = this.mode.getText(); - @Nullable Text right = literal(Integer.toString(this.mode.getStatValue(stat))); + //prepare variables + if(this.mode == null) this.mode = Stats.KILLED; + @Nullable Text left = getEntityStatTypePhrase(this.mode); + @Nullable Text right = literal(Integer.toString(this.statsProvider.getStatValue(this.mode, this.entityType))); + //create and return - return new CustomStatElement(i, 0, WIDTH - i, left, right); + return new CustomStatElement(ItemStatWidget.SIZE, 0, WIDTH - ItemStatWidget.SIZE, left, right); } // ================================================== private final class Element extends TElement diff --git a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/MenuBarPanel.java b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/MenuBarPanel.java index cd7274fd..172468be 100644 --- a/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/MenuBarPanel.java +++ b/betterstats-3-fabric-1.20.1/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/MenuBarPanel.java @@ -7,6 +7,7 @@ import static io.github.thecsdev.betterstats.BetterStats.URL_MODRINTH; import static io.github.thecsdev.betterstats.BetterStats.URL_SOURCES; import static io.github.thecsdev.betterstats.BetterStats.URL_YOUTUBE; +import static io.github.thecsdev.betterstats.BetterStatsConfig.RESTRICTED_MODE; import static io.github.thecsdev.betterstats.api.client.registry.BSClientRegistries.STATS_TAB; import static io.github.thecsdev.betterstats.client.BetterStatsClient.MC_CLIENT; import static io.github.thecsdev.tcdcommons.api.client.gui.util.GuiUtils.showUrlPrompt; @@ -14,7 +15,6 @@ import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable; import java.awt.Color; -import java.util.Locale; import java.util.Map.Entry; import java.util.Objects; @@ -166,10 +166,9 @@ public MenuBarPanel(int x, int y, int width, MenuBarPanelProxy proxy) throws Nul { //create the context menu final var cMenu = new TContextMenuPanel(btn); - final boolean cn = "CN".equalsIgnoreCase(Locale.getDefault().getCountry()); //url-s - if(!cn) + if(!RESTRICTED_MODE) { cMenu.addButton(translatable(tr + "menu_about.source"), __ -> showUrlPrompt(URL_SOURCES, false)); cMenu.addButton(translatable("menu.reportBugs"), __ -> showUrlPrompt(URL_ISSUES, false)); @@ -177,7 +176,7 @@ public MenuBarPanel(int x, int y, int width, MenuBarPanelProxy proxy) throws Nul } cMenu.addButton(translatable(tr + "menu_about.curseforge"), __ -> showUrlPrompt(URL_CURSEFORGE, false)); cMenu.addButton(translatable(tr + "menu_about.modrinth"), __ -> showUrlPrompt(URL_MODRINTH, false)); - if(!cn) + if(!RESTRICTED_MODE) { cMenu.addSeparator(); cMenu.addButton(translatable(tr + "menu_about.youtube"), __ -> showUrlPrompt(URL_YOUTUBE, false)); 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 46c06d26..77507cd1 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 @@ -37,8 +37,8 @@ "betterstats.api.util.enumerations.filtergroupby.default": "Default", "betterstats.api.util.enumerations.filtergroupby.mod": "Mod", - "betterstats.api.client.gui.stats.widget.mobstatwidget.kills": "Kills", - "betterstats.api.client.gui.stats.widget.mobstatwidget.deaths": "Deaths", + "betterstats.api.client.gui.stats.widget.mobstatwidget.kills": "Killed", + "betterstats.api.client.gui.stats.widget.mobstatwidget.deaths": "Died to", "betterstats.api.client.gui.stats.widget.playerbadgestatwidget.obtained": "Obtained", "betterstats.api.client.gui.stats.widget.generalstatwidget.value": "Value", diff --git a/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/BetterStatsConfig.java b/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/BetterStatsConfig.java index 34b65a12..046a596f 100644 --- a/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/BetterStatsConfig.java +++ b/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/BetterStatsConfig.java @@ -1,5 +1,7 @@ package io.github.thecsdev.betterstats; +import java.util.Locale; + import io.github.thecsdev.betterstats.util.stats.SASConfig; import io.github.thecsdev.tcdcommons.api.config.AutoConfig; import io.github.thecsdev.tcdcommons.api.config.annotation.NonSerialized; @@ -17,6 +19,13 @@ public class BetterStatsConfig extends AutoConfig * MUST NOT AND SHALL NOT BE DONE WITHOUT THE USER'S CONSENT! */ public static @NonSerialized boolean CLIENT_NET_CONSENT = false; + + /** + * Defines whether or not certain features are available for + * a given user, such as specific API endpoints, and the + * user being shown certain links in GUI interfaces. + */ + public static final @NonSerialized boolean RESTRICTED_MODE; // -------------------------------------------------- public @SerializedAs("client-guiMobsFollowCursor") boolean guiMobsFollowCursor = true; public @SerializedAs("client-trustAllServersBssNet") boolean trustAllServersBssNet = true; @@ -25,5 +34,12 @@ public class BetterStatsConfig extends AutoConfig public @SerializedAs("server-sasConfig") SASConfig sasConfig = new SASConfig(); // ================================================== public BetterStatsConfig(String name) { super(name); } + static + { + //define RESTRICTED_MODE value + final var lc = Locale.getDefault().getCountry().toLowerCase(); + final var rc = "cn".equals(lc); + RESTRICTED_MODE = rc; //TODO - How do I check if the client is authenticated with Mojang? + } // ================================================== } \ No newline at end of file diff --git a/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/api/registry/BSRegistries.java b/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/api/registry/BSRegistries.java index ed45b143..c8958280 100644 --- a/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/api/registry/BSRegistries.java +++ b/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/api/registry/BSRegistries.java @@ -1,5 +1,6 @@ package io.github.thecsdev.betterstats.api.registry; +import static io.github.thecsdev.tcdcommons.api.util.TextUtils.literal; import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable; import java.util.HashMap; @@ -16,6 +17,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.item.Item; +import net.minecraft.registry.Registries; import net.minecraft.stat.StatType; import net.minecraft.stat.Stats; import net.minecraft.text.Text; @@ -63,6 +65,15 @@ private BSRegistries() {} * @apiNote The {@link Function} must not return {@code null}! */ public static final Map>, Function> ENTITY_STAT_TEXT_FORMATTER; + + /** + * A {@link Map} of {@link Text}s representing "phrases" for each entity stat type.
+ * For example:
+ * - {@link Stats#KILLED} becomes "Kills"
+ * - {@link Stats#KILLED_BY} becomes "Died to"
+ * - and so on... + */ + public static final Map>, Text> ENTITY_STAT_PHRASE; // -------------------------------------------------- static { @@ -70,6 +81,7 @@ private BSRegistries() {} ITEM_WIKIS = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); MOB_WIKIS = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); ENTITY_STAT_TEXT_FORMATTER = new HashMap<>(); + ENTITY_STAT_PHRASE = new HashMap<>(); //the default Wiki for 'minecraft' is now 'minecraft.wiki' final String mc = new Identifier("air").getNamespace(); @@ -91,6 +103,9 @@ private BSRegistries() {} translatable("stat_type.minecraft.killed_by.none", entityName) : translatable("stat_type.minecraft.killed_by", entityName, Integer.toString(stat.deaths)); }); + + ENTITY_STAT_PHRASE.put(Stats.KILLED, translatable("betterstats.api.client.gui.stats.widget.mobstatwidget.kills")); + ENTITY_STAT_PHRASE.put(Stats.KILLED_BY, translatable("betterstats.api.client.gui.stats.widget.mobstatwidget.deaths")); } // ================================================== /** @@ -99,7 +114,7 @@ private BSRegistries() {} * @return {@code null} if the URL is not found. * @throws NullPointerException If the argument is null. */ - public static @Nullable String getItemWikiURL(Identifier itemId) throws NullPointerException + public static final @Nullable String getItemWikiURL(Identifier itemId) throws NullPointerException { Objects.requireNonNull(itemId); var supplier = ITEM_WIKIS.get(itemId.getNamespace()); @@ -113,12 +128,23 @@ private BSRegistries() {} * @return {@code null} if the URL is not found. * @throws NullPointerException If the argument is null. */ - public static @Nullable String getMobWikiURL(Identifier entityId) throws NullPointerException + public static final @Nullable String getMobWikiURL(Identifier entityId) throws NullPointerException { Objects.requireNonNull(entityId); var supplier = MOB_WIKIS.get(entityId.getNamespace()); if(supplier == null) return null; else return supplier.apply(entityId); } + + /** + * Obtains the {@link Text} representing the "phrase" for a given entity {@link StatType}. + * @param statType The {@link StatType}. + */ + public static final Text getEntityStatTypePhrase(StatType> statType) + { + final @Nullable var p = ENTITY_STAT_PHRASE.get(statType); + if(p != null) return p; + else return literal(Objects.toString(Registries.STAT_TYPE.getId(statType))); + } // ================================================== } \ No newline at end of file diff --git a/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/hud/entry/StatsHudMobEntry.java b/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/hud/entry/StatsHudMobEntry.java index f99f347b..4423d8ac 100644 --- a/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/hud/entry/StatsHudMobEntry.java +++ b/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/hud/entry/StatsHudMobEntry.java @@ -1,5 +1,6 @@ package io.github.thecsdev.betterstats.client.gui.screen.hud.entry; +import static io.github.thecsdev.betterstats.api.registry.BSRegistries.getEntityStatTypePhrase; import static io.github.thecsdev.tcdcommons.api.util.TextUtils.literal; import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable; @@ -11,7 +12,6 @@ import io.github.thecsdev.betterstats.api.client.gui.stats.widget.ItemStatWidget; import io.github.thecsdev.betterstats.api.client.gui.stats.widget.MobStatWidget; import io.github.thecsdev.betterstats.api.client.util.io.LocalPlayerStatsProvider; -import io.github.thecsdev.betterstats.api.util.enumerations.MobStatType; import io.github.thecsdev.betterstats.api.util.io.IStatsProvider; import io.github.thecsdev.betterstats.api.util.stats.SUMobStat; import io.github.thecsdev.tcdcommons.api.client.gui.TElement; @@ -19,6 +19,9 @@ import io.github.thecsdev.tcdcommons.api.client.gui.screen.TWidgetHudScreen; import io.github.thecsdev.tcdcommons.api.client.gui.util.TDrawContext; import net.minecraft.entity.EntityType; +import net.minecraft.registry.Registries; +import net.minecraft.stat.StatType; +import net.minecraft.stat.Stats; import net.minecraft.text.Text; public final class StatsHudMobEntry extends TWidgetHudScreen.WidgetEntry @@ -28,7 +31,7 @@ public final class StatsHudMobEntry extends TWidgetHudScreen.WidgetEntry entityType; - protected MobStatType mode = MobStatType.KILLED; + protected StatType> mode = Stats.KILLED; // ================================================== public StatsHudMobEntry(SUMobStat stat) throws NullPointerException { this(stat.getStatsProvider(), stat.getEntityType()); } public StatsHudMobEntry(IStatsProvider statsProvider, EntityType entityType) throws NullPointerException @@ -48,11 +51,18 @@ public StatsHudMobEntry(IStatsProvider statsProvider, EntityType entityType) final var el = new Element(); el.eContextMenu.register((__, cMenu) -> { - for(final var ist : MobStatType.values()) + //entity stat type entries + for(final var statType : Registries.STAT_TYPE) { - cMenu.addButton(ist.getText(), ___ -> + //check the stat type and if it's compatible + if(statType.getRegistry() != Registries.ENTITY_TYPE) + continue; + final @SuppressWarnings("unchecked") var statTypeE = (StatType>)statType; + + //create a button that will switch to the given stat type, and refresh + cMenu.addButton(getEntityStatTypePhrase(statTypeE), ___ -> { - this.mode = ist; + this.mode = statTypeE; refreshEntry(); }); } @@ -64,12 +74,13 @@ public StatsHudMobEntry(IStatsProvider statsProvider, EntityType entityType) // -------------------------------------------------- private final CustomStatElement createCustomStatElement(SUMobStat stat) { - //collect info - final int i = ItemStatWidget.SIZE; - @Nullable Text left = this.mode.getText(); - @Nullable Text right = literal(Integer.toString(this.mode.getStatValue(stat))); + //prepare variables + if(this.mode == null) this.mode = Stats.KILLED; + @Nullable Text left = getEntityStatTypePhrase(this.mode); + @Nullable Text right = literal(Integer.toString(this.statsProvider.getStatValue(this.mode, this.entityType))); + //create and return - return new CustomStatElement(i, 0, WIDTH - i, left, right); + return new CustomStatElement(ItemStatWidget.SIZE, 0, WIDTH - ItemStatWidget.SIZE, left, right); } // ================================================== private final class Element extends TElement diff --git a/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/MenuBarPanel.java b/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/MenuBarPanel.java index cd7274fd..172468be 100644 --- a/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/MenuBarPanel.java +++ b/betterstats-3-fabric-1.20.2/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/MenuBarPanel.java @@ -7,6 +7,7 @@ import static io.github.thecsdev.betterstats.BetterStats.URL_MODRINTH; import static io.github.thecsdev.betterstats.BetterStats.URL_SOURCES; import static io.github.thecsdev.betterstats.BetterStats.URL_YOUTUBE; +import static io.github.thecsdev.betterstats.BetterStatsConfig.RESTRICTED_MODE; import static io.github.thecsdev.betterstats.api.client.registry.BSClientRegistries.STATS_TAB; import static io.github.thecsdev.betterstats.client.BetterStatsClient.MC_CLIENT; import static io.github.thecsdev.tcdcommons.api.client.gui.util.GuiUtils.showUrlPrompt; @@ -14,7 +15,6 @@ import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable; import java.awt.Color; -import java.util.Locale; import java.util.Map.Entry; import java.util.Objects; @@ -166,10 +166,9 @@ public MenuBarPanel(int x, int y, int width, MenuBarPanelProxy proxy) throws Nul { //create the context menu final var cMenu = new TContextMenuPanel(btn); - final boolean cn = "CN".equalsIgnoreCase(Locale.getDefault().getCountry()); //url-s - if(!cn) + if(!RESTRICTED_MODE) { cMenu.addButton(translatable(tr + "menu_about.source"), __ -> showUrlPrompt(URL_SOURCES, false)); cMenu.addButton(translatable("menu.reportBugs"), __ -> showUrlPrompt(URL_ISSUES, false)); @@ -177,7 +176,7 @@ public MenuBarPanel(int x, int y, int width, MenuBarPanelProxy proxy) throws Nul } cMenu.addButton(translatable(tr + "menu_about.curseforge"), __ -> showUrlPrompt(URL_CURSEFORGE, false)); cMenu.addButton(translatable(tr + "menu_about.modrinth"), __ -> showUrlPrompt(URL_MODRINTH, false)); - if(!cn) + if(!RESTRICTED_MODE) { cMenu.addSeparator(); cMenu.addButton(translatable(tr + "menu_about.youtube"), __ -> showUrlPrompt(URL_YOUTUBE, false)); 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 28b5b070..f130708d 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 @@ -37,8 +37,8 @@ "betterstats.api.util.enumerations.filtergroupby.default": "Default", "betterstats.api.util.enumerations.filtergroupby.mod": "Mod", - "betterstats.api.client.gui.stats.widget.mobstatwidget.kills": "Kills", - "betterstats.api.client.gui.stats.widget.mobstatwidget.deaths": "Deaths", + "betterstats.api.client.gui.stats.widget.mobstatwidget.kills": "Killed", + "betterstats.api.client.gui.stats.widget.mobstatwidget.deaths": "Died to", "betterstats.api.client.gui.stats.widget.playerbadgestatwidget.obtained": "Obtained", "betterstats.api.client.gui.stats.widget.generalstatwidget.value": "Value", diff --git a/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/BetterStatsConfig.java b/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/BetterStatsConfig.java index 34b65a12..046a596f 100644 --- a/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/BetterStatsConfig.java +++ b/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/BetterStatsConfig.java @@ -1,5 +1,7 @@ package io.github.thecsdev.betterstats; +import java.util.Locale; + import io.github.thecsdev.betterstats.util.stats.SASConfig; import io.github.thecsdev.tcdcommons.api.config.AutoConfig; import io.github.thecsdev.tcdcommons.api.config.annotation.NonSerialized; @@ -17,6 +19,13 @@ public class BetterStatsConfig extends AutoConfig * MUST NOT AND SHALL NOT BE DONE WITHOUT THE USER'S CONSENT! */ public static @NonSerialized boolean CLIENT_NET_CONSENT = false; + + /** + * Defines whether or not certain features are available for + * a given user, such as specific API endpoints, and the + * user being shown certain links in GUI interfaces. + */ + public static final @NonSerialized boolean RESTRICTED_MODE; // -------------------------------------------------- public @SerializedAs("client-guiMobsFollowCursor") boolean guiMobsFollowCursor = true; public @SerializedAs("client-trustAllServersBssNet") boolean trustAllServersBssNet = true; @@ -25,5 +34,12 @@ public class BetterStatsConfig extends AutoConfig public @SerializedAs("server-sasConfig") SASConfig sasConfig = new SASConfig(); // ================================================== public BetterStatsConfig(String name) { super(name); } + static + { + //define RESTRICTED_MODE value + final var lc = Locale.getDefault().getCountry().toLowerCase(); + final var rc = "cn".equals(lc); + RESTRICTED_MODE = rc; //TODO - How do I check if the client is authenticated with Mojang? + } // ================================================== } \ No newline at end of file diff --git a/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/api/registry/BSRegistries.java b/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/api/registry/BSRegistries.java index ed45b143..c8958280 100644 --- a/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/api/registry/BSRegistries.java +++ b/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/api/registry/BSRegistries.java @@ -1,5 +1,6 @@ package io.github.thecsdev.betterstats.api.registry; +import static io.github.thecsdev.tcdcommons.api.util.TextUtils.literal; import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable; import java.util.HashMap; @@ -16,6 +17,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.item.Item; +import net.minecraft.registry.Registries; import net.minecraft.stat.StatType; import net.minecraft.stat.Stats; import net.minecraft.text.Text; @@ -63,6 +65,15 @@ private BSRegistries() {} * @apiNote The {@link Function} must not return {@code null}! */ public static final Map>, Function> ENTITY_STAT_TEXT_FORMATTER; + + /** + * A {@link Map} of {@link Text}s representing "phrases" for each entity stat type.
+ * For example:
+ * - {@link Stats#KILLED} becomes "Kills"
+ * - {@link Stats#KILLED_BY} becomes "Died to"
+ * - and so on... + */ + public static final Map>, Text> ENTITY_STAT_PHRASE; // -------------------------------------------------- static { @@ -70,6 +81,7 @@ private BSRegistries() {} ITEM_WIKIS = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); MOB_WIKIS = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); ENTITY_STAT_TEXT_FORMATTER = new HashMap<>(); + ENTITY_STAT_PHRASE = new HashMap<>(); //the default Wiki for 'minecraft' is now 'minecraft.wiki' final String mc = new Identifier("air").getNamespace(); @@ -91,6 +103,9 @@ private BSRegistries() {} translatable("stat_type.minecraft.killed_by.none", entityName) : translatable("stat_type.minecraft.killed_by", entityName, Integer.toString(stat.deaths)); }); + + ENTITY_STAT_PHRASE.put(Stats.KILLED, translatable("betterstats.api.client.gui.stats.widget.mobstatwidget.kills")); + ENTITY_STAT_PHRASE.put(Stats.KILLED_BY, translatable("betterstats.api.client.gui.stats.widget.mobstatwidget.deaths")); } // ================================================== /** @@ -99,7 +114,7 @@ private BSRegistries() {} * @return {@code null} if the URL is not found. * @throws NullPointerException If the argument is null. */ - public static @Nullable String getItemWikiURL(Identifier itemId) throws NullPointerException + public static final @Nullable String getItemWikiURL(Identifier itemId) throws NullPointerException { Objects.requireNonNull(itemId); var supplier = ITEM_WIKIS.get(itemId.getNamespace()); @@ -113,12 +128,23 @@ private BSRegistries() {} * @return {@code null} if the URL is not found. * @throws NullPointerException If the argument is null. */ - public static @Nullable String getMobWikiURL(Identifier entityId) throws NullPointerException + public static final @Nullable String getMobWikiURL(Identifier entityId) throws NullPointerException { Objects.requireNonNull(entityId); var supplier = MOB_WIKIS.get(entityId.getNamespace()); if(supplier == null) return null; else return supplier.apply(entityId); } + + /** + * Obtains the {@link Text} representing the "phrase" for a given entity {@link StatType}. + * @param statType The {@link StatType}. + */ + public static final Text getEntityStatTypePhrase(StatType> statType) + { + final @Nullable var p = ENTITY_STAT_PHRASE.get(statType); + if(p != null) return p; + else return literal(Objects.toString(Registries.STAT_TYPE.getId(statType))); + } // ================================================== } \ No newline at end of file diff --git a/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/hud/entry/StatsHudMobEntry.java b/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/hud/entry/StatsHudMobEntry.java index f99f347b..4423d8ac 100644 --- a/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/hud/entry/StatsHudMobEntry.java +++ b/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/client/gui/screen/hud/entry/StatsHudMobEntry.java @@ -1,5 +1,6 @@ package io.github.thecsdev.betterstats.client.gui.screen.hud.entry; +import static io.github.thecsdev.betterstats.api.registry.BSRegistries.getEntityStatTypePhrase; import static io.github.thecsdev.tcdcommons.api.util.TextUtils.literal; import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable; @@ -11,7 +12,6 @@ import io.github.thecsdev.betterstats.api.client.gui.stats.widget.ItemStatWidget; import io.github.thecsdev.betterstats.api.client.gui.stats.widget.MobStatWidget; import io.github.thecsdev.betterstats.api.client.util.io.LocalPlayerStatsProvider; -import io.github.thecsdev.betterstats.api.util.enumerations.MobStatType; import io.github.thecsdev.betterstats.api.util.io.IStatsProvider; import io.github.thecsdev.betterstats.api.util.stats.SUMobStat; import io.github.thecsdev.tcdcommons.api.client.gui.TElement; @@ -19,6 +19,9 @@ import io.github.thecsdev.tcdcommons.api.client.gui.screen.TWidgetHudScreen; import io.github.thecsdev.tcdcommons.api.client.gui.util.TDrawContext; import net.minecraft.entity.EntityType; +import net.minecraft.registry.Registries; +import net.minecraft.stat.StatType; +import net.minecraft.stat.Stats; import net.minecraft.text.Text; public final class StatsHudMobEntry extends TWidgetHudScreen.WidgetEntry @@ -28,7 +31,7 @@ public final class StatsHudMobEntry extends TWidgetHudScreen.WidgetEntry entityType; - protected MobStatType mode = MobStatType.KILLED; + protected StatType> mode = Stats.KILLED; // ================================================== public StatsHudMobEntry(SUMobStat stat) throws NullPointerException { this(stat.getStatsProvider(), stat.getEntityType()); } public StatsHudMobEntry(IStatsProvider statsProvider, EntityType entityType) throws NullPointerException @@ -48,11 +51,18 @@ public StatsHudMobEntry(IStatsProvider statsProvider, EntityType entityType) final var el = new Element(); el.eContextMenu.register((__, cMenu) -> { - for(final var ist : MobStatType.values()) + //entity stat type entries + for(final var statType : Registries.STAT_TYPE) { - cMenu.addButton(ist.getText(), ___ -> + //check the stat type and if it's compatible + if(statType.getRegistry() != Registries.ENTITY_TYPE) + continue; + final @SuppressWarnings("unchecked") var statTypeE = (StatType>)statType; + + //create a button that will switch to the given stat type, and refresh + cMenu.addButton(getEntityStatTypePhrase(statTypeE), ___ -> { - this.mode = ist; + this.mode = statTypeE; refreshEntry(); }); } @@ -64,12 +74,13 @@ public StatsHudMobEntry(IStatsProvider statsProvider, EntityType entityType) // -------------------------------------------------- private final CustomStatElement createCustomStatElement(SUMobStat stat) { - //collect info - final int i = ItemStatWidget.SIZE; - @Nullable Text left = this.mode.getText(); - @Nullable Text right = literal(Integer.toString(this.mode.getStatValue(stat))); + //prepare variables + if(this.mode == null) this.mode = Stats.KILLED; + @Nullable Text left = getEntityStatTypePhrase(this.mode); + @Nullable Text right = literal(Integer.toString(this.statsProvider.getStatValue(this.mode, this.entityType))); + //create and return - return new CustomStatElement(i, 0, WIDTH - i, left, right); + return new CustomStatElement(ItemStatWidget.SIZE, 0, WIDTH - ItemStatWidget.SIZE, left, right); } // ================================================== private final class Element extends TElement diff --git a/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/MenuBarPanel.java b/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/MenuBarPanel.java index cd7274fd..172468be 100644 --- a/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/MenuBarPanel.java +++ b/betterstats-3-fabric-1.20.4/src/main/java/io/github/thecsdev/betterstats/client/gui/stats/panel/MenuBarPanel.java @@ -7,6 +7,7 @@ import static io.github.thecsdev.betterstats.BetterStats.URL_MODRINTH; import static io.github.thecsdev.betterstats.BetterStats.URL_SOURCES; import static io.github.thecsdev.betterstats.BetterStats.URL_YOUTUBE; +import static io.github.thecsdev.betterstats.BetterStatsConfig.RESTRICTED_MODE; import static io.github.thecsdev.betterstats.api.client.registry.BSClientRegistries.STATS_TAB; import static io.github.thecsdev.betterstats.client.BetterStatsClient.MC_CLIENT; import static io.github.thecsdev.tcdcommons.api.client.gui.util.GuiUtils.showUrlPrompt; @@ -14,7 +15,6 @@ import static io.github.thecsdev.tcdcommons.api.util.TextUtils.translatable; import java.awt.Color; -import java.util.Locale; import java.util.Map.Entry; import java.util.Objects; @@ -166,10 +166,9 @@ public MenuBarPanel(int x, int y, int width, MenuBarPanelProxy proxy) throws Nul { //create the context menu final var cMenu = new TContextMenuPanel(btn); - final boolean cn = "CN".equalsIgnoreCase(Locale.getDefault().getCountry()); //url-s - if(!cn) + if(!RESTRICTED_MODE) { cMenu.addButton(translatable(tr + "menu_about.source"), __ -> showUrlPrompt(URL_SOURCES, false)); cMenu.addButton(translatable("menu.reportBugs"), __ -> showUrlPrompt(URL_ISSUES, false)); @@ -177,7 +176,7 @@ public MenuBarPanel(int x, int y, int width, MenuBarPanelProxy proxy) throws Nul } cMenu.addButton(translatable(tr + "menu_about.curseforge"), __ -> showUrlPrompt(URL_CURSEFORGE, false)); cMenu.addButton(translatable(tr + "menu_about.modrinth"), __ -> showUrlPrompt(URL_MODRINTH, false)); - if(!cn) + if(!RESTRICTED_MODE) { cMenu.addSeparator(); cMenu.addButton(translatable(tr + "menu_about.youtube"), __ -> showUrlPrompt(URL_YOUTUBE, false)); 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 28b5b070..f130708d 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 @@ -37,8 +37,8 @@ "betterstats.api.util.enumerations.filtergroupby.default": "Default", "betterstats.api.util.enumerations.filtergroupby.mod": "Mod", - "betterstats.api.client.gui.stats.widget.mobstatwidget.kills": "Kills", - "betterstats.api.client.gui.stats.widget.mobstatwidget.deaths": "Deaths", + "betterstats.api.client.gui.stats.widget.mobstatwidget.kills": "Killed", + "betterstats.api.client.gui.stats.widget.mobstatwidget.deaths": "Died to", "betterstats.api.client.gui.stats.widget.playerbadgestatwidget.obtained": "Obtained", "betterstats.api.client.gui.stats.widget.generalstatwidget.value": "Value",