|
| 1 | +# PrismaticAPI |
| 2 | + |
| 3 | +PrismaticAPI is a powerful, versatile utility designed to enhance text formatting and color manipulation in your Bukkit/Spigot/Paper plugins. It provides a robust API for converting hexadecimal color codes to Bukkit's ChatColor objects, creating dynamic gradients and rainbow effects, and processing strings for both legacy and modern color formats. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +The **PrismaticAPI** package offers a suite of methods to: |
| 10 | + |
| 11 | +- **Map Colors:** |
| 12 | + Convert AWT `Color` objects to Bukkit `ChatColor` using a predefined color map, ensuring that both legacy and modern RGB color support are handled. |
| 13 | + |
| 14 | +- **Apply Color Effects:** |
| 15 | + Apply gradient and rainbow effects to strings. These methods generate arrays of `ChatColor` objects that are then applied character-by-character to create smooth color transitions. |
| 16 | + |
| 17 | +- **Colorize Text:** |
| 18 | + Process input strings by applying registered color patterns, translating alternate color codes (using `&`), and adjusting output based on the player's client version. |
| 19 | + |
| 20 | +- **Strip Formatting:** |
| 21 | + Remove Bukkit, RGB, and special formatting codes from strings to yield plain text. |
| 22 | + |
| 23 | +All these functionalities are provided in a single, unified API that makes it simple to integrate advanced color effects into chat messages, GUIs, logs, and more. |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Key Features |
| 28 | + |
| 29 | +- **Color Mapping:** |
| 30 | + Uses an immutable map to associate standard AWT `Color` objects with their corresponding Bukkit `ChatColor` codes. |
| 31 | + |
| 32 | +- **Gradient Effects:** |
| 33 | + Create smooth color gradients between two colors by generating an array of intermediary colors that can be applied to text. |
| 34 | + |
| 35 | +- **Rainbow Effects:** |
| 36 | + Dynamically generate a rainbow effect across a string based on a defined number of steps and a saturation parameter. |
| 37 | + |
| 38 | +- **Legacy and Modern Support:** |
| 39 | + Automatically adapts to legacy (16-color mode) and modern RGB color support based on the server version and player client. |
| 40 | + |
| 41 | +- **Text Processing:** |
| 42 | + Provides methods to apply all registered color patterns to text, as well as strip any color or formatting codes, ensuring clean plain text output when needed. |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +## Usage Examples |
| 47 | + |
| 48 | +### Example 1: Colorizing a Chat Message |
| 49 | + |
| 50 | +```java |
| 51 | +package com.example.myplugin; |
| 52 | + |
| 53 | +import me.croabeast.prismatic.PrismaticAPI; |
| 54 | +import org.bukkit.entity.Player; |
| 55 | +import org.bukkit.plugin.java.JavaPlugin; |
| 56 | + |
| 57 | +public class MyPlugin extends JavaPlugin { |
| 58 | + |
| 59 | + @Override |
| 60 | + public void onEnable() { |
| 61 | + // Example player (could be obtained from an event) |
| 62 | + Player player = /* get player reference */; |
| 63 | + |
| 64 | + // Colorize a message using PrismaticAPI |
| 65 | + String message = "&aHello, &bworld!"; |
| 66 | + String coloredMessage = PrismaticAPI.colorize(player, message); |
| 67 | + |
| 68 | + // Send the colorized message |
| 69 | + player.sendMessage(coloredMessage); |
| 70 | + } |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +### Example 2: Applying a Gradient Effect |
| 75 | + |
| 76 | +```java |
| 77 | +package com.example.myplugin; |
| 78 | + |
| 79 | +import me.croabeast.prismatic.PrismaticAPI; |
| 80 | +import org.bukkit.ChatColor; |
| 81 | +import org.bukkit.Color; |
| 82 | +import org.bukkit.plugin.java.JavaPlugin; |
| 83 | + |
| 84 | +public class MyPlugin extends JavaPlugin { |
| 85 | + |
| 86 | + @Override |
| 87 | + public void onEnable() { |
| 88 | + // Define the start and end colors for the gradient |
| 89 | + Color startColor = new Color(255, 0, 0); // Red |
| 90 | + Color endColor = new Color(0, 0, 255); // Blue |
| 91 | + |
| 92 | + // Apply a gradient effect to the text "Gradient Text" |
| 93 | + String gradientText = PrismaticAPI.applyGradient("Gradient Text", startColor, endColor, false); |
| 94 | + |
| 95 | + // Log the gradient text (or send it to a player) |
| 96 | + getLogger().info(gradientText); |
| 97 | + } |
| 98 | +} |
| 99 | +``` |
| 100 | + |
| 101 | +### Example 3: Stripping All Formatting |
| 102 | + |
| 103 | +```java |
| 104 | +package com.example.myplugin; |
| 105 | + |
| 106 | +import me.croabeast.prismatic.PrismaticAPI; |
| 107 | +import org.bukkit.plugin.java.JavaPlugin; |
| 108 | + |
| 109 | +public class MyPlugin extends JavaPlugin { |
| 110 | + |
| 111 | + @Override |
| 112 | + public void onEnable() { |
| 113 | + String formattedText = "&aThis &btext &chas &dcolored &ewith &6codes"; |
| 114 | + |
| 115 | + // Remove all color and formatting codes |
| 116 | + String plainText = PrismaticAPI.stripAll(formattedText); |
| 117 | + |
| 118 | + getLogger().info("Plain text: " + plainText); |
| 119 | + } |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +## Conclusion |
| 126 | + |
| 127 | +**PrismaticAPI** consolidates advanced color manipulation and text formatting functions into a single, easy-to-use API. Whether you need to create eye-catching gradients, implement dynamic rainbow effects, or simply clean up formatted text, PrismaticAPI provides the tools to do so effectively. Its support for both legacy and modern RGB formats ensures broad compatibility across different server versions and player clients. |
| 128 | + |
| 129 | +Enhance your plugin’s visual presentation and user experience with PrismaticAPI! |
| 130 | + |
| 131 | +Happy coding! |
| 132 | +— *CroaBeast* |
0 commit comments