Add API for client-side signs (#11903)

This commit is contained in:
Md5Lukas
2025-05-24 19:16:23 +00:00
committed by GitHub
parent b70bca6b69
commit 3efaf477c4
4 changed files with 135 additions and 2 deletions

View File

@ -2486,7 +2486,7 @@
} else if (flag && flag2) {
if (this.dropSpamThrottler.isUnderThreshold()) {
this.dropSpamThrottler.increment();
@@ -1895,11 +_,24 @@
@@ -1895,15 +_,38 @@
@Override
public void handleSignUpdate(ServerboundSignUpdatePacket packet) {
@ -2512,6 +2512,20 @@
this.player.resetLastActionTime();
ServerLevel serverLevel = this.player.serverLevel();
BlockPos pos = packet.getPos();
if (serverLevel.hasChunkAt(pos)) {
+ // Paper start - Add API for client-side signs
+ if (!new io.papermc.paper.event.packet.UncheckedSignChangeEvent(
+ this.player.getBukkitEntity(),
+ io.papermc.paper.util.MCUtil.toPosition(pos),
+ packet.isFrontText() ? org.bukkit.block.sign.Side.FRONT : org.bukkit.block.sign.Side.BACK,
+ filteredText.stream().<net.kyori.adventure.text.Component>map(line -> net.kyori.adventure.text.Component.text(line.raw())).toList())
+ .callEvent()) {
+ return;
+ }
+ // Paper end - Add API for client-side signs
if (!(serverLevel.getBlockEntity(pos) instanceof SignBlockEntity signBlockEntity)) {
return;
}
@@ -1915,14 +_,32 @@
@Override
public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) {

View File

@ -12,6 +12,8 @@ import io.papermc.paper.configuration.GlobalConfiguration;
import io.papermc.paper.entity.LookAnchor;
import io.papermc.paper.entity.PaperPlayerGiveResult;
import io.papermc.paper.entity.PlayerGiveResult;
import io.papermc.paper.math.Position;
import io.papermc.paper.util.MCUtil;
import it.unimi.dsi.fastutil.shorts.ShortArraySet;
import it.unimi.dsi.fastutil.shorts.ShortSet;
import java.io.ByteArrayOutputStream;
@ -73,6 +75,7 @@ import net.minecraft.network.protocol.game.ClientboundHurtAnimationPacket;
import net.minecraft.network.protocol.game.ClientboundLevelEventPacket;
import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket;
import net.minecraft.network.protocol.game.ClientboundMapItemDataPacket;
import net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket;
@ -3037,6 +3040,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
CraftSign.openSign(sign, this, side);
}
@Override
public void openVirtualSign(Position block, Side side) {
if (this.getHandle().connection == null) return;
this.getHandle().connection.send(new ClientboundOpenSignEditorPacket(MCUtil.toBlockPos(block), side == Side.FRONT));
}
@Override
public void showDemoScreen() {
if (this.getHandle().connection == null) return;