Skip to content

Commit 590aafa

Browse files
Fix bug in combine placeholder (#3840)
1 parent e88000d commit 590aafa

6 files changed

Lines changed: 47 additions & 13 deletions

File tree

src/generated/resources/assets/gtceu/lang/en_ud.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3576,6 +3576,12 @@
35763576
"gtceu.placeholder_info.energyCapacity.0": "pǝɹoʇs ǝq uɐɔ ʇɐɥʇ ʎbɹǝuǝ ɟo ʇunoɯɐ xɐɯ ǝɥʇ suɹnʇǝᴚ",
35773577
"gtceu.placeholder_info.energyCapacity.1": ":ǝbɐs∩",
35783578
"gtceu.placeholder_info.energyCapacity.2": "ʎʇıɔɐdɐɔ ʎbɹǝuǝ ǝɥʇ >- }ʎʇıɔɐdɐƆʎbɹǝuǝ{",
3579+
"gtceu.placeholder_info.eval.0": "sɹǝpןoɥǝɔɐןd ʎɐɯ ɥɔıɥʍ buıɹʇs pǝpıʌoɹd ǝɥʇ buıʇɐnןɐʌǝ ɟo ʇןnsǝɹ ǝɥʇ suɹnʇǝᴚ",
3580+
"gtceu.placeholder_info.eval.1": ":ǝbɐs∩",
3581+
"gtceu.placeholder_info.eval.2": "bɟǝpɔqɐ >- }bɟǝpɔqɐ ןɐʌǝ{ ",
3582+
"gtceu.placeholder_info.eval.3": " ɐ ɐ ɐ ɐ ɐ :ɐ buıʇɐǝdǝɹ >- \"}\"\\ ɐ\"\\ ϛ ʇɐǝdǝɹ{ :ɐ buıʇɐǝdǝɹ\" ןɐʌǝ{ ",
3583+
"gtceu.placeholder_info.eval.4": "}ʇxǝʇ ɯopuɐɹ ǝɯos{ >- \"\\\"}ʇxǝʇ ɯopuɐɹ ǝɯos{\"\"\\ ןɐʌǝ{ ",
3584+
"gtceu.placeholder_info.eval.5": "ʇxǝʇ ǝɹoɯ }sǝɔɐds ɥʇıʍ buıɥʇǝɯos{ ʇxǝʇ >- \"ʇxǝʇ ǝɹoɯ \"\"\\\"}sǝɔɐds ɥʇıʍ buıɥʇǝɯos{\"\"\\\" ʇxǝʇ\" ןɐʌǝ{ ",
35793585
"gtceu.placeholder_info.fluidCount.0": "˙)pǝɹǝʇןıɟ ǝq uɐɔ( spınןɟ ɟo ʇunoɯɐ ǝɥʇ suɹnʇǝᴚ",
35803586
"gtceu.placeholder_info.fluidCount.1": ":ǝbɐs∩",
35813587
"gtceu.placeholder_info.fluidCount.2": "pǝıɟıɔǝds ɟı pIpınןɟ ɥʇıʍ pınןɟ ǝɥʇ ɹo 'spınןɟ ןןɐ ɟo ʇunoɯɐ ǝɥʇ >- }]pIpınןɟ[ ʇunoƆpınןɟ{ ",

src/generated/resources/assets/gtceu/lang/en_us.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3576,6 +3576,12 @@
35763576
"gtceu.placeholder_info.energyCapacity.0": "Returns the max amount of energy that can be stored",
35773577
"gtceu.placeholder_info.energyCapacity.1": "Usage:",
35783578
"gtceu.placeholder_info.energyCapacity.2": "{energyCapacity} -> the energy capacity",
3579+
"gtceu.placeholder_info.eval.0": "Returns the result of evaluating the provided string which may placeholders",
3580+
"gtceu.placeholder_info.eval.1": "Usage:",
3581+
"gtceu.placeholder_info.eval.2": " {eval abcdefg} -> abcdefg",
3582+
"gtceu.placeholder_info.eval.3": " {eval \"repeating a: {repeat 5 \\\"a \\\"}\" -> repeating a: a a a a a ",
3583+
"gtceu.placeholder_info.eval.4": " {eval \\\"\"{some random text}\"\\\" -> {some random text}",
3584+
"gtceu.placeholder_info.eval.5": " {eval \"text \"\\\"\"{something with spaces}\"\\\"\" more text\" -> text {something with spaces} more text",
35793585
"gtceu.placeholder_info.fluidCount.0": "Returns the amount of fluids (can be filtered).",
35803586
"gtceu.placeholder_info.fluidCount.1": "Usage:",
35813587
"gtceu.placeholder_info.fluidCount.2": " {fluidCount [fluidId]} -> the amount of all fluids, or the fluid with fluidId if specified",

src/main/java/com/gregtechceu/gtceu/api/placeholder/MultiLineComponent.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import net.minecraft.network.chat.*;
1010

1111
import lombok.Getter;
12-
import lombok.Setter;
1312
import org.jetbrains.annotations.Nullable;
1413

1514
import java.util.ArrayList;
@@ -19,7 +18,6 @@
1918
public class MultiLineComponent extends ArrayList<MutableComponent> {
2019

2120
@Getter
22-
@Setter
2321
private boolean ignoreSpaces = false;
2422

2523
public MultiLineComponent(List<MutableComponent> components) {
@@ -150,4 +148,9 @@ public long toLong() {
150148
if (this.size() > 1) throw new NumberFormatException(this.toString());
151149
return Long.parseLong(this.get(0).getString());
152150
}
151+
152+
public MultiLineComponent setIgnoreSpaces(boolean ignoreSpaces) {
153+
this.ignoreSpaces = ignoreSpaces;
154+
return this;
155+
}
153156
}

src/main/java/com/gregtechceu/gtceu/api/placeholder/PlaceholderHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public static MultiLineComponent processPlaceholders(String s, PlaceholderContex
111111
try {
112112
if (stack.isEmpty()) throw new UnexpectedBracketException();
113113
MultiLineComponent result = processPlaceholder(placeholder, ctx);
114-
if (result.isIgnoreSpaces()) {
114+
if (result.isIgnoreSpaces() || stack.size() == 1) {
115115
GTUtil.getLast(stack.peek()).append(result);
116116
} else {
117117
for (int i = 0; i < result.size(); i++) {

src/main/java/com/gregtechceu/gtceu/common/data/GTPlaceholders.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,10 @@ public MultiLineComponent apply(PlaceholderContext ctx,
157157
PlaceholderUtils.checkArgs(args, 2, true);
158158
try {
159159
if (GTStringUtils.toDouble(args.get(0)) != 0) {
160-
return args.get(1);
161-
} else if (args.size() > 2) return args.get(2);
162-
else return MultiLineComponent.empty();
160+
return new MultiLineComponent(args.get(1)).setIgnoreSpaces(true);
161+
} else if (args.size() > 2) {
162+
return new MultiLineComponent(args.get(2)).setIgnoreSpaces(true);
163+
} else return MultiLineComponent.empty();
163164
} catch (NumberFormatException e) {
164165
return args.get(1);
165166
}
@@ -223,9 +224,10 @@ public MultiLineComponent apply(PlaceholderContext ctx,
223224
List<MultiLineComponent> args) throws PlaceholderException {
224225
PlaceholderUtils.checkArgs(args, 2);
225226
int count = PlaceholderUtils.toInt(args.get(0));
227+
PlaceholderUtils.checkRange("n", 0, 50000, count);
226228
MultiLineComponent out = MultiLineComponent.empty();
227229
for (int i = 0; i < count; i++) out.append(args.get(1));
228-
return out;
230+
return out.setIgnoreSpaces(true);
229231
}
230232
});
231233
PlaceholderHandler.addPlaceholder(new Placeholder("block") {
@@ -256,7 +258,7 @@ public MultiLineComponent apply(PlaceholderContext ctx,
256258
PlaceholderUtils.checkArgs(args, 1, true);
257259
int i = PlaceholderUtils.toInt(args.get(0));
258260
PlaceholderUtils.checkArgs(args, i + 1, true);
259-
return args.get(i + 1);
261+
return new MultiLineComponent(args.get(i + 1)).setIgnoreSpaces(true);
260262
}
261263
});
262264
PlaceholderHandler.addPlaceholder(new Placeholder("redstone") {
@@ -290,7 +292,7 @@ public MultiLineComponent apply(PlaceholderContext ctx,
290292
int i = PlaceholderUtils.toInt(args.get(0));
291293
if (ctx.previousText() == null) throw new NotSupportedException();
292294
PlaceholderUtils.checkRange("line", 1, ctx.previousText().size(), i);
293-
return MultiLineComponent.of(ctx.previousText().get(i - 1));
295+
return MultiLineComponent.of(ctx.previousText().get(i - 1)).setIgnoreSpaces(true);
294296
}
295297
});
296298
PlaceholderHandler.addPlaceholder(new Placeholder("progress") {
@@ -407,7 +409,8 @@ public MultiLineComponent apply(PlaceholderContext ctx,
407409
if (GTStringUtils.equals(args.get(2), "")) args.set(2, MultiLineComponent.literal(p));
408410
if (GTStringUtils.equals(args.get(0), "get"))
409411
return MultiLineComponent
410-
.literal(data.getString(PlaceholderUtils.toInt(args.get(2)) % capacity));
412+
.literal(data.getString(PlaceholderUtils.toInt(args.get(2)) % capacity))
413+
.setIgnoreSpaces(true);
411414
else if (args.get(0).equalsString("set")) {
412415
data.set(PlaceholderUtils.toInt(args.get(2)) % capacity,
413416
StringTag.valueOf(args.get(3).toString()));
@@ -438,8 +441,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, List<MultiLineComponent>
438441
out.append(args.get(i));
439442
if (i != args.size() - 1) out.append(" ");
440443
}
441-
out.setIgnoreSpaces(true);
442-
return out;
444+
return out.setIgnoreSpaces(true);
443445
}
444446
});
445447
PlaceholderHandler.addPlaceholder(new Placeholder("nbt") {
@@ -488,7 +490,7 @@ public MultiLineComponent apply(PlaceholderContext ctx,
488490
public MultiLineComponent apply(PlaceholderContext ctx,
489491
List<MultiLineComponent> args) throws PlaceholderException {
490492
PlaceholderUtils.checkArgs(args, 1);
491-
return MultiLineComponent.literal((char) PlaceholderUtils.toInt(args.get(0)));
493+
return MultiLineComponent.literal((char) PlaceholderUtils.toInt(args.get(0))).setIgnoreSpaces(true);
492494
}
493495
});
494496
PlaceholderHandler.addPlaceholder(new Placeholder("subList") {
@@ -504,6 +506,7 @@ public MultiLineComponent apply(PlaceholderContext ctx,
504506
MultiLineComponent out = MultiLineComponent.empty();
505507
for (int i = l; i < r - 1; i++) out.append(args.get(i)).append(' ');
506508
out.append(args.get(r - 1));
509+
out.setIgnoreSpaces(true);
507510
return out;
508511
}
509512
});
@@ -807,5 +810,14 @@ public MultiLineComponent apply(PlaceholderContext ctx,
807810
}
808811
}
809812
});
813+
PlaceholderHandler.addPlaceholder(new Placeholder("eval") {
814+
815+
@Override
816+
public MultiLineComponent apply(PlaceholderContext ctx,
817+
List<MultiLineComponent> args) throws PlaceholderException {
818+
PlaceholderUtils.checkArgs(args, 1);
819+
return PlaceholderHandler.processPlaceholders(args.get(0).toString(), ctx);
820+
}
821+
});
810822
}
811823
}

src/main/java/com/gregtechceu/gtceu/data/lang/LangHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,13 @@ public static void init(RegistrateLangProvider provider) {
15921592
" {ender redstone <channel> [player_data_item_slot] -> redstone signal level",
15931593
" {ender redstone <channel> <player_data_item_slot> <signal> -> sets the redstone signal outputed to the ender redstone link, returns empty string",
15941594
"The player_data_item_slot argument may be left empty (not 0, empty string)");
1595+
multiLang(provider, "gtceu.placeholder_info.eval",
1596+
"Returns the result of evaluating the provided string which may placeholders",
1597+
"Usage:",
1598+
" {eval abcdefg} -> abcdefg",
1599+
" {eval \"repeating a: {repeat 5 \\\"a \\\"}\" -> repeating a: a a a a a ",
1600+
" {eval \\\"\"{some random text}\"\\\" -> {some random text}",
1601+
" {eval \"text \"\\\"\"{something with spaces}\"\\\"\" more text\" -> text {something with spaces} more text");
15951602
provider.add("gtceu.ender_item_link_cover.title", "Ender Item Link");
15961603
provider.add("gtceu.ender_redstone_link_cover.title", "Ender Redstone Link");
15971604
provider.add("gtceu.ender_redstone_link_cover.label", "Redstone power: %d");

0 commit comments

Comments
 (0)