Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Advancement: fix strings for translatable component
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Nov 25, 2023
1 parent bfa1d4c commit 6954d5d
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package net.flectone.chat.model.advancement;

import net.flectone.chat.util.NMSUtil;
import org.bukkit.Bukkit;
import org.bukkit.advancement.Advancement;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

// Thanks, @CroaBeast, for these methods
// Source https://github.com/CroaBeast/AdvancementInfo
Expand Down Expand Up @@ -49,8 +53,8 @@ public FAdvancement(@NotNull Advancement adv) {
Object rawTitle = NMSUtil.getObject(display, "a");
Object rawDesc = NMSUtil.getObject(display, "b");

translateKey = String.valueOf(NMSUtil.getObject(NMSUtil.getObject(rawTitle, "b"), "a"));
translateDesc = String.valueOf(NMSUtil.getObject(NMSUtil.getObject(rawDesc, "b"), "a"));
translateKey = getTranslateString(rawTitle);
translateDesc = getTranslateString(rawDesc);

String typeName = NMSUtil.checkValue(NMSUtil.getObject(display, "e"), "PROGRESS");
this.type = Type.getType(typeName);
Expand All @@ -68,7 +72,13 @@ public FAdvancement(@NotNull Advancement adv) {
}
}

private static boolean getBool(String string) {
@NotNull
private String getTranslateString(@Nullable Object object) {
String string = String.valueOf(object);
return string.substring(string.indexOf("key='") + 5, string.indexOf("',"));
}

private boolean getBool(String string) {
return string.matches("(?i)true|false") && string.matches("(?i)true");
}

Expand Down

0 comments on commit 6954d5d

Please sign in to comment.