mirror of
https://github.com/CarmJos/UserPrefix.git
synced 2026-06-05 00:35:02 +08:00
fix(color): 修复前缀颜色显示的问题。
This commit is contained in:
@@ -9,6 +9,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class ListCommand extends SubCommand<AdminCommand> {
|
||||
|
||||
public ListCommand(@NotNull AdminCommand parent, String name, String... aliases) {
|
||||
@@ -21,7 +23,7 @@ public class ListCommand extends SubCommand<AdminCommand> {
|
||||
for (PrefixConfig value : UserPrefixAPI.getPrefixManager().getPrefixes().values()) {
|
||||
PluginMessages.LIST.VALUE.sendTo(sender,
|
||||
value.getWeight(), value.getIdentifier(),
|
||||
value.getName(), value.getPermission(),
|
||||
value.getName(), Optional.ofNullable(value.getPermission()).orElse("~"),
|
||||
value.getContent(sender), sender.getName()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -108,18 +108,18 @@ public class PrefixConfig {
|
||||
public String getContent(CommandSender viewer) {
|
||||
if (content.isEmpty()) return "?";
|
||||
if (period < 0 || content.size() == 1) {
|
||||
return MessageUtils.setPlaceholders(viewer, content.get(0));
|
||||
return ColorParser.parse(MessageUtils.setPlaceholders(viewer, content.get(0)));
|
||||
}
|
||||
if (period == 0) {
|
||||
// PERIOD 为0时,随机返回一个内容
|
||||
int index = RANDOM.nextInt(content.size());
|
||||
return MessageUtils.setPlaceholders(viewer, content.get(index));
|
||||
return ColorParser.parse(MessageUtils.setPlaceholders(viewer, content.get(index)));
|
||||
} else {
|
||||
// 可变化的内容,则基于偏移量与时间戳计算目标index
|
||||
long curr = System.currentTimeMillis();
|
||||
long offset = curr % period; // 计算偏移量
|
||||
int index = (int) (offset / (period / content.size())); // 计算索引
|
||||
return MessageUtils.setPlaceholders(viewer, content.get(index));
|
||||
return ColorParser.parse(MessageUtils.setPlaceholders(viewer, content.get(index)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user