diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 5add4c53..4d48a3e1 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -3,7 +3,7 @@ import net.labymod.labygradle.common.extension.LabyModAnnotationProcessorExtensi dependencies { labyProcessor() labyApi("api") - addonMavenDependency("com.rappytv.globaltags:GlobalTagsJava:1.1.9") + addonMavenDependency("com.rappytv.globaltags:GlobalTagsJava:1.2.0") } labyModAnnotationProcessor { diff --git a/api/src/main/java/com/rappytv/globaltags/api/GlobalTagAPI.java b/api/src/main/java/com/rappytv/globaltags/api/GlobalTagAPI.java index 0232e847..f6c5076f 100644 --- a/api/src/main/java/com/rappytv/globaltags/api/GlobalTagAPI.java +++ b/api/src/main/java/com/rappytv/globaltags/api/GlobalTagAPI.java @@ -2,16 +2,15 @@ import com.rappytv.globaltags.wrapper.GlobalTagsAPI; import com.rappytv.globaltags.wrapper.enums.AuthProvider; +import java.util.UUID; +import java.util.function.Supplier; import net.labymod.api.Laby; import net.labymod.api.client.component.Component; -import net.labymod.api.client.component.serializer.legacy.LegacyComponentSerializer; import net.labymod.api.labyconnect.LabyConnectSession; import net.labymod.api.labyconnect.TokenStorage.Purpose; import net.labymod.api.labyconnect.TokenStorage.Token; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.UUID; -import java.util.function.Supplier; public class GlobalTagAPI extends GlobalTagsAPI { @@ -25,20 +24,21 @@ public GlobalTagAPI(Agent agent, Supplier language) { @Override public @NotNull Agent getAgent() { - return agent; + return this.agent; } @Override public @NotNull String getLanguageCode() { - return language.get(); + return this.language.get(); } @Override public @NotNull Component translateColorCodes(@Nullable String string) { - if(string == null) string = ""; - return LegacyComponentSerializer - .legacyAmpersand() - .deserialize(string); + if (string == null || string.isEmpty()) { + return Component.empty(); + } + + return GlobalTagDeserializer.deserialize(string); } @Override diff --git a/api/src/main/java/com/rappytv/globaltags/api/GlobalTagDeserializer.java b/api/src/main/java/com/rappytv/globaltags/api/GlobalTagDeserializer.java new file mode 100644 index 00000000..dcca4173 --- /dev/null +++ b/api/src/main/java/com/rappytv/globaltags/api/GlobalTagDeserializer.java @@ -0,0 +1,197 @@ +package com.rappytv.globaltags.api; + +import net.labymod.api.client.component.Component; +import net.labymod.api.client.component.TextComponent; +import net.labymod.api.client.component.format.NamedTextColor; +import net.labymod.api.client.component.format.TextColor; +import net.labymod.api.client.component.format.TextDecoration; +import net.labymod.api.util.Color; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.include.com.google.common.collect.BiMap; +import org.spongepowered.include.com.google.common.collect.HashBiMap; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Originally from net.labymod.api.client.component.serializer.legacy.LegacyComponentSerializer + */ +public class GlobalTagDeserializer { + + private static final char RESET_CHAR = 'r'; + private static final GlobalTagDeserializer INSTANCE = new GlobalTagDeserializer(); + + private static final BiMap TEXT_COLOR_CHARS = HashBiMap.create(16); + private static final BiMap DECORATION_CHARS = HashBiMap.create(5); + + static { + TEXT_COLOR_CHARS.put(NamedTextColor.BLACK, '0'); + TEXT_COLOR_CHARS.put(NamedTextColor.DARK_BLUE, '1'); + TEXT_COLOR_CHARS.put(NamedTextColor.DARK_GREEN, '2'); + TEXT_COLOR_CHARS.put(NamedTextColor.DARK_AQUA, '3'); + TEXT_COLOR_CHARS.put(NamedTextColor.DARK_RED, '4'); + TEXT_COLOR_CHARS.put(NamedTextColor.DARK_PURPLE, '5'); + TEXT_COLOR_CHARS.put(NamedTextColor.GOLD, '6'); + TEXT_COLOR_CHARS.put(NamedTextColor.GRAY, '7'); + TEXT_COLOR_CHARS.put(NamedTextColor.DARK_GRAY, '8'); + TEXT_COLOR_CHARS.put(NamedTextColor.BLUE, '9'); + TEXT_COLOR_CHARS.put(NamedTextColor.GREEN, 'a'); + TEXT_COLOR_CHARS.put(NamedTextColor.AQUA, 'b'); + TEXT_COLOR_CHARS.put(NamedTextColor.RED, 'c'); + TEXT_COLOR_CHARS.put(NamedTextColor.LIGHT_PURPLE, 'd'); + TEXT_COLOR_CHARS.put(NamedTextColor.YELLOW, 'e'); + TEXT_COLOR_CHARS.put(NamedTextColor.WHITE, 'f'); + + DECORATION_CHARS.put(TextDecoration.BOLD, 'l'); + DECORATION_CHARS.put(TextDecoration.ITALIC, 'o'); + DECORATION_CHARS.put(TextDecoration.UNDERLINED, 'n'); + DECORATION_CHARS.put(TextDecoration.STRIKETHROUGH, 'm'); + DECORATION_CHARS.put(TextDecoration.OBFUSCATED, 'k'); + } + + private final char character = '&'; + + private GlobalTagDeserializer() { + // Static access only + } + + public static Component deserialize(String input) { + return INSTANCE.deserializeString(input); + } + + public Component deserializeString(@Nullable String input) { + if (input == null) { + return Component.empty(); + } + + int nextSection = this.nextColor(input, input.length() - 1); + if (nextSection == -1) { + return Component.text(input); + } + + boolean reset = false; + int pos = input.length(); + + TextComponent.Builder current = null; + List parts = new ArrayList<>(); + + do { + char format; + TextColor textColor = null; + TextDecoration decoration = null; + int from; + + char formatIndicator = input.charAt(nextSection); + if (formatIndicator == this.character) { + format = input.charAt(nextSection + 1); + from = nextSection + 2; + } else if (formatIndicator == '#') { + format = formatIndicator; + int nextHexEnd = input.indexOf('>', nextSection); + if (nextHexEnd != -1) { + String hex = input.substring(nextSection, nextHexEnd); + int value; + try { + value = Integer.parseInt(hex.substring(1), 16); + } catch (IllegalArgumentException ignored) { + value = Color.WHITE.getValue(); + } + + textColor = TextColor.color(value); + + from = nextHexEnd + 1; + } else { + from = nextSection; + } + } else { + format = RESET_CHAR; + from = nextSection; + } + + if (format != RESET_CHAR && format != '#') { + textColor = TEXT_COLOR_CHARS.inverse().get(format); + if (textColor == null) { + decoration = DECORATION_CHARS.inverse().get(format); + } + } + + if (format == RESET_CHAR || textColor != null || decoration != null) { + if (from != pos) { + if (current != null) { + if (reset) { + parts.add(current.build()); + reset = false; + current = Component.text(); + } else { + current = Component.text().append(current.build()); + } + } else { + current = Component.text(); + } + + current.text(input.substring(from, pos)); + } else if (current == null) { + current = Component.text(); + } + + if (!reset) { + if (format == RESET_CHAR) { + reset = true; + } else if (textColor != null) { + current.color(textColor); + reset = true; + } else { + current.decorate(decoration); + } + } + + pos = formatIndicator == '#' ? nextSection - 1 : nextSection; + } + + nextSection = this.nextColor(input, nextSection - 1); + } while (nextSection != -1); + + if (current != null) { + parts.add(current.build()); + } + + final String remaining = pos > 0 ? input.substring(0, pos) : ""; + if (parts.size() == 1 && remaining.isEmpty()) { + return parts.getFirst(); + } else { + Collections.reverse(parts); + return Component.text().text(remaining).append(parts).build(); + } + } + + private int nextColor(String input, int fromIndex) { + if (fromIndex < 0) { + return -1; + } + + int nextSection = input.lastIndexOf(this.character, fromIndex); + if (nextSection > input.length() - 2) { + // there cannot be a legacy color code at the end of the string + nextSection = -1; + } + + int nextHexEnd = input.lastIndexOf('>', fromIndex); + if (nextHexEnd == -1) { + // no hex color, so use the next section + return nextSection; + } + + int nextHexStart = input.lastIndexOf("<#", nextHexEnd); + if (nextHexStart == -1) { + // no hex color, so use the next section + return nextSection; + } + + if (nextHexStart > nextSection) { + return nextHexStart + 1; + } + + return nextSection; + } +} diff --git a/api/src/main/java/com/rappytv/globaltags/api/Util.java b/api/src/main/java/com/rappytv/globaltags/api/Util.java index d95a6afe..4257b98e 100644 --- a/api/src/main/java/com/rappytv/globaltags/api/Util.java +++ b/api/src/main/java/com/rappytv/globaltags/api/Util.java @@ -73,8 +73,8 @@ public static void notify(Component title, Component description) { public static Component getResponseComponent(ApiResponse response) { return Component.text( - response.data(), - response.successful() ? NamedTextColor.GREEN : NamedTextColor.RED + response.getData(), + response.isSuccessful() ? NamedTextColor.GREEN : NamedTextColor.RED ); } diff --git a/build.gradle.kts b/build.gradle.kts index 00476ef7..c05b4fba 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { val versions = providers.gradleProperty("net.labymod.minecraft-versions").get().split(";") group = "org.example" -version = providers.environmentVariable("VERSION").getOrElse("1.3.4") +version = providers.environmentVariable("VERSION").getOrElse("1.3.5") labyMod { defaultPackageName = "com.rappytv.globaltags" //change this to your main package name (used by all modules) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 4a185704..16f705c4 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -3,7 +3,7 @@ import net.labymod.labygradle.common.extension.LabyModAnnotationProcessorExtensi dependencies { labyProcessor() api(project(":api")) - addonMavenDependency("com.rappytv.globaltags:GlobalTagsJava:1.1.9") + addonMavenDependency("com.rappytv.globaltags:GlobalTagsJava:1.2.0") } labyModAnnotationProcessor { diff --git a/core/src/main/java/com/rappytv/globaltags/GlobalTagAddon.java b/core/src/main/java/com/rappytv/globaltags/GlobalTagAddon.java index e889bdd4..67fb821d 100644 --- a/core/src/main/java/com/rappytv/globaltags/GlobalTagAddon.java +++ b/core/src/main/java/com/rappytv/globaltags/GlobalTagAddon.java @@ -3,14 +3,14 @@ import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.command.GlobalTagCommand; import com.rappytv.globaltags.config.GlobalTagConfig; +import com.rappytv.globaltags.interaction.ChangeTagBulletPoint; +import com.rappytv.globaltags.interaction.ClearTagBulletPoint; import com.rappytv.globaltags.interaction.EditBanInfoBulletPoint; import com.rappytv.globaltags.interaction.ReferPlayerBulletPoint; +import com.rappytv.globaltags.interaction.ReportBulletPoint; import com.rappytv.globaltags.interaction.StaffNotesBulletPoint; import com.rappytv.globaltags.interaction.TagHistoryBulletPoint; import com.rappytv.globaltags.interaction.ToggleBanBulletPoint; -import com.rappytv.globaltags.interaction.ChangeTagBulletPoint; -import com.rappytv.globaltags.interaction.ClearTagBulletPoint; -import com.rappytv.globaltags.interaction.ReportBulletPoint; import com.rappytv.globaltags.listener.BroadcastListener; import com.rappytv.globaltags.listener.ServerNavigationListener; import com.rappytv.globaltags.nametag.CustomTag; @@ -22,6 +22,8 @@ import net.labymod.api.client.component.format.TextDecoration; import net.labymod.api.client.entity.player.tag.PositionType; import net.labymod.api.client.entity.player.tag.TagRegistry; +import net.labymod.api.client.gui.icon.Icon; +import net.labymod.api.client.resources.ResourceLocation; import net.labymod.api.models.addon.annotation.AddonMain; import net.labymod.api.revision.SimpleRevision; import net.labymod.api.util.version.SemanticVersion; @@ -32,6 +34,7 @@ public class GlobalTagAddon extends LabyAddon { public static final Component prefix = Component.empty() .append(Component.text("GlobalTags").color(NamedTextColor.BLUE).decorate(TextDecoration.BOLD)) .append(Component.text(" » ", NamedTextColor.DARK_GRAY)); + public static Icon roundIcon; private static GlobalTagAPI api; @@ -41,19 +44,22 @@ protected void preConfigurationLoad() { Laby.references().revisionRegistry().register(new SimpleRevision("globaltags", new SemanticVersion("1.1.7"), "2024-02-27")); Laby.references().revisionRegistry().register(new SimpleRevision("globaltags", new SemanticVersion("1.1.9"), "2024-06-01")); Laby.references().revisionRegistry().register(new SimpleRevision("globaltags", new SemanticVersion("1.2.0"), "2024-07-14")); + Laby.references().revisionRegistry() + .register(new SimpleRevision("globaltags", new SemanticVersion("1.3.5"), "2024-12-15")); } @Override protected void enable() { - registerSettingCategory(); + this.registerSettingCategory(); api = new GlobalTagAPI( - new Agent("LabyAddon", addonInfo().getVersion(), Laby.labyAPI().minecraft().getVersion()), - () -> configuration().localizedResponses().get() + new Agent("LabyAddon", this.addonInfo().getVersion(), Laby.labyAPI().minecraft().getVersion()), + () -> this.configuration().localizedResponses().get() ? Laby.labyAPI().minecraft().options().getCurrentLanguage() : "en_us" ); + roundIcon = Icon.texture(ResourceLocation.create("globaltags", "textures/icon_round.png")); - TagRegistry tagRegistry = labyAPI().tagRegistry(); + TagRegistry tagRegistry = this.labyAPI().tagRegistry(); for (PositionType positionType : PositionType.values()) tagRegistry.registerBefore( "friendtags_tag", @@ -61,17 +67,17 @@ protected void enable() { positionType, new CustomTag(this, positionType) ); - registerListener(new BroadcastListener(api)); - registerListener(new ServerNavigationListener()); - labyAPI().interactionMenuRegistry().register(new ChangeTagBulletPoint()); - labyAPI().interactionMenuRegistry().register(new ClearTagBulletPoint()); - labyAPI().interactionMenuRegistry().register(new EditBanInfoBulletPoint()); - labyAPI().interactionMenuRegistry().register(new ReferPlayerBulletPoint()); - labyAPI().interactionMenuRegistry().register(new ReportBulletPoint()); - labyAPI().interactionMenuRegistry().register(new StaffNotesBulletPoint()); - labyAPI().interactionMenuRegistry().register(new TagHistoryBulletPoint()); - labyAPI().interactionMenuRegistry().register(new ToggleBanBulletPoint()); - registerCommand(new GlobalTagCommand(this)); + this.registerListener(new BroadcastListener(api)); + this.registerListener(new ServerNavigationListener()); + this.labyAPI().interactionMenuRegistry().register(new ChangeTagBulletPoint()); + this.labyAPI().interactionMenuRegistry().register(new ClearTagBulletPoint()); + this.labyAPI().interactionMenuRegistry().register(new EditBanInfoBulletPoint()); + this.labyAPI().interactionMenuRegistry().register(new ReferPlayerBulletPoint()); + this.labyAPI().interactionMenuRegistry().register(new ReportBulletPoint()); + this.labyAPI().interactionMenuRegistry().register(new StaffNotesBulletPoint()); + this.labyAPI().interactionMenuRegistry().register(new TagHistoryBulletPoint()); + this.labyAPI().interactionMenuRegistry().register(new ToggleBanBulletPoint()); + this.registerCommand(new GlobalTagCommand(this)); } @Override diff --git a/core/src/main/java/com/rappytv/globaltags/activities/BanActivity.java b/core/src/main/java/com/rappytv/globaltags/activities/BanActivity.java index 76750b3a..875e40ee 100644 --- a/core/src/main/java/com/rappytv/globaltags/activities/BanActivity.java +++ b/core/src/main/java/com/rappytv/globaltags/activities/BanActivity.java @@ -55,8 +55,8 @@ public void initialize(Parent parent) { sendButton.setEnabled(false); sendButton.setActionListener(() -> { Laby.labyAPI().minecraft().minecraftWindow().displayScreen((ScreenInstance) null); - api.getApiHandler().banPlayer(uuid, inputWidget.getText(), (response) -> { - if(response.successful()) Util.broadcastTagUpdate(uuid); + this.api.getApiHandler().banPlayer(this.uuid, inputWidget.getText(), (response) -> { + if(response.isSuccessful()) Util.broadcastTagUpdate(this.uuid); Laby.references().chatExecutor().displayClientMessage( Component.empty() .append(GlobalTagAddon.prefix) diff --git a/core/src/main/java/com/rappytv/globaltags/activities/ChangeTagActivity.java b/core/src/main/java/com/rappytv/globaltags/activities/ChangeTagActivity.java index 146762fb..ab45c0e4 100644 --- a/core/src/main/java/com/rappytv/globaltags/activities/ChangeTagActivity.java +++ b/core/src/main/java/com/rappytv/globaltags/activities/ChangeTagActivity.java @@ -1,9 +1,9 @@ package com.rappytv.globaltags.activities; -import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.GlobalTagAddon; -import java.util.UUID; +import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.api.Util; +import java.util.UUID; import net.labymod.api.Laby; import net.labymod.api.client.component.Component; import net.labymod.api.client.component.format.NamedTextColor; @@ -39,7 +39,11 @@ public ChangeTagActivity(GlobalTagAPI api, UUID uuid, String username) { @Override public void initialize(Parent parent) { super.initialize(parent); - api.getCache().resolve(uuid, (info) -> { + this.api.getCache().resolve(this.uuid, (info) -> { + if (info == null) { + Laby.labyAPI().minecraft().minecraftWindow().displayScreen((ScreenInstance) null); + return; + } FlexibleContentWidget windowWidget = new FlexibleContentWidget().addId("window"); HorizontalListWidget profileWrapper = new HorizontalListWidget().addId("header"); IconWidget headWidget = new IconWidget(Icon.head(this.uuid)).addId("head"); @@ -57,8 +61,8 @@ public void initialize(Parent parent) { sendButton.setEnabled(!inputWidget.getText().isBlank() && (!hasTag || !inputWidget.getText().equals(info.getPlainTag()))); sendButton.setActionListener(() -> { Laby.labyAPI().minecraft().minecraftWindow().displayScreen((ScreenInstance) null); - api.getApiHandler().setTag(uuid, inputWidget.getText(), (response) -> { - if(response.successful()) Util.broadcastTagUpdate(uuid); + this.api.getApiHandler().setTag(this.uuid, inputWidget.getText(), (response) -> { + if(response.isSuccessful()) Util.broadcastTagUpdate(this.uuid); Laby.references().chatExecutor().displayClientMessage( Component.empty() .append(GlobalTagAddon.prefix) diff --git a/core/src/main/java/com/rappytv/globaltags/activities/CreateNoteActivity.java b/core/src/main/java/com/rappytv/globaltags/activities/CreateNoteActivity.java index 180c4a9e..2bae384d 100644 --- a/core/src/main/java/com/rappytv/globaltags/activities/CreateNoteActivity.java +++ b/core/src/main/java/com/rappytv/globaltags/activities/CreateNoteActivity.java @@ -52,7 +52,7 @@ public void initialize(Parent parent) { .updateComponent(Component.translatable("globaltags.context.staff_notes.create.send", NamedTextColor.AQUA)) .addId("send-button"); sendButton.setEnabled(false); - sendButton.setActionListener(() -> api.getApiHandler().createNote(uuid, inputWidget.getText(), (response) -> { + sendButton.setActionListener(() -> this.api.getApiHandler().createNote(this.uuid, inputWidget.getText(), (response) -> { Laby.references().chatExecutor().displayClientMessage( Component.empty() .append(GlobalTagAddon.prefix) diff --git a/core/src/main/java/com/rappytv/globaltags/activities/EditBanActivity.java b/core/src/main/java/com/rappytv/globaltags/activities/EditBanActivity.java index c8c69e27..5f014f46 100644 --- a/core/src/main/java/com/rappytv/globaltags/activities/EditBanActivity.java +++ b/core/src/main/java/com/rappytv/globaltags/activities/EditBanActivity.java @@ -1,11 +1,11 @@ package com.rappytv.globaltags.activities; -import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.GlobalTagAddon; -import java.util.UUID; -import java.util.function.Consumer; +import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.api.Util; import com.rappytv.globaltags.wrapper.model.PlayerInfo.Suspension; +import java.util.UUID; +import java.util.function.Consumer; import net.labymod.api.Laby; import net.labymod.api.client.component.Component; import net.labymod.api.client.component.format.NamedTextColor; @@ -43,7 +43,11 @@ public EditBanActivity(GlobalTagAPI api, UUID uuid, String username) { @Override public void initialize(Parent parent) { super.initialize(parent); - api.getCache().resolve(uuid, (info) -> { + this.api.getCache().resolve(this.uuid, (info) -> { + if (info == null) { + Laby.labyAPI().minecraft().minecraftWindow().displayScreen((ScreenInstance) null); + return; + } Suspension suspension = info.getSuspension(); FlexibleContentWidget windowWidget = new FlexibleContentWidget().addId("window"); HorizontalListWidget profileWrapper = new HorizontalListWidget().addId("header"); @@ -81,7 +85,7 @@ public void initialize(Parent parent) { inputWidget.getText(), checkBoxWidget.state() == State.CHECKED ); - api.getApiHandler().editBan(uuid, editedSuspension, (response) -> + this.api.getApiHandler().editBan(this.uuid, editedSuspension, (response) -> Laby.references().chatExecutor().displayClientMessage( Component.empty() .append(GlobalTagAddon.prefix) diff --git a/core/src/main/java/com/rappytv/globaltags/activities/ReferralLeaderboardActivity.java b/core/src/main/java/com/rappytv/globaltags/activities/ReferralLeaderboardActivity.java new file mode 100644 index 00000000..ad0625b8 --- /dev/null +++ b/core/src/main/java/com/rappytv/globaltags/activities/ReferralLeaderboardActivity.java @@ -0,0 +1,111 @@ +package com.rappytv.globaltags.activities; + +import com.rappytv.globaltags.GlobalTagAddon; +import com.rappytv.globaltags.activities.widgets.ReferralLeaderboardEntryWidget; +import com.rappytv.globaltags.api.GlobalTagAPI; +import com.rappytv.globaltags.wrapper.enums.ReferralLeaderboardType; +import com.rappytv.globaltags.wrapper.model.ReferralLeaderboardEntry; +import java.util.List; +import java.util.Map; +import net.labymod.api.Laby; +import net.labymod.api.client.component.format.NamedTextColor; +import net.labymod.api.client.gui.screen.Parent; +import net.labymod.api.client.gui.screen.activity.AutoActivity; +import net.labymod.api.client.gui.screen.activity.Link; +import net.labymod.api.client.gui.screen.activity.types.SimpleActivity; +import net.labymod.api.client.gui.screen.widget.widgets.ComponentWidget; +import net.labymod.api.client.gui.screen.widget.widgets.input.ButtonWidget; +import net.labymod.api.client.gui.screen.widget.widgets.layout.FlexibleContentWidget; +import net.labymod.api.client.gui.screen.widget.widgets.layout.ScrollWidget; +import net.labymod.api.client.gui.screen.widget.widgets.layout.list.HorizontalListWidget; +import net.labymod.api.client.gui.screen.widget.widgets.layout.list.VerticalListWidget; +import net.labymod.api.util.ThreadSafe; + +@Link("leaderboard.lss") +@AutoActivity +public class ReferralLeaderboardActivity extends SimpleActivity { + + private final VerticalListWidget entries = new VerticalListWidget<>().addId( + "leaderboard-entries"); + private final HorizontalListWidget buttonMenu; + private ReferralLeaderboardType selectedLeaderboard = ReferralLeaderboardType.TOTAL; + private Map> leaderboards = null; + + public ReferralLeaderboardActivity() { + this.buttonMenu = new HorizontalListWidget().addId("button-menu"); + ButtonWidget totalViewButton = ButtonWidget.i18n( + "globaltags.settings.referralLeaderboards.activity.total"); + ButtonWidget currentMonthViewButton = ButtonWidget.i18n( + "globaltags.settings.referralLeaderboards.activity.current_month"); + totalViewButton.setEnabled(this.selectedLeaderboard != ReferralLeaderboardType.TOTAL); + totalViewButton.setPressable(() -> { + this.selectedLeaderboard = ReferralLeaderboardType.TOTAL; + totalViewButton.setEnabled(false); + currentMonthViewButton.setEnabled(true); + this.initializeWithInfo(true); + }); + currentMonthViewButton.setEnabled( + this.selectedLeaderboard != ReferralLeaderboardType.CURRENT_MONTH); + currentMonthViewButton.setPressable(() -> { + this.selectedLeaderboard = ReferralLeaderboardType.CURRENT_MONTH; + totalViewButton.setEnabled(true); + currentMonthViewButton.setEnabled(false); + this.initializeWithInfo(true); + }); + + this.buttonMenu.addEntry(totalViewButton); + this.buttonMenu.addEntry(currentMonthViewButton); + } + + @Override + public void initialize(Parent parent) { + super.initialize(parent); + GlobalTagAPI api = GlobalTagAddon.getAPI(); + + FlexibleContentWidget container = new FlexibleContentWidget().addId("container"); + + container.addContent(this.buttonMenu); + ScrollWidget scroll = new ScrollWidget(this.entries); + container.addContent(scroll); + this.document.addChild(container); + + api.getApiHandler().getReferralLeaderboards(response -> { + if (!response.isSuccessful()) { + Laby.labyAPI().minecraft().executeOnRenderThread( + () -> container.addContentInitialized( + ComponentWidget.text(response.getError(), NamedTextColor.RED) + .addId("error-component") + ) + ); + scroll.setVisible(false); + return; + } + this.leaderboards = response.getData(); + this.initializeWithInfo(); + }); + } + + private void initializeWithInfo() { + if (ThreadSafe.isRenderThread()) { + this.initializeWithInfo(false); + } else { + Laby.labyAPI().minecraft().executeOnRenderThread( + () -> this.initializeWithInfo(true) + ); + } + } + + private void initializeWithInfo(boolean initialized) { + this.entries.getChildren().clear(); + if (this.leaderboards == null) { + return; + } + for (ReferralLeaderboardEntry entry : this.leaderboards.get(this.selectedLeaderboard)) { + if (initialized) { + this.entries.addChildInitialized(new ReferralLeaderboardEntryWidget(entry)); + } else { + this.entries.addChild(new ReferralLeaderboardEntryWidget(entry)); + } + } + } +} diff --git a/core/src/main/java/com/rappytv/globaltags/activities/ReportUUIDActivity.java b/core/src/main/java/com/rappytv/globaltags/activities/ReportUUIDActivity.java index 628056a7..2265c289 100644 --- a/core/src/main/java/com/rappytv/globaltags/activities/ReportUUIDActivity.java +++ b/core/src/main/java/com/rappytv/globaltags/activities/ReportUUIDActivity.java @@ -54,7 +54,8 @@ public void initialize(Parent parent) { sendButton.setEnabled(false); sendButton.setActionListener(() -> { Laby.labyAPI().minecraft().minecraftWindow().displayScreen((ScreenInstance) null); - api.getApiHandler().reportPlayer(uuid, inputWidget.getText(), (response) -> Laby.references().chatExecutor().displayClientMessage( + this.api.getApiHandler().reportPlayer( + this.uuid, inputWidget.getText(), (response) -> Laby.references().chatExecutor().displayClientMessage( Component.empty() .append(GlobalTagAddon.prefix) .append(Util.getResponseComponent(response)) diff --git a/core/src/main/java/com/rappytv/globaltags/activities/StaffNotesActivity.java b/core/src/main/java/com/rappytv/globaltags/activities/StaffNotesActivity.java index a4efbc08..985a22ad 100644 --- a/core/src/main/java/com/rappytv/globaltags/activities/StaffNotesActivity.java +++ b/core/src/main/java/com/rappytv/globaltags/activities/StaffNotesActivity.java @@ -40,13 +40,13 @@ public StaffNotesActivity(GlobalTagAPI api, UUID uuid, String username) { @Override public void initialize(Parent parent) { super.initialize(parent); - api.getApiHandler().getNotes(uuid, (response) -> Laby.labyAPI().minecraft().executeOnRenderThread(() -> { - if(document.getChild("window") != null) return; - if(!response.successful()) { + this.api.getApiHandler().getNotes(this.uuid, (response) -> Laby.labyAPI().minecraft().executeOnRenderThread(() -> { + if(this.document.getChild("window") != null) return; + if(!response.isSuccessful()) { Laby.references().chatExecutor().displayClientMessage( TextComponent.builder() .append(GlobalTagAddon.prefix) - .append(Component.text(response.error(), NamedTextColor.RED)) + .append(Component.text(response.getError(), NamedTextColor.RED)) .build() ); Laby.labyAPI().minecraft().minecraftWindow().displayScreen((ScreenInstance) null); @@ -56,15 +56,15 @@ public void initialize(Parent parent) { HorizontalListWidget profileWrapper = new HorizontalListWidget().addId("header"); ButtonWidget createButton = ButtonWidget .text("+", () -> Laby.labyAPI().minecraft().minecraftWindow().displayScreen( - new CreateNoteActivity(api, uuid, username) + new CreateNoteActivity(this.api, this.uuid, this.username) )) .addId("create-button"); createButton.setHoverComponent(Component.translatable("globaltags.context.staff_notes.hover.create")); IconWidget headWidget = new IconWidget(Icon.head(this.uuid)).addId("head"); ComponentWidget titleWidget = ComponentWidget.i18n("globaltags.context.staff_notes.title", this.username).addId("username"); VerticalListWidget notes = new VerticalListWidget<>().addId("item-list"); - for (PlayerNote note : response.data()) { - notes.addChild(new StaffNoteWidget(uuid, api, note)); + for (PlayerNote note : response.getData()) { + notes.addChild(new StaffNoteWidget(this.uuid, this.api, note)); } profileWrapper.addEntryInitialized(headWidget); diff --git a/core/src/main/java/com/rappytv/globaltags/activities/TagHistoryActivity.java b/core/src/main/java/com/rappytv/globaltags/activities/TagHistoryActivity.java index d5a3eec6..2017f81a 100644 --- a/core/src/main/java/com/rappytv/globaltags/activities/TagHistoryActivity.java +++ b/core/src/main/java/com/rappytv/globaltags/activities/TagHistoryActivity.java @@ -39,14 +39,13 @@ public TagHistoryActivity(GlobalTagAPI api, UUID uuid, String username) { @Override public void initialize(Parent parent) { super.initialize(parent); - api.getApiHandler().getTagHistory(uuid, (response) -> Laby.labyAPI().minecraft().executeOnRenderThread(() -> { - if(document.getChild("window") != null) return; - System.out.println(response.data()); - if(!response.successful()) { + this.api.getApiHandler().getTagHistory(this.uuid, (response) -> Laby.labyAPI().minecraft().executeOnRenderThread(() -> { + if(this.document.getChild("window") != null) return; + if(!response.isSuccessful()) { Laby.references().chatExecutor().displayClientMessage( TextComponent.builder() .append(GlobalTagAddon.prefix) - .append(Component.text(response.error(), NamedTextColor.RED)) + .append(Component.text(response.getError(), NamedTextColor.RED)) .build() ); Laby.labyAPI().minecraft().minecraftWindow().displayScreen((ScreenInstance) null); @@ -57,8 +56,8 @@ public void initialize(Parent parent) { IconWidget headWidget = new IconWidget(Icon.head(this.uuid)).addId("head"); ComponentWidget titleWidget = ComponentWidget.i18n("globaltags.context.tag_history.title", this.username).addId("username"); VerticalListWidget notes = new VerticalListWidget<>().addId("item-list"); - for(int i = 0; i < response.data().size(); i++) { - notes.addChild(new TagHistoryEntryWidget(i + 1, api, response.data().get(i))); + for(int i = 0; i < response.getData().size(); i++) { + notes.addChild(new TagHistoryEntryWidget(i + 1, this.api, response.getData().get(i))); } profileWrapper.addEntryInitialized(headWidget); diff --git a/core/src/main/java/com/rappytv/globaltags/activities/widgets/ReferralLeaderboardEntryWidget.java b/core/src/main/java/com/rappytv/globaltags/activities/widgets/ReferralLeaderboardEntryWidget.java new file mode 100644 index 00000000..d39ee30c --- /dev/null +++ b/core/src/main/java/com/rappytv/globaltags/activities/widgets/ReferralLeaderboardEntryWidget.java @@ -0,0 +1,98 @@ +package com.rappytv.globaltags.activities.widgets; + +import com.rappytv.globaltags.wrapper.model.ReferralLeaderboardEntry; +import net.labymod.api.Laby; +import net.labymod.api.client.component.Component; +import net.labymod.api.client.component.event.ClickEvent; +import net.labymod.api.client.component.format.NamedTextColor; +import net.labymod.api.client.gui.icon.Icon; +import net.labymod.api.client.gui.lss.property.annotation.AutoWidget; +import net.labymod.api.client.gui.screen.Parent; +import net.labymod.api.client.gui.screen.widget.widgets.ComponentWidget; +import net.labymod.api.client.gui.screen.widget.widgets.layout.list.HorizontalListWidget; +import net.labymod.api.client.gui.screen.widget.widgets.renderer.IconWidget; +import net.labymod.api.util.ThreadSafe; + +@AutoWidget +public class ReferralLeaderboardEntryWidget extends HorizontalListWidget { + + private final ReferralLeaderboardEntry entry; + + public ReferralLeaderboardEntryWidget(ReferralLeaderboardEntry entry) { + this.entry = entry; + } + + @Override + public void initialize(Parent parent) { + if (this.isInitialized()) { + return; + } + super.initialize(parent); + + IconWidget headWidget = new IconWidget(Icon.head(this.entry.getUUID())) + .addId("player-head"); + + ComponentWidget text = ComponentWidget + .component(this.getUsernameComponent(true, null)) + .addId("username-component"); + + ComponentWidget value = ComponentWidget + .component( + Component + .empty() + .append(Component.translatable( + "globaltags.settings.referralLeaderboards.activity.total")) + .append(Component.text(": ", NamedTextColor.DARK_GRAY)) + .append(Component.text(this.entry.getTotalReferrals(), NamedTextColor.AQUA)) + .append(Component.newline()) + .append(Component.translatable( + "globaltags.settings.referralLeaderboards.activity.current_month")) + .append(Component.text(": ", NamedTextColor.DARK_GRAY)) + .append( + Component.text(this.entry.getCurrentMonthReferrals(), NamedTextColor.AQUA)) + ) + .addId("referral-count-component"); + + this.addEntry(headWidget); + this.addEntry(text); + this.addEntry(value); + + Laby.references() + .labyNetController() + .loadNameByUniqueId(this.entry.getUUID(), (name) -> { + if (ThreadSafe.isRenderThread()) { + text.setComponent(this.getUsernameComponent(false, name.getNullable())); + text.addId("loaded"); + } else { + Laby.labyAPI().minecraft().executeOnRenderThread(() -> { + text.setComponent(this.getUsernameComponent(false, name.getNullable())); + text.addId("loaded"); + }); + } + }); + } + + private Component getUsernameComponent(boolean loading, String username) { + Component component = Component + .empty() + .append(Component.text(this.entry.getRank() + ". ", NamedTextColor.AQUA)) + .clickEvent(ClickEvent.openUrl("https://laby.net/@" + this.entry.getUUID())); + + if (loading) { + component.append(Component.translatable( + "globaltags.settings.referralLeaderboards.activity.loading", + NamedTextColor.GRAY + )); + } else { + if (username == null) { + component.append(Component.translatable( + "globaltags.settings.referralLeaderboards.activity.open" + )); + } else { + component.append(Component.text(username)); + } + } + + return component; + } +} diff --git a/core/src/main/java/com/rappytv/globaltags/activities/widgets/StaffNoteWidget.java b/core/src/main/java/com/rappytv/globaltags/activities/widgets/StaffNoteWidget.java index d0947907..9e759d36 100644 --- a/core/src/main/java/com/rappytv/globaltags/activities/widgets/StaffNoteWidget.java +++ b/core/src/main/java/com/rappytv/globaltags/activities/widgets/StaffNoteWidget.java @@ -37,32 +37,32 @@ public StaffNoteWidget(UUID holder, GlobalTagAPI api, PlayerNote note) { @Override public void initialize(Parent parent) { - if(isInitialized()) return; + if(this.isInitialized()) return; super.initialize(parent); - IconWidget headWidget = new IconWidget(Icon.head(note.getAuthor())) + IconWidget headWidget = new IconWidget(Icon.head(this.note.getAuthor())) .addId("author-head"); ComponentWidget text = ComponentWidget - .text(note.getText()) + .text(this.note.getText()) .addId("text-component"); - text.setHoverComponent(Component.text(note.getText())); + text.setHoverComponent(Component.text(this.note.getText())); ComponentWidget description = ComponentWidget .text( I18n.translate( "globaltags.context.staff_notes.description", - formatDate(note.getCreatedAt()), - note.getId() + this.formatDate(this.note.getCreatedAt()), + this.note.getId() ), NamedTextColor.DARK_GRAY ) .addId("description-component"); - deleteButton = ButtonWidget + this.deleteButton = ButtonWidget .component(Component.text("✗", NamedTextColor.RED), this::delete) .addId("delete-button"); - deleteButton.setHoverComponent(Component.translatable( + this.deleteButton.setHoverComponent(Component.translatable( "globaltags.context.staff_notes.hover.delete", NamedTextColor.RED )); @@ -70,7 +70,7 @@ public void initialize(Parent parent) { this.addChild(headWidget); this.addChild(text); this.addChild(description); - this.addChild(deleteButton); + this.addChild(this.deleteButton); } private String formatDate(Date date) { @@ -78,21 +78,21 @@ private String formatDate(Date date) { } private void delete() { - deleteButton.setEnabled(false); - api.getApiHandler().deleteNote(holder, note.getId(), (response) -> { + this.deleteButton.setEnabled(false); + this.api.getApiHandler().deleteNote(this.holder, this.note.getId(), (response) -> { Laby.references().chatExecutor().displayClientMessage( TextComponent.builder() .append(GlobalTagAddon.prefix) .append(Util.getResponseComponent(response)) .build() ); - if(!response.successful()) { - deleteButton.setEnabled(true); + if(!response.isSuccessful()) { + this.deleteButton.setEnabled(true); return; } Laby.labyAPI().minecraft().executeOnRenderThread(() -> { - deleteButton.updateComponent(Component.text("✓", NamedTextColor.GREEN)); - deleteButton.setHoverComponent(Component.translatable( + this.deleteButton.updateComponent(Component.text("✓", NamedTextColor.GREEN)); + this.deleteButton.setHoverComponent(Component.translatable( "globaltags.context.staff_notes.hover.deleted", NamedTextColor.GREEN )); diff --git a/core/src/main/java/com/rappytv/globaltags/activities/widgets/TagHistoryEntryWidget.java b/core/src/main/java/com/rappytv/globaltags/activities/widgets/TagHistoryEntryWidget.java index 3b9c6ea4..ab5c8f60 100644 --- a/core/src/main/java/com/rappytv/globaltags/activities/widgets/TagHistoryEntryWidget.java +++ b/core/src/main/java/com/rappytv/globaltags/activities/widgets/TagHistoryEntryWidget.java @@ -24,25 +24,25 @@ public TagHistoryEntryWidget(int number, GlobalTagAPI api, TagHistoryEntry entry @Override public void initialize(Parent parent) { - if(isInitialized()) return; + if(this.isInitialized()) return; super.initialize(parent); ComponentWidget text = ComponentWidget .component( Component .empty() - .append(Component.text(number + ". ", NamedTextColor.AQUA)) - .append(api.translateColorCodes(entry.tag())) + .append(Component.text(this.number + ". ", NamedTextColor.AQUA)) + .append(this.api.translateColorCodes(this.entry.getTag())) ) .addId("text-component"); this.addChild(text); - if(!entry.flaggedWords().isEmpty()) { + if(!this.entry.getFlaggedWords().isEmpty()) { Component hoverComponent = Component.translatable( "globaltags.context.tag_history.flagged_words", NamedTextColor.GOLD ); - for(String word : entry.flaggedWords()) { + for(String word : this.entry.getFlaggedWords()) { hoverComponent .append(Component.newline()) .append(Component.text( diff --git a/core/src/main/java/com/rappytv/globaltags/command/GlobalTagCommand.java b/core/src/main/java/com/rappytv/globaltags/command/GlobalTagCommand.java index dd6b0a52..45b53348 100644 --- a/core/src/main/java/com/rappytv/globaltags/command/GlobalTagCommand.java +++ b/core/src/main/java/com/rappytv/globaltags/command/GlobalTagCommand.java @@ -25,16 +25,16 @@ public GlobalTagCommand(GlobalTagAddon addon) { this.api = GlobalTagAddon.getAPI(); this.version = addon.addonInfo().getVersion(); - withSubCommand(new ClearCacheCommand(api)); - withSubCommand(new LinkSubcommand(api)); - withSubCommand(new RenewCacheCommand(api)); - withSubCommand(new UnlinkSubcommand(api)); - withSubCommand(new VerifyCommand(api)); + this.withSubCommand(new ClearCacheCommand(this.api)); + this.withSubCommand(new LinkSubcommand(this.api)); + this.withSubCommand(new RenewCacheCommand(this.api)); + this.withSubCommand(new UnlinkSubcommand(this.api)); + this.withSubCommand(new VerifyCommand(this.api)); } @Override public boolean execute(String prefix, String[] arguments) { - api.getApiHandler().getApiInfo((response) -> { + this.api.getApiHandler().getApiInfo((response) -> { TextComponent clearComponent = TextComponent.builder() .append(GlobalTagAddon.prefix) .append(Component.translatable( @@ -47,8 +47,8 @@ public boolean execute(String prefix, String[] arguments) { .append(Component.translatable( "globaltags.commands.base.api.version", NamedTextColor.GREEN, - response != null && response.successful() - ? Component.text(response.data(), NamedTextColor.AQUA) + response != null && response.isSuccessful() + ? Component.text(response.getData(), NamedTextColor.AQUA) : Component.translatable( "globaltags.commands.base.api.offline", NamedTextColor.RED @@ -67,7 +67,7 @@ public boolean execute(String prefix, String[] arguments) { .clickEvent(ClickEvent.suggestCommand("/" + prefix + " cc"))) .build(); - displayMessage(clearComponent); + this.displayMessage(clearComponent); }); return true; } diff --git a/core/src/main/java/com/rappytv/globaltags/command/subcommands/ClearCacheCommand.java b/core/src/main/java/com/rappytv/globaltags/command/subcommands/ClearCacheCommand.java index fa57e40d..d42153ec 100644 --- a/core/src/main/java/com/rappytv/globaltags/command/subcommands/ClearCacheCommand.java +++ b/core/src/main/java/com/rappytv/globaltags/command/subcommands/ClearCacheCommand.java @@ -17,9 +17,9 @@ public ClearCacheCommand(GlobalTagAPI api) { @Override public boolean execute(String prefix, String[] arguments) { - api.getCache().clear(); - api.getCache().resolveSelf(); - displayMessage( + this.api.getCache().clear(); + this.api.getCache().resolveSelf(); + this.displayMessage( Component.empty() .append(GlobalTagAddon.prefix) .append(Component.translatable( diff --git a/core/src/main/java/com/rappytv/globaltags/command/subcommands/LinkSubcommand.java b/core/src/main/java/com/rappytv/globaltags/command/subcommands/LinkSubcommand.java index c23fd63c..5ed96a64 100644 --- a/core/src/main/java/com/rappytv/globaltags/command/subcommands/LinkSubcommand.java +++ b/core/src/main/java/com/rappytv/globaltags/command/subcommands/LinkSubcommand.java @@ -23,18 +23,18 @@ public LinkSubcommand(GlobalTagAPI api) { public boolean execute(String prefix, String[] arguments) { switch (arguments.length > 0 ? arguments[0].toLowerCase() : "none") { case "discord": - api.getApiHandler().linkDiscord((info) -> { - if (info.successful()) { - String code = info.data(); + this.api.getApiHandler().linkDiscord((info) -> { + if (info.isSuccessful()) { + String code = info.getData(); Laby.references().chatExecutor().copyToClipboard(code); - displayMessage(GlobalTagAddon.prefix.copy().append(Component.translatable( + this.displayMessage(GlobalTagAddon.prefix.copy().append(Component.translatable( "globaltags.commands.link.discord.copied", NamedTextColor.GREEN ))); } else { - displayMessage( + this.displayMessage( GlobalTagAddon.prefix.copy().append(Component.text( - info.data(), + info.getData(), NamedTextColor.RED )) ); @@ -43,7 +43,7 @@ public boolean execute(String prefix, String[] arguments) { break; case "email": if (arguments.length < 2) { - displayMessage( + this.displayMessage( Component.empty() .append(GlobalTagAddon.prefix) .append(Component.translatable( @@ -55,12 +55,12 @@ public boolean execute(String prefix, String[] arguments) { return true; } - api.getApiHandler().linkEmail(arguments[1], (info) -> { - if (info.successful()) { - displayMessage( + this.api.getApiHandler().linkEmail(arguments[1], (info) -> { + if (info.isSuccessful()) { + this.displayMessage( Component.empty() .append(GlobalTagAddon.prefix) - .append(Component.text(info.data(), NamedTextColor.GREEN)) + .append(Component.text(info.getData(), NamedTextColor.GREEN)) .append(Component.newline()) .append(GlobalTagAddon.prefix) .append( @@ -77,16 +77,16 @@ public boolean execute(String prefix, String[] arguments) { ) ); } else { - displayMessage( + this.displayMessage( Component.empty() .append(GlobalTagAddon.prefix) - .append(Component.text(info.data(), NamedTextColor.RED)) + .append(Component.text(info.getData(), NamedTextColor.RED)) ); } }); break; default: - displayMessage( + this.displayMessage( Component.empty() .append(GlobalTagAddon.prefix) .append(Component.translatable( diff --git a/core/src/main/java/com/rappytv/globaltags/command/subcommands/RenewCacheCommand.java b/core/src/main/java/com/rappytv/globaltags/command/subcommands/RenewCacheCommand.java index d2ffb253..13980f43 100644 --- a/core/src/main/java/com/rappytv/globaltags/command/subcommands/RenewCacheCommand.java +++ b/core/src/main/java/com/rappytv/globaltags/command/subcommands/RenewCacheCommand.java @@ -17,8 +17,8 @@ public RenewCacheCommand(GlobalTagAPI api) { @Override public boolean execute(String prefix, String[] arguments) { - api.getCache().renewAll(); - displayMessage( + this.api.getCache().renewAll(); + this.displayMessage( Component.empty() .append(GlobalTagAddon.prefix) .append(Component.translatable( diff --git a/core/src/main/java/com/rappytv/globaltags/command/subcommands/UnlinkSubcommand.java b/core/src/main/java/com/rappytv/globaltags/command/subcommands/UnlinkSubcommand.java index c7fe7ee6..11ae70ad 100644 --- a/core/src/main/java/com/rappytv/globaltags/command/subcommands/UnlinkSubcommand.java +++ b/core/src/main/java/com/rappytv/globaltags/command/subcommands/UnlinkSubcommand.java @@ -20,17 +20,17 @@ public UnlinkSubcommand(GlobalTagAPI api) { public boolean execute(String prefix, String[] arguments) { switch (arguments.length > 0 ? arguments[0].toLowerCase() : "none") { case "discord": - api.getApiHandler().unlinkDiscord((response) -> displayMessage( + this.api.getApiHandler().unlinkDiscord((response) -> this.displayMessage( GlobalTagAddon.prefix.copy().append(Util.getResponseComponent(response))) ); break; case "email": - api.getApiHandler().unlinkEmail((response) -> displayMessage( + this.api.getApiHandler().unlinkEmail((response) -> this.displayMessage( GlobalTagAddon.prefix.copy().append(Util.getResponseComponent(response))) ); break; default: - displayMessage( + this.displayMessage( Component.empty() .append(GlobalTagAddon.prefix) .append(Component.translatable( diff --git a/core/src/main/java/com/rappytv/globaltags/command/subcommands/VerifyCommand.java b/core/src/main/java/com/rappytv/globaltags/command/subcommands/VerifyCommand.java index 74ebfa03..9c7b7fc0 100644 --- a/core/src/main/java/com/rappytv/globaltags/command/subcommands/VerifyCommand.java +++ b/core/src/main/java/com/rappytv/globaltags/command/subcommands/VerifyCommand.java @@ -21,7 +21,7 @@ public boolean execute(String prefix, String[] arguments) { switch (arguments.length > 0 ? arguments[0].toLowerCase() : "none") { case "email": if(arguments.length < 2) { - displayMessage( + this.displayMessage( Component.empty() .append(GlobalTagAddon.prefix) .append(Component.translatable( @@ -33,12 +33,12 @@ public boolean execute(String prefix, String[] arguments) { return true; } - api.getApiHandler().verifyEmail(arguments[1], (response) -> displayMessage( + this.api.getApiHandler().verifyEmail(arguments[1], (response) -> this.displayMessage( GlobalTagAddon.prefix.copy().append(Util.getResponseComponent(response)) )); break; default: - displayMessage( + this.displayMessage( Component.empty() .append(GlobalTagAddon.prefix) .append(Component.translatable( diff --git a/core/src/main/java/com/rappytv/globaltags/config/GlobalTagConfig.java b/core/src/main/java/com/rappytv/globaltags/config/GlobalTagConfig.java index dbbc8ed9..55da5b9e 100644 --- a/core/src/main/java/com/rappytv/globaltags/config/GlobalTagConfig.java +++ b/core/src/main/java/com/rappytv/globaltags/config/GlobalTagConfig.java @@ -1,10 +1,13 @@ package com.rappytv.globaltags.config; import com.rappytv.globaltags.GlobalTagAddon; +import com.rappytv.globaltags.activities.ReferralLeaderboardActivity; import com.rappytv.globaltags.api.Util; import com.rappytv.globaltags.config.subconfig.TagSubConfig; import net.labymod.api.Laby; import net.labymod.api.addon.AddonConfig; +import net.labymod.api.client.gui.screen.activity.Activity; +import net.labymod.api.client.gui.screen.widget.widgets.activity.settings.ActivitySettingWidget.ActivitySetting; import net.labymod.api.client.gui.screen.widget.widgets.input.ButtonWidget.ButtonSetting; import net.labymod.api.client.gui.screen.widget.widgets.input.SliderWidget.SliderSetting; import net.labymod.api.client.gui.screen.widget.widgets.input.SwitchWidget.SwitchSetting; @@ -25,10 +28,12 @@ public class GlobalTagConfig extends AddonConfig { @SwitchSetting @SpriteSlot(size = 32) private final ConfigProperty enabled = new ConfigProperty<>(true); + @IntroducedIn(namespace = "globaltags", value = "1.1.9") @SpriteSlot(size = 32, y = 2, x = 2) @SwitchSetting private final ConfigProperty localizedResponses = new ConfigProperty<>(true); + @IntroducedIn(namespace = "globaltags", value = "1.2.0") @MethodOrder(after = "localizedResponses") @SpriteSlot(size = 32, y = 2, x = 3) @@ -37,13 +42,22 @@ public void joinDiscord(Setting setting) { Laby.references().chatExecutor().openUrl("https://globaltags.xyz/discord"); } + @IntroducedIn(namespace = "globaltags", value = "1.3.5") + @MethodOrder(after = "joinDiscord") + @ActivitySetting + public Activity referralLeaderboards() { + return new ReferralLeaderboardActivity(); + } + @SettingSection("display") @SwitchSetting @SpriteSlot(size = 32, x = 1) private final ConfigProperty showOwnTag = new ConfigProperty<>(true); + @SpriteSlot(size = 32, x = 2) @SliderSetting(min = 5, max = 10) private final ConfigProperty tagSize = new ConfigProperty<>(10); + @IntroducedIn(namespace = "globaltags", value = "1.1.7") @SpriteSlot(size = 32, y = 2, x = 1) @SwitchSetting @@ -67,18 +81,18 @@ public void clearCache(Setting setting) { @Override public ConfigProperty enabled() { - return enabled; + return this.enabled; } public ConfigProperty localizedResponses() { - return localizedResponses; + return this.localizedResponses; } public ConfigProperty showOwnTag() { - return showOwnTag; + return this.showOwnTag; } public ConfigProperty tagSize() { - return tagSize; + return this.tagSize; } public ConfigProperty showBackground() { - return showBackground; + return this.showBackground; } } diff --git a/core/src/main/java/com/rappytv/globaltags/config/subconfig/TagSubConfig.java b/core/src/main/java/com/rappytv/globaltags/config/subconfig/TagSubConfig.java index 53a6b713..135bd123 100644 --- a/core/src/main/java/com/rappytv/globaltags/config/subconfig/TagSubConfig.java +++ b/core/src/main/java/com/rappytv/globaltags/config/subconfig/TagSubConfig.java @@ -29,9 +29,9 @@ public TagSubConfig() { 1000, TagPreviewWidget::change ); - tag.addChangeListener(runnable); - position.addChangeListener(runnable); - globalIcon.addChangeListener(runnable); + this.tag.addChangeListener(runnable); + this.position.addChangeListener(runnable); + this.globalIcon.addChangeListener(runnable); } @SpriteSlot(size = 32, x = 1) @@ -64,19 +64,22 @@ public void updateSettings(Setting setting) { ); return; } - if(info == null || !info.getPlainTag().equals(tag.get())) api.getApiHandler().setTag(tag.get(), (response) -> { - if(response.successful()) Util.update(api, ResultType.TAG, Component.text("✔", NamedTextColor.GREEN)); - else Util.update(api, ResultType.TAG, Component.text(response.data(), NamedTextColor.RED)); + if(info == null || !info.getPlainTag().equals(this.tag.get())) api.getApiHandler().setTag( + this.tag.get(), (response) -> { + if(response.isSuccessful()) Util.update(api, ResultType.TAG, Component.text("✔", NamedTextColor.GREEN)); + else Util.update(api, ResultType.TAG, Component.text(response.getData(), NamedTextColor.RED)); }); else Util.update(api, ResultType.TAG, Util.unchanged); - if(info != null && !info.getPosition().equals(position.get())) api.getApiHandler().setPosition(position.get(), (response) -> { - if(response.successful()) Util.update(api, ResultType.POSITION, Component.text("✔", NamedTextColor.GREEN)); - else Util.update(api, ResultType.POSITION, Component.text(response.data(), NamedTextColor.RED)); + if(info != null && !info.getPosition().equals(this.position.get())) api.getApiHandler().setPosition( + this.position.get(), (response) -> { + if(response.isSuccessful()) Util.update(api, ResultType.POSITION, Component.text("✔", NamedTextColor.GREEN)); + else Util.update(api, ResultType.POSITION, Component.text(response.getData(), NamedTextColor.RED)); }); else Util.update(api, ResultType.POSITION, Util.unchanged); - if(info != null && !info.getGlobalIcon().equals(globalIcon.get())) api.getApiHandler().setIcon(globalIcon.get(), (response) -> { - if(response.successful()) Util.update(api, ResultType.ICON, Component.text("✔", NamedTextColor.GREEN)); - else Util.update(api, ResultType.ICON, Component.text(response.data(), NamedTextColor.RED)); + if(info != null && !info.getGlobalIcon().equals(this.globalIcon.get())) api.getApiHandler().setIcon( + this.globalIcon.get(), (response) -> { + if(response.isSuccessful()) Util.update(api, ResultType.ICON, Component.text("✔", NamedTextColor.GREEN)); + else Util.update(api, ResultType.ICON, Component.text(response.getData(), NamedTextColor.RED)); }); else Util.update(api, ResultType.ICON, Util.unchanged); }); @@ -88,27 +91,27 @@ public void updateSettings(Setting setting) { public void resetTag(Setting setting) { GlobalTagAPI api = GlobalTagAddon.getAPI(); api.getApiHandler().resetTag((info) -> { - if(info.successful()) { + if(info.isSuccessful()) { Util.broadcastTagUpdate(); TagPreviewWidget.refetch(); } Util.notify( - Component.translatable(info.successful() + Component.translatable(info.isSuccessful() ? "globaltags.general.success" : "globaltags.general.error" ), - Component.text(info.data(), NamedTextColor.WHITE) + Component.text(info.getData(), NamedTextColor.WHITE) ); }); } public ConfigProperty tag() { - return tag; + return this.tag; } public ConfigProperty position() { - return position; + return this.position; } public ConfigProperty icon() { - return globalIcon; + return this.globalIcon; } } diff --git a/core/src/main/java/com/rappytv/globaltags/config/widget/AppealPopup.java b/core/src/main/java/com/rappytv/globaltags/config/widget/AppealPopup.java index 1364ed79..66004c1a 100644 --- a/core/src/main/java/com/rappytv/globaltags/config/widget/AppealPopup.java +++ b/core/src/main/java/com/rappytv/globaltags/config/widget/AppealPopup.java @@ -40,13 +40,13 @@ public AppealPopup(GlobalTagAPI api) { .addId("send-button", "popup-description"); sendButton.setEnabled(false); sendButton.setActionListener(() -> - api.getApiHandler().appealBan(inputWidget.getText(), (response) -> + this.api.getApiHandler().appealBan(inputWidget.getText(), (response) -> Util.notify( - Component.translatable(response.successful() + Component.translatable(response.isSuccessful() ? "globaltags.general.success" : "globaltags.general.error" ), - Component.text(response.data(), NamedTextColor.WHITE) + Component.text(response.getData(), NamedTextColor.WHITE) ) ) ); diff --git a/core/src/main/java/com/rappytv/globaltags/config/widget/TagPreviewWidget.java b/core/src/main/java/com/rappytv/globaltags/config/widget/TagPreviewWidget.java index ece4ed3d..d85b17ba 100644 --- a/core/src/main/java/com/rappytv/globaltags/config/widget/TagPreviewWidget.java +++ b/core/src/main/java/com/rappytv/globaltags/config/widget/TagPreviewWidget.java @@ -14,6 +14,7 @@ import net.labymod.api.client.gui.lss.property.annotation.AutoWidget; import net.labymod.api.client.gui.screen.Parent; import net.labymod.api.client.gui.screen.activity.Link; +import net.labymod.api.client.gui.screen.widget.Widget; import net.labymod.api.client.gui.screen.widget.widgets.ComponentWidget; import net.labymod.api.client.gui.screen.widget.widgets.input.ButtonWidget; import net.labymod.api.client.gui.screen.widget.widgets.layout.list.HorizontalListWidget; @@ -25,10 +26,13 @@ import net.labymod.api.configuration.settings.annotation.SettingWidget; import net.labymod.api.configuration.settings.widget.WidgetFactory; import net.labymod.api.util.I18n; +import net.labymod.api.util.ThreadSafe; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import java.util.function.Consumer; @Link("preview.lss") @AutoWidget @@ -49,7 +53,7 @@ public void tick() { if(!refetch && !changed) return; if(refetch) GlobalTagAddon.getAPI().getCache().remove(GlobalTagAddon.getAPI().getClientUUID()); - reInitialize(); + this.reInitialize(); refetch = false; changed = false; } @@ -57,75 +61,88 @@ public void tick() { @Override public void initialize(Parent parent) { super.initialize(parent); - initialize(refetch); + this.initialize(refetch); } @SuppressWarnings("ConstantConditions") public void initialize(boolean refetched) { GlobalTagAPI api = GlobalTagAddon.getAPI(); - api.getCache().resolveSelf((info) -> - Laby.labyAPI().minecraft().executeOnRenderThread(() -> { - Component error = getError(info); - if (error != null) { - ComponentWidget errorComponent = ComponentWidget.component(error) - .addId("text", "error"); - this.addEntryInitialized(errorComponent); - } else { - if(refetched) { - config.tag().set(info.getPlainTag()); - config.position().set(info.getPosition()); - config.icon().set(info.getGlobalIcon()); - } - boolean updated = !config.tag().get().equals(info.getPlainTag()) - || !config.position().get().equals(info.getPosition()) - || !config.icon().get().equals(info.getGlobalIcon()); - if(changed && updated) { - Util.notify( - I18n.translate("globaltags.settings.tags.staged.title"), - I18n.translate("globaltags.settings.tags.staged.description") - ); - } - ComponentWidget tag = ComponentWidget.component( - config.tag().get().isBlank() - ? Component.translatable( - "globaltags.settings.tags.tagPreview.empty", - NamedTextColor.RED - ) - : api.translateColorCodes(config.tag().get()) - ).addId("text"); - - if (config.icon().get() != GlobalIcon.NONE) { - String iconUrl = config.icon().get() == GlobalIcon.CUSTOM && info.getGlobalIconHash() != null - ? api.getUrls().getCustomIcon(api.getClientUUID(), info.getGlobalIconHash()) - : api.getUrls().getDefaultIcon(config.icon().get()); - this.addEntryInitialized( - new IconWidget(Icon.url(iconUrl)) - .addId("icon") - ); - } - this.addEntryInitialized(tag); - if (info.getHighestRoleIcon() != null) - this.addEntryInitialized( - new IconWidget(Icon.url(info.getHighestRoleIcon())) - .addId("staff-icon") - ); - } - ButtonWidget refreshButton = ButtonWidget.icon(SpriteCommon.REFRESH, TagPreviewWidget::refetch) - .addId("refresh-button"); - addEntryInitialized(refreshButton); - if(info != null && info.isSuspended()) { - ButtonWidget appealButton = ButtonWidget.i18n( - "globaltags.settings.tags.tagPreview.appeal.name", - () -> new AppealPopup(api).displayInOverlay() - ).addId("appeal-button"); - appealButton.setHoverComponent(Component.translatable( - "globaltags.settings.tags.tagPreview.appeal.description", - NamedTextColor.GOLD - )); - appealButton.setEnabled(info.getSuspension().isAppealable()); - addEntryInitialized(appealButton); - } - })); + + this.addEntry(ButtonWidget + .icon(SpriteCommon.REFRESH, TagPreviewWidget::refetch) + .addId("refresh-button") + ); + api.getCache().resolveSelf((info) -> { + if (ThreadSafe.isRenderThread()) { + this.initializeWithInfo(info, refetched, false); + } else { + Laby.labyAPI().minecraft().executeOnRenderThread( + () -> this.initializeWithInfo(info, refetched, true) + ); + } + }); + } + + private void initializeWithInfo(PlayerInfo info, boolean refetched, boolean async) { + GlobalTagAPI api = GlobalTagAddon.getAPI(); + Consumer addEntry = async ? this::addEntryInitialized : this::addEntry; + + Component error = this.getError(info); + if (error != null) { + ComponentWidget errorComponent = ComponentWidget.component(error) + .addId("text", "error"); + addEntry.accept(errorComponent); + } else { + if (refetched) { + this.config.tag().set(info.getPlainTag()); + this.config.position().set(info.getPosition()); + this.config.icon().set(info.getGlobalIcon()); + } + boolean updated = !this.config.tag().get().equals(info.getPlainTag()) + || !this.config.position().get().equals(info.getPosition()) + || !this.config.icon().get().equals(info.getGlobalIcon()); + if (changed && updated) { + Util.notify( + I18n.translate("globaltags.settings.tags.staged.title"), + I18n.translate("globaltags.settings.tags.staged.description") + ); + } + ComponentWidget tag = ComponentWidget.component( + this.config.tag().get().isBlank() + ? Component.translatable( + "globaltags.settings.tags.tagPreview.empty", + NamedTextColor.RED + ) + : api.translateColorCodes(this.config.tag().get()) + ).addId("text"); + + if (this.config.icon().get() != GlobalIcon.NONE) { + addEntry.accept( + new IconWidget(Icon.url(this.getIconUrl(api, info))) + .addId("icon") + ); + } + addEntry.accept(tag); + if (info.getHighestRoleIcon() != null) { + addEntry.accept( + new IconWidget(Icon.url(info.getHighestRoleIcon())) + .addId("staff-icon") + ); + } + } + + if (info != null && info.isSuspended()) { + ButtonWidget appealButton = ButtonWidget.i18n( + "globaltags.settings.tags.tagPreview.appeal.name", + () -> new AppealPopup(api).displayInOverlay() + ).addId("appeal-button"); + appealButton.setHoverComponent(Component.translatable( + "globaltags.settings.tags.tagPreview.appeal.description", + NamedTextColor.GOLD + )); + appealButton.setEnabled(info.getSuspension().isAppealable()); + addEntry.accept(appealButton); + } } public static void change() { @@ -133,7 +150,13 @@ public static void change() { } public static void refetch() { - refetch = true; + TagPreviewWidget.refetch = true; + } + + private String getIconUrl(GlobalTagAPI api, PlayerInfo info) { + return this.config.icon().get() == GlobalIcon.CUSTOM && info.getGlobalIconHash() != null + ? api.getUrls().getCustomIcon(api.getClientUUID(), info.getGlobalIconHash()) + : api.getUrls().getDefaultIcon(this.config.icon().get()); } private Component getError(PlayerInfo info) { diff --git a/core/src/main/java/com/rappytv/globaltags/interaction/ChangeTagBulletPoint.java b/core/src/main/java/com/rappytv/globaltags/interaction/ChangeTagBulletPoint.java index 17887b67..31ccadbb 100644 --- a/core/src/main/java/com/rappytv/globaltags/interaction/ChangeTagBulletPoint.java +++ b/core/src/main/java/com/rappytv/globaltags/interaction/ChangeTagBulletPoint.java @@ -1,8 +1,8 @@ package com.rappytv.globaltags.interaction; -import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.GlobalTagAddon; import com.rappytv.globaltags.activities.ChangeTagActivity; +import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.wrapper.enums.GlobalPermission; import com.rappytv.globaltags.wrapper.model.PlayerInfo; import net.labymod.api.Laby; @@ -26,14 +26,14 @@ public Component getTitle() { @Override public Icon getIcon() { - return null; + return GlobalTagAddon.roundIcon; } @Override public void execute(Player player) { Laby.labyAPI().minecraft().executeNextTick(() -> Laby.labyAPI().minecraft().minecraftWindow().displayScreen(new ChangeTagActivity( - api, + this.api, player.getUniqueId(), player.getName() )) @@ -42,8 +42,9 @@ public void execute(Player player) { @Override public boolean isVisible(Player player) { - PlayerInfo executer = api.getCache().get(Laby.labyAPI().getUniqueId()); - PlayerInfo target = api.getCache().get(player.getUniqueId()); - return executer != null && executer.hasPermission(GlobalPermission.MANAGE_TAGS) && target != null; + PlayerInfo executor = this.api.getCache().get(Laby.labyAPI().getUniqueId()); + PlayerInfo target = this.api.getCache().get(player.getUniqueId()); + return executor != null && executor.hasPermission(GlobalPermission.MANAGE_TAGS) + && target != null; } } diff --git a/core/src/main/java/com/rappytv/globaltags/interaction/ClearTagBulletPoint.java b/core/src/main/java/com/rappytv/globaltags/interaction/ClearTagBulletPoint.java index 2c216781..0ecc8004 100644 --- a/core/src/main/java/com/rappytv/globaltags/interaction/ClearTagBulletPoint.java +++ b/core/src/main/java/com/rappytv/globaltags/interaction/ClearTagBulletPoint.java @@ -1,7 +1,7 @@ package com.rappytv.globaltags.interaction; -import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.GlobalTagAddon; +import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.api.Util; import com.rappytv.globaltags.wrapper.enums.GlobalPermission; import com.rappytv.globaltags.wrapper.model.PlayerInfo; @@ -26,12 +26,12 @@ public Component getTitle() { @Override public Icon getIcon() { - return null; + return GlobalTagAddon.roundIcon; } @Override public void execute(Player player) { - api.getApiHandler().resetTag(player.getUniqueId(), (response) -> Laby.references().chatExecutor().displayClientMessage( + this.api.getApiHandler().resetTag(player.getUniqueId(), (response) -> Laby.references().chatExecutor().displayClientMessage( Component.empty() .append(GlobalTagAddon.prefix) .append(Util.getResponseComponent(response)) @@ -40,8 +40,9 @@ public void execute(Player player) { @Override public boolean isVisible(Player player) { - PlayerInfo executer = api.getCache().get(Laby.labyAPI().getUniqueId()); - PlayerInfo target = api.getCache().get(player.getUniqueId()); - return executer != null && executer.hasPermission(GlobalPermission.MANAGE_TAGS) && target != null && target.getTag() != null; + PlayerInfo executor = this.api.getCache().get(Laby.labyAPI().getUniqueId()); + PlayerInfo target = this.api.getCache().get(player.getUniqueId()); + return executor != null && executor.hasPermission(GlobalPermission.MANAGE_TAGS) + && target != null && target.getTag() != null; } } diff --git a/core/src/main/java/com/rappytv/globaltags/interaction/EditBanInfoBulletPoint.java b/core/src/main/java/com/rappytv/globaltags/interaction/EditBanInfoBulletPoint.java index 1987bf9a..7420246d 100644 --- a/core/src/main/java/com/rappytv/globaltags/interaction/EditBanInfoBulletPoint.java +++ b/core/src/main/java/com/rappytv/globaltags/interaction/EditBanInfoBulletPoint.java @@ -1,8 +1,8 @@ package com.rappytv.globaltags.interaction; -import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.GlobalTagAddon; import com.rappytv.globaltags.activities.EditBanActivity; +import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.wrapper.enums.GlobalPermission; import com.rappytv.globaltags.wrapper.model.PlayerInfo; import net.labymod.api.Laby; @@ -26,14 +26,14 @@ public Component getTitle() { @Override public Icon getIcon() { - return null; + return GlobalTagAddon.roundIcon; } @Override public void execute(Player player) { Laby.labyAPI().minecraft().executeNextTick(() -> Laby.labyAPI().minecraft().minecraftWindow().displayScreen(new EditBanActivity( - api, + this.api, player.getUniqueId(), player.getName() )) @@ -42,8 +42,9 @@ public void execute(Player player) { @Override public boolean isVisible(Player player) { - PlayerInfo executer = api.getCache().get(Laby.labyAPI().getUniqueId()); - PlayerInfo target = api.getCache().get(player.getUniqueId()); - return executer != null && executer.hasPermission(GlobalPermission.MANAGE_BANS) && target != null && target.isSuspended(); + PlayerInfo executor = this.api.getCache().get(Laby.labyAPI().getUniqueId()); + PlayerInfo target = this.api.getCache().get(player.getUniqueId()); + return executor != null && executor.hasPermission(GlobalPermission.MANAGE_BANS) + && target != null && target.isSuspended(); } } diff --git a/core/src/main/java/com/rappytv/globaltags/interaction/ReferPlayerBulletPoint.java b/core/src/main/java/com/rappytv/globaltags/interaction/ReferPlayerBulletPoint.java index acd36b37..a385e744 100644 --- a/core/src/main/java/com/rappytv/globaltags/interaction/ReferPlayerBulletPoint.java +++ b/core/src/main/java/com/rappytv/globaltags/interaction/ReferPlayerBulletPoint.java @@ -1,7 +1,7 @@ package com.rappytv.globaltags.interaction; -import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.GlobalTagAddon; +import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.api.Util; import com.rappytv.globaltags.wrapper.model.PlayerInfo; import net.labymod.api.Laby; @@ -25,12 +25,12 @@ public Component getTitle() { @Override public Icon getIcon() { - return null; + return GlobalTagAddon.roundIcon; } @Override public void execute(Player player) { - api.getApiHandler().referPlayer(player.getUniqueId(), (response) -> Laby.references().chatExecutor().displayClientMessage( + this.api.getApiHandler().referPlayer(player.getUniqueId(), (response) -> Laby.references().chatExecutor().displayClientMessage( Component.empty() .append(GlobalTagAddon.prefix) .append(Util.getResponseComponent(response)) @@ -39,7 +39,8 @@ public void execute(Player player) { @Override public boolean isVisible(Player player) { - PlayerInfo executer = api.getCache().get(Laby.labyAPI().getUniqueId()); - return executer != null && !executer.hasReferred(); + PlayerInfo executor = this.api.getCache().get(Laby.labyAPI().getUniqueId()); + PlayerInfo target = this.api.getCache().get(player.getUniqueId()); + return (executor == null || !executor.hasReferred()) && target != null; } } diff --git a/core/src/main/java/com/rappytv/globaltags/interaction/ReportBulletPoint.java b/core/src/main/java/com/rappytv/globaltags/interaction/ReportBulletPoint.java index 2ccfe664..32e09970 100644 --- a/core/src/main/java/com/rappytv/globaltags/interaction/ReportBulletPoint.java +++ b/core/src/main/java/com/rappytv/globaltags/interaction/ReportBulletPoint.java @@ -1,8 +1,8 @@ package com.rappytv.globaltags.interaction; -import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.GlobalTagAddon; import com.rappytv.globaltags.activities.ReportUUIDActivity; +import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.wrapper.model.PlayerInfo; import net.labymod.api.Laby; import net.labymod.api.client.component.Component; @@ -25,14 +25,14 @@ public Component getTitle() { @Override public Icon getIcon() { - return null; + return GlobalTagAddon.roundIcon; } @Override public void execute(Player player) { Laby.labyAPI().minecraft().executeNextTick(() -> Laby.labyAPI().minecraft().minecraftWindow().displayScreen(new ReportUUIDActivity( - api, + this.api, player.getUniqueId(), player.getName() )) @@ -41,7 +41,7 @@ public void execute(Player player) { @Override public boolean isVisible(Player player) { - PlayerInfo playerInfo = api.getCache().get(player.getUniqueId()); + PlayerInfo playerInfo = this.api.getCache().get(player.getUniqueId()); return playerInfo != null && playerInfo.getTag() != null; } } diff --git a/core/src/main/java/com/rappytv/globaltags/interaction/StaffNotesBulletPoint.java b/core/src/main/java/com/rappytv/globaltags/interaction/StaffNotesBulletPoint.java index 35d5de4f..5243c24f 100644 --- a/core/src/main/java/com/rappytv/globaltags/interaction/StaffNotesBulletPoint.java +++ b/core/src/main/java/com/rappytv/globaltags/interaction/StaffNotesBulletPoint.java @@ -26,14 +26,14 @@ public Component getTitle() { @Override public Icon getIcon() { - return null; + return GlobalTagAddon.roundIcon; } @Override public void execute(Player player) { Laby.labyAPI().minecraft().executeNextTick(() -> Laby.labyAPI().minecraft().minecraftWindow().displayScreen(new StaffNotesActivity( - api, + this.api, player.getUniqueId(), player.getName() )) @@ -42,7 +42,8 @@ public void execute(Player player) { @Override public boolean isVisible(Player player) { - PlayerInfo executer = api.getCache().get(Laby.labyAPI().getUniqueId()); - return executer != null && executer.hasPermission(GlobalPermission.MANAGE_NOTES) && api.getCache().get(player.getUniqueId()) != null; + PlayerInfo executor = this.api.getCache().get(Laby.labyAPI().getUniqueId()); + return executor != null && executor.hasPermission(GlobalPermission.MANAGE_NOTES) && + this.api.getCache().get(player.getUniqueId()) != null; } } diff --git a/core/src/main/java/com/rappytv/globaltags/interaction/TagHistoryBulletPoint.java b/core/src/main/java/com/rappytv/globaltags/interaction/TagHistoryBulletPoint.java index f3e36dd6..45653680 100644 --- a/core/src/main/java/com/rappytv/globaltags/interaction/TagHistoryBulletPoint.java +++ b/core/src/main/java/com/rappytv/globaltags/interaction/TagHistoryBulletPoint.java @@ -26,14 +26,14 @@ public Component getTitle() { @Override public Icon getIcon() { - return null; + return GlobalTagAddon.roundIcon; } @Override public void execute(Player player) { Laby.labyAPI().minecraft().executeNextTick(() -> Laby.labyAPI().minecraft().minecraftWindow().displayScreen(new TagHistoryActivity( - api, + this.api, player.getUniqueId(), player.getName() )) @@ -42,7 +42,8 @@ public void execute(Player player) { @Override public boolean isVisible(Player player) { - PlayerInfo executer = api.getCache().get(Laby.labyAPI().getUniqueId()); - return executer != null && executer.hasPermission(GlobalPermission.MANAGE_TAGS) && api.getCache().get(player.getUniqueId()) != null; + PlayerInfo executor = this.api.getCache().get(Laby.labyAPI().getUniqueId()); + return executor != null && executor.hasPermission(GlobalPermission.MANAGE_TAGS) && + this.api.getCache().get(player.getUniqueId()) != null; } } diff --git a/core/src/main/java/com/rappytv/globaltags/interaction/ToggleBanBulletPoint.java b/core/src/main/java/com/rappytv/globaltags/interaction/ToggleBanBulletPoint.java index ee4edf4b..8548d48a 100644 --- a/core/src/main/java/com/rappytv/globaltags/interaction/ToggleBanBulletPoint.java +++ b/core/src/main/java/com/rappytv/globaltags/interaction/ToggleBanBulletPoint.java @@ -1,8 +1,8 @@ package com.rappytv.globaltags.interaction; -import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.GlobalTagAddon; import com.rappytv.globaltags.activities.BanActivity; +import com.rappytv.globaltags.api.GlobalTagAPI; import com.rappytv.globaltags.api.Util; import com.rappytv.globaltags.wrapper.enums.GlobalPermission; import com.rappytv.globaltags.wrapper.model.PlayerInfo; @@ -23,19 +23,19 @@ public ToggleBanBulletPoint() { @Override public Component getTitle() { - return Component.translatable("globaltags.context." + (target.isSuspended() ? "unban" : "ban") + ".name"); + return Component.translatable("globaltags.context." + (this.target.isSuspended() ? "unban" : "ban") + ".name"); } @Override public Icon getIcon() { - return null; + return GlobalTagAddon.roundIcon; } @Override public void execute(Player player) { - if(target.isSuspended()) { - api.getApiHandler().unbanPlayer(target.getUUID(), (response) -> { - if(response.successful()) Util.broadcastTagUpdate(target.getUUID()); + if(this.target.isSuspended()) { + this.api.getApiHandler().unbanPlayer(this.target.getUUID(), (response) -> { + if(response.isSuccessful()) Util.broadcastTagUpdate(this.target.getUUID()); Laby.references().chatExecutor().displayClientMessage( Component.empty() .append(GlobalTagAddon.prefix) @@ -45,7 +45,7 @@ public void execute(Player player) { } else { Laby.labyAPI().minecraft().executeNextTick(() -> Laby.labyAPI().minecraft().minecraftWindow().displayScreen(new BanActivity( - api, + this.api, player.getUniqueId(), player.getName() )) @@ -55,8 +55,9 @@ public void execute(Player player) { @Override public boolean isVisible(Player player) { - PlayerInfo executer = api.getCache().get(Laby.labyAPI().getUniqueId()); - target = api.getCache().get(player.getUniqueId()); - return executer != null && executer.hasPermission(GlobalPermission.MANAGE_BANS) && target != null; + PlayerInfo executor = this.api.getCache().get(Laby.labyAPI().getUniqueId()); + this.target = this.api.getCache().get(player.getUniqueId()); + return executor != null && executor.hasPermission(GlobalPermission.MANAGE_BANS) && + this.target != null; } } diff --git a/core/src/main/java/com/rappytv/globaltags/listener/BroadcastListener.java b/core/src/main/java/com/rappytv/globaltags/listener/BroadcastListener.java index 03c5fb4a..e90db7fc 100644 --- a/core/src/main/java/com/rappytv/globaltags/listener/BroadcastListener.java +++ b/core/src/main/java/com/rappytv/globaltags/listener/BroadcastListener.java @@ -3,9 +3,9 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.rappytv.globaltags.api.GlobalTagAPI; +import java.util.UUID; import net.labymod.api.event.Subscribe; import net.labymod.api.event.labymod.labyconnect.session.LabyConnectBroadcastEvent; -import java.util.UUID; public class BroadcastListener { @@ -25,12 +25,13 @@ public void onBroadcastReceive(LabyConnectBroadcastEvent event) { try { UUID uuid = UUID.fromString(object.get("uuid").getAsString()); - api.getCache().renew(uuid); + this.api.getCache().renew(uuid); return; - } catch (IllegalStateException e) {} + } catch (IllegalStateException ignored) { + } } } - api.getCache().renew(event.getSender()); + this.api.getCache().renew(event.getSender()); } } diff --git a/core/src/main/java/com/rappytv/globaltags/listener/ServerNavigationListener.java b/core/src/main/java/com/rappytv/globaltags/listener/ServerNavigationListener.java index be90fb70..b16ffc3c 100644 --- a/core/src/main/java/com/rappytv/globaltags/listener/ServerNavigationListener.java +++ b/core/src/main/java/com/rappytv/globaltags/listener/ServerNavigationListener.java @@ -16,7 +16,7 @@ public ServerNavigationListener() { @Subscribe public void onLeave(ServerDisconnectEvent event) { - cache.clear(); - cache.resolveSelf(); + this.cache.clear(); + this.cache.resolveSelf(); } } diff --git a/core/src/main/java/com/rappytv/globaltags/nametag/CustomTag.java b/core/src/main/java/com/rappytv/globaltags/nametag/CustomTag.java index 56a369dd..e4daf86c 100644 --- a/core/src/main/java/com/rappytv/globaltags/nametag/CustomTag.java +++ b/core/src/main/java/com/rappytv/globaltags/nametag/CustomTag.java @@ -36,28 +36,28 @@ public CustomTag(GlobalTagAddon addon, PositionType position) { @Override public float getScale() { - return (float) config.tagSize().get() / 10; + return (float) this.config.tagSize().get() / 10; } @Override protected @Nullable RenderableComponent getRenderableComponent() { - if(!config.enabled().get()) return null; - if(entity == null || !(entity instanceof Player)) return null; - UUID uuid = entity.getUniqueId(); - if(!config.showOwnTag().get() && Laby.labyAPI().getUniqueId().equals(uuid)) + if(!this.config.enabled().get()) return null; + if(this.entity == null || !(this.entity instanceof Player)) return null; + UUID uuid = this.entity.getUniqueId(); + if(!this.config.showOwnTag().get() && Laby.labyAPI().getUniqueId().equals(uuid)) return null; - info = null; - if(api.getCache().has(uuid)) - info = api.getCache().get(uuid); + this.info = null; + if(this.api.getCache().has(uuid)) + this.info = this.api.getCache().get(uuid); else { - if(position == PositionType.ABOVE_NAME) - api.getCache().resolve(uuid); + if(this.position == PositionType.ABOVE_NAME) + this.api.getCache().resolve(uuid); } - if(info == null || info.getTag() == null) return null; - if(!getGlobalPosition(position).equals(info.getPosition())) return null; + if(this.info == null || this.info.getTag() == null) return null; + if(!this.getGlobalPosition(this.position).equals(this.info.getPosition())) return null; - return RenderableComponent.of(info.getTag()); + return RenderableComponent.of(this.info.getTag()); } @Override @@ -65,19 +65,19 @@ public float getScale() { public void render(Stack stack, Entity entity) { super.render(stack, entity); if(this.getRenderableComponent() == null) return; - if(info == null) return; + if(this.info == null) return; Laby.labyAPI().renderPipeline().renderSeeThrough(entity, () -> { - if(info.getGlobalIcon() != GlobalIcon.NONE) Icon.url(info.getIconUrl()).render( + if(this.info.getGlobalIcon() != GlobalIcon.NONE) Icon.url(this.info.getIconUrl()).render( stack, -11, 0, 9, 9 ); - if(info.getHighestRoleIcon() != null) Icon.url(info.getHighestRoleIcon()).render( + if(this.info.getHighestRoleIcon() != null) Icon.url(this.info.getHighestRoleIcon()).render( stack, - getWidth() + 0.9F, + this.getWidth() + 0.9F, -1.2F, 11, 11 @@ -95,11 +95,11 @@ private GlobalPosition getGlobalPosition(PositionType type) { @Override protected NameTagBackground getCustomBackground() { - boolean enabled = config.showBackground().get(); + boolean enabled = this.config.showBackground().get(); NameTagBackground background = super.getCustomBackground(); if (background == null) - background = NameTagBackground.custom(enabled, black); + background = NameTagBackground.custom(enabled, this.black); background.setEnabled(enabled); return background; diff --git a/core/src/main/resources/assets/globaltags/i18n/en_us.json b/core/src/main/resources/assets/globaltags/i18n/en_us.json index 1f5d25f3..d042a5dd 100644 --- a/core/src/main/resources/assets/globaltags/i18n/en_us.json +++ b/core/src/main/resources/assets/globaltags/i18n/en_us.json @@ -20,6 +20,17 @@ "name": "Discord Server", "text": "Join" }, + "referralLeaderboards": { + "name": "Referral leaderboards", + "description": "Displays a leaderboard of players who invited the most players to GlobalTags.", + "text": "View", + "activity": { + "total": "Total", + "current_month": "This month", + "open": "Open laby.net profile", + "loading": "Loading..." + } + }, "showOwnTag": { "name": "Show own tag" }, diff --git a/core/src/main/resources/assets/globaltags/textures/icon_round.png b/core/src/main/resources/assets/globaltags/textures/icon_round.png new file mode 100644 index 00000000..2e50b025 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icon_round.png differ diff --git a/core/src/main/resources/assets/globaltags/themes/fancy/lss/preview.lss b/core/src/main/resources/assets/globaltags/themes/fancy/lss/preview.lss index 183000c0..67c61663 100644 --- a/core/src/main/resources/assets/globaltags/themes/fancy/lss/preview.lss +++ b/core/src/main/resources/assets/globaltags/themes/fancy/lss/preview.lss @@ -3,10 +3,14 @@ TagPreview { orientation: horizontal; .text { + max-width: 75%; + scale-to-fit: false; + max-lines: 1; margin-left: 2; } .error { + max-lines: 2 !important; text-color: red; } @@ -26,7 +30,6 @@ TagPreview { .appeal-button { height: 20; width: fit-content; - # padding: 0; alignment: right; } diff --git a/core/src/main/resources/assets/globaltags/themes/vanilla/lss/leaderboard.lss b/core/src/main/resources/assets/globaltags/themes/vanilla/lss/leaderboard.lss new file mode 100644 index 00000000..5e1e41c8 --- /dev/null +++ b/core/src/main/resources/assets/globaltags/themes/vanilla/lss/leaderboard.lss @@ -0,0 +1,76 @@ +.container { + height: 100%; + width: 100%; + + .button-menu { + width: 90%; + height: 20; + margin-top: 5; + top: 5; + left: 50%; + alignment-x: center; + layout: fill; + space-between-entries: 8; + } + + Scroll { + width: 100%; + height: 100%; + + .leaderboard-entries { + margin-top: 5; + width: 100%; + height: 90%; + } + + Scrollbar { + left: 0; + top: 0; + width: 5; + height: 100%; + margin-left: 5; + } + } + + .error-component { + font-size: 0.8; + width: fit-content; + margin-top: 100; + alignment-x: center; + alignment-y: center; + } +} + +ReferralLeaderboardEntry { + width: 100%; + height: 20; + padding: 1; + + .player-head { + margin-left: 3; + width: 16; + height: width; + } + + .username-component { + max-width: 80%; + width: fit-content; + scale-to-fit: true; + max-lines: 1; + margin-left: 2; + top: 2; + } + + .loaded:hover { + text-color: aqua; + } + + .referral-count-component { + max-width: 50%; + alignment: right; + scale-to-fit: true; + max-lines: 2; + right: 2; + alignment-y: center; + } +} \ No newline at end of file diff --git a/core/src/main/resources/assets/globaltags/themes/vanilla/lss/preview.lss b/core/src/main/resources/assets/globaltags/themes/vanilla/lss/preview.lss index 183000c0..67c61663 100644 --- a/core/src/main/resources/assets/globaltags/themes/vanilla/lss/preview.lss +++ b/core/src/main/resources/assets/globaltags/themes/vanilla/lss/preview.lss @@ -3,10 +3,14 @@ TagPreview { orientation: horizontal; .text { + max-width: 75%; + scale-to-fit: false; + max-lines: 1; margin-left: 2; } .error { + max-lines: 2 !important; text-color: red; } @@ -26,7 +30,6 @@ TagPreview { .appeal-button { height: 20; width: fit-content; - # padding: 0; alignment: right; } diff --git a/readme.md b/readme.md index a61e25e2..87d3040f 100644 --- a/readme.md +++ b/readme.md @@ -6,7 +6,9 @@ The [API](https://github.com/Global-Tags/API) for the storage of the tags is ofc ### Installation 1. Press `Win` + `R` 2. Paste this into the window that popped up: `%appdata%/.minecraft/LabyMod-neo/addons` and press enter -3. It should open your Labymod addon directory; Paste the [Global-Tags.jar](https://github.com/Global-Tags/LabyAddon/releases/latest/download/Global-Tags.jar) in there. +3. It should open your Labymod addon directory; Paste + the [GlobalTags.jar](https://github.com/Global-Tags/LabyAddon/releases/latest/download/GlobalTags.jar) + in there. 4. Launch your Labymod client. If you have any problems with the addon/have update ideas, feel free to diff --git a/settings.gradle.kts b/settings.gradle.kts index e2d82066..34138e9f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,7 @@ rootProject.name = "globaltags" pluginManagement { - val labyGradlePluginVersion = "0.5.6" + val labyGradlePluginVersion = "0.5.7" buildscript { repositories {