From 73eb90351754c985c0c19dc9a0f9b880aaf35df3 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Fri, 4 Nov 2022 18:39:58 +0100 Subject: [PATCH] Implements RGB support for setLore and setName --- .../bookswithoutborders/command/CommandSetLore.java | 4 ++-- .../bookswithoutborders/command/CommandSetTitle.java | 10 ++++++---- .../config/BooksWithoutBordersConfig.java | 2 +- .../listener/SignEventListener.java | 4 ++-- .../bookswithoutborders/utility/BookFormatter.java | 2 +- .../bookswithoutborders/utility/EncryptionHelper.java | 2 +- .../bookswithoutborders/utility/FileHelper.java | 2 +- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetLore.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetLore.java index 96acf98..89dfe10 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetLore.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetLore.java @@ -2,8 +2,8 @@ package net.knarcraft.bookswithoutborders.command; import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.config.BooksWithoutBordersConfig; +import net.knarcraft.bookswithoutborders.utility.BookFormatter; import net.knarcraft.bookswithoutborders.utility.InventoryHelper; -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -44,7 +44,7 @@ public class CommandSetLore implements TabExecutor { String rawLore = String.join(" ", args); //Format lore - rawLore = ChatColor.translateAlternateColorCodes('&', rawLore); + rawLore = BookFormatter.translateAllColorCodes(rawLore); String[] loreParts = rawLore.split(BooksWithoutBordersConfig.getLoreSeparator()); List newLore = new ArrayList<>(Arrays.asList(loreParts)); diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetTitle.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetTitle.java index 09f9fdc..8e1c909 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetTitle.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSetTitle.java @@ -1,8 +1,8 @@ package net.knarcraft.bookswithoutborders.command; import net.knarcraft.bookswithoutborders.BooksWithoutBorders; +import net.knarcraft.bookswithoutborders.utility.BookFormatter; import net.knarcraft.bookswithoutborders.utility.InventoryHelper; -import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -22,7 +22,8 @@ import java.util.List; public class CommandSetTitle implements TabExecutor { @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, + @NotNull String[] args) { if (!(sender instanceof Player player)) { BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!"); return false; @@ -40,7 +41,7 @@ public class CommandSetTitle implements TabExecutor { } String title = String.join(" ", args); - title = ChatColor.translateAlternateColorCodes('&', title); + title = BookFormatter.translateAllColorCodes(title); ItemMeta itemMetadata = heldItem.getItemMeta(); if (itemMetadata == null) { @@ -66,7 +67,8 @@ public class CommandSetTitle implements TabExecutor { } @Override - public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { + public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, + @NotNull String[] args) { List options = new ArrayList<>(); options.add(""); return options; diff --git a/src/main/java/net/knarcraft/bookswithoutborders/config/BooksWithoutBordersConfig.java b/src/main/java/net/knarcraft/bookswithoutborders/config/BooksWithoutBordersConfig.java index e8706a2..24ad2d1 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/config/BooksWithoutBordersConfig.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/config/BooksWithoutBordersConfig.java @@ -2,7 +2,7 @@ package net.knarcraft.bookswithoutborders.config; import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.utility.EconomyHelper; -import org.bukkit.ChatColor; +import net.md_5.bungee.api.ChatColor; import org.bukkit.Material; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.Configuration; diff --git a/src/main/java/net/knarcraft/bookswithoutborders/listener/SignEventListener.java b/src/main/java/net/knarcraft/bookswithoutborders/listener/SignEventListener.java index 3bbecdf..2f30cf9 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/listener/SignEventListener.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/listener/SignEventListener.java @@ -7,7 +7,7 @@ import net.knarcraft.bookswithoutborders.utility.BookLoader; import net.knarcraft.bookswithoutborders.utility.EncryptionHelper; import net.knarcraft.bookswithoutborders.utility.FileHelper; import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper; -import org.bukkit.ChatColor; +import net.md_5.bungee.api.ChatColor; import org.bukkit.Material; import org.bukkit.Tag; import org.bukkit.block.Sign; @@ -158,7 +158,7 @@ public class SignEventListener implements Listener { private ChatColor getSignLine2Color(Sign sign) { String line = sign.getLine(2); if (!ChatColor.stripColor(line).equals(line)) { - return ChatColor.getByChar(sign.getLine(2).substring(1, 2)); + return ChatColor.getByChar(sign.getLine(2).substring(1, 2).charAt(0)); } else { return null; } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/utility/BookFormatter.java b/src/main/java/net/knarcraft/bookswithoutborders/utility/BookFormatter.java index 78e6449..186ade1 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/utility/BookFormatter.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/utility/BookFormatter.java @@ -121,7 +121,7 @@ public final class BookFormatter { * @param message

The string to search for color codes

* @return

The message with color codes translated

*/ - private static String translateAllColorCodes(String message) { + public static String translateAllColorCodes(String message) { message = ChatColor.translateAlternateColorCodes('&', message); Pattern pattern = Pattern.compile("(#[a-fA-F0-9]{6})"); Matcher matcher = pattern.matcher(message); diff --git a/src/main/java/net/knarcraft/bookswithoutborders/utility/EncryptionHelper.java b/src/main/java/net/knarcraft/bookswithoutborders/utility/EncryptionHelper.java index 632a0c2..819908e 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/utility/EncryptionHelper.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/utility/EncryptionHelper.java @@ -5,7 +5,7 @@ import net.knarcraft.bookswithoutborders.config.BooksWithoutBordersConfig; import net.knarcraft.bookswithoutborders.encryption.GenenCrypt; import net.knarcraft.bookswithoutborders.encryption.SubstitutionCipher; import net.knarcraft.bookswithoutborders.state.EncryptionStyle; -import org.bukkit.ChatColor; +import net.md_5.bungee.api.ChatColor; import org.bukkit.Material; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/net/knarcraft/bookswithoutborders/utility/FileHelper.java b/src/main/java/net/knarcraft/bookswithoutborders/utility/FileHelper.java index efd2099..6fe0158 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/utility/FileHelper.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/utility/FileHelper.java @@ -3,7 +3,7 @@ package net.knarcraft.bookswithoutborders.utility; import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.config.BooksWithoutBordersConfig; import net.knarcraft.bookswithoutborders.state.BookDirectory; -import org.bukkit.ChatColor; +import net.md_5.bungee.api.ChatColor; import org.bukkit.command.CommandSender; import java.io.BufferedReader;