Adventure
== AT == public net.minecraft.network.chat.HoverEvent$ItemStackInfo item public net.minecraft.network.chat.HoverEvent$ItemStackInfo count public net.minecraft.network.chat.HoverEvent$ItemStackInfo components public net.minecraft.network.chat.contents.TranslatableContents filterAllowedArguments(Ljava/lang/Object;)Lcom/mojang/serialization/DataResult; Co-authored-by: zml <zml@stellardrift.ca> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
This commit is contained in:
@@ -81,6 +81,19 @@ public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implem
|
||||
this.getSnapshot().secondaryPower = (effect != null) ? CraftPotionEffectType.bukkitToMinecraftHolder(effect) : null;
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component customName() {
|
||||
final BeaconBlockEntity be = this.getSnapshot();
|
||||
return be.name != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.name) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customName(final net.kyori.adventure.text.Component customName) {
|
||||
this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String getCustomName() {
|
||||
BeaconBlockEntity beacon = this.getSnapshot();
|
||||
|
||||
@@ -45,4 +45,16 @@ public class CraftCommandBlock extends CraftBlockEntityState<CommandBlockEntity>
|
||||
public CraftCommandBlock copy(Location location) {
|
||||
return new CraftCommandBlock(this, location);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component name() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(getSnapshot().getCommandBlock().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void name(net.kyori.adventure.text.Component name) {
|
||||
getSnapshot().getCommandBlock().setCustomName(name == null ? net.minecraft.network.chat.Component.literal("@") : io.papermc.paper.adventure.PaperAdventure.asVanilla(name));
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@@ -57,6 +57,19 @@ public abstract class CraftContainer<T extends BaseContainerBlockEntity> extends
|
||||
}
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component customName() {
|
||||
final T be = this.getSnapshot();
|
||||
return be.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.getCustomName()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customName(final net.kyori.adventure.text.Component customName) {
|
||||
this.getSnapshot().name = (customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String getCustomName() {
|
||||
T container = this.getSnapshot();
|
||||
|
||||
@@ -16,6 +16,19 @@ public class CraftEnchantingTable extends CraftBlockEntityState<EnchantingTableB
|
||||
super(state, location);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component customName() {
|
||||
final EnchantingTableBlockEntity be = this.getSnapshot();
|
||||
return be.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.getCustomName()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customName(final net.kyori.adventure.text.Component customName) {
|
||||
this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String getCustomName() {
|
||||
EnchantingTableBlockEntity enchant = this.getSnapshot();
|
||||
|
||||
@@ -36,6 +36,23 @@ public class CraftSign<T extends SignBlockEntity> extends CraftBlockEntityState<
|
||||
this.back = new CraftSignSide(this.getSnapshot().getBackText());
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public java.util.@NotNull List<net.kyori.adventure.text.Component> lines() {
|
||||
return this.front.lines();
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.@NotNull Component line(int index) {
|
||||
return this.front.line(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void line(int index, net.kyori.adventure.text.@NotNull Component line) {
|
||||
this.front.line(index, line);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String[] getLines() {
|
||||
return this.front.getLines();
|
||||
@@ -161,6 +178,20 @@ public class CraftSign<T extends SignBlockEntity> extends CraftBlockEntityState<
|
||||
((CraftPlayer) player).getHandle().openTextEdit(handle, Side.FRONT == side);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
public static Component[] sanitizeLines(java.util.List<? extends net.kyori.adventure.text.Component> lines) {
|
||||
Component[] components = new Component[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (i < lines.size() && lines.get(i) != null) {
|
||||
components[i] = io.papermc.paper.adventure.PaperAdventure.asVanilla(lines.get(i));
|
||||
} else {
|
||||
components[i] = net.minecraft.network.chat.Component.literal("");
|
||||
}
|
||||
}
|
||||
return components;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
public static Component[] sanitizeLines(String[] lines) {
|
||||
Component[] components = new Component[4];
|
||||
|
||||
|
||||
@@ -12,37 +12,70 @@ import org.jetbrains.annotations.Nullable;
|
||||
public class CraftSignSide implements SignSide {
|
||||
|
||||
// Lazily initialized only if requested:
|
||||
private String[] originalLines = null;
|
||||
private String[] lines = null;
|
||||
// Paper start
|
||||
private java.util.ArrayList<net.kyori.adventure.text.Component> originalLines = null; // ArrayList for RandomAccess
|
||||
private java.util.ArrayList<net.kyori.adventure.text.Component> lines = null; // ArrayList for RandomAccess
|
||||
// Paper end
|
||||
private SignText signText;
|
||||
|
||||
public CraftSignSide(SignText signText) {
|
||||
this.signText = signText;
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public java.util.@NotNull List<net.kyori.adventure.text.Component> lines() {
|
||||
this.loadLines();
|
||||
return this.lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.@NotNull Component line(final int index) throws IndexOutOfBoundsException {
|
||||
this.loadLines();
|
||||
return this.lines.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void line(final int index, final net.kyori.adventure.text.@NotNull Component line) throws IndexOutOfBoundsException {
|
||||
com.google.common.base.Preconditions.checkArgument(line != null, "Line cannot be null");
|
||||
this.loadLines();
|
||||
this.lines.set(index, line);
|
||||
}
|
||||
|
||||
private void loadLines() {
|
||||
if (this.lines != null) {
|
||||
return;
|
||||
}
|
||||
// Lazy initialization:
|
||||
this.lines = io.papermc.paper.adventure.PaperAdventure.asAdventure(com.google.common.collect.Lists.newArrayList(this.signText.getMessages(false)));
|
||||
this.originalLines = new java.util.ArrayList<>(this.lines);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] getLines() {
|
||||
if (this.lines == null) {
|
||||
// Lazy initialization:
|
||||
Component[] messages = this.signText.getMessages(false);
|
||||
this.lines = new String[messages.length];
|
||||
System.arraycopy(CraftSign.revertComponents(messages), 0, this.lines, 0, this.lines.length);
|
||||
this.originalLines = new String[this.lines.length];
|
||||
System.arraycopy(this.lines, 0, this.originalLines, 0, this.originalLines.length);
|
||||
}
|
||||
return this.lines;
|
||||
// Paper start
|
||||
this.loadLines();
|
||||
return this.lines.stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::serialize).toArray(String[]::new); // Paper
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getLine(int index) throws IndexOutOfBoundsException {
|
||||
return this.getLines()[index];
|
||||
// Paper start
|
||||
this.loadLines();
|
||||
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.lines.get(index));
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
|
||||
this.getLines()[index] = line;
|
||||
// Paper start
|
||||
this.loadLines();
|
||||
this.lines.set(index, line != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(line) : net.kyori.adventure.text.Component.empty());
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,13 +101,16 @@ public class CraftSignSide implements SignSide {
|
||||
|
||||
public SignText applyLegacyStringToSignSide() {
|
||||
if (this.lines != null) {
|
||||
for (int i = 0; i < this.lines.length; i++) {
|
||||
String line = (this.lines[i] == null) ? "" : this.lines[i];
|
||||
if (line.equals(this.originalLines[i])) {
|
||||
// Paper start
|
||||
for (int i = 0; i < this.lines.size(); ++i) {
|
||||
net.kyori.adventure.text.Component component = this.lines.get(i);
|
||||
net.kyori.adventure.text.Component origComp = this.originalLines.get(i);
|
||||
if (component.equals(origComp)) {
|
||||
continue; // The line contents are still the same, skip.
|
||||
}
|
||||
this.signText = this.signText.setMessage(i, CraftChatMessage.fromString(line)[0]);
|
||||
this.signText = this.signText.setMessage(i, io.papermc.paper.adventure.PaperAdventure.asVanilla(component));
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
||||
return this.signText;
|
||||
|
||||
Reference in New Issue
Block a user