Build Chat API over Adventure instead of Bungeecord-chat
This commit is contained in:
@@ -34,9 +34,17 @@ public class GUIInventory implements Listener {
|
||||
private boolean isOpened = false;
|
||||
private Map<Integer, Callback<InventoryClickEvent>> onClickEvents;
|
||||
|
||||
@Deprecated
|
||||
public GUIInventory(Player p, int nbLines, String title, Callback<InventoryCloseEvent> closeEventAction,
|
||||
Plugin pl) {
|
||||
inv = Bukkit.createInventory(null, nbLines * 9, title);
|
||||
this(p, nbLines, title == null ? null : Chat.legacyText(title), closeEventAction, pl);
|
||||
}
|
||||
public GUIInventory(Player p, int nbLines, Chat title, Callback<InventoryCloseEvent> closeEventAction,
|
||||
Plugin pl) {
|
||||
if (title == null)
|
||||
inv = Bukkit.createInventory(null, nbLines * 9);
|
||||
else
|
||||
inv = Bukkit.createInventory(null, nbLines * 9, title.getAdv());
|
||||
|
||||
setCloseEvent(closeEventAction);
|
||||
|
||||
|
@@ -20,6 +20,7 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import fr.pandacube.lib.core.util.Log;
|
||||
import fr.pandacube.lib.paper.PandaLibPaper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class AutoUpdatedBossBar implements Listener {
|
||||
|
||||
@@ -100,7 +101,7 @@ public class AutoUpdatedBossBar implements Listener {
|
||||
followPlayerList = true;
|
||||
BukkitEvent.register(this);
|
||||
Bukkit.getServer().getOnlinePlayers().forEach(p -> {
|
||||
onPlayerJoin(new PlayerJoinEvent(p, ""));
|
||||
onPlayerJoin(new PlayerJoinEvent(p, Component.text("")));
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -15,7 +15,9 @@ import com.google.common.collect.Streams;
|
||||
|
||||
import fr.pandacube.lib.core.chat.Chat;
|
||||
import fr.pandacube.lib.core.chat.Chat.FormatableChat;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.format.TextDecoration.State;
|
||||
|
||||
public class ItemStackBuilder {
|
||||
|
||||
@@ -57,28 +59,28 @@ public class ItemStackBuilder {
|
||||
stack.setAmount(a);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStackBuilder rawDisplayName(BaseComponent[] displayName) {
|
||||
|
||||
public ItemStackBuilder rawDisplayName(Component displayName) {
|
||||
if (displayName != null)
|
||||
getOrInitMeta().setDisplayNameComponent(displayName);
|
||||
getOrInitMeta().displayName(displayName);
|
||||
else
|
||||
getOrInitMeta().setDisplayName(null);
|
||||
getOrInitMeta().displayName(null);
|
||||
updateMeta();
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStackBuilder displayName(Chat displayName) {
|
||||
if (displayName != null) {
|
||||
if (displayName.get().isItalicRaw() == null)
|
||||
if (displayName.getAdv().style().decoration(TextDecoration.ITALIC) == State.NOT_SET)
|
||||
((FormatableChat)displayName).italic(false);
|
||||
return rawDisplayName(displayName.getAsArray());
|
||||
return rawDisplayName(displayName.getAdv());
|
||||
}
|
||||
else
|
||||
return rawDisplayName(null);
|
||||
return rawDisplayName((Component) null);
|
||||
}
|
||||
|
||||
public ItemStackBuilder rawLore(List<BaseComponent[]> lore) {
|
||||
getOrInitMeta().setLoreComponents(lore);
|
||||
public ItemStackBuilder rawLore(List<Component> lore) {
|
||||
getOrInitMeta().lore(lore);
|
||||
updateMeta();
|
||||
return this;
|
||||
}
|
||||
@@ -86,11 +88,7 @@ public class ItemStackBuilder {
|
||||
public ItemStackBuilder lore(List<Chat> lore) {
|
||||
if (lore != null) {
|
||||
return rawLore(lore.stream()
|
||||
.map(line -> {
|
||||
if (line.get().isItalicRaw() == null)
|
||||
((FormatableChat)line).italic(false);
|
||||
return line.getAsArray();
|
||||
})
|
||||
.map(line -> Chat.italicFalseIfNotSet(line).getAdv())
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
else
|
||||
@@ -99,17 +97,13 @@ public class ItemStackBuilder {
|
||||
|
||||
public ItemStackBuilder addLoreAfter(List<Chat> lore) {
|
||||
if (lore != null) {
|
||||
List<BaseComponent[]> baseLore = getOrInitMeta().getLoreComponents();
|
||||
List<Component> baseLore = getOrInitMeta().lore();
|
||||
if (baseLore == null) baseLore = Collections.emptyList();
|
||||
return rawLore(
|
||||
Streams.concat(
|
||||
baseLore.stream(),
|
||||
lore.stream()
|
||||
.map(line -> {
|
||||
if (line.get().isItalicRaw() == null)
|
||||
((FormatableChat)line).italic(false);
|
||||
return line.getAsArray();
|
||||
})
|
||||
.map(line -> Chat.italicFalseIfNotSet(line).getAdv())
|
||||
)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
@@ -9,11 +9,11 @@ import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Score;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
import fr.pandacube.lib.core.chat.Chat;
|
||||
import fr.pandacube.lib.core.chat.ChatUtil;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public class ScoreBoardUtil {
|
||||
|
||||
/**
|
||||
* Met à jour la Sidebar d'un Scoreboard donné
|
||||
*
|
||||
@@ -23,7 +23,21 @@ public class ScoreBoardUtil {
|
||||
* tableau est null, il sera compté comme une chaine vide. Toutes les
|
||||
* lignes seront rognés aux 40 premiers caractères
|
||||
*/
|
||||
@Deprecated
|
||||
public static void updateScoreboardSidebar(Scoreboard scBrd, String title, String[] lines) {
|
||||
updateScoreboardSidebar(scBrd, Chat.legacyText(title), lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour la Sidebar d'un Scoreboard donné
|
||||
*
|
||||
* @param scBrd Le Scoreboard à mettre à jour (ne doit pas être null)
|
||||
* @param title Le titre de la Sidebar
|
||||
* @param lines Les lignes qui doivent être affichés. Si un éléments du
|
||||
* tableau est null, il sera compté comme une chaine vide. Toutes les
|
||||
* lignes seront rognés aux 40 premiers caractères
|
||||
*/
|
||||
public static void updateScoreboardSidebar(Scoreboard scBrd, Chat title, String[] lines) {
|
||||
if (scBrd == null) throw new IllegalArgumentException("scBrd doit être non null");
|
||||
if (lines == null) lines = new String[0];
|
||||
|
||||
@@ -33,15 +47,15 @@ public class ScoreBoardUtil {
|
||||
obj = null;
|
||||
}
|
||||
|
||||
title = title == null ? "" : ChatUtil.truncateAtLengthWithoutReset(title, 32);
|
||||
|
||||
if (obj == null)
|
||||
obj = scBrd.registerNewObjective("sidebar_autogen", "dummy", title);
|
||||
obj = scBrd.registerNewObjective("sidebar_autogen", "dummy", title.getAdv());
|
||||
else {
|
||||
if (!title.getAdv().equals(obj.displayName()))
|
||||
obj.displayName(title.getAdv());
|
||||
if (!DisplaySlot.SIDEBAR.equals(obj.getDisplaySlot()))
|
||||
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
}
|
||||
|
||||
if (!title.equals(obj.getDisplayName()))
|
||||
obj.setDisplayName(title);
|
||||
if (!DisplaySlot.SIDEBAR.equals(obj.getDisplaySlot()))
|
||||
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
|
||||
filterLines(lines);
|
||||
|
||||
|
@@ -99,10 +99,10 @@ public enum Skull {
|
||||
boolean b = meta.setOwner(name);
|
||||
|
||||
if (dispName != null)
|
||||
meta.setDisplayNameComponent(dispName.getAsArray());
|
||||
meta.displayName(dispName.getAdv());
|
||||
|
||||
if (lore != null)
|
||||
meta.setLoreComponents(lore.stream().map(c -> c.getAsArray()).collect(Collectors.toList()));
|
||||
meta.lore(lore.stream().map(c -> c.getAdv()).collect(Collectors.toList()));
|
||||
|
||||
itemStack.setItemMeta(meta);
|
||||
return itemStack;
|
||||
@@ -172,10 +172,10 @@ public enum Skull {
|
||||
headMeta.setPlayerProfile(profile);
|
||||
|
||||
if (dispName != null)
|
||||
headMeta.setDisplayNameComponent(dispName.getAsArray());
|
||||
headMeta.displayName(dispName.getAdv());
|
||||
|
||||
if (lore != null)
|
||||
headMeta.setLoreComponents(lore.stream().map(c -> c.getAsArray()).collect(Collectors.toList()));
|
||||
headMeta.lore(lore.stream().map(c -> c.getAdv()).collect(Collectors.toList()));
|
||||
|
||||
head.setItemMeta(headMeta);
|
||||
|
||||
|
Reference in New Issue
Block a user