Skip to content

Commit c4bd666

Browse files
committed
Stonecutter build code cleanup.
Fix 26.2 placeholders while removing deprecated usage on older versions
1 parent 9b0dd4d commit c4bd666

13 files changed

Lines changed: 66 additions & 119 deletions

File tree

build.gradle.kts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,14 @@ dependencies {
8686
modCompileOnly("maven.modrinth:vanish:${project.property("deps.vanish")}")
8787
}
8888

89-
val accessWidener = if (sc.current.parsed >= "26.1") {
90-
layout.buildDirectory.file("solstice-official.accesswidener")
91-
.get().asFile.apply {
92-
parentFile.mkdirs()
93-
writeText(
94-
rootProject.file("src/main/resources/solstice.accesswidener")
95-
.readText()
96-
.replaceFirst("accessWidener v2 named", "accessWidener v2 official")
97-
)
98-
}
99-
}
100-
else rootProject.file("src/main/resources/solstice.accesswidener")
101-
10289
loom {
10390
fabricModJsonPath = rootProject.file("src/main/resources/fabric.mod.json") // Useful for interface injection
104-
accessWidenerPath = accessWidener
91+
92+
accessWidenerPath = sc.process(
93+
rootProject.file("src/main/resources/solstice.ct"),
94+
".gradle/processed.ct"
95+
)
96+
10597
decompilerOptions.named("vineflower") {
10698
options.put("mark-corresponding-synthetics", "1") // Adds names to lambdas - useful for mixins
10799
}
@@ -141,17 +133,6 @@ tasks {
141133
val mixinJava = "JAVA_${requiredJava.majorVersion}"
142134
filesMatching("*.mixins.json") { expand("java" to mixinJava) }
143135
}
144-
145-
register<Copy>("buildAndCollect") {
146-
group = "build"
147-
description = "Builds mod jars and copies results to `build/libs/{mod version}/`"
148-
149-
inputs.property("version", project.property("mod.version"))
150-
// loomx.mod(Sources)Jar returns the jar task for the applied loom variant
151-
from(loomx.modJar.flatMap { it.archiveFile }, loomx.modSourcesJar.flatMap { it.archiveFile })
152-
into(rootProject.layout.buildDirectory.file("libs/${project.property("mod.version")}"))
153-
}
154-
155136
}
156137

157138

src/main/java/me/alexdevs/solstice/api/text/Format.java

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,74 +6,74 @@
66
import eu.pb4.placeholders.api.node.TextNode;
77
import eu.pb4.placeholders.api.parsers.*;
88
import me.alexdevs.solstice.api.text.tag.PhaseGradientTag;
9+
import me.alexdevs.solstice.api.utils.PlaceholderUtils;
910
import net.minecraft.network.chat.Component;
1011
import java.util.Map;
1112
import java.util.regex.Pattern;
1213

1314
public class Format {
14-
//? if >= 26.1 {
15-
/*public static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("(?<!((?<!(\\\\))\\\\))\\$[{](?<id>[^}]+)}");
16-
*///? } elif >= 1.21.1 {
15+
//? if >= 26.1
16+
//public static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("(?<!((?<!(\\\\))\\\\))\\$[{](?<id>[^}]+)}");
17+
//? if < 26.1
1718
public static final Pattern PLACEHOLDER_PATTERN = PatternPlaceholderParser.PREDEFINED_PLACEHOLDER_PATTERN;
18-
//? }
1919
public static final NodeParser LEGACY_PARSER = LegacyFormattingParser.ALL;
2020
public static final NodeParser PARSER;
2121

2222
static {
23-
//? if >= 26.1 {
24-
/*var parser = eu.pb4.placeholders.api.parsers.TagParser.DEFAULT.copy();
25-
26-
*///? } elif >= 1.21.1 {
27-
var parser = TextParserV1.createDefault();
28-
//? }
29-
parser.register(PhaseGradientTag.createTag());
30-
PARSER = parser;
23+
var gradientParser = eu.pb4.placeholders.api.parsers.TagParser.DEFAULT.copy();
24+
gradientParser.register(PhaseGradientTag.createTag());
25+
PARSER = NodeParser.builder()
26+
.simplifiedTextFormat()
27+
//? if >= 26.1
28+
//.serverPlaceholders()
29+
//? if < 26.1
30+
.globalPlaceholders()
31+
.quickText()
32+
.add(gradientParser)
33+
.build();
3134
}
3235

3336
public static Component parse(String text) {
34-
//? if >= 26.1 {
35-
/*return PARSER.parseNode(text).toComponent();
36-
*///? } elif >= 1.21.1 {
37-
return PARSER.parseNode(text).toText();
38-
//? }
37+
return PARSER.parseNode(text)
38+
//? if >= 26.1
39+
//.toComponent();
40+
//? if < 26.1
41+
.toText();
3942
}
4043

4144
public static Component parse(TextNode textNode, PlaceholderContext context, Map<String, Component> placeholders) {
42-
//? if >= 26.1 {
43-
/*var predefinedNode = new MapPlaceholderParser(PLACEHOLDER_PATTERN, placeholders).parseNode(textNode);
44-
return Placeholders.COMMON_PLACEHOLDER_PARSER.parseNode(predefinedNode)
45-
.toComponent(ParserContext.of(PlaceholderContext.COMMON_KEY, context));
46-
*///? } elif >= 1.21.1 {
47-
var predefinedNode = Placeholders.parseNodes(textNode, PLACEHOLDER_PATTERN, placeholders);
48-
return Placeholders.parseText(predefinedNode, context);
49-
//? }
45+
return PARSER.parseNode(new MapPlaceholderParser(PLACEHOLDER_PATTERN, placeholders).parseNode(textNode))
46+
//? if < 26.1
47+
.toText(context);
48+
//? if >= 26.1
49+
//.toComponent(context);
5050
}
5151

5252
public static Component parse(Component text, PlaceholderContext context, Map<String, Component> placeholders) {
5353
return parse(TextNode.convert(text), context, placeholders);
5454
}
5555

5656
public static Component parse(String text, PlaceholderContext context, Map<String, Component> placeholders) {
57-
return parse(parse(text), context, placeholders);
57+
return parse(PARSER.parseNode(text), context, placeholders);
5858
}
5959

6060
public static Component parse(String text, PlaceholderContext context) {
61-
return parse(parse(text), context, Map.of());
61+
return parse(PARSER.parseNode(text), context, Map.of());
6262
}
6363

6464
public static Component parse(String text, Map<String, Component> placeholders) {
65-
//? if >= 26.1 {
66-
/*return new MapPlaceholderParser(PLACEHOLDER_PATTERN, placeholders).parseNode(TextNode.convert(parse(text))).toComponent();
67-
*///? } elif >= 1.21.1 {
68-
return Placeholders.parseText(parse(text), PLACEHOLDER_PATTERN, placeholders);
69-
//? }
65+
return new MapPlaceholderParser(PLACEHOLDER_PATTERN, placeholders).parseNode(PARSER.parseNode(text))
66+
//? if < 26.1
67+
.toText();
68+
//? if >= 26.1
69+
//.toComponent();
7070
}
7171

7272
public static Component parse(Component text, Map<String, Component> placeholders) {
73-
//? if >= 26.1 {
74-
/*return new MapPlaceholderParser(PLACEHOLDER_PATTERN, placeholders).parseNode(TextNode.convert(text)).toComponent();
75-
*///? } elif >= 1.21.1 {
76-
return Placeholders.parseText(TextNode.convert(text), PLACEHOLDER_PATTERN, placeholders);
77-
//? }
73+
return new MapPlaceholderParser(PLACEHOLDER_PATTERN, placeholders).parseNode(PARSER.parseNode(TextNode.convert(text)))
74+
//? if < 26.1
75+
.toText();
76+
//? if >= 26.1
77+
//.toComponent();
7878
}
7979
}

src/main/java/me/alexdevs/solstice/api/text/MapPlaceholderParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public TextNode[] parseNodes(TextNode text) {
5252
for (var child : parentNode.getChildren()) {
5353
out.add(TextNode.asSingle(this.parseNodes(child)));
5454
}
55-
return new TextNode[]{parentNode.copyWith(out.toArray(new TextNode[0]))};
55+
return new TextNode[]{parentNode.copyWith(out.toArray(new TextNode[0]), this)};
5656
}
5757

5858
return new TextNode[]{text};

src/main/java/me/alexdevs/solstice/api/text/tag/PhaseGradientTag.java

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
import eu.pb4.placeholders.api.node.TextNode;
44
import eu.pb4.placeholders.api.node.parent.GradientNode;
5-
//? < 26.1
6-
import eu.pb4.placeholders.api.parsers.TextParserV1;
7-
//? < 26.1
8-
import eu.pb4.placeholders.impl.textparser.TextParserImpl;
95
import me.alexdevs.solstice.api.utils.MathUtils;
106
import net.minecraft.network.chat.TextColor;
117
import me.alexdevs.solstice.api.color.Gradient;
@@ -25,8 +21,7 @@
2521
*/
2622
public class PhaseGradientTag {
2723

28-
//? if >= 26.1 {
29-
/*public static eu.pb4.placeholders.api.parsers.tag.TextTag createTag() {
24+
public static eu.pb4.placeholders.api.parsers.tag.TextTag createTag() {
3025
return eu.pb4.placeholders.api.parsers.tag.TextTag.enclosing("phase_gradient", List.of("pgr", "sgr"), "gradient", true,
3126
(children, args, parser) -> {
3227
var rawArgs = args.input().split(":");
@@ -66,49 +61,6 @@ public class PhaseGradientTag {
6661
return PhaseGradientTag.smoother(textColors, phase, children);
6762
});
6863
}
69-
*///? } elif >= 1.21.1 {
70-
public static TextParserV1.TextTag createTag() {
71-
return TextParserV1.TextTag.of("phase_gradient", List.of("pgr", "sgr"), "gradient", true,
72-
(tag, data, input, handlers, endAt) -> {
73-
var rawArgs = data.split(":");
74-
var out = TextParserImpl.recursiveParsing(input, handlers, endAt);
75-
76-
double phase = 0;
77-
final List<TextColor> textColors;
78-
79-
var args = Arrays.stream(rawArgs).iterator();
80-
81-
if (args.hasNext()) {
82-
textColors = new ArrayList<>();
83-
while (args.hasNext()) {
84-
var arg = args.next();
85-
if (!args.hasNext()) {
86-
final var possiblePhase = MathUtils.parseDouble(arg);
87-
if (possiblePhase.isPresent()) {
88-
phase = MathUtils.clamp(possiblePhase.get(), -1d, 1d);
89-
break;
90-
}
91-
}
92-
93-
var parsedColor = TextColor.parseColor(arg);
94-
if (parsedColor.isError()) {
95-
textColors.add(TextColor.fromRgb(0));
96-
} else {
97-
textColors.add(parsedColor.getOrThrow());
98-
}
99-
}
100-
101-
if (textColors.size() == 1) {
102-
return out.value(GradientNode.colors(textColors, out.nodes()));
103-
}
104-
} else {
105-
textColors = List.of();
106-
}
107-
108-
return out.value(PhaseGradientTag.smoother(textColors, phase, out.nodes()));
109-
});
110-
}
111-
//? }
11264

11365
public static GradientNode smoother(List<TextColor> colors, double phase, TextNode... nodes) {
11466
if (colors.isEmpty()) {

src/main/java/me/alexdevs/solstice/api/utils/PlaceholderUtils.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import eu.pb4.placeholders.api.PlaceholderContext;
55
import net.minecraft.commands.CommandSourceStack;
66
import net.minecraft.server.MinecraftServer;
7+
import net.minecraft.server.level.ServerPlayer;
8+
import net.minecraft.world.entity.player.Player;
79

810
public final class PlaceholderUtils {
911
private PlaceholderUtils() {
@@ -31,4 +33,8 @@ public static PlaceholderContext of(GameProfile profile, MinecraftServer server)
3133
//? if < 26.1
3234
return PlaceholderContext.of(profile, server);
3335
}
36+
37+
public static PlaceholderContext of(Player player) {
38+
return PlaceholderContext.of(player);
39+
}
3440
}

src/main/java/me/alexdevs/solstice/modules/afk/AfkModule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import me.alexdevs.solstice.api.events.SolsticeEvents;
1111
import me.alexdevs.solstice.api.module.ModuleBase;
1212
import me.alexdevs.solstice.api.text.Format;
13+
import me.alexdevs.solstice.api.utils.PlaceholderUtils;
1314
import me.alexdevs.solstice.api.utils.PlayerUtils;
1415
import me.alexdevs.solstice.modules.afk.commands.ActiveTimeCommand;
1516
import me.alexdevs.solstice.modules.afk.commands.AfkCommand;
@@ -82,7 +83,7 @@ public void init() {
8283
//? }
8384

8485
if (isPlayerAfk(player))
85-
return PlaceholderResult.value(Format.parse(getConfig().tag));
86+
return PlaceholderResult.value(Format.parse(getConfig().tag, PlaceholderUtils.of(player)));
8687
else
8788
return PlaceholderResult.value("");
8889
});

src/main/java/me/alexdevs/solstice/modules/info/commands/MotdCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.alexdevs.solstice.modules.info.commands;
22

33
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
4+
import eu.pb4.placeholders.api.PlaceholderContext;
45
import me.alexdevs.solstice.api.utils.PlaceholderUtils;
56
import me.alexdevs.solstice.api.module.ModCommand;
67
import me.alexdevs.solstice.modules.info.InfoModule;

src/main/java/me/alexdevs/solstice/modules/note/commands/NotesCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import me.alexdevs.solstice.api.module.ModCommand;
1010
import me.alexdevs.solstice.api.text.Components;
1111
import me.alexdevs.solstice.api.text.Format;
12+
import me.alexdevs.solstice.api.utils.PlaceholderUtils;
1213
import me.alexdevs.solstice.api.utils.PlayerUtils;
1314
import me.alexdevs.solstice.core.coreModule.CoreModule;
1415
import me.alexdevs.solstice.modules.note.NoteModule;
@@ -94,7 +95,7 @@ private int listNotes(CommandContext<CommandSourceStack> context) throws Command
9495
"index", Component.nullToEmpty(String.valueOf(i)),
9596
"operator", Component.nullToEmpty(senderName),
9697
"date", Component.nullToEmpty(dateFormatter.format(note.creationDate)),
97-
"message", Format.parse(note.note),
98+
"message", Format.parse(note.note,PlaceholderUtils.of(context.getSource())),
9899
"checkButton", checkButton
99100
);
100101
output = output.append(module.locale().get("noteListEntry", placeholders));
@@ -130,7 +131,7 @@ private int checkNote(CommandContext<CommandSourceStack> context) throws Command
130131
var placeholders = Map.of(
131132
"operator", Component.nullToEmpty(operator),
132133
"date", Component.nullToEmpty(dateFormatter.format(note.creationDate)),
133-
"message", Format.parse(note.note),
134+
"message", Format.parse(note.note, PlaceholderUtils.of(context.getSource())),
134135
"deleteButton", deleteButton
135136
);
136137

src/main/java/me/alexdevs/solstice/modules/rtp/core/Locator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ private void load() {
192192
//? if >= 26.1 {
193193
/*world.getChunkSource().addTicketWithRadius(RTP_TICKET, ChunkPos.containing(attemptPos), 0);
194194
*///? } elif >= 1.21.11 {
195-
//world.getChunkSource().addTicketWithRadius(RTP_TICKET, new ChunkPos(attemptPos),0);
196-
//? } else {
195+
/*world.getChunkSource().addTicketWithRadius(RTP_TICKET, new ChunkPos(attemptPos),0);
196+
*///? } else {
197197
world.getChunkSource().addRegionTicket(RTP_TICKET, new ChunkPos(attemptPos), 0, attemptPos);
198198
//? }
199199
}

src/main/java/me/alexdevs/solstice/modules/styling/StylingModule.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import net.minecraft.server.players.PlayerList;
2020
import net.minecraft.world.scores.PlayerTeam;
2121

22+
import java.util.Locale;
23+
2224
public class StylingModule extends ModuleBase.Toggleable {
2325
public static final String ADVANCED_CHAT_FORMATTING_PERMISSION = "solstice.chat.advanced";
2426
public static final String LEGACY_CHAT_FORMATTING_PERMISSION = "solstice.chat.legacy";
@@ -133,7 +135,7 @@ public ChatFormatting getNameplateColor(ServerPlayer player) {
133135
}
134136

135137
//? if >= 26.1
136-
//return ChatFormatting.valueOf(color);
138+
//return ChatFormatting.valueOf(color.toUpperCase(Locale.ROOT));
137139
//? if < 26.1
138140
return ChatFormatting.getByName(color);
139141
}

0 commit comments

Comments
 (0)