Skip to content

Commit 2acac06

Browse files
authored
Merge pull request #10 from GoldenShad0w/v1.0.10
v1.0.10
2 parents d73be05 + 4e5bb88 commit 2acac06

File tree

6 files changed

+97
-14
lines changed

6 files changed

+97
-14
lines changed

pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>goldenshadow</groupId>
88
<artifactId>DisplayEntityEditor</artifactId>
9-
<version>1.0.9</version>
9+
<version>1.0.10</version>
1010
<packaging>jar</packaging>
1111

1212
<name>DisplayEntityEditor</name>
@@ -104,5 +104,15 @@
104104
<version>3.0.2</version>
105105
<scope>compile</scope>
106106
</dependency>
107+
<dependency>
108+
<groupId>net.kyori</groupId>
109+
<artifactId>adventure-text-minimessage</artifactId>
110+
<version>4.14.0</version>
111+
</dependency>
112+
<dependency>
113+
<groupId>net.kyori</groupId>
114+
<artifactId>adventure-platform-bukkit</artifactId>
115+
<version>4.3.0</version>
116+
</dependency>
107117
</dependencies>
108118
</project>

src/main/java/goldenshadow/displayentityeditor/DisplayEntityEditor.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import goldenshadow.displayentityeditor.inventories.InventoryFactory;
1010
import goldenshadow.displayentityeditor.items.GUIItems;
1111
import goldenshadow.displayentityeditor.items.InventoryItems;
12+
import net.kyori.adventure.text.minimessage.MiniMessage;
13+
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
14+
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
1215
import org.bstats.bukkit.Metrics;
1316
import org.bukkit.Bukkit;
1417
import org.bukkit.NamespacedKey;
@@ -30,6 +33,22 @@ public final class DisplayEntityEditor extends JavaPlugin {
3033
public static HashMap<UUID, Display> currentEditMap = new HashMap<>();
3134
public static NamespacedKey toolPrecisionKey;
3235
public static boolean alternateTextInput = false;
36+
public static boolean useMiniMessageFormat = false;
37+
public static MiniMessage miniMessage = MiniMessage.builder()
38+
.tags(TagResolver.builder()
39+
.resolver(StandardTags.color())
40+
.resolver(StandardTags.decorations())
41+
.resolver(StandardTags.gradient())
42+
.resolver(StandardTags.rainbow())
43+
.resolver(StandardTags.font())
44+
.resolver(StandardTags.newline())
45+
.resolver(StandardTags.keybind())
46+
.resolver(StandardTags.nbt())
47+
.resolver(StandardTags.score())
48+
.resolver(StandardTags.transition())
49+
.build()
50+
)
51+
.build();
3352

3453
/**
3554
* Used for when the plugin starts up
@@ -41,6 +60,7 @@ public void onEnable() {
4160
getConfig().options().copyDefaults(true);
4261
saveConfig();
4362
alternateTextInput = getConfig().getBoolean("alternate-text-input");
63+
useMiniMessageFormat = getConfig().getBoolean("use-minimessage-format");
4464

4565
conversationFactory = new ConversationFactory(plugin);
4666
inventoryFactory = new InventoryFactory(new GUIItems(), new InventoryItems());

src/main/java/goldenshadow/displayentityeditor/commands/Command.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public boolean onCommand(@NotNull CommandSender sender,@NotNull org.bukkit.comma
5959
if (args[0].equalsIgnoreCase("reload")) {
6060
DisplayEntityEditor.getPlugin().reloadConfig();
6161
DisplayEntityEditor.alternateTextInput = DisplayEntityEditor.getPlugin().getConfig().getBoolean("alternate-text-input");
62+
DisplayEntityEditor.useMiniMessageFormat = DisplayEntityEditor.getPlugin().getConfig().getBoolean("use-minimessage-format");
6263
p.sendMessage(Utilities.getInfoMessageFormat("Config reloaded!"));
6364
return true;
6465
}

src/main/java/goldenshadow/displayentityeditor/conversation/InputManager.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import goldenshadow.displayentityeditor.DisplayEntityEditor;
44
import goldenshadow.displayentityeditor.Utilities;
55
import goldenshadow.displayentityeditor.enums.InputType;
6+
import net.kyori.adventure.text.Component;
7+
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
8+
import net.md_5.bungee.api.chat.BaseComponent;
9+
import net.md_5.bungee.api.chat.TextComponent;
610
import org.bukkit.Bukkit;
711
import org.bukkit.ChatColor;
812
import org.bukkit.Color;
@@ -17,6 +21,7 @@
1721
*/
1822
public class InputManager {
1923

24+
2025
/**
2126
* Used to create a text input that awaits a string
2227
* @param player The player whose input is awaited
@@ -157,20 +162,42 @@ public static void successfulFloatInput(InputData inputData, float f, Player pla
157162
public static void successfulTextInput(InputData inputData, String s ,Player player) {
158163
switch (inputData.inputType()) {
159164
case NAME -> {
165+
160166
inputData.entity().setCustomNameVisible(true);
161-
inputData.entity().setCustomName(ChatColor.translateAlternateColorCodes('&', s));
167+
168+
if (DisplayEntityEditor.useMiniMessageFormat) {
169+
Component c = DisplayEntityEditor.miniMessage.deserialize(s);
170+
BaseComponent[] b = BungeeComponentSerializer.get().serialize(c);
171+
inputData.entity().setCustomName(TextComponent.toLegacyText(b));
172+
} else {
173+
inputData.entity().setCustomName(ChatColor.translateAlternateColorCodes('&', s));
174+
}
162175
player.sendRawMessage(Utilities.getInfoMessageFormat("Name set!"));
163176
}
164177
case TEXT -> {
165178
String message = s;
166-
message = message.replace("\\n", "\n");
167-
((TextDisplay) inputData.entity()).setText(ChatColor.translateAlternateColorCodes('&', message));
179+
180+
if (DisplayEntityEditor.useMiniMessageFormat) {
181+
Component c = DisplayEntityEditor.miniMessage.deserialize(s);
182+
BaseComponent[] b = BungeeComponentSerializer.get().serialize(c);
183+
((TextDisplay) inputData.entity()).setText(TextComponent.toLegacyText(b));
184+
} else {
185+
message = message.replace("\\n", "\n");
186+
((TextDisplay) inputData.entity()).setText(ChatColor.translateAlternateColorCodes('&', message));
187+
}
188+
168189
player.sendRawMessage(Utilities.getInfoMessageFormat("Set text!"));
169190
}
170191
case TEXT_APPEND -> {
171192
String message = s;
172-
message = message.replace("\\n", "\n");
173-
((TextDisplay) inputData.entity()).setText(ChatColor.translateAlternateColorCodes('&', ((TextDisplay) inputData.entity()).getText() + message));
193+
if (DisplayEntityEditor.useMiniMessageFormat) {
194+
Component c = DisplayEntityEditor.miniMessage.deserialize(s);
195+
BaseComponent[] b = BungeeComponentSerializer.get().serialize(c);
196+
((TextDisplay) inputData.entity()).setText(((TextDisplay) inputData.entity()).getText() + TextComponent.toLegacyText(b));
197+
} else {
198+
message = message.replace("\\n", "\n");
199+
((TextDisplay) inputData.entity()).setText(ChatColor.translateAlternateColorCodes('&', ((TextDisplay) inputData.entity()).getText() + message));
200+
}
174201
player.sendRawMessage(Utilities.getInfoMessageFormat("Appended text!"));
175202
}
176203
case BACKGROUND_COLOR -> {

src/main/java/goldenshadow/displayentityeditor/events/InventoryClick.java

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,17 @@ public void inventoryClick(InventoryClickEvent event) {
3838
if (event.isLeftClick()) {
3939
player.closeInventory();
4040
if (DisplayEntityEditor.alternateTextInput) {
41-
player.spigot().sendMessage(Utilities.getCommandMessage("name <new_name>", "You can use '&' for color codes."));
41+
if (DisplayEntityEditor.useMiniMessageFormat) {
42+
player.spigot().sendMessage(Utilities.getCommandMessage("name <new_name>", "Use MiniMessage formatting to stylize your input."));
43+
} else {
44+
player.spigot().sendMessage(Utilities.getCommandMessage("name <new_name>", "You can use '&' for color codes."));
45+
}
4246
} else {
43-
InputManager.createTextInput(player, "Please enter the new name it chat! You can use '&' for color codes.", new InputData(entity, InputType.NAME, null));
47+
if (DisplayEntityEditor.useMiniMessageFormat) {
48+
InputManager.createTextInput(player, "Please enter the new name it chat! Use MiniMessage formatting to stylize your input.", new InputData(entity, InputType.NAME, null));
49+
} else {
50+
InputManager.createTextInput(player, "Please enter the new name it chat! You can use '&' for color codes.", new InputData(entity, InputType.NAME, null));
51+
}
4452
}
4553
} else {
4654
entity.setCustomNameVisible(false);
@@ -374,18 +382,34 @@ public void inventoryClick(InventoryClickEvent event) {
374382
player.closeInventory();
375383

376384
if (DisplayEntityEditor.alternateTextInput) {
377-
player.spigot().sendMessage(Utilities.getCommandMessage("text <new_text>", "You can use '&' for color codes and \\n to create line breaks."));
378-
} else {
379-
InputManager.createTextInput(player, "Please enter the new text in chat! You can use '&' for color codes and \\n to create line breaks.", new InputData(entity, InputType.TEXT, null));
385+
if (DisplayEntityEditor.useMiniMessageFormat) {
386+
player.spigot().sendMessage(Utilities.getCommandMessage("text <new_text>", "Use MiniMessage formatting to stylize your input."));
387+
} else {
388+
player.spigot().sendMessage(Utilities.getCommandMessage("text <new_text>", "You can use '&' for color codes and \\n to create line breaks."));
389+
}
390+
} else {
391+
if (DisplayEntityEditor.useMiniMessageFormat) {
392+
InputManager.createTextInput(player, "Please enter the new text in chat! Use MiniMessage formatting to stylize your input.", new InputData(entity, InputType.TEXT, null));
393+
} else {
394+
InputManager.createTextInput(player, "Please enter the new text in chat! You can use '&' for color codes and \\n to create line breaks.", new InputData(entity, InputType.TEXT, null));
395+
}
380396
}
381397
}
382398
if (event.isRightClick()) {
383399
player.closeInventory();
384400

385401
if (DisplayEntityEditor.alternateTextInput) {
386-
player.spigot().sendMessage(Utilities.getCommandMessage("text_append <text_to_append>", "You can use '&' for color codes and \\n to create line breaks."));
402+
if (DisplayEntityEditor.useMiniMessageFormat) {
403+
player.spigot().sendMessage(Utilities.getCommandMessage("text_append <text_to_append>", "Use MiniMessage formatting to stylize your input."));
404+
} else {
405+
player.spigot().sendMessage(Utilities.getCommandMessage("text_append <text_to_append>", "You can use '&' for color codes and \\n to create line breaks."));
406+
}
387407
} else {
388-
InputManager.createTextInput(player, "Please enter the text in chat that should be appended! You can use '&' for color codes and \\n to create line breaks.", new InputData(entity, InputType.TEXT_APPEND, null));
408+
if (DisplayEntityEditor.useMiniMessageFormat) {
409+
InputManager.createTextInput(player, "Please enter the text in chat that should be appended! Use MiniMessage formatting to stylize your input.", new InputData(entity, InputType.TEXT_APPEND, null));
410+
} else {
411+
InputManager.createTextInput(player, "Please enter the text in chat that should be appended! You can use '&' for color codes and \\n to create line breaks.", new InputData(entity, InputType.TEXT_APPEND, null));
412+
}
389413
}
390414
}
391415
}

src/main/resources/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
send-update-message-on-join: true
2-
alternate-text-input: false
2+
alternate-text-input: false
3+
use-minimessage-format: false

0 commit comments

Comments
 (0)