mirror of
https://github.com/CarmJos/UserPrefix.git
synced 2024-09-19 20:15:47 +00:00
支持支持Hex颜色!(1.16以上版本) 格式 &(#颜色代码) 。
This commit is contained in:
parent
8bf19a69f8
commit
b6319eec78
13
README.md
13
README.md
@ -1,5 +1,7 @@
|
||||
![BANNER](https://raw.githubusercontent.com/CarmJos/UserPrefix/master/img/banner.png)
|
||||
|
||||
# 用户前缀系统插件
|
||||
|
||||
[![CodeFactor](https://www.codefactor.io/repository/github/carmjos/userprefix/badge?s=b76fec1f64726b5f19989aace6adb5f85fdab840)](https://www.codefactor.io/repository/github/carmjos/userprefix)
|
||||
[![Java CI with Maven](https://github.com/CarmJos/UserPrefix/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/CarmJos/UserPrefix/actions/workflows/maven.yml)
|
||||
![](https://visitor-badge.glitch.me/badge?page_id=userprefix.readme)
|
||||
@ -11,9 +13,11 @@
|
||||
本插件已在 [MCBBS](https://www.mcbbs.net/forum.php?mod=viewthread&tid=1261503) 上发布。
|
||||
|
||||
## 示例
|
||||
|
||||
![example](https://raw.githubusercontent.com/CarmJos/UserPrefix/master/img/using-example.png)
|
||||
|
||||
## 依赖
|
||||
|
||||
- **[必须]** 插件本体基于 [Spigot-API](https://hub.spigotmc.org/stash/projects/SPIGOT)、[BukkitAPI](http://bukkit.org/) 实现。
|
||||
- **[必须]** 数据部分基于 [LuckPerms](https://www.spigotmc.org/resources/luckperms.28140/) 实现。
|
||||
- **[推荐]** 变量部分基于 [PlaceholderAPI](https://www.spigotmc.org/resources/6245/) 实现。
|
||||
@ -31,8 +35,10 @@
|
||||
- 具体的设定请参考其他文档哦~
|
||||
- TabList自动按照前缀的权重排序 (如有冲突可关掉)
|
||||
- 玩家头顶前缀显示 (如有冲突可关掉)
|
||||
- 自动排序,且可翻页的GUI
|
||||
- 支持PlaceholderAPI变量
|
||||
- 自动排序,且可翻页的GUI!
|
||||
- 支持PlaceholderAPI变量!(凡支持的都可以使用,如BungeeTabListPlus)
|
||||
- 支持Hex颜色!(1.16以上版本) 格式 `&(#颜色代码)`
|
||||
- 示例: LightSlateBlue `&(#8470FF)` 、 DarkSlateBlue `&(#483D8B)`
|
||||
|
||||
## 注意事项
|
||||
|
||||
@ -49,6 +55,7 @@
|
||||
如有冲突导致其他插件的计分板无法显示,请关掉配置文件中`functions.OnNamePrefix`。
|
||||
|
||||
### 3. 物品图标配置问题
|
||||
|
||||
物品相关均通过Bukkit提供的ItemStack序列化方法读取,相关配置方式请参考[ItemStack Serialization(物品序列化)](https://www.spigotmc.org/wiki/itemstack-serialization/)。
|
||||
|
||||
## 指令
|
||||
@ -190,6 +197,7 @@ prefixes:
|
||||
```
|
||||
|
||||
## 支持与捐赠
|
||||
|
||||
本项目由 [YourCraft(你的世界)](https://www.ycraft.cn) 团队提供长期支持与维护。
|
||||
![TeamLogo](https://raw.githubusercontent.com/CarmJos/UserPrefix/master/img/team-logo.png)
|
||||
|
||||
@ -200,5 +208,6 @@ prefixes:
|
||||
<img height=25% width=25% src="https://raw.githubusercontent.com/CarmJos/UserPrefix/master/img/PAY.jpg" />
|
||||
|
||||
## 开源协议
|
||||
|
||||
本项目源码采用 [GNU General Public License v3.0](https://opensource.org/licenses/GPL-3.0) 开源协议。
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<artifactId>UserPrefix</artifactId>
|
||||
<version>1.2.2</version>
|
||||
<version>1.2.3</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
|
@ -83,12 +83,12 @@ public class Main extends JavaPlugin {
|
||||
}
|
||||
|
||||
public static void log(String message) {
|
||||
Bukkit.getConsoleSender().sendMessage(ColorParser.parseColor("[" + getInstance().getName() + "] " + message));
|
||||
Bukkit.getConsoleSender().sendMessage(ColorParser.parse("[" + getInstance().getName() + "] " + message));
|
||||
}
|
||||
|
||||
public static void debug(String message) {
|
||||
if (PrefixConfig.DEBUG.get()) {
|
||||
log("[DEBUG] " + ColorParser.parseColor(message));
|
||||
log("[DEBUG] " + message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import cc.carm.plugin.userprefix.manager.PrefixManager;
|
||||
import cc.carm.plugin.userprefix.manager.UserManager;
|
||||
import cc.carm.plugin.userprefix.model.ConfiguredPrefix;
|
||||
import cc.carm.plugin.userprefix.ui.PrefixSelectGUI;
|
||||
import cc.carm.plugin.userprefix.util.ColorParser;
|
||||
import cc.carm.plugin.userprefix.util.MessageUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -21,11 +21,11 @@ public class UserPrefixAdminCommand implements CommandExecutor {
|
||||
if (args.length == 1) {
|
||||
String aim = args[0];
|
||||
if (aim.equalsIgnoreCase("list")) {
|
||||
sender.sendMessage(ColorParser.parseColor("&3&l用户前缀系统 &f前缀列表"));
|
||||
MessageUtil.send(sender, "&3&l用户前缀系统 &f前缀列表");
|
||||
for (ConfiguredPrefix value : PrefixManager.getPrefixes().values()) {
|
||||
sender.sendMessage(ColorParser.parseColor("&8#" + value.getWeight() + " &f" + value.getIdentifier()));
|
||||
sender.sendMessage(ColorParser.parseColor("&8- &7显示名 &r" + value.getName() + " &7权限&r " + value.getPermission()));
|
||||
sender.sendMessage(ColorParser.parseColor("&8- &7内容示例&r " + value.getContent() + sender.getName()));
|
||||
MessageUtil.send(sender, "&8#" + value.getWeight() + " &f" + value.getIdentifier());
|
||||
MessageUtil.send(sender, "&8- &7显示名 &r" + value.getName() + " &7权限&r " + value.getPermission());
|
||||
MessageUtil.send(sender, "&8- &7内容示例&r " + value.getContent() + sender.getName());
|
||||
}
|
||||
return true;
|
||||
} else if (aim.equalsIgnoreCase("reload")) {
|
||||
@ -42,7 +42,7 @@ public class UserPrefixAdminCommand implements CommandExecutor {
|
||||
*/
|
||||
UserManager.updatePrefixView(onlinePlayer, false);
|
||||
}
|
||||
sender.sendMessage(ColorParser.parseColor("&a&l重载完成!&7共耗时 &f" + (System.currentTimeMillis() - s1) + " ms&7。"));
|
||||
MessageUtil.send(sender, "&a&l重载完成!&7共耗时 &f" + (System.currentTimeMillis() - s1) + " ms&7。");
|
||||
return true;
|
||||
}
|
||||
return help(sender);
|
||||
@ -51,11 +51,11 @@ public class UserPrefixAdminCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
public static boolean help(CommandSender sender) {
|
||||
sender.sendMessage(ColorParser.parseColor("&3&l用户前缀系统 &f帮助"));
|
||||
sender.sendMessage(ColorParser.parseColor("&8#&f list"));
|
||||
sender.sendMessage(ColorParser.parseColor("&8- &7查看当前前缀列表。"));
|
||||
sender.sendMessage(ColorParser.parseColor("&8#&f reload"));
|
||||
sender.sendMessage(ColorParser.parseColor("&8- &7重载前缀配置。"));
|
||||
MessageUtil.send(sender, "&3&l用户前缀系统 &f帮助");
|
||||
MessageUtil.send(sender, "&8#&f list");
|
||||
MessageUtil.send(sender, "&8- &7查看当前前缀列表。");
|
||||
MessageUtil.send(sender, "&8#&f reload");
|
||||
MessageUtil.send(sender, "&8- &7重载前缀配置。");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class ConfiguredPrefix {
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return ColorParser.parseColor(content);
|
||||
return ColorParser.parse(content);
|
||||
}
|
||||
|
||||
public int getWeight() {
|
||||
|
@ -1,10 +1,33 @@
|
||||
|
||||
package cc.carm.plugin.userprefix.util;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ColorParser {
|
||||
|
||||
public static String parse(String text) {
|
||||
text = parseHexColor(text);
|
||||
return parseColor(text);
|
||||
}
|
||||
|
||||
public static String parseColor(final String text) {
|
||||
return text.replaceAll("&", "§").replace("§§", "&");
|
||||
}
|
||||
|
||||
public static String parseHexColor(String text) {
|
||||
Pattern pattern = Pattern.compile("&\\((&?#[0-9a-fA-F]{6})\\)");
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
while (matcher.find()) {
|
||||
String hexColor = text.substring(matcher.start() + 2, matcher.end() - 1);
|
||||
hexColor = hexColor.replace("&", "");
|
||||
StringBuilder bukkitColorCode = new StringBuilder('§' + "x");
|
||||
for (int i = 1; i < hexColor.length(); i++) {
|
||||
bukkitColorCode.append('§').append(hexColor.charAt(i));
|
||||
}
|
||||
text = text.replaceAll("&\\(" + hexColor + "\\)", bukkitColorCode.toString().toLowerCase());
|
||||
matcher.reset(text);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public class ItemStackFactory {
|
||||
public ItemStackFactory setDisplayName(@NotNull String name) {
|
||||
ItemMeta im = this.item.getItemMeta();
|
||||
if (im != null) {
|
||||
im.setDisplayName(ColorParser.parseColor(name));
|
||||
im.setDisplayName(ColorParser.parse(name));
|
||||
this.item.setItemMeta(im);
|
||||
}
|
||||
return this;
|
||||
@ -71,7 +71,7 @@ public class ItemStackFactory {
|
||||
if (im != null) {
|
||||
im.setLore(
|
||||
loreList.stream()
|
||||
.map(ColorParser::parseColor)
|
||||
.map(ColorParser::parse)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
this.item.setItemMeta(im);
|
||||
@ -83,7 +83,7 @@ public class ItemStackFactory {
|
||||
ItemMeta im = this.item.getItemMeta();
|
||||
if (im != null) {
|
||||
List<String> lore = im.getLore() != null ? im.getLore() : new ArrayList<>();
|
||||
lore.add(ColorParser.parseColor(s));
|
||||
lore.add(ColorParser.parse(s));
|
||||
im.setLore(lore);
|
||||
this.item.setItemMeta(im);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cc.carm.plugin.userprefix.util;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
@ -12,34 +13,34 @@ public class MessageUtil {
|
||||
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||
}
|
||||
|
||||
public static void send(Player player, List<String> messages) {
|
||||
public static void send(CommandSender sender, List<String> messages) {
|
||||
for (String s : messages) {
|
||||
player.sendMessage(ColorParser.parseColor(s));
|
||||
sender.sendMessage(ColorParser.parse(s));
|
||||
}
|
||||
}
|
||||
|
||||
public static void send(Player player, String... messages) {
|
||||
send(player, Arrays.asList(messages));
|
||||
public static void send(CommandSender sender, String... messages) {
|
||||
send(sender, Arrays.asList(messages));
|
||||
}
|
||||
|
||||
public static void sendWithPlaceholders(Player player, String... messages) {
|
||||
sendWithPlaceholders(player, Arrays.asList(messages));
|
||||
public static void sendWithPlaceholders(CommandSender sender, String... messages) {
|
||||
sendWithPlaceholders(sender, Arrays.asList(messages));
|
||||
}
|
||||
|
||||
public static void sendWithPlaceholders(Player player, List<String> messages) {
|
||||
if (hasPlaceholderAPI()) {
|
||||
send(player, PlaceholderAPI.setPlaceholders(player, messages));
|
||||
public static void sendWithPlaceholders(CommandSender sender, List<String> messages) {
|
||||
if (hasPlaceholderAPI() && sender instanceof Player) {
|
||||
send(sender, PlaceholderAPI.setPlaceholders((Player) sender, messages));
|
||||
} else {
|
||||
send(player, messages);
|
||||
send(sender, messages);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendWithPlaceholders(Player player, List<String> messages, String param, Object value) {
|
||||
sendWithPlaceholders(player, messages, new String[]{param}, new Object[]{value});
|
||||
public static void sendWithPlaceholders(CommandSender sender, List<String> messages, String param, Object value) {
|
||||
sendWithPlaceholders(sender, messages, new String[]{param}, new Object[]{value});
|
||||
}
|
||||
|
||||
public static void sendWithPlaceholders(Player player, List<String> messages, String[] params, Object[] values) {
|
||||
sendWithPlaceholders(player, setCustomParams(messages, params, values));
|
||||
public static void sendWithPlaceholders(CommandSender sender, List<String> messages, String[] params, Object[] values) {
|
||||
sendWithPlaceholders(sender, setCustomParams(messages, params, values));
|
||||
}
|
||||
|
||||
public static List<String> setCustomParams(List<String> messages, String param, Object value) {
|
||||
|
@ -38,7 +38,7 @@ public class GUI {
|
||||
|
||||
public GUI(GUIType type, String name) {
|
||||
this.type = type;
|
||||
this.name = ColorParser.parseColor(name);
|
||||
this.name = ColorParser.parse(name);
|
||||
switch (type) {
|
||||
case ONEBYNINE:
|
||||
this.items = new GUIItem[9];
|
||||
|
14
src/test/java/ColorParseTest.java
Normal file
14
src/test/java/ColorParseTest.java
Normal file
@ -0,0 +1,14 @@
|
||||
import cc.carm.plugin.userprefix.util.ColorParser;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ColorParseTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void onTest() {
|
||||
String testString = "&f爱的人永远不爱我,为何付出得到的只有&(#aaaaaa)背叛。";
|
||||
|
||||
System.out.println(ColorParser.parseHexColor(testString));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user