Skip to content

Commit

Permalink
color code fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeTheTech committed Nov 29, 2023
1 parent d69c79b commit 0c8a7a4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/lee/code/pets/listeners/RenameListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public RenameListener(Pets pets) {
public void onPetRename(AsyncChatEvent e) {
if (!pets.getRenameManager().isPlayerRenaming(e.getPlayer().getUniqueId())) return;
e.setCancelled(true);
final String name = CoreUtil.trimToMaxCharacters(CoreUtil.removeSpecialCharacters(PlainTextComponentSerializer.plainText().serialize(e.message())), 20);
final String name = CoreUtil.trimToMaxCharacters(CoreUtil.removeSpecialCharactersButColorCodes(PlainTextComponentSerializer.plainText().serialize(e.message())), 20);
if (name.isBlank()) {
e.getPlayer().sendMessage(Lang.PREFIX.getComponent(null).append(Lang.ERROR_RENAME_BLANK.getComponent(null)));
return;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/lee/code/pets/utils/CoreUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.md_5.bungee.api.ChatColor;
import org.apache.commons.lang3.text.WordUtils;
import org.bukkit.Location;
import org.bukkit.Particle;
Expand Down Expand Up @@ -98,9 +97,9 @@ public static void spawnLoveAroundLocation(Location location) {
}
}

public static String removeSpecialCharacters(String input) {
public static String removeSpecialCharactersButColorCodes(String input) {
final StringBuilder output = new StringBuilder();
final String regex = "[^a-zA-Z0-9\\s]";
final String regex = "[^a-zA-Z0-9\\s#&]";
for (int i = 0; i < input.length(); i++) {
final char c = input.charAt(i);
if (Character.toString(c).matches(regex)) continue;
Expand Down

0 comments on commit 0c8a7a4

Please sign in to comment.