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:
Riley Park
2021-01-29 17:54:03 +01:00
parent b01c811c2f
commit 66779f5c86
103 changed files with 4975 additions and 392 deletions

View File

@@ -59,6 +59,7 @@ public class CraftJukeboxSong implements JukeboxSong, Handleable<net.minecraft.w
@NotNull
@Override
public String getTranslationKey() {
if (!(this.handle.description().getContents() instanceof TranslatableContents)) throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
return ((TranslatableContents) this.handle.description().getContents()).getKey();
}
}

View File

@@ -648,8 +648,10 @@ public final class CraftServer implements Server {
}
@Override
@Deprecated // Paper start
public int broadcastMessage(String message) {
return this.broadcast(message, BROADCAST_CHANNEL_USERS);
// Paper end
}
@Override
@@ -1627,7 +1629,15 @@ public final class CraftServer implements Server {
return this.configuration.getInt("settings.spawn-radius", -1);
}
// Paper start
@Override
public net.kyori.adventure.text.Component shutdownMessage() {
String msg = getShutdownMessage();
return msg != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(msg) : null;
}
// Paper end
@Override
@Deprecated // Paper
public String getShutdownMessage() {
return this.configuration.getString("settings.shutdown-message");
}
@@ -1801,7 +1811,20 @@ public final class CraftServer implements Server {
}
@Override
@Deprecated // Paper
public int broadcast(String message, String permission) {
// Paper start - Adventure
return this.broadcast(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message), permission);
}
@Override
public int broadcast(net.kyori.adventure.text.Component message) {
return this.broadcast(message, BROADCAST_CHANNEL_USERS);
}
@Override
public int broadcast(net.kyori.adventure.text.Component message, String permission) {
// Paper end
Set<CommandSender> recipients = new HashSet<>();
for (Permissible permissible : this.getPluginManager().getPermissionSubscriptions(permission)) {
if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
@@ -1809,14 +1832,14 @@ public final class CraftServer implements Server {
}
}
BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients);
BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients); // Paper - Adventure
this.getPluginManager().callEvent(broadcastMessageEvent);
if (broadcastMessageEvent.isCancelled()) {
return 0;
}
message = broadcastMessageEvent.getMessage();
message = broadcastMessageEvent.message(); // Paper - Adventure
for (CommandSender recipient : recipients) {
recipient.sendMessage(message);
@@ -2078,6 +2101,14 @@ public final class CraftServer implements Server {
return CraftInventoryCreator.INSTANCE.createInventory(owner, type);
}
// Paper start
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
Preconditions.checkArgument(type.isCreatable(), "Cannot open an inventory of type ", type);
return CraftInventoryCreator.INSTANCE.createInventory(owner, type, title);
}
// Paper end
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
Preconditions.checkArgument(type != null, "InventoryType cannot be null");
@@ -2092,13 +2123,28 @@ public final class CraftServer implements Server {
return CraftInventoryCreator.INSTANCE.createInventory(owner, size);
}
// Paper start
@Override
public Inventory createInventory(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) throws IllegalArgumentException {
Preconditions.checkArgument(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots (got " + size + ")");
return CraftInventoryCreator.INSTANCE.createInventory(owner, size, title);
}
// Paper end
@Override
public Inventory createInventory(InventoryHolder owner, int size, String title) throws IllegalArgumentException {
Preconditions.checkArgument(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots (got %s)", size);
return CraftInventoryCreator.INSTANCE.createInventory(owner, size, title);
}
// Paper start
@Override
public Merchant createMerchant(net.kyori.adventure.text.Component title) {
return new org.bukkit.craftbukkit.inventory.CraftMerchantCustom(title == null ? InventoryType.MERCHANT.defaultTitle() : title);
}
// Paper end
@Override
@Deprecated // Paper
public Merchant createMerchant(String title) {
return new CraftMerchantCustom(title == null ? InventoryType.MERCHANT.getDefaultTitle() : title);
}
@@ -2163,6 +2209,17 @@ public final class CraftServer implements Server {
return Thread.currentThread().equals(this.console.serverThread) || this.console.hasStopped() || !org.spigotmc.AsyncCatcher.enabled; // All bets are off if we have shut down (e.g. due to watchdog)
}
// Paper start - Adventure
@Override
public net.kyori.adventure.text.Component motd() {
return this.console.motd();
}
@Override
public void motd(final net.kyori.adventure.text.Component motd) {
this.console.motd(motd);
}
// Paper end
@Override
public String getMotd() {
return this.console.getMotd();
@@ -2632,4 +2689,57 @@ public final class CraftServer implements Server {
public double[] getTPS() {
return new double[]{0, 0, 0}; // TODO
}
// Paper start - adventure sounds
@Override
public void playSound(final net.kyori.adventure.sound.Sound sound) {
if (sound.seed().isEmpty()) org.spigotmc.AsyncCatcher.catchOp("play sound; cannot generate seed with world random"); // Paper
final long seed = sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong);
for (ServerPlayer player : this.playerList.getPlayers()) {
player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player.getX(), player.getY(), player.getZ(), seed, null));
}
}
@Override
public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, x, y, z, sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong), this.playSound0(x, y, z, this.console.getAllLevels()));
}
@Override
public void playSound(final net.kyori.adventure.sound.Sound sound, final net.kyori.adventure.sound.Sound.Emitter emitter) {
if (sound.seed().isEmpty()) org.spigotmc.AsyncCatcher.catchOp("play sound; cannot generate seed with world random"); // Paper
final long seed = sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong);
if (emitter == net.kyori.adventure.sound.Sound.Emitter.self()) {
for (ServerPlayer player : this.playerList.getPlayers()) {
player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player, seed, null));
}
} else if (emitter instanceof org.bukkit.craftbukkit.entity.CraftEntity craftEntity) {
org.spigotmc.AsyncCatcher.catchOp("play sound; cannot use entity emitter"); // Paper
final net.minecraft.world.entity.Entity entity = craftEntity.getHandle();
io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, entity, seed, this.playSound0(entity.getX(), entity.getY(), entity.getZ(), List.of((ServerLevel) entity.level())));
} else {
throw new IllegalArgumentException("Sound emitter must be an Entity or self(), but was: " + emitter);
}
}
private java.util.function.BiConsumer<net.minecraft.network.protocol.Packet<?>, Float> playSound0(final double x, final double y, final double z, final Iterable<ServerLevel> levels) {
return (packet, distance) -> {
for (final ServerLevel level : levels) {
level.getServer().getPlayerList().broadcast(null, x, y, z, distance, level.dimension(), packet);
}
};
}
// Paper end
// Paper start
private Iterable<? extends net.kyori.adventure.audience.Audience> adventure$audiences;
@Override
public Iterable<? extends net.kyori.adventure.audience.Audience> audiences() {
if (this.adventure$audiences == null) {
this.adventure$audiences = com.google.common.collect.Iterables.concat(java.util.Collections.singleton(this.getConsoleSender()), this.getOnlinePlayers());
}
return this.adventure$audiences;
}
// Paper end
}

View File

@@ -61,6 +61,19 @@ public class CraftServerLinks implements ServerLinks {
return link;
}
// Paper start - Adventure
@Override
public ServerLink addLink(net.kyori.adventure.text.Component displayName, URI url) {
Preconditions.checkArgument(displayName != null, "displayName cannot be null");
Preconditions.checkArgument(url != null, "url cannot be null");
CraftServerLink link = new CraftServerLink(net.minecraft.server.ServerLinks.Entry.custom(io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName), url));
this.addLink(link);
return link;
}
// Paper end - Adventure
@Override
public ServerLink addLink(String displayName, URI url) {
Preconditions.checkArgument(displayName != null, "displayName cannot be null");
@@ -134,6 +147,13 @@ public class CraftServerLinks implements ServerLinks {
return CraftChatMessage.fromComponent(this.handle.displayName());
}
// Paper start - Adventure
@Override
public net.kyori.adventure.text.Component displayName() {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.displayName());
}
// Paper end - Adventure
@Override
public URI getUrl() {
return this.handle.link();

View File

@@ -167,6 +167,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
private final BlockMetadataStore blockMetadata = new BlockMetadataStore(this);
private final Object2IntOpenHashMap<SpawnCategory> spawnCategoryLimit = new Object2IntOpenHashMap<>();
private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(CraftWorld.DATA_TYPE_REGISTRY);
private net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers
private static final Random rand = new Random();
@@ -1710,6 +1711,15 @@ public class CraftWorld extends CraftRegionAccessor implements World {
entityTracker.broadcastAndSend(packet);
}
}
// Paper start - Adventure
@Override
public void playSound(final net.kyori.adventure.sound.Sound sound) {
org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
final long seed = sound.seed().orElseGet(this.world.getRandom()::nextLong);
for (ServerPlayer player : this.getHandle().players()) {
player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player.getX(), player.getY(), player.getZ(), seed, null));
}
}
@Override
public void playSound(Entity entity, String sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) {
@@ -1722,6 +1732,33 @@ public class CraftWorld extends CraftRegionAccessor implements World {
}
}
@Override
public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, x, y, z, sound.seed().orElseGet(this.world.getRandom()::nextLong), this.playSound0(x, y, z));
}
@Override
public void playSound(final net.kyori.adventure.sound.Sound sound, final net.kyori.adventure.sound.Sound.Emitter emitter) {
org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
final long seed = sound.seed().orElseGet(this.getHandle().getRandom()::nextLong);
if (emitter == net.kyori.adventure.sound.Sound.Emitter.self()) {
for (ServerPlayer player : this.getHandle().players()) {
player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player, seed, null));
}
} else if (emitter instanceof CraftEntity craftEntity) {
final net.minecraft.world.entity.Entity entity = craftEntity.getHandle();
io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, entity, seed, this.playSound0(entity.getX(), entity.getY(), entity.getZ()));
} else {
throw new IllegalArgumentException("Sound emitter must be an Entity or self(), but was: " + emitter);
}
}
private java.util.function.BiConsumer<net.minecraft.network.protocol.Packet<?>, Float> playSound0(final double x, final double y, final double z) {
return (packet, distance) -> this.world.getServer().getPlayerList().broadcast(null, x, y, z, distance, this.world.dimension(), packet);
}
// Paper end - Adventure
private Map<String, GameRules.Key<?>> gamerules;
public synchronized Map<String, GameRules.Key<?>> getGameRulesNMS() {
if (this.gamerules != null) {
@@ -2161,5 +2198,18 @@ public class CraftWorld extends CraftRegionAccessor implements World {
public void setSendViewDistance(final int viewDistance) {
throw new UnsupportedOperationException("Not implemented yet");
}
// Paper start - implement pointers
@Override
public net.kyori.adventure.pointer.Pointers pointers() {
if (this.adventure$pointers == null) {
this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
.withDynamic(net.kyori.adventure.identity.Identity.NAME, this::getName)
.withDynamic(net.kyori.adventure.identity.Identity.UUID, this::getUID)
.build();
}
return this.adventure$pointers;
}
// Paper end
}

View File

@@ -20,6 +20,12 @@ public class Main {
public static boolean useConsole = true;
public static void main(String[] args) {
// Paper start
final String warnWhenLegacyFormattingDetected = String.join(".", "net", "kyori", "adventure", "text", "warnWhenLegacyFormattingDetected");
if (false && System.getProperty(warnWhenLegacyFormattingDetected) == null) {
System.setProperty(warnWhenLegacyFormattingDetected, String.valueOf(true));
}
// Paper end
// Todo: Installation script
OptionParser parser = new OptionParser() {
{

View File

@@ -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();

View File

@@ -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
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -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];

View File

@@ -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;

View File

@@ -61,6 +61,18 @@ public class CraftBlockCommandSender extends ServerCommandSender implements Bloc
return this.block.getTextName();
}
// Paper start
@Override
public void sendMessage(net.kyori.adventure.identity.Identity identity, net.kyori.adventure.text.Component message, net.kyori.adventure.audience.MessageType type) {
block.source.sendSystemMessage(io.papermc.paper.adventure.PaperAdventure.asVanilla(message));
}
@Override
public net.kyori.adventure.text.Component name() {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.block.getDisplayName());
}
// Paper end
@Override
public boolean isOp() {
return CraftBlockCommandSender.SHARED_PERM.isOp();

View File

@@ -46,6 +46,13 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
return "CONSOLE";
}
// Paper start
@Override
public net.kyori.adventure.text.Component name() {
return net.kyori.adventure.text.Component.text(this.getName());
}
// Paper end
@Override
public boolean isOp() {
return true;
@@ -80,4 +87,11 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
public boolean isConversing() {
return this.conversationTracker.isConversing();
}
// Paper start
@Override
public void sendMessage(final net.kyori.adventure.identity.Identity identity, final net.kyori.adventure.text.Component message, final net.kyori.adventure.audience.MessageType type) {
this.sendRawMessage(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(message));
}
// Paper end
}

View File

@@ -39,6 +39,13 @@ public class CraftRemoteConsoleCommandSender extends ServerCommandSender impleme
return "Rcon";
}
// Paper start
@Override
public net.kyori.adventure.text.Component name() {
return net.kyori.adventure.text.Component.text(this.getName());
}
// Paper end
@Override
public boolean isOp() {
return true;

View File

@@ -67,6 +67,13 @@ public class ProxiedNativeCommandSender implements ProxiedCommandSender {
return this.getCallee().getName();
}
// Paper start
@Override
public net.kyori.adventure.text.Component name() {
return this.getCallee().name();
}
// Paper end
@Override
public boolean isPermissionSet(String name) {
return this.getCaller().isPermissionSet(name);

View File

@@ -13,6 +13,7 @@ import org.bukkit.plugin.Plugin;
public abstract class ServerCommandSender implements CommandSender {
private final PermissibleBase perm;
private net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers
protected ServerCommandSender() {
this.perm = new PermissibleBase(this);
@@ -130,4 +131,18 @@ public abstract class ServerCommandSender implements CommandSender {
return this.spigot;
}
// Spigot end
// Paper start - implement pointers
@Override
public net.kyori.adventure.pointer.Pointers pointers() {
if (this.adventure$pointers == null) {
this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
.withDynamic(net.kyori.adventure.identity.Identity.DISPLAY_NAME, this::name)
.withStatic(net.kyori.adventure.permission.PermissionChecker.POINTER, this::permissionValue)
.build();
}
return this.adventure$pointers;
}
// Paper end
}

View File

@@ -145,6 +145,12 @@ public class CraftEnchantment extends Enchantment implements Handleable<net.mine
CraftEnchantment ench = (CraftEnchantment) other;
return !net.minecraft.world.item.enchantment.Enchantment.areCompatible(this.handle, ench.handle);
}
// Paper start
@Override
public net.kyori.adventure.text.Component displayName(int level) {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().getFullname(level));
}
// Paper end
@Override
public String getTranslationKey() {

View File

@@ -70,6 +70,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
private final EntityType entityType;
private EntityDamageEvent lastDamageEvent;
private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(CraftEntity.DATA_TYPE_REGISTRY);
protected net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers
public CraftEntity(final CraftServer server, final Entity entity) {
this.server = server;
@@ -526,6 +527,32 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return this.getHandle().getVehicle().getBukkitEntity();
}
// Paper start
@Override
public net.kyori.adventure.text.Component customName() {
final Component name = this.getHandle().getCustomName();
return name != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(name) : null;
}
@Override
public void customName(final net.kyori.adventure.text.Component customName) {
this.getHandle().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
}
@Override
public net.kyori.adventure.pointer.Pointers pointers() {
if (this.adventure$pointers == null) {
this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
.withDynamic(net.kyori.adventure.identity.Identity.DISPLAY_NAME, this::name)
.withDynamic(net.kyori.adventure.identity.Identity.UUID, this::getUniqueId)
.withStatic(net.kyori.adventure.permission.PermissionChecker.POINTER, this::permissionValue)
.build();
}
return this.adventure$pointers;
}
// Paper end
@Override
public void setCustomName(String name) {
// sane limit for name length
@@ -622,6 +649,17 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
public String getName() {
return CraftChatMessage.fromComponent(this.getHandle().getName());
}
// Paper start
@Override
public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component name() {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getName());
}
@Override
public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component teamDisplayName() {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getDisplayName());
}
// Paper end
@Override
public boolean isPermissionSet(String name) {

View File

@@ -330,9 +330,12 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
container = CraftEventFactory.callInventoryOpenEvent(player, container);
if (container == null) return;
String title = container.getBukkitView().getTitle();
//String title = container.getBukkitView().getTitle(); // Paper - comment
net.kyori.adventure.text.Component adventure$title = container.getBukkitView().title(); // Paper
if (adventure$title == null) adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(container.getBukkitView().getTitle()); // Paper
player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0]));
//player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
player.containerMenu = container;
player.initMenu(container);
}
@@ -402,8 +405,12 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
// Now open the window
MenuType<?> windowType = CraftContainer.getNotchInventoryType(inventory.getTopInventory());
String title = inventory.getTitle();
player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0]));
//String title = inventory.getTitle(); // Paper - comment
net.kyori.adventure.text.Component adventure$title = inventory.title(); // Paper
if (adventure$title == null) adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(inventory.getTitle()); // Paper
//player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
player.containerMenu = container;
player.initMenu(container);
}

View File

@@ -59,6 +59,13 @@ public class CraftMinecartCommand extends CraftMinecart implements CommandMineca
return CraftChatMessage.fromComponent(this.getHandle().getCommandBlock().getName());
}
// Paper start
@Override
public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component name() {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getCommandBlock().getName());
}
// Paper end
@Override
public boolean isOp() {
return true;

View File

@@ -395,14 +395,40 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public String getDisplayName() {
if(true) return io.papermc.paper.adventure.DisplayNames.getLegacy(this); // Paper
return this.getHandle().displayName;
}
@Override
public void setDisplayName(final String name) {
this.getHandle().adventure$displayName = name != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(name) : net.kyori.adventure.text.Component.text(this.getName()); // Paper
this.getHandle().displayName = name == null ? this.getName() : name;
}
// Paper start
@Override
public void playerListName(net.kyori.adventure.text.Component name) {
getHandle().listName = name == null ? null : io.papermc.paper.adventure.PaperAdventure.asVanilla(name);
if (getHandle().connection == null) return; // Updates are possible before the player has fully joined
for (ServerPlayer player : server.getHandle().players) {
if (player.getBukkitEntity().canSee(this)) {
player.connection.send(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME, getHandle()));
}
}
}
@Override
public net.kyori.adventure.text.Component playerListName() {
return getHandle().listName == null ? net.kyori.adventure.text.Component.text(getName()) : io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().listName);
}
@Override
public net.kyori.adventure.text.Component playerListHeader() {
return playerListHeader;
}
@Override
public net.kyori.adventure.text.Component playerListFooter() {
return playerListFooter;
}
// Paper end
@Override
public String getPlayerListName() {
return this.getHandle().listName == null ? this.getName() : CraftChatMessage.fromComponent(this.getHandle().listName);
@@ -414,6 +440,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
name = this.getName();
}
this.getHandle().listName = name.equals(this.getName()) ? null : CraftChatMessage.fromStringOrNull(name);
if (this.getHandle().connection == null) return; // Paper - Updates are possible before the player has fully joined
for (ServerPlayer player : (List<ServerPlayer>) this.server.getHandle().players) {
if (player.getBukkitEntity().canSee(this)) {
player.connection.send(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME, this.getHandle()));
@@ -433,42 +460,42 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
this.getHandle().listOrder = order;
}
private Component playerListHeader;
private Component playerListFooter;
private net.kyori.adventure.text.Component playerListHeader; // Paper - Adventure
private net.kyori.adventure.text.Component playerListFooter; // Paper - Adventure
@Override
public String getPlayerListHeader() {
return (this.playerListHeader == null) ? null : CraftChatMessage.fromComponent(this.playerListHeader);
return (this.playerListHeader == null) ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.playerListHeader);
}
@Override
public String getPlayerListFooter() {
return (this.playerListFooter == null) ? null : CraftChatMessage.fromComponent(this.playerListFooter);
return (this.playerListFooter == null) ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.playerListFooter); // Paper - Adventure
}
@Override
public void setPlayerListHeader(String header) {
this.playerListHeader = CraftChatMessage.fromStringOrNull(header, true);
this.playerListHeader = header == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(header); // Paper - Adventure
this.updatePlayerListHeaderFooter();
}
@Override
public void setPlayerListFooter(String footer) {
this.playerListFooter = CraftChatMessage.fromStringOrNull(footer, true);
this.playerListFooter = footer == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(footer); // Paper - Adventure
this.updatePlayerListHeaderFooter();
}
@Override
public void setPlayerListHeaderFooter(String header, String footer) {
this.playerListHeader = CraftChatMessage.fromStringOrNull(header, true);
this.playerListFooter = CraftChatMessage.fromStringOrNull(footer, true);
this.playerListHeader = header == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(header); // Paper - Adventure
this.playerListFooter = footer == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(footer); // Paper - Adventure
this.updatePlayerListHeaderFooter();
}
private void updatePlayerListHeaderFooter() {
if (this.getHandle().connection == null) return;
ClientboundTabListPacket packet = new ClientboundTabListPacket((this.playerListHeader == null) ? Component.empty() : this.playerListHeader, (this.playerListFooter == null) ? Component.empty() : this.playerListFooter);
ClientboundTabListPacket packet = new ClientboundTabListPacket(io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(this.playerListHeader), io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(this.playerListFooter)); // Paper - adventure
this.getHandle().connection.send(packet);
}
@@ -498,6 +525,23 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
this.getHandle().transferCookieConnection.kickPlayer(CraftChatMessage.fromStringOrEmpty(message, true));
}
// Paper start
private static final net.kyori.adventure.text.Component DEFAULT_KICK_COMPONENT = net.kyori.adventure.text.Component.translatable("multiplayer.disconnect.kicked");
@Override
public void kick() {
this.kick(DEFAULT_KICK_COMPONENT);
}
@Override
public void kick(final net.kyori.adventure.text.Component message) {
org.spigotmc.AsyncCatcher.catchOp("player kick");
final ServerGamePacketListenerImpl connection = this.getHandle().connection;
if (connection != null) {
connection.disconnect(message == null ? net.kyori.adventure.text.Component.empty() : message);
}
}
// Paper end
@Override
public void setCompassTarget(Location loc) {
Preconditions.checkArgument(loc != null, "Location cannot be null");
@@ -794,6 +838,24 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
this.getHandle().connection.send(packet);
}
// Paper start
@Override
public void sendSignChange(Location loc, @Nullable List<? extends net.kyori.adventure.text.Component> lines, DyeColor dyeColor, boolean hasGlowingText) {
if (getHandle().connection == null) {
return;
}
if (lines == null) {
lines = new java.util.ArrayList<>(4);
}
Preconditions.checkArgument(loc != null, "Location cannot be null");
Preconditions.checkArgument(dyeColor != null, "DyeColor cannot be null");
if (lines.size() < 4) {
throw new IllegalArgumentException("Must have at least 4 lines");
}
Component[] components = CraftSign.sanitizeLines(lines);
this.sendSignChange0(components, loc, dyeColor, hasGlowingText);
}
// Paper end
@Override
public void sendSignChange(Location loc, String[] lines) {
this.sendSignChange(loc, lines, DyeColor.BLACK);
@@ -817,6 +879,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
if (this.getHandle().connection == null) return;
Component[] components = CraftSign.sanitizeLines(lines);
// Paper start - adventure
this.sendSignChange0(components, loc, dyeColor, hasGlowingText);
}
private void sendSignChange0(Component[] components, Location loc, DyeColor dyeColor, boolean hasGlowingText) {
// Paper end
SignBlockEntity sign = new SignBlockEntity(CraftLocation.toBlockPosition(loc), Blocks.OAK_SIGN.defaultBlockState());
SignText text = sign.getFrontText();
text = text.setColor(net.minecraft.world.item.DyeColor.byId(dyeColor.getWoolData()));
@@ -1843,7 +1911,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public void setResourcePack(String url) {
this.setResourcePack(url, null);
this.setResourcePack(url, (byte[]) null);
}
@Override
@@ -1858,7 +1926,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public void setResourcePack(String url, byte[] hash, boolean force) {
this.setResourcePack(url, hash, null, force);
this.setResourcePack(url, hash, (String) null, force);
}
@Override
@@ -1895,6 +1963,59 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
this.handlePushResourcePack(new ClientboundResourcePackPushPacket(id, url, hashStr, force, CraftChatMessage.fromStringOrOptional(prompt, true)), false);
}
// Paper start - adventure
@Override
public void setResourcePack(final UUID uuid, final String url, final byte[] hashBytes, final net.kyori.adventure.text.Component prompt, final boolean force) {
Preconditions.checkArgument(uuid != null, "Resource pack UUID cannot be null");
Preconditions.checkArgument(url != null, "Resource pack URL cannot be null");
final String hash;
if (hashBytes != null) {
Preconditions.checkArgument(hashBytes.length == 20, "Resource pack hash should be 20 bytes long but was " + hashBytes.length);
hash = BaseEncoding.base16().lowerCase().encode(hashBytes);
} else {
hash = "";
}
this.getHandle().connection.send(new ClientboundResourcePackPopPacket(Optional.empty()));
this.getHandle().connection.send(new ClientboundResourcePackPushPacket(uuid, url, hash, force, Optional.ofNullable(prompt).map(io.papermc.paper.adventure.PaperAdventure::asVanilla)));
}
@SuppressWarnings({"unchecked", "rawtypes"})
void sendBundle(final List<? extends net.minecraft.network.protocol.Packet<? extends net.minecraft.network.protocol.common.ClientCommonPacketListener>> packet) {
this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundBundlePacket((List) packet));
}
@Override
public void sendResourcePacks(final net.kyori.adventure.resource.ResourcePackRequest request) {
if (this.getHandle().connection == null) return;
final List<ClientboundResourcePackPushPacket> packs = new java.util.ArrayList<>(request.packs().size());
if (request.replace()) {
this.clearResourcePacks();
}
final Component prompt = io.papermc.paper.adventure.PaperAdventure.asVanilla(request.prompt());
for (final java.util.Iterator<net.kyori.adventure.resource.ResourcePackInfo> iter = request.packs().iterator(); iter.hasNext();) {
final net.kyori.adventure.resource.ResourcePackInfo pack = iter.next();
packs.add(new ClientboundResourcePackPushPacket(pack.id(), pack.uri().toASCIIString(), pack.hash(), request.required(), iter.hasNext() ? Optional.empty() : Optional.ofNullable(prompt)));
if (request.callback() != net.kyori.adventure.resource.ResourcePackCallback.noOp()) {
this.getHandle().connection.packCallbacks.put(pack.id(), request.callback()); // just override if there is a previously existing callback
}
}
this.sendBundle(packs);
super.sendResourcePacks(request);
}
@Override
public void removeResourcePacks(final UUID id, final UUID ... others) {
if (this.getHandle().connection == null) return;
this.sendBundle(net.kyori.adventure.util.MonkeyBars.nonEmptyArrayToList(pack -> new ClientboundResourcePackPopPacket(Optional.of(pack)), id, others));
}
@Override
public void clearResourcePacks() {
if (this.getHandle().connection == null) return;
this.getHandle().connection.send(new ClientboundResourcePackPopPacket(Optional.empty()));
}
// Paper end - adventure
@Override
public void removeResourcePack(UUID id) {
Preconditions.checkArgument(id != null, "Resource pack id cannot be null");
@@ -2300,6 +2421,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return (this.getHandle().requestedViewDistance() == 0) ? Bukkit.getViewDistance() : this.getHandle().requestedViewDistance();
}
// Paper start
@Override
public java.util.Locale locale() {
return getHandle().adventure$locale;
}
// Paper end
@Override
public int getPing() {
return this.getHandle().connection.latency();
@@ -2350,6 +2477,248 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return this.getHandle().allowsListing();
}
// Paper start
@Override
public net.kyori.adventure.text.Component displayName() {
return this.getHandle().adventure$displayName;
}
@Override
public void displayName(final net.kyori.adventure.text.Component displayName) {
this.getHandle().adventure$displayName = displayName != null ? displayName : net.kyori.adventure.text.Component.text(this.getName());
this.getHandle().displayName = null;
}
@Override
public void deleteMessage(net.kyori.adventure.chat.SignedMessage.Signature signature) {
if (getHandle().connection == null) return;
net.minecraft.network.chat.MessageSignature sig = new net.minecraft.network.chat.MessageSignature(signature.bytes());
this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundDeleteChatPacket(new net.minecraft.network.chat.MessageSignature.Packed(sig)));
}
private net.minecraft.network.chat.ChatType.Bound toHandle(net.kyori.adventure.chat.ChatType.Bound boundChatType) {
net.minecraft.core.Registry<net.minecraft.network.chat.ChatType> chatTypeRegistry = this.getHandle().level().registryAccess().lookupOrThrow(net.minecraft.core.registries.Registries.CHAT_TYPE);
return new net.minecraft.network.chat.ChatType.Bound(
chatTypeRegistry.getOrThrow(net.minecraft.resources.ResourceKey.create(net.minecraft.core.registries.Registries.CHAT_TYPE, io.papermc.paper.adventure.PaperAdventure.asVanilla(boundChatType.type().key()))),
io.papermc.paper.adventure.PaperAdventure.asVanilla(boundChatType.name()),
Optional.ofNullable(io.papermc.paper.adventure.PaperAdventure.asVanilla(boundChatType.target()))
);
}
@Override
public void sendMessage(net.kyori.adventure.text.Component message, net.kyori.adventure.chat.ChatType.Bound boundChatType) {
if (getHandle().connection == null) return;
net.minecraft.network.chat.Component component = io.papermc.paper.adventure.PaperAdventure.asVanilla(message);
this.getHandle().sendChatMessage(new net.minecraft.network.chat.OutgoingChatMessage.Disguised(component), this.getHandle().isTextFilteringEnabled(), this.toHandle(boundChatType));
}
@Override
public void sendMessage(net.kyori.adventure.chat.SignedMessage signedMessage, net.kyori.adventure.chat.ChatType.Bound boundChatType) {
if (getHandle().connection == null) return;
if (signedMessage instanceof PlayerChatMessage.AdventureView view) {
this.getHandle().sendChatMessage(net.minecraft.network.chat.OutgoingChatMessage.create(view.playerChatMessage()), this.getHandle().isTextFilteringEnabled(), this.toHandle(boundChatType));
return;
}
net.kyori.adventure.text.Component message = signedMessage.unsignedContent() == null ? net.kyori.adventure.text.Component.text(signedMessage.message()) : signedMessage.unsignedContent();
if (signedMessage.isSystem()) {
this.sendMessage(message, boundChatType);
} else {
super.sendMessage(signedMessage, boundChatType);
}
// net.minecraft.network.chat.PlayerChatMessage playerChatMessage = new net.minecraft.network.chat.PlayerChatMessage(
// null, // TODO:
// new net.minecraft.network.chat.MessageSignature(signedMessage.signature().bytes()),
// null, // TODO
// io.papermc.paper.adventure.PaperAdventure.asVanilla(signedMessage.unsignedContent()),
// net.minecraft.network.chat.FilterMask.PASS_THROUGH
// );
//
// this.getHandle().sendChatMessage(net.minecraft.network.chat.OutgoingChatMessage.create(playerChatMessage), this.getHandle().isTextFilteringEnabled(), this.toHandle(boundChatType));
}
@Deprecated(forRemoval = true)
@Override
public void sendMessage(final net.kyori.adventure.identity.Identity identity, final net.kyori.adventure.text.Component message, final net.kyori.adventure.audience.MessageType type) {
if (getHandle().connection == null) return;
final net.minecraft.core.Registry<net.minecraft.network.chat.ChatType> chatTypeRegistry = this.getHandle().level().registryAccess().lookupOrThrow(net.minecraft.core.registries.Registries.CHAT_TYPE);
this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundSystemChatPacket(message, false));
}
@Override
public void sendActionBar(final net.kyori.adventure.text.Component message) {
final net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket packet = new net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket(io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(message));
this.getHandle().connection.send(packet);
}
@Override
public void sendPlayerListHeader(final net.kyori.adventure.text.Component header) {
this.playerListHeader = header;
this.adventure$sendPlayerListHeaderAndFooter();
}
@Override
public void sendPlayerListFooter(final net.kyori.adventure.text.Component footer) {
this.playerListFooter = footer;
this.adventure$sendPlayerListHeaderAndFooter();
}
@Override
public void sendPlayerListHeaderAndFooter(final net.kyori.adventure.text.Component header, final net.kyori.adventure.text.Component footer) {
this.playerListHeader = header;
this.playerListFooter = footer;
this.adventure$sendPlayerListHeaderAndFooter();
}
private void adventure$sendPlayerListHeaderAndFooter() {
final ServerGamePacketListenerImpl connection = this.getHandle().connection;
if (connection == null) return;
final ClientboundTabListPacket packet = new ClientboundTabListPacket(
io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(this.playerListHeader),
io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(this.playerListFooter)
);
connection.send(packet);
}
@Override
public void showTitle(final net.kyori.adventure.title.Title title) {
final ServerGamePacketListenerImpl connection = this.getHandle().connection;
final net.kyori.adventure.title.Title.Times times = title.times();
if (times != null) {
connection.send(new ClientboundSetTitlesAnimationPacket(ticks(times.fadeIn()), ticks(times.stay()), ticks(times.fadeOut())));
}
final ClientboundSetSubtitleTextPacket sp = new ClientboundSetSubtitleTextPacket(io.papermc.paper.adventure.PaperAdventure.asVanilla(title.subtitle()));
connection.send(sp);
final ClientboundSetTitleTextPacket tp = new ClientboundSetTitleTextPacket(io.papermc.paper.adventure.PaperAdventure.asVanilla(title.title()));
connection.send(tp);
}
@Override
public <T> void sendTitlePart(final net.kyori.adventure.title.TitlePart<T> part, T value) {
java.util.Objects.requireNonNull(part, "part");
java.util.Objects.requireNonNull(value, "value");
if (part == net.kyori.adventure.title.TitlePart.TITLE) {
final ClientboundSetTitleTextPacket tp = new ClientboundSetTitleTextPacket(io.papermc.paper.adventure.PaperAdventure.asVanilla((net.kyori.adventure.text.Component)value));
this.getHandle().connection.send(tp);
} else if (part == net.kyori.adventure.title.TitlePart.SUBTITLE) {
final ClientboundSetSubtitleTextPacket sp = new ClientboundSetSubtitleTextPacket(io.papermc.paper.adventure.PaperAdventure.asVanilla((net.kyori.adventure.text.Component)value));
this.getHandle().connection.send(sp);
} else if (part == net.kyori.adventure.title.TitlePart.TIMES) {
final net.kyori.adventure.title.Title.Times times = (net.kyori.adventure.title.Title.Times) value;
this.getHandle().connection.send(new ClientboundSetTitlesAnimationPacket(ticks(times.fadeIn()), ticks(times.stay()), ticks(times.fadeOut())));
} else {
throw new IllegalArgumentException("Unknown TitlePart");
}
}
private static int ticks(final java.time.Duration duration) {
if (duration == null) {
return -1;
}
return (int) (duration.toMillis() / 50L);
}
@Override
public void clearTitle() {
this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundClearTitlesPacket(false));
}
// resetTitle implemented above
private @Nullable Set<net.kyori.adventure.bossbar.BossBar> activeBossBars;
@Override
public @NotNull Iterable<? extends net.kyori.adventure.bossbar.BossBar> activeBossBars() {
if (this.activeBossBars != null) {
return java.util.Collections.unmodifiableSet(this.activeBossBars);
}
return Set.of();
}
@Override
public void showBossBar(final net.kyori.adventure.bossbar.BossBar bar) {
net.kyori.adventure.bossbar.BossBarImplementation.get(bar, io.papermc.paper.adventure.BossBarImplementationImpl.class).playerShow(this);
if (this.activeBossBars == null) {
this.activeBossBars = new HashSet<>();
}
this.activeBossBars.add(bar);
}
@Override
public void hideBossBar(final net.kyori.adventure.bossbar.BossBar bar) {
net.kyori.adventure.bossbar.BossBarImplementation.get(bar, io.papermc.paper.adventure.BossBarImplementationImpl.class).playerHide(this);
if (this.activeBossBars != null) {
this.activeBossBars.remove(bar);
if (this.activeBossBars.isEmpty()) {
this.activeBossBars = null;
}
}
}
@Override
public void playSound(final net.kyori.adventure.sound.Sound sound) {
final net.minecraft.world.phys.Vec3 pos = this.getHandle().position();
this.playSound(sound, pos.x, pos.y, pos.z);
}
@Override
public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
this.getHandle().connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, x, y, z, sound.seed().orElseGet(this.getHandle().getRandom()::nextLong), null));
}
@Override
public void playSound(final net.kyori.adventure.sound.Sound sound, final net.kyori.adventure.sound.Sound.Emitter emitter) {
final Entity entity;
if (emitter == net.kyori.adventure.sound.Sound.Emitter.self()) {
entity = this.getHandle();
} else if (emitter instanceof CraftEntity craftEntity) {
entity = craftEntity.getHandle();
} else {
throw new IllegalArgumentException("Sound emitter must be an Entity or self(), but was: " + emitter);
}
this.getHandle().connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, entity, sound.seed().orElseGet(this.getHandle().getRandom()::nextLong), null));
}
@Override
public void stopSound(final net.kyori.adventure.sound.SoundStop stop) {
this.getHandle().connection.send(new ClientboundStopSoundPacket(
io.papermc.paper.adventure.PaperAdventure.asVanillaNullable(stop.sound()),
io.papermc.paper.adventure.PaperAdventure.asVanillaNullable(stop.source())
));
}
@Override
public void openBook(final net.kyori.adventure.inventory.Book book) {
final java.util.Locale locale = this.getHandle().adventure$locale;
final net.minecraft.world.item.ItemStack item = io.papermc.paper.adventure.PaperAdventure.asItemStack(book, locale);
final ServerPlayer player = this.getHandle();
final ServerGamePacketListenerImpl connection = player.connection;
final net.minecraft.world.entity.player.Inventory inventory = player.getInventory();
final int slot = inventory.items.size() + inventory.selected;
final int stateId = getHandle().containerMenu.getStateId();
connection.send(new net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket(0, stateId, slot, item));
connection.send(new net.minecraft.network.protocol.game.ClientboundOpenBookPacket(net.minecraft.world.InteractionHand.MAIN_HAND));
connection.send(new net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket(0, stateId, slot, inventory.getSelected()));
}
@Override
public net.kyori.adventure.pointer.Pointers pointers() {
if (this.adventure$pointers == null) {
this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
.withDynamic(net.kyori.adventure.identity.Identity.DISPLAY_NAME, this::displayName)
.withDynamic(net.kyori.adventure.identity.Identity.NAME, this::getName)
.withDynamic(net.kyori.adventure.identity.Identity.UUID, this::getUniqueId)
.withStatic(net.kyori.adventure.permission.PermissionChecker.POINTER, this::permissionValue)
.withDynamic(net.kyori.adventure.identity.Identity.LOCALE, this::locale)
.build();
}
return this.adventure$pointers;
}
// Paper end
// Spigot start
private final Player.Spigot spigot = new Player.Spigot()
{

View File

@@ -32,6 +32,17 @@ public class CraftTextDisplay extends CraftDisplay implements TextDisplay {
public void setText(String text) {
this.getHandle().setText(CraftChatMessage.fromString(text, true)[0]);
}
// Paper start
@Override
public net.kyori.adventure.text.Component text() {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getText());
}
@Override
public void text(net.kyori.adventure.text.Component text) {
this.getHandle().setText(text == null ? net.minecraft.network.chat.Component.empty() : io.papermc.paper.adventure.PaperAdventure.asVanilla(text));
}
// Paper end
@Override
public int getLineWidth() {

View File

@@ -915,7 +915,7 @@ public class CraftEventFactory {
return event;
}
public static PlayerDeathEvent callPlayerDeathEvent(ServerPlayer victim, DamageSource damageSource, List<org.bukkit.inventory.ItemStack> drops, String deathMessage, boolean keepInventory) {
public static PlayerDeathEvent callPlayerDeathEvent(ServerPlayer victim, DamageSource damageSource, List<org.bukkit.inventory.ItemStack> drops, net.kyori.adventure.text.Component deathMessage, boolean keepInventory) { // Paper - Adventure
CraftPlayer entity = victim.getBukkitEntity();
CraftDamageSource bukkitDamageSource = new CraftDamageSource(damageSource);
PlayerDeathEvent event = new PlayerDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(victim.serverLevel(), damageSource.getEntity()), 0, deathMessage);
@@ -948,7 +948,7 @@ public class CraftEventFactory {
* Server methods
*/
public static ServerListPingEvent callServerListPingEvent(SocketAddress address, String motd, int numPlayers, int maxPlayers) {
ServerListPingEvent event = new ServerListPingEvent("", ((InetSocketAddress) address).getAddress(), motd, numPlayers, maxPlayers);
ServerListPingEvent event = new ServerListPingEvent("", ((InetSocketAddress) address).getAddress(), Bukkit.getServer().motd(), numPlayers, maxPlayers);
Bukkit.getServer().getPluginManager().callEvent(event);
return event;
}

View File

@@ -72,6 +72,13 @@ public class CraftContainer extends AbstractContainerMenu {
return inventory.getType();
}
// Paper start
@Override
public net.kyori.adventure.text.Component title() {
return inventory instanceof CraftInventoryCustom ? ((CraftInventoryCustom.MinecraftInventory) ((CraftInventory) inventory).getInventory()).title() : net.kyori.adventure.text.Component.text(inventory.getType().getDefaultTitle());
}
// Paper end
@Override
public String getTitle() {
return this.title;

View File

@@ -19,6 +19,12 @@ public class CraftInventoryCustom extends CraftInventory {
super(new MinecraftInventory(owner, type));
}
// Paper start
public CraftInventoryCustom(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
super(new MinecraftInventory(owner, type, title));
}
// Paper end
public CraftInventoryCustom(InventoryHolder owner, InventoryType type, String title) {
super(new MinecraftInventory(owner, type, title));
}
@@ -27,6 +33,12 @@ public class CraftInventoryCustom extends CraftInventory {
super(new MinecraftInventory(owner, size));
}
// Paper start
public CraftInventoryCustom(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) {
super(new MinecraftInventory(owner, size, title));
}
// Paper end
public CraftInventoryCustom(InventoryHolder owner, int size, String title) {
super(new MinecraftInventory(owner, size, title));
}
@@ -36,9 +48,17 @@ public class CraftInventoryCustom extends CraftInventory {
private int maxStack = MAX_STACK;
private final List<HumanEntity> viewers;
private final String title;
private final net.kyori.adventure.text.Component adventure$title; // Paper
private InventoryType type;
private final InventoryHolder owner;
// Paper start
public MinecraftInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
this(owner, type.getDefaultSize(), title);
this.type = type;
}
// Paper end
public MinecraftInventory(InventoryHolder owner, InventoryType type) {
this(owner, type.getDefaultSize(), type.getDefaultTitle());
this.type = type;
@@ -57,11 +77,24 @@ public class CraftInventoryCustom extends CraftInventory {
Preconditions.checkArgument(title != null, "title cannot be null");
this.items = NonNullList.withSize(size, ItemStack.EMPTY);
this.title = title;
this.adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(title);
this.viewers = new ArrayList<HumanEntity>();
this.owner = owner;
this.type = InventoryType.CHEST;
}
// Paper start
public MinecraftInventory(final InventoryHolder owner, final int size, final net.kyori.adventure.text.Component title) {
Preconditions.checkArgument(title != null, "Title cannot be null");
this.items = NonNullList.withSize(size, ItemStack.EMPTY);
this.title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(title);
this.adventure$title = title;
this.viewers = new ArrayList<HumanEntity>();
this.owner = owner;
this.type = InventoryType.CHEST;
}
// Paper end
@Override
public int getContainerSize() {
return this.items.size();
@@ -183,6 +216,12 @@ public class CraftInventoryCustom extends CraftInventory {
return null;
}
// Paper start
public net.kyori.adventure.text.Component title() {
return this.adventure$title;
}
// Paper end
public String getTitle() {
return this.title;
}

View File

@@ -73,6 +73,13 @@ public class CraftInventoryView<T extends AbstractContainerMenu, I extends Inven
return CraftItemStack.asCraftMirror(this.container.getSlot(slot).getItem());
}
// Paper start
@Override
public net.kyori.adventure.text.Component title() {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.container.getTitle());
}
// Paper end
@Override
public String getTitle() {
return this.title;

View File

@@ -211,4 +211,21 @@ public final class CraftItemFactory implements ItemFactory {
Optional<HolderSet.Named<Enchantment>> optional = (allowTreasures) ? Optional.empty() : registry.lookupOrThrow(Registries.ENCHANTMENT).get(EnchantmentTags.IN_ENCHANTING_TABLE);
return CraftItemStack.asCraftMirror(EnchantmentHelper.enchantItem(source, craft.handle, level, registry, optional));
}
// Paper start - Adventure
@Override
public net.kyori.adventure.text.event.HoverEvent<net.kyori.adventure.text.event.HoverEvent.ShowItem> asHoverEvent(final ItemStack item, final java.util.function.UnaryOperator<net.kyori.adventure.text.event.HoverEvent.ShowItem> op) {
return net.kyori.adventure.text.event.HoverEvent.showItem(op.apply(
net.kyori.adventure.text.event.HoverEvent.ShowItem.showItem(
item.getType().getKey(),
item.getAmount(),
io.papermc.paper.adventure.PaperAdventure.asAdventure(CraftItemStack.unwrap(item).getComponentsPatch())) // unwrap is fine here because the components patch will be safely copied
));
}
@Override
public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component displayName(@org.jetbrains.annotations.NotNull ItemStack itemStack) {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(CraftItemStack.asNMSCopy(itemStack).getDisplayName());
}
// Paper end - Adventure
}

View File

@@ -37,6 +37,12 @@ public class CraftMenuType<V extends InventoryView> implements MenuType.Typed<V>
@Override
public V create(final HumanEntity player, final String title) {
// Paper start - adventure
return create(player, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(title));
}
@Override
public V create(final HumanEntity player, final net.kyori.adventure.text.Component title) {
// Paper end - adventure
Preconditions.checkArgument(player != null, "The given player must not be null");
Preconditions.checkArgument(title != null, "The given title must not be null");
Preconditions.checkArgument(player instanceof CraftHumanEntity, "The given player must be a CraftHumanEntity");
@@ -45,7 +51,7 @@ public class CraftMenuType<V extends InventoryView> implements MenuType.Typed<V>
final ServerPlayer serverPlayer = (ServerPlayer) craftHuman.getHandle();
final AbstractContainerMenu container = this.typeData.get().menuBuilder().build(serverPlayer, this.handle);
container.setTitle(CraftChatMessage.fromString(title)[0]);
container.setTitle(io.papermc.paper.adventure.PaperAdventure.asVanilla(title)); // Paper - adventure
container.checkReachable = false;
return (V) container.getBukkitView();
}

View File

@@ -15,10 +15,17 @@ public class CraftMerchantCustom implements CraftMerchant {
private MinecraftMerchant merchant;
@Deprecated // Paper - Adventure
public CraftMerchantCustom(String title) {
this.merchant = new MinecraftMerchant(title);
this.getMerchant().craftMerchant = this;
}
// Paper start
public CraftMerchantCustom(net.kyori.adventure.text.Component title) {
this.merchant = new MinecraftMerchant(title);
getMerchant().craftMerchant = this;
}
// Paper end
@Override
public String toString() {
@@ -37,10 +44,17 @@ public class CraftMerchantCustom implements CraftMerchant {
private Player tradingPlayer;
protected CraftMerchant craftMerchant;
@Deprecated // Paper - Adventure
public MinecraftMerchant(String title) {
Preconditions.checkArgument(title != null, "Title cannot be null");
this.title = CraftChatMessage.fromString(title)[0];
}
// Paper start
public MinecraftMerchant(net.kyori.adventure.text.Component title) {
Preconditions.checkArgument(title != null, "Title cannot be null");
this.title = io.papermc.paper.adventure.PaperAdventure.asVanilla(title);
}
// Paper end
@Override
public CraftMerchant getCraftMerchant() {

View File

@@ -2,8 +2,9 @@ package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.Lists;
import com.google.common.collect.ImmutableMap; // Paper
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -170,6 +171,128 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta, WritableBo
public void setGeneration(Generation generation) {
}
// Paper start
@Override
public net.kyori.adventure.text.Component title() {
return null;
}
@Override
public org.bukkit.inventory.meta.BookMeta title(net.kyori.adventure.text.Component title) {
return this;
}
@Override
public net.kyori.adventure.text.Component author() {
return null;
}
@Override
public org.bukkit.inventory.meta.BookMeta author(net.kyori.adventure.text.Component author) {
return this;
}
@Override
public net.kyori.adventure.text.Component page(final int page) {
Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s/%s)", page, this.getPageCount());
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(this.pages.get(page - 1));
}
@Override
public void page(final int page, net.kyori.adventure.text.Component data) {
Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s/%s)", page, this.getPageCount());
if (data == null) {
data = net.kyori.adventure.text.Component.empty();
}
this.pages.set(page - 1, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(data));
}
@Override
public List<net.kyori.adventure.text.Component> pages() {
if (this.pages == null) return ImmutableList.of();
return this.pages.stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::deserialize).collect(ImmutableList.toImmutableList());
}
@Override
public BookMeta pages(List<net.kyori.adventure.text.Component> pages) {
if (this.pages != null) this.pages.clear();
for (net.kyori.adventure.text.Component page : pages) {
this.addPages(page);
}
return this;
}
@Override
public BookMeta pages(net.kyori.adventure.text.Component... pages) {
if (this.pages != null) this.pages.clear();
this.addPages(pages);
return this;
}
@Override
public void addPages(net.kyori.adventure.text.Component... pages) {
if (this.pages == null) this.pages = new ArrayList<>();
for (net.kyori.adventure.text.Component page : pages) {
if (this.pages.size() >= MAX_PAGES) {
return;
}
if (page == null) {
page = net.kyori.adventure.text.Component.empty();
}
this.pages.add(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(page));
}
}
private CraftMetaBook(List<net.kyori.adventure.text.Component> pages) {
super((org.bukkit.craftbukkit.inventory.CraftMetaItem) org.bukkit.Bukkit.getItemFactory().getItemMeta(org.bukkit.Material.WRITABLE_BOOK));
this.pages = pages.subList(0, Math.min(MAX_PAGES, pages.size())).stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::serialize).collect(java.util.stream.Collectors.toList());
}
static class CraftMetaBookBuilder implements BookMetaBuilder {
protected final List<net.kyori.adventure.text.Component> pages = new java.util.ArrayList<>();
@Override
public BookMetaBuilder title(net.kyori.adventure.text.Component title) {
return this;
}
@Override
public BookMetaBuilder author(net.kyori.adventure.text.Component author) {
return this;
}
@Override
public BookMetaBuilder addPage(net.kyori.adventure.text.Component page) {
this.pages.add(page);
return this;
}
@Override
public BookMetaBuilder pages(net.kyori.adventure.text.Component... pages) {
java.util.Collections.addAll(this.pages, pages);
return this;
}
@Override
public BookMetaBuilder pages(java.util.Collection<net.kyori.adventure.text.Component> pages) {
this.pages.addAll(pages);
return this;
}
@Override
public BookMeta build() {
return new CraftMetaBook(this.pages);
}
}
@Override
public BookMetaBuilder toBuilder() {
return new CraftMetaBookBuilder();
}
// Paper end
@Override
public String getPage(final int page) {
Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s)", page);
@@ -286,7 +409,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta, WritableBo
}
@Override
Builder<String, Object> serialize(Builder<String, Object> builder) {
ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
super.serialize(builder);
if (this.pages != null) {

View File

@@ -346,7 +346,7 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta {
}
@Override
Builder<String, Object> serialize(Builder<String, Object> builder) {
com.google.common.collect.ImmutableMap.Builder<String, Object> serialize(com.google.common.collect.ImmutableMap.Builder<String, Object> builder) { // Paper - adventure - fqn as it conflicts with adventure book builder
super.serialize(builder);
if (this.hasTitle()) {
@@ -459,4 +459,111 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta {
return this.spigot;
}
// Spigot end
// Paper start - adventure
public static final net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.builder()
.character(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.SECTION_CHAR)
.build();
private CraftMetaBookSigned(net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, java.util.List<net.kyori.adventure.text.Component> pages) {
super((org.bukkit.craftbukkit.inventory.CraftMetaItem) org.bukkit.Bukkit.getItemFactory().getItemMeta(Material.WRITABLE_BOOK));
this.title = title == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(title);
this.author = author == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(author);
this.pages = io.papermc.paper.adventure.PaperAdventure.asVanilla(pages.subList(0, Math.min(MAX_PAGES, pages.size())));
}
static final class CraftMetaBookSignedBuilder extends CraftMetaBook.CraftMetaBookBuilder {
private net.kyori.adventure.text.Component title;
private net.kyori.adventure.text.Component author;
@Override
public org.bukkit.inventory.meta.BookMeta.BookMetaBuilder title(final net.kyori.adventure.text.Component title) {
this.title = title;
return this;
}
@Override
public org.bukkit.inventory.meta.BookMeta.BookMetaBuilder author(final net.kyori.adventure.text.Component author) {
this.author = author;
return this;
}
@Override
public org.bukkit.inventory.meta.BookMeta build() {
return new CraftMetaBookSigned(this.title, this.author, this.pages);
}
}
@Override
public BookMetaBuilder toBuilder() {
return new CraftMetaBookSignedBuilder();
}
@Override
public net.kyori.adventure.text.Component title() {
return this.title == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.deserialize(this.title);
}
@Override
public org.bukkit.inventory.meta.BookMeta title(net.kyori.adventure.text.Component title) {
this.setTitle(title == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(title));
return this;
}
@Override
public net.kyori.adventure.text.Component author() {
return this.author == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.deserialize(this.author);
}
@Override
public org.bukkit.inventory.meta.BookMeta author(net.kyori.adventure.text.Component author) {
this.setAuthor(author == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(author));
return this;
}
@Override
public net.kyori.adventure.text.Component page(final int page) {
Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s/%s)", page, this.getPageCount());
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.pages.get(page - 1));
}
@Override
public void page(final int page, net.kyori.adventure.text.Component data) {
Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s/%s)", page, this.getPageCount());
this.pages.set(page - 1, io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(data));
}
@Override
public List<net.kyori.adventure.text.Component> pages() {
if (this.pages == null) return ImmutableList.of();
return this.pages.stream().map(io.papermc.paper.adventure.PaperAdventure::asAdventure).collect(ImmutableList.toImmutableList());
}
@Override
public BookMeta pages(List<net.kyori.adventure.text.Component> pages) {
if (this.pages != null) this.pages.clear();
for (net.kyori.adventure.text.Component page : pages) {
this.addPages(page);
}
return this;
}
@Override
public BookMeta pages(net.kyori.adventure.text.Component... pages) {
if (this.pages != null) this.pages.clear();
this.addPages(pages);
return this;
}
@Override
public void addPages(net.kyori.adventure.text.Component... pages) {
if (this.pages == null) this.pages = new ArrayList<>();
for (net.kyori.adventure.text.Component page : pages) {
if (this.pages.size() >= MAX_PAGES) {
return;
}
this.pages.add(io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(page));
}
}
// Paper end
}

View File

@@ -1103,6 +1103,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
return !(this.hasDisplayName() || this.hasItemName() || this.hasLocalizedName() || this.hasEnchants() || (this.lore != null) || this.hasCustomModelData() || this.hasEnchantable() || this.hasBlockData() || this.hasRepairCost() || !this.unhandledTags.build().isEmpty() || !this.removedTags.isEmpty() || !this.persistentDataContainer.isEmpty() || this.hideFlag != 0 || this.isHideTooltip() || this.hasTooltipStyle() || this.hasItemModel() || this.isUnbreakable() || this.hasEnchantmentGlintOverride() || this.isGlider() || this.hasDamageResistant() || this.hasMaxStackSize() || this.hasRarity() || this.hasUseRemainder() || this.hasUseCooldown() || this.hasFood() || this.hasTool() || this.hasJukeboxPlayable() || this.hasEquippable() || this.hasDamage() || this.hasMaxDamage() || this.hasAttributeModifiers() || this.customTag != null);
}
// Paper start
@Override
public net.kyori.adventure.text.Component customName() {
return displayName == null ? null : io.papermc.paper.adventure.PaperAdventure.asAdventure(displayName);
}
@Override
public void customName(final net.kyori.adventure.text.Component customName) {
this.displayName = customName == null ? null : io.papermc.paper.adventure.PaperAdventure.asVanilla(customName);
}
// Paper end
@Override
public String getDisplayName() {
return CraftChatMessage.fromComponent(this.displayName);
@@ -1114,7 +1126,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
}
@Override
public boolean hasDisplayName() {
public boolean hasCustomName() {
return this.displayName != null;
}
@@ -1133,6 +1145,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
return this.itemName != null;
}
// Paper start - Adventure
@Override
public net.kyori.adventure.text.Component itemName() {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.itemName);
}
@Override
public void itemName(final net.kyori.adventure.text.Component name) {
this.itemName = io.papermc.paper.adventure.PaperAdventure.asVanilla(name);
}
// Paper end - Adventure
@Override
public String getLocalizedName() {
return this.getDisplayName();
@@ -1152,6 +1176,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
return this.lore != null && !this.lore.isEmpty();
}
// Paper start
@Override
public List<net.kyori.adventure.text.Component> lore() {
return this.lore != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(this.lore) : null;
}
@Override
public void lore(final List<? extends net.kyori.adventure.text.Component> lore) {
this.lore = lore != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(lore) : null;
}
// Paper end
@Override
public boolean hasRepairCost() {
return this.repairCost > 0;

View File

@@ -109,7 +109,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
String name = SerializableMeta.getString(map, CraftMetaPotion.CUSTOM_NAME.BUKKIT, true);
if (name != null) {
this.setCustomName(name);
this.setCustomPotionName(name);
}
Iterable<?> rawEffectList = SerializableMeta.getObject(Iterable.class, map, CraftMetaPotion.POTION_EFFECTS.BUKKIT, true);
@@ -151,7 +151,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
}
boolean isPotionEmpty() {
return (this.type == null) && !(this.hasCustomEffects() || this.hasColor() || this.hasCustomName());
return (this.type == null) && !(this.hasCustomEffects() || this.hasColor() || this.hasCustomPotionName());
}
@Override
@@ -306,17 +306,17 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
}
@Override
public boolean hasCustomName() {
public boolean hasCustomPotionName() {
return this.customName != null;
}
@Override
public String getCustomName() {
public String getCustomPotionName() {
return this.customName;
}
@Override
public void setCustomName(String customName) {
public void setCustomPotionName(String customName) {
this.customName = customName;
}
@@ -330,7 +330,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
if (this.hasColor()) {
hash = 73 * hash + this.color.hashCode();
}
if (this.hasCustomName()) {
if (this.hasCustomPotionName()) {
hash = 73 * hash + this.customName.hashCode();
}
if (this.hasCustomEffects()) {
@@ -350,7 +350,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
return Objects.equals(this.type, that.type)
&& (this.hasCustomEffects() ? that.hasCustomEffects() && this.customEffects.equals(that.customEffects) : !that.hasCustomEffects())
&& (this.hasColor() ? that.hasColor() && this.color.equals(that.color) : !that.hasColor())
&& (this.hasCustomName() ? that.hasCustomName() && this.customName.equals(that.customName) : !that.hasCustomName());
&& (this.hasCustomPotionName() ? that.hasCustomPotionName() && this.customName.equals(that.customName) : !that.hasCustomPotionName());
}
return true;
}
@@ -371,8 +371,8 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
builder.put(CraftMetaPotion.POTION_COLOR.BUKKIT, this.getColor());
}
if (this.hasCustomName()) {
builder.put(CraftMetaPotion.CUSTOM_NAME.BUKKIT, this.getCustomName());
if (this.hasCustomPotionName()) {
builder.put(CraftMetaPotion.CUSTOM_NAME.BUKKIT, this.getCustomPotionName());
}
if (this.hasCustomEffects()) {

View File

@@ -60,6 +60,14 @@ public class CraftTrimMaterial implements TrimMaterial, Handleable<net.minecraft
@NotNull
@Override
public String getTranslationKey() {
if (!(this.handle.description().getContents() instanceof TranslatableContents)) throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
return ((TranslatableContents) this.handle.description().getContents()).getKey();
}
// Paper start - adventure
@Override
public net.kyori.adventure.text.Component description() {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.description());
}
// Paper end - adventure
}

View File

@@ -60,6 +60,14 @@ public class CraftTrimPattern implements TrimPattern, Handleable<net.minecraft.w
@NotNull
@Override
public String getTranslationKey() {
if (!(this.handle.description().getContents() instanceof TranslatableContents)) throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
return ((TranslatableContents) this.handle.description().getContents()).getKey();
}
// Paper start - adventure
@Override
public net.kyori.adventure.text.Component description() {
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.description());
}
// Paper end - adventure
}

View File

@@ -12,6 +12,13 @@ public class CraftCustomInventoryConverter implements CraftInventoryCreator.Inve
return new CraftInventoryCustom(holder, type);
}
// Paper start
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
return new CraftInventoryCustom(owner, type, title);
}
// Paper end
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
return new CraftInventoryCustom(owner, type, title);
@@ -21,6 +28,12 @@ public class CraftCustomInventoryConverter implements CraftInventoryCreator.Inve
return new CraftInventoryCustom(owner, size);
}
// Paper start
public Inventory createInventory(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) {
return new CraftInventoryCustom(owner, size, title);
}
// Paper end
public Inventory createInventory(InventoryHolder owner, int size, String title) {
return new CraftInventoryCustom(owner, size, title);
}

View File

@@ -45,6 +45,12 @@ public final class CraftInventoryCreator {
return this.converterMap.get(type).createInventory(holder, type);
}
// Paper start
public Inventory createInventory(InventoryHolder holder, InventoryType type, net.kyori.adventure.text.Component title) {
return converterMap.get(type).createInventory(holder, type, title);
}
// Paper end
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
return this.converterMap.get(type).createInventory(holder, type, title);
}
@@ -53,6 +59,12 @@ public final class CraftInventoryCreator {
return this.DEFAULT_CONVERTER.createInventory(holder, size);
}
// Paper start
public Inventory createInventory(InventoryHolder holder, int size, net.kyori.adventure.text.Component title) {
return DEFAULT_CONVERTER.createInventory(holder, size, title);
}
// Paper end
public Inventory createInventory(InventoryHolder holder, int size, String title) {
return this.DEFAULT_CONVERTER.createInventory(holder, size, title);
}
@@ -61,6 +73,10 @@ public final class CraftInventoryCreator {
Inventory createInventory(InventoryHolder holder, InventoryType type);
// Paper start
Inventory createInventory(InventoryHolder holder, InventoryType type, net.kyori.adventure.text.Component title);
// Paper end
Inventory createInventory(InventoryHolder holder, InventoryType type, String title);
}
}

View File

@@ -31,6 +31,18 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
return this.getInventory(this.getTileEntity());
}
// Paper start
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
Container te = getTileEntity();
if (te instanceof RandomizableContainerBlockEntity) {
((RandomizableContainerBlockEntity) te).name = io.papermc.paper.adventure.PaperAdventure.asVanilla(title);
}
return getInventory(te);
}
// Paper end
@Override
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
Container te = this.getTileEntity();
@@ -53,6 +65,15 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
return furnace;
}
// Paper start
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
Container tileEntity = getTileEntity();
((AbstractFurnaceBlockEntity) tileEntity).setCustomName(io.papermc.paper.adventure.PaperAdventure.asVanilla(title));
return getInventory(tileEntity);
}
// Paper end
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
Container tileEntity = this.getTileEntity();
@@ -73,6 +94,18 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
return new BrewingStandBlockEntity(BlockPos.ZERO, Blocks.BREWING_STAND.defaultBlockState());
}
// Paper start
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
// BrewingStand does not extend TileEntityLootable
Container tileEntity = getTileEntity();
if (tileEntity instanceof BrewingStandBlockEntity) {
((BrewingStandBlockEntity) tileEntity).name = io.papermc.paper.adventure.PaperAdventure.asVanilla(title);
}
return getInventory(tileEntity);
}
// Paper end
@Override
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
// BrewingStand does not extend TileEntityLootable

View File

@@ -43,7 +43,7 @@ public class CraftMapRenderer extends MapRenderer {
}
MapDecoration decoration = this.worldMap.decorations.get(key);
cursors.addCursor(new MapCursor(decoration.x(), decoration.y(), (byte) (decoration.rot() & 15), CraftMapCursor.CraftType.minecraftHolderToBukkit(decoration.type()), true, CraftChatMessage.fromComponent(decoration.name().orElse(null))));
cursors.addCursor(new MapCursor(decoration.x(), decoration.y(), (byte) (decoration.rot() & 15), CraftMapCursor.CraftType.minecraftHolderToBukkit(decoration.type()), true, decoration.name().isEmpty() ? null : io.papermc.paper.adventure.PaperAdventure.asAdventure(decoration.name().get()))); // Paper
}
}

View File

@@ -31,6 +31,21 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective
return this.objective.getName();
}
// Paper start
@Override
public net.kyori.adventure.text.Component displayName() throws IllegalStateException {
CraftScoreboard scoreboard = checkState();
return io.papermc.paper.adventure.PaperAdventure.asAdventure(objective.getDisplayName());
}
@Override
public void displayName(net.kyori.adventure.text.Component displayName) throws IllegalStateException, IllegalArgumentException {
if (displayName == null) {
displayName = net.kyori.adventure.text.Component.empty();
}
CraftScoreboard scoreboard = checkState();
objective.setDisplayName(io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName));
}
// Paper end
@Override
public String getDisplayName() {
this.checkState();

View File

@@ -29,6 +29,33 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
public CraftObjective registerNewObjective(String name, String criteria) {
return this.registerNewObjective(name, criteria, name);
}
// Paper start - Adventure
@Override
public CraftObjective registerNewObjective(String name, String criteria, net.kyori.adventure.text.Component displayName) {
return this.registerNewObjective(name, CraftCriteria.getFromBukkit(criteria), displayName, RenderType.INTEGER);
}
@Override
public CraftObjective registerNewObjective(String name, String criteria, net.kyori.adventure.text.Component displayName, RenderType renderType) {
return this.registerNewObjective(name, CraftCriteria.getFromBukkit(criteria), displayName, renderType);
}
@Override
public CraftObjective registerNewObjective(String name, Criteria criteria, net.kyori.adventure.text.Component displayName) throws IllegalArgumentException {
return this.registerNewObjective(name, criteria, displayName, RenderType.INTEGER);
}
@Override
public CraftObjective registerNewObjective(String name, Criteria criteria, net.kyori.adventure.text.Component displayName, RenderType renderType) throws IllegalArgumentException {
if (displayName == null) {
displayName = net.kyori.adventure.text.Component.empty();
}
Preconditions.checkArgument(name != null, "Objective name cannot be null");
Preconditions.checkArgument(criteria != null, "Criteria cannot be null");
Preconditions.checkArgument(renderType != null, "RenderType cannot be null");
Preconditions.checkArgument(name.length() <= Short.MAX_VALUE, "The name '%s' is longer than the limit of 32767 characters (%s)", name, name.length());
Preconditions.checkArgument(this.board.getObjective(name) == null, "An objective of name '%s' already exists", name);
net.minecraft.world.scores.Objective objective = this.board.addObjective(name, ((CraftCriteria) criteria).criteria, io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType), true, null);
return new CraftObjective(this, objective);
}
// Paper end - Adventure
@Override
public CraftObjective registerNewObjective(String name, String criteria, String displayName) {
@@ -47,15 +74,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
@Override
public CraftObjective registerNewObjective(String name, Criteria criteria, String displayName, RenderType renderType) {
Preconditions.checkArgument(name != null, "Objective name cannot be null");
Preconditions.checkArgument(criteria != null, "Criteria cannot be null");
Preconditions.checkArgument(displayName != null, "Display name cannot be null");
Preconditions.checkArgument(renderType != null, "RenderType cannot be null");
Preconditions.checkArgument(name.length() <= Short.MAX_VALUE, "The name '%s' is longer than the limit of 32767 characters (%s)", name, name.length());
Preconditions.checkArgument(this.board.getObjective(name) == null, "An objective of name '%s' already exists", name);
net.minecraft.world.scores.Objective objective = this.board.addObjective(name, ((CraftCriteria) criteria).criteria, CraftChatMessage.fromStringOrEmpty(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType), true, null);
return new CraftObjective(this, objective);
return this.registerNewObjective(name, criteria, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(displayName), renderType); // Paper - Adventure
}
@Override

View File

@@ -26,6 +26,63 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
return this.team.getName();
}
// Paper start
@Override
public net.kyori.adventure.text.Component displayName() throws IllegalStateException {
CraftScoreboard scoreboard = checkState();
return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getDisplayName());
}
@Override
public void displayName(net.kyori.adventure.text.Component displayName) throws IllegalStateException, IllegalArgumentException {
if (displayName == null) displayName = net.kyori.adventure.text.Component.empty();
CraftScoreboard scoreboard = checkState();
team.setDisplayName(io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName));
}
@Override
public net.kyori.adventure.text.Component prefix() throws IllegalStateException {
CraftScoreboard scoreboard = checkState();
return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getPlayerPrefix());
}
@Override
public void prefix(net.kyori.adventure.text.Component prefix) throws IllegalStateException, IllegalArgumentException {
if (prefix == null) prefix = net.kyori.adventure.text.Component.empty();
CraftScoreboard scoreboard = checkState();
team.setPlayerPrefix(io.papermc.paper.adventure.PaperAdventure.asVanilla(prefix));
}
@Override
public net.kyori.adventure.text.Component suffix() throws IllegalStateException {
CraftScoreboard scoreboard = checkState();
return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getPlayerSuffix());
}
@Override
public void suffix(net.kyori.adventure.text.Component suffix) throws IllegalStateException, IllegalArgumentException {
if (suffix == null) suffix = net.kyori.adventure.text.Component.empty();
CraftScoreboard scoreboard = checkState();
team.setPlayerSuffix(io.papermc.paper.adventure.PaperAdventure.asVanilla(suffix));
}
@Override
public boolean hasColor() {
CraftScoreboard scoreboard = checkState();
return this.team.getColor().getColor() != null;
}
@Override
public net.kyori.adventure.text.format.TextColor color() throws IllegalStateException {
CraftScoreboard scoreboard = checkState();
if (team.getColor().getColor() == null) throw new IllegalStateException("Team colors must have hex values");
net.kyori.adventure.text.format.TextColor color = net.kyori.adventure.text.format.TextColor.color(team.getColor().getColor());
if (!(color instanceof net.kyori.adventure.text.format.NamedTextColor)) throw new IllegalStateException("Team doesn't have a NamedTextColor");
return (net.kyori.adventure.text.format.NamedTextColor) color;
}
@Override
public void color(net.kyori.adventure.text.format.NamedTextColor color) {
CraftScoreboard scoreboard = checkState();
if (color == null) {
this.team.setColor(net.minecraft.ChatFormatting.RESET);
} else {
this.team.setColor(io.papermc.paper.adventure.PaperAdventure.asVanilla(color));
}
}
// Paper end
@Override
public String getDisplayName() {
@@ -303,4 +360,20 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
return !(this.team != other.team && (this.team == null || !this.team.equals(other.team)));
}
// Paper start - make Team extend ForwardingAudience
@Override
public @org.jetbrains.annotations.NotNull Iterable<? extends net.kyori.adventure.audience.Audience> audiences() {
this.checkState();
java.util.List<net.kyori.adventure.audience.Audience> audiences = new java.util.ArrayList<>();
for (String playerName : this.team.getPlayers()) {
org.bukkit.entity.Player player = Bukkit.getPlayerExact(playerName);
if (player != null) {
audiences.add(player);
}
}
return audiences;
}
// Paper end - make Team extend ForwardingAudience
}

View File

@@ -90,7 +90,7 @@ public final class CraftChatMessage {
this.hex.append(c);
if (this.hex.length() == 7) {
this.modifier = StringMessage.RESET.withColor(TextColor.parseColor(this.hex.toString()).result().get());
this.modifier = StringMessage.RESET.withColor(TextColor.parseColor(this.hex.toString()).result().orElse(null)); // Paper
this.hex = null;
}
} else if (format.isFormat() && format != ChatFormatting.RESET) {
@@ -264,6 +264,7 @@ public final class CraftChatMessage {
public static String fromComponent(Component component) {
if (component == null) return "";
if (component instanceof io.papermc.paper.adventure.AdventureComponent) component = ((io.papermc.paper.adventure.AdventureComponent) component).deepConverted();
StringBuilder out = new StringBuilder();
boolean hadFormat = false;

View File

@@ -80,6 +80,43 @@ public final class CraftMagicNumbers implements UnsafeValues {
private CraftMagicNumbers() {}
// Paper start
@Override
public net.kyori.adventure.text.flattener.ComponentFlattener componentFlattener() {
return io.papermc.paper.adventure.PaperAdventure.FLATTENER;
}
@Override
public net.kyori.adventure.text.serializer.gson.GsonComponentSerializer colorDownsamplingGsonComponentSerializer() {
return net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.colorDownsamplingGson();
}
@Override
public net.kyori.adventure.text.serializer.gson.GsonComponentSerializer gsonComponentSerializer() {
return net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson();
}
@Override
public net.kyori.adventure.text.serializer.plain.PlainComponentSerializer plainComponentSerializer() {
return io.papermc.paper.adventure.PaperAdventure.PLAIN;
}
@Override
public net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer plainTextSerializer() {
return net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer.plainText();
}
@Override
public net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer legacyComponentSerializer() {
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection();
}
@Override
public net.kyori.adventure.text.Component resolveWithContext(final net.kyori.adventure.text.Component component, final org.bukkit.command.CommandSender context, final org.bukkit.entity.Entity scoreboardSubject, final boolean bypassPermissions) throws IOException {
return io.papermc.paper.adventure.PaperAdventure.resolveWithContext(component, context, scoreboardSubject, bypassPermissions);
}
// Paper end
public static BlockState getBlock(MaterialData material) {
return CraftMagicNumbers.getBlock(material.getItemType(), material.getData());
}

View File

@@ -80,7 +80,7 @@ public abstract class LazyHashSet<E> implements Set<E> {
return this.reference = this.makeReference();
}
abstract Set<E> makeReference();
protected abstract Set<E> makeReference(); // Paper - protected
public boolean isLazy() {
return this.reference == null;

View File

@@ -16,9 +16,14 @@ public class LazyPlayerSet extends LazyHashSet<Player> {
}
@Override
HashSet<Player> makeReference() {
protected HashSet<Player> makeReference() { // Paper - protected
Preconditions.checkState(this.reference == null, "Reference already created!");
List<ServerPlayer> players = this.server.getPlayerList().players;
// Paper start
return makePlayerSet(this.server);
}
public static HashSet<Player> makePlayerSet(final MinecraftServer server) {
List<ServerPlayer> players = server.getPlayerList().players;
// Paper end
HashSet<Player> reference = new HashSet<Player>(players.size());
for (ServerPlayer player : players) {
reference.add(player.getBukkitEntity());