Skip to content

Commit e214d39

Browse files
committed
Allow fill with component
1 parent 61c6b33 commit e214d39

File tree

12 files changed

+259
-30
lines changed

12 files changed

+259
-30
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,5 +848,12 @@
848848
<version>2.8.0</version>
849849
<scope>provided</scope>
850850
</dependency>
851+
<dependency>
852+
<groupId>b</groupId>
853+
<artifactId>b</artifactId>
854+
<version>b</version>
855+
<scope>system</scope>
856+
<systemPath>${basedir}/lib/patched_1.17.1.jar</systemPath>
857+
</dependency>
851858
</dependencies>
852859
</project>

src/main/java/org/maxgamer/quickshop/api/localization/text/TextManager.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* This file is a part of project QuickShop, the name is TextManager.java
3+
* Copyright (C) PotatoCraft Studio and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License as published by the
7+
* Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
120
package org.maxgamer.quickshop.api.localization.text;
221

322
import org.bukkit.command.CommandSender;
@@ -29,7 +48,7 @@ public interface TextManager {
2948
* @return The text object
3049
*/
3150
@NotNull
32-
Text of(@NotNull String path, String... args);
51+
Text of(@NotNull String path, Object... args);
3352

3453
/**
3554
* Getting the translation with path with player's locale (if available)
@@ -40,7 +59,7 @@ public interface TextManager {
4059
* @return The text object
4160
*/
4261
@NotNull
43-
Text of(@Nullable CommandSender sender, @NotNull String path, String... args);
62+
Text of(@Nullable CommandSender sender, @NotNull String path, Object... args);
4463

4564
/**
4665
* Getting the translation with path with player's locale (if available)
@@ -51,7 +70,7 @@ public interface TextManager {
5170
* @return The text object
5271
*/
5372
@NotNull
54-
Text of(@Nullable UUID sender, @NotNull String path, String... args);
73+
Text of(@Nullable UUID sender, @NotNull String path, Object... args);
5574

5675
/**
5776
* Getting the translation with path with default locale (if available)
@@ -61,7 +80,7 @@ public interface TextManager {
6180
* @return The text object
6281
*/
6382
@NotNull
64-
TextList ofList(@NotNull String path, String... args);
83+
TextList ofList(@NotNull String path, Object... args);
6584

6685
/**
6786
* Getting the translation with path with player's locale (if available)
@@ -72,7 +91,7 @@ public interface TextManager {
7291
* @return The text object
7392
*/
7493
@NotNull
75-
TextList ofList(@Nullable UUID sender, @NotNull String path, String... args);
94+
TextList ofList(@Nullable UUID sender, @NotNull String path, Object... args);
7695

7796
/**
7897
* Getting the translation with path with player's locale (if available)
@@ -83,5 +102,5 @@ public interface TextManager {
83102
* @return The text object
84103
*/
85104
@NotNull
86-
TextList ofList(@Nullable CommandSender sender, @NotNull String path, String... args);
105+
TextList ofList(@Nullable CommandSender sender, @NotNull String path, Object... args);
87106
}

src/main/java/org/maxgamer/quickshop/api/localization/text/postprocessor/PostProcessor.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* This file is a part of project QuickShop, the name is PostProcessor.java
3+
* Copyright (C) PotatoCraft Studio and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License as published by the
7+
* Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
120
package org.maxgamer.quickshop.api.localization.text.postprocessor;
221

322
import org.bukkit.command.CommandSender;
@@ -14,5 +33,5 @@ public interface PostProcessor {
1433
* @return The string that processed
1534
*/
1635
@NotNull
17-
String process(@NotNull String text, @Nullable CommandSender sender, String... args);
36+
String process(@NotNull String text, @Nullable CommandSender sender, Object... args);
1837
}

src/main/java/org/maxgamer/quickshop/command/subcommand/SubCommand_Buy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public class SubCommand_Buy implements CommandHandler<Player> {
3636
private final QuickShop plugin;
3737

3838
@Override
39-
public void onCommand(@NotNull Player sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
39+
public void onCommand(@NotNull Player sender
40+
, @NotNull String commandLabel, @NotNull String[] cmdArg) {
4041
BlockIterator bIt = new BlockIterator(sender, 10);
4142

4243
while (bIt.hasNext()) {

src/main/java/org/maxgamer/quickshop/localization/text/JavaTextManager.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private JsonConfiguration getOverrideConfiguration(@NotNull String overrideFile,
244244
* @return The text object
245245
*/
246246
@Override
247-
public @NotNull Text of(@NotNull String path, String... args) {
247+
public @NotNull Text of(@NotNull String path, Object... args) {
248248
return new Text(this, (CommandSender) null, mapper.getDistribution(CROWDIN_LANGUAGE_FILE), mapper.getBundled(CROWDIN_LANGUAGE_FILE), path, args);
249249
}
250250

@@ -257,7 +257,7 @@ private JsonConfiguration getOverrideConfiguration(@NotNull String overrideFile,
257257
* @return The text object
258258
*/
259259
@Override
260-
public @NotNull Text of(@Nullable CommandSender sender, @NotNull String path, String... args) {
260+
public @NotNull Text of(@Nullable CommandSender sender, @NotNull String path, Object... args) {
261261
return new Text(this, sender, mapper.getDistribution(CROWDIN_LANGUAGE_FILE), mapper.getBundled(CROWDIN_LANGUAGE_FILE), path, args);
262262
}
263263

@@ -270,7 +270,7 @@ private JsonConfiguration getOverrideConfiguration(@NotNull String overrideFile,
270270
* @return The text object
271271
*/
272272
@Override
273-
public @NotNull Text of(@Nullable UUID sender, @NotNull String path, String... args) {
273+
public @NotNull Text of(@Nullable UUID sender, @NotNull String path, Object... args) {
274274
return new Text(this, sender, mapper.getDistribution(CROWDIN_LANGUAGE_FILE), mapper.getBundled(CROWDIN_LANGUAGE_FILE), path, args);
275275
}
276276

@@ -282,7 +282,7 @@ private JsonConfiguration getOverrideConfiguration(@NotNull String overrideFile,
282282
* @return The text object
283283
*/
284284
@Override
285-
public @NotNull TextList ofList(@NotNull String path, String... args) {
285+
public @NotNull TextList ofList(@NotNull String path, Object... args) {
286286
return new TextList(this, (CommandSender) null, mapper.getDistribution(CROWDIN_LANGUAGE_FILE), mapper.getBundled(CROWDIN_LANGUAGE_FILE), path, args);
287287
}
288288

@@ -295,7 +295,7 @@ private JsonConfiguration getOverrideConfiguration(@NotNull String overrideFile,
295295
* @return The text object
296296
*/
297297
@Override
298-
public @NotNull TextList ofList(@Nullable UUID sender, @NotNull String path, String... args) {
298+
public @NotNull TextList ofList(@Nullable UUID sender, @NotNull String path, Object... args) {
299299
return new TextList(this, sender, mapper.getDistribution(CROWDIN_LANGUAGE_FILE), mapper.getBundled(CROWDIN_LANGUAGE_FILE), path, args);
300300
}
301301

@@ -308,7 +308,7 @@ private JsonConfiguration getOverrideConfiguration(@NotNull String overrideFile,
308308
* @return The text object
309309
*/
310310
@Override
311-
public @NotNull TextList ofList(@Nullable CommandSender sender, @NotNull String path, String... args) {
311+
public @NotNull TextList ofList(@Nullable CommandSender sender, @NotNull String path, Object... args) {
312312
return new TextList(this, sender, mapper.getDistribution(CROWDIN_LANGUAGE_FILE), mapper.getBundled(CROWDIN_LANGUAGE_FILE), path, args);
313313
}
314314

@@ -318,10 +318,10 @@ public static class TextList implements org.maxgamer.quickshop.api.localization.
318318
private final QuickShop plugin;
319319
private final Map<String, JsonConfiguration> mapping;
320320
private final CommandSender sender;
321-
private final String[] args;
321+
private final Object[] args;
322322
private final JsonConfiguration bundled;
323323

324-
private TextList(JavaTextManager manager, CommandSender sender, Map<String, JsonConfiguration> mapping, JsonConfiguration bundled, String path, String... args) {
324+
private TextList(JavaTextManager manager, CommandSender sender, Map<String, JsonConfiguration> mapping, JsonConfiguration bundled, String path, Object... args) {
325325
this.plugin = manager.plugin;
326326
this.manager = manager;
327327
this.sender = sender;
@@ -331,7 +331,7 @@ private TextList(JavaTextManager manager, CommandSender sender, Map<String, Json
331331
this.args = args;
332332
}
333333

334-
private TextList(JavaTextManager manager, UUID sender, Map<String, JsonConfiguration> mapping, JsonConfiguration bundled, String path, String... args) {
334+
private TextList(JavaTextManager manager, UUID sender, Map<String, JsonConfiguration> mapping, JsonConfiguration bundled, String path, Object... args) {
335335
this.plugin = manager.plugin;
336336
this.manager = manager;
337337
if (sender != null) {
@@ -437,10 +437,10 @@ public static class Text implements org.maxgamer.quickshop.api.localization.text
437437
private final QuickShop plugin;
438438
private final Map<String, JsonConfiguration> mapping;
439439
private final CommandSender sender;
440-
private final String[] args;
440+
private final Object[] args;
441441
private final JsonConfiguration bundled;
442442

443-
private Text(JavaTextManager manager, CommandSender sender, Map<String, JsonConfiguration> mapping, JsonConfiguration bundled, String path, String... args) {
443+
private Text(JavaTextManager manager, CommandSender sender, Map<String, JsonConfiguration> mapping, JsonConfiguration bundled, String path, Object... args) {
444444
this.plugin = manager.plugin;
445445
this.manager = manager;
446446
this.sender = sender;
@@ -450,7 +450,7 @@ private Text(JavaTextManager manager, CommandSender sender, Map<String, JsonConf
450450
this.args = args;
451451
}
452452

453-
private Text(JavaTextManager manager, UUID sender, Map<String, JsonConfiguration> mapping, JsonConfiguration bundled, String path, String... args) {
453+
private Text(JavaTextManager manager, UUID sender, Map<String, JsonConfiguration> mapping, JsonConfiguration bundled, String path, Object... args) {
454454
this.plugin = manager.plugin;
455455
this.manager = manager;
456456
if (sender != null) {

src/main/java/org/maxgamer/quickshop/localization/text/postprocessing/impl/ColorProcessor.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* This file is a part of project QuickShop, the name is ColorProcessor.java
3+
* Copyright (C) PotatoCraft Studio and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License as published by the
7+
* Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
120
package org.maxgamer.quickshop.localization.text.postprocessing.impl;
221

322
import org.bukkit.command.CommandSender;
@@ -8,7 +27,7 @@
827

928
public class ColorProcessor implements PostProcessor {
1029
@Override
11-
public @NotNull String process(@NotNull String text, @Nullable CommandSender sender, String... args) {
30+
public @NotNull String process(@NotNull String text, @Nullable CommandSender sender, Object... args) {
1231
return Util.parseColours(text);
1332
}
1433

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,53 @@
1+
/*
2+
* This file is a part of project QuickShop, the name is FillerProcessor.java
3+
* Copyright (C) PotatoCraft Studio and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License as published by the
7+
* Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
120
package org.maxgamer.quickshop.localization.text.postprocessing.impl;
221

22+
import net.md_5.bungee.api.chat.BaseComponent;
323
import org.bukkit.command.CommandSender;
424
import org.jetbrains.annotations.NotNull;
525
import org.jetbrains.annotations.Nullable;
626
import org.maxgamer.quickshop.api.localization.text.postprocessor.PostProcessor;
727
import org.maxgamer.quickshop.util.MsgUtil;
28+
import org.maxgamer.quickshop.util.TextSplitter;
829

930
public class FillerProcessor implements PostProcessor {
1031
@Override
11-
public @NotNull String process(@NotNull String text, @Nullable CommandSender sender, String... args) {
12-
return MsgUtil.fillArgs(text, args);
32+
public @NotNull String process(@NotNull String text, @Nullable CommandSender sender, Object... args) {
33+
String[] strings = new String[args.length];
34+
boolean hit = false;
35+
for (int i = 0; i < args.length; i++) {
36+
37+
if (args[i].getClass() == String.class) {
38+
strings[i] = String.valueOf(args[i]);
39+
continue;
40+
}
41+
42+
if (args[i] instanceof BaseComponent[]) {
43+
if (hit) {
44+
throw new IllegalStateException("Only one BaseComponent[] can be applied into text");
45+
}
46+
strings[i] = TextSplitter.bakeComponent((BaseComponent[]) args[i]);
47+
hit = true;
48+
}
49+
strings[i] = String.valueOf(args[i]);
50+
}
51+
return MsgUtil.fillArgs(text, strings);
1352
}
1453
}

src/main/java/org/maxgamer/quickshop/localization/text/postprocessing/impl/PlaceHolderApiProcessor.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
* This file is a part of project QuickShop, the name is PlaceHolderApiProcessor.java
3+
* Copyright (C) PotatoCraft Studio and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License as published by the
7+
* Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
120
package org.maxgamer.quickshop.localization.text.postprocessing.impl;
221

322
import me.clip.placeholderapi.PlaceholderAPI;
@@ -10,7 +29,7 @@
1029

1130
public class PlaceHolderApiProcessor implements PostProcessor {
1231
@Override
13-
public @NotNull String process(@NotNull String text, @Nullable CommandSender sender, String... args) {
32+
public @NotNull String process(@NotNull String text, @Nullable CommandSender sender, Object... args) {
1433
if (sender instanceof OfflinePlayer) {
1534
if (Bukkit.getPluginManager().isPluginEnabled("PlaceHolderAPI")) {
1635
return PlaceholderAPI.setPlaceholders((OfflinePlayer) sender, text);

src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.maxgamer.quickshop.api.chat.ComponentPackage;
5353
import org.maxgamer.quickshop.api.event.*;
5454
import org.maxgamer.quickshop.api.shop.*;
55+
import org.maxgamer.quickshop.util.ReflectFactory;
5556
import org.maxgamer.quickshop.util.Util;
5657
import org.maxgamer.quickshop.util.logging.container.ShopRemoveLog;
5758

@@ -737,16 +738,15 @@ public List<ComponentPackage> getSignText(@NotNull String locale) {
737738
//line 3
738739
if (!plugin.getConfiguration().getBoolean("shop.force-use-item-original-name") && (!this.getItem().hasItemMeta() || !this.getItem().getItemMeta().hasDisplayName())) {
739740
TextComponent left = new TextComponent(plugin.text().of("signs.item-left").forLocale());
740-
TranslatableComponent mediumItem = new TranslatableComponent("item." + getItem().getType().getKey().getNamespace() + "." + getItem().getType().getKey().getKey());
741741
TextComponent right = new TextComponent(plugin.text().of("signs.item-right").forLocale());
742742
lines.add(new ComponentPackage(new ComponentBuilder()
743743
.append(left)
744-
.append(mediumItem)
744+
.append(new TranslatableComponent(ReflectFactory.getMaterialMinecraftNamespacedKey(getItem().getType())))
745745
.append(right)
746746
.create()));
747747
} else {
748748
lines.add(new ComponentPackage(new ComponentBuilder().append(TextComponent.fromLegacyText(plugin.text().of("signs.item-left").forLocale()))
749-
.append(TextComponent.fromLegacyText(Util.getItemStackName(getItem())))
749+
.append(new TextComponent(Util.getItemStackName(getItem())).toLegacyText())
750750
.append(TextComponent.fromLegacyText(plugin.text().of("signs.item-right").forLocale())).create()));
751751
}
752752

0 commit comments

Comments
 (0)