Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/com/chunkmc/usertitle/UserTitlePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public String getActiveTitlePrefix(Player player) {
if (config == null) {
return null;
}
return config.getRarity().getColorCode() + "[" + config.getName() + "]";
return config.rarity().getColorCode() + "[" + config.name() + "]";
}

public Component getActiveTitleComponent(Player player) {
Expand All @@ -221,14 +221,14 @@ public Component getActiveTitleComponent(Player player) {
return Component.empty();
}

TextColor color = switch (config.getRarity()) {
TextColor color = switch (config.rarity()) {
case LEGENDARY -> NamedTextColor.GOLD;
case EPIC -> NamedTextColor.DARK_PURPLE;
case HERO -> NamedTextColor.BLUE;
case COMMON -> NamedTextColor.WHITE;
};

return Component.text("[" + config.getName() + "]")
return Component.text("[" + config.name() + "]")
.color(color)
.append(Component.space());
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/chunkmc/usertitle/command/TitleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
plugin.addPlayerTitle(target.getUniqueId(), titleId);
plugin.getServer().getScheduler().runTask(plugin, () -> {
sender.sendMessage("§a已将头衔 §6【" + config.getName() + "】§a 赠送给 " + target.getName());
target.sendMessage("§a你获得了新头衔 §6【" + config.getName() + "】§a!输入 /ut 查看");
sender.sendMessage("§a已将头衔 §6【" + config.name() + "】§a 赠送给 " + target.getName());
target.sendMessage("§a你获得了新头衔 §6【" + config.name() + "】§a!输入 /ut 查看");
});
});
}
case "list" -> {
sender.sendMessage("§6===== 可用头衔列表 =====");
for (TitleConfig config : plugin.getTitleConfigs().values()) {
sender.sendMessage(config.getFormattedTooltip() + " §7(ID: " + config.getId() + ")");
sender.sendMessage(config.getFormattedTooltip() + " §7(ID: " + config.id() + ")");
}
}
default -> {
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/chunkmc/usertitle/gui/TitleGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import com.chunkmc.usertitle.UserTitlePlugin;
import com.chunkmc.usertitle.model.PlayerTitleData;
import com.chunkmc.usertitle.model.TitleConfig;
import com.chunkmc.usertitle.model.TitleRarity;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
Expand All @@ -19,7 +17,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class TitleGui {

Expand Down Expand Up @@ -76,20 +73,20 @@ private ItemStack createTitleItem(TitleConfig config, boolean isOwned, boolean i
ItemMeta meta = item.getItemMeta();

// Title name with rarity color
TextColor color = switch (config.getRarity()) {
TextColor color = switch (config.rarity()) {
case LEGENDARY -> NamedTextColor.GOLD;
case EPIC -> NamedTextColor.DARK_PURPLE;
case HERO -> NamedTextColor.BLUE;
case COMMON -> NamedTextColor.WHITE;
};

meta.displayName(Component.text("【" + config.getName() + "】")
meta.displayName(Component.text("【" + config.name() + "】")
.color(color)
.decorate(TextDecoration.BOLD));

// Lore
List<Component> lore = new ArrayList<>();
lore.add(Component.text("(" + config.getRarity().getDisplayName() + ")")
lore.add(Component.text("(" + config.rarity().getDisplayName() + ")")
.color(color));
lore.add(Component.empty());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void onAsyncChat(AsyncChatEvent event) {
return;
}

TextColor color = switch (config.getRarity()) {
TextColor color = switch (config.rarity()) {
case LEGENDARY -> NamedTextColor.GOLD;
case EPIC -> NamedTextColor.DARK_PURPLE;
case HERO -> NamedTextColor.BLUE;
Expand All @@ -43,7 +43,7 @@ public void onAsyncChat(AsyncChatEvent event) {
// Custom renderer: [称号]<Steve> 消息
event.renderer((source, sourceDisplayName, message, viewer) ->
Component.text("[")
.append(Component.text(config.getName()).color(color))
.append(Component.text(config.name()).color(color))
.append(Component.text("]<"))
.append(Component.text(source.getName()))
.append(Component.text("> "))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void onInventoryClick(InventoryClickEvent event) {

TitleConfig clickedTitle = null;
for (Map.Entry<String, TitleConfig> entry : plugin.getTitleConfigs().entrySet()) {
if (displayName.contains(entry.getValue().getName())) {
if (displayName.contains(entry.getValue().name())) {
clickedTitle = entry.getValue();
break;
}
Expand All @@ -54,7 +54,7 @@ public void onInventoryClick(InventoryClickEvent event) {

final TitleConfig selectedTitle = clickedTitle;
PlayerTitleData playerData = plugin.getTitleCache().getOrCreate(player.getUniqueId());
String titleId = selectedTitle.getId();
String titleId = selectedTitle.id();
String activeTitleId = playerData.getActiveTitleId();

// Check if player owns this title
Expand All @@ -71,7 +71,7 @@ public void onInventoryClick(InventoryClickEvent event) {
plugin.getServer().getScheduler().runTask(plugin, () -> {
plugin.updatePlayerDisplayName(player);
plugin.updatePlayerTabList(player);
player.sendMessage(Component.text("§a已取消装备头衔 §6【" + selectedTitle.getName() + "】"));
player.sendMessage(Component.text("§a已取消装备头衔 §6【" + selectedTitle.name() + "】"));
new TitleGui(plugin).open(player);
});
});
Expand All @@ -82,7 +82,7 @@ public void onInventoryClick(InventoryClickEvent event) {
plugin.getServer().getScheduler().runTask(plugin, () -> {
plugin.updatePlayerDisplayName(player);
plugin.updatePlayerTabList(player);
player.sendMessage(Component.text("§a已装备头衔 §6【" + selectedTitle.getName() + "】"));
player.sendMessage(Component.text("§a已装备头衔 §6【" + selectedTitle.name() + "】"));
new TitleGui(plugin).open(player);
});
});
Expand Down
29 changes: 5 additions & 24 deletions src/main/java/com/chunkmc/usertitle/model/TitleConfig.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
package com.chunkmc.usertitle.model;

public class TitleConfig {

private final String id;
private final String name;
private final TitleRarity rarity;

public TitleConfig(String id, String name, TitleRarity rarity) {
this.id = id;
this.name = name;
this.rarity = rarity;
}

public String getId() {
return id;
}

public String getName() {
return name;
}

public TitleRarity getRarity() {
return rarity;
}

public record TitleConfig(
String id,
String name,
TitleRarity rarity
) {
public String getDisplayName() {
return rarity.getColorCode() + "【" + name + "】";
}
Expand Down
Loading