Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.3.5 #82

Merged
merged 20 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions api/src/main/java/com/rappytv/globaltags/api/GlobalTagAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Component> {

Expand All @@ -25,20 +24,21 @@ public GlobalTagAPI(Agent agent, Supplier<String> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<TextColor, Character> TEXT_COLOR_CHARS = HashBiMap.create(16);
private static final BiMap<TextDecoration, Character> 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<Component> 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;
}
}
4 changes: 2 additions & 2 deletions api/src/main/java/com/rappytv/globaltags/api/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public static void notify(Component title, Component description) {

public static Component getResponseComponent(ApiResponse<String> response) {
return Component.text(
response.data(),
response.successful() ? NamedTextColor.GREEN : NamedTextColor.RED
response.getData(),
response.isSuccessful() ? NamedTextColor.GREEN : NamedTextColor.RED
);
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
42 changes: 24 additions & 18 deletions core/src/main/java/com/rappytv/globaltags/GlobalTagAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -32,6 +34,7 @@ public class GlobalTagAddon extends LabyAddon<GlobalTagConfig> {
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;

Expand All @@ -41,37 +44,40 @@ 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",
"globaltag",
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Loading