Update paper plugin to MC 1.20.6
- Convert Brigadier command to use the new Brigadier/Paper API - EquipmentSlot now has BODY value for horses and wolves armor - ItemMeta’ canPlaceOn and canDestroy does not work anymore. Removed the related methods from ItemStackBuilder - Enchantment DURABILITY now has the proper vanilla name UNBREAKING - Pandalib-chat now uses Adventure’s TranslationArgument
This commit is contained in:
@@ -5,6 +5,8 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentBuilder;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslationArgument;
|
||||
import net.kyori.adventure.text.TranslationArgumentLike;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.event.HoverEventSource;
|
||||
@@ -972,21 +974,38 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
||||
|
||||
|
||||
|
||||
/* package */ static ComponentLike filterObjToComponentLike(Object v) {
|
||||
return switch (v) {
|
||||
case BaseComponent[] baseComponents -> toAdventure(baseComponents);
|
||||
case BaseComponent baseComponent -> toAdventure(baseComponent);
|
||||
case ComponentLike componentLike -> componentLike;
|
||||
case null, default -> Component.text(Objects.toString(v));
|
||||
};
|
||||
}
|
||||
|
||||
/* package */ static ComponentLike[] filterObjToComponentLike(Object[] values) {
|
||||
if (values == null)
|
||||
return null;
|
||||
ComponentLike[] ret = new ComponentLike[values.length];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
ret[i] = filterObjToComponentLike(values[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* package */ static TranslationArgumentLike[] filterObjToTranslationArgumentLike(Object[] values) {
|
||||
if (values == null)
|
||||
return null;
|
||||
TranslationArgumentLike[] ret = new TranslationArgumentLike[values.length];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
Object v = values[i];
|
||||
if (v instanceof BaseComponent[])
|
||||
ret[i] = toAdventure((BaseComponent[]) v);
|
||||
else if (v instanceof BaseComponent)
|
||||
ret[i] = toAdventure((BaseComponent) v);
|
||||
else if (v instanceof ComponentLike)
|
||||
ret[i] = (ComponentLike) v;
|
||||
if (v instanceof Number n)
|
||||
ret[i] = TranslationArgument.numeric(n);
|
||||
else if (v instanceof Boolean b)
|
||||
ret[i] = TranslationArgument.bool(b);
|
||||
else
|
||||
ret[i] = Component.text(Objects.toString(v));
|
||||
ret[i] = TranslationArgument.component(filterObjToComponentLike(values[i]));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* A custom gradient with at least 2 colors in it.
|
||||
*/
|
||||
public class ChatColorGradient {
|
||||
|
||||
private record GradientColor(
|
||||
float location,
|
||||
TextColor color
|
||||
@@ -48,7 +49,7 @@ public class ChatColorGradient {
|
||||
if (colors.isEmpty())
|
||||
throw new IllegalStateException("Must define at least one color in this ChatColorGradient instance.");
|
||||
if (colors.size() == 1)
|
||||
return colors.get(0).color();
|
||||
return colors.getFirst().color();
|
||||
|
||||
int i = 0;
|
||||
for (; i < colors.size(); i++) {
|
||||
@@ -59,7 +60,7 @@ public class ChatColorGradient {
|
||||
if (i == 0)
|
||||
return colors.get(i).color();
|
||||
if (i == colors.size())
|
||||
return colors.get(colors.size() - 1).color();
|
||||
return colors.getLast().color();
|
||||
|
||||
int p = i - 1;
|
||||
float pLoc = colors.get(p).location();
|
||||
|
@@ -264,7 +264,7 @@ public abstract class ChatStatic {
|
||||
* @return a new {@link FormatableChat} with the provided translation key and parameters.
|
||||
*/
|
||||
public static FormatableChat translation(String key, Object... with) {
|
||||
return new FormatableChat(Component.translatable().key(key).args(Chat.filterObjToComponentLike(with)));
|
||||
return new FormatableChat(Component.translatable().key(key).arguments(Chat.filterObjToTranslationArgumentLike(with)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -632,50 +632,32 @@ public abstract class ChatStatic {
|
||||
|
||||
|
||||
private static ComponentBuilder<?, ?> componentToBuilder(Component c) {
|
||||
ComponentBuilder<?, ?> builder;
|
||||
if (c instanceof TextComponent) {
|
||||
builder = Component.text()
|
||||
.content(((TextComponent) c).content());
|
||||
}
|
||||
else if (c instanceof TranslatableComponent) {
|
||||
builder = Component.translatable()
|
||||
.key(((TranslatableComponent) c).key())
|
||||
.args(((TranslatableComponent) c).args());
|
||||
}
|
||||
else if (c instanceof SelectorComponent) {
|
||||
builder = Component.selector()
|
||||
.pattern(((SelectorComponent) c).pattern());
|
||||
}
|
||||
else if (c instanceof ScoreComponent) {
|
||||
builder = Component.score()
|
||||
.name(((ScoreComponent) c).name())
|
||||
.objective(((ScoreComponent) c).objective());
|
||||
}
|
||||
else if (c instanceof KeybindComponent) {
|
||||
builder = Component.keybind()
|
||||
.keybind(((KeybindComponent) c).keybind());
|
||||
}
|
||||
else if (c instanceof BlockNBTComponent) {
|
||||
builder = Component.blockNBT()
|
||||
.interpret(((BlockNBTComponent) c).interpret())
|
||||
.nbtPath(((BlockNBTComponent) c).nbtPath())
|
||||
.pos(((BlockNBTComponent) c).pos());
|
||||
}
|
||||
else if (c instanceof EntityNBTComponent) {
|
||||
builder = Component.entityNBT()
|
||||
.interpret(((EntityNBTComponent) c).interpret())
|
||||
.nbtPath(((EntityNBTComponent) c).nbtPath())
|
||||
.selector(((EntityNBTComponent) c).selector());
|
||||
}
|
||||
else if (c instanceof StorageNBTComponent) {
|
||||
builder = Component.storageNBT()
|
||||
.interpret(((StorageNBTComponent) c).interpret())
|
||||
.nbtPath(((StorageNBTComponent) c).nbtPath())
|
||||
.storage(((StorageNBTComponent) c).storage());
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unknown component type " + c.getClass());
|
||||
}
|
||||
ComponentBuilder<?, ?> builder = switch (c) {
|
||||
case TextComponent textComponent -> Component.text()
|
||||
.content(textComponent.content());
|
||||
case TranslatableComponent translatableComponent -> Component.translatable()
|
||||
.key(translatableComponent.key()).arguments(translatableComponent.arguments());
|
||||
case SelectorComponent selectorComponent -> Component.selector()
|
||||
.pattern(selectorComponent.pattern());
|
||||
case ScoreComponent scoreComponent -> Component.score()
|
||||
.name(scoreComponent.name())
|
||||
.objective(scoreComponent.objective());
|
||||
case KeybindComponent keybindComponent -> Component.keybind()
|
||||
.keybind(keybindComponent.keybind());
|
||||
case BlockNBTComponent blockNBTComponent -> Component.blockNBT()
|
||||
.interpret(blockNBTComponent.interpret())
|
||||
.nbtPath(blockNBTComponent.nbtPath())
|
||||
.pos(blockNBTComponent.pos());
|
||||
case EntityNBTComponent entityNBTComponent -> Component.entityNBT()
|
||||
.interpret(entityNBTComponent.interpret())
|
||||
.nbtPath(entityNBTComponent.nbtPath())
|
||||
.selector(entityNBTComponent.selector());
|
||||
case StorageNBTComponent storageNBTComponent -> Component.storageNBT()
|
||||
.interpret(storageNBTComponent.interpret())
|
||||
.nbtPath(storageNBTComponent.nbtPath())
|
||||
.storage(storageNBTComponent.storage());
|
||||
case null, default -> throw new IllegalArgumentException("Unknown component type " + (c == null ? "null" : c.getClass()));
|
||||
};
|
||||
return builder.style(c.style()).append(c.children());
|
||||
}
|
||||
|
||||
|
@@ -14,6 +14,7 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.TranslationArgument;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
@@ -265,8 +266,8 @@ public class ChatUtil {
|
||||
count += strWidth(((TextComponent)component).content(), console, actuallyBold);
|
||||
}
|
||||
else if (component instanceof TranslatableComponent) {
|
||||
for (Component c : ((TranslatableComponent)component).args())
|
||||
count += componentWidth(c, console, actuallyBold);
|
||||
for (TranslationArgument c : ((TranslatableComponent)component).arguments())
|
||||
count += componentWidth(c.asComponent(), console, actuallyBold);
|
||||
}
|
||||
|
||||
for (Component c : component.children())
|
||||
@@ -480,7 +481,7 @@ public class ChatUtil {
|
||||
spacedRow.thenText(space);
|
||||
}
|
||||
if (!row.isEmpty())
|
||||
spacedRow.then(row.get(row.size() - 1));
|
||||
spacedRow.then(row.getLast());
|
||||
spacedRows.add(spacedRow.getAdv());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user