aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorShane Freeder <[email protected]>2022-01-11 10:43:27 +0000
committerShane Freeder <[email protected]>2022-03-13 20:48:57 +0000
commit43e47c1d334e6f93859c7666ba8fc872c75a1141 (patch)
tree6649d117d48c73c9d86c391219bfe3e5b833f088
parent1358d1e9146ca80d0ff84a644c7796d20b39765c (diff)
downloadPaper-43e47c1d334e6f93859c7666ba8fc872c75a1141.tar.gz
Paper-43e47c1d334e6f93859c7666ba8fc872c75a1141.zip
Port SendSignEvent event to Paper
after many years on the fabled todo list, a port of the SendSignEvent from EMC, this uses components given our move away from legacy I also modified the hook point for this for maintainability and reducing copied code
-rw-r--r--patches/api/0356-SendSignEvent.patch81
-rw-r--r--patches/server/0850-SendSignEvent.patch119
2 files changed, 200 insertions, 0 deletions
diff --git a/patches/api/0356-SendSignEvent.patch b/patches/api/0356-SendSignEvent.patch
new file mode 100644
index 0000000000..d61f8aedea
--- /dev/null
+++ b/patches/api/0356-SendSignEvent.patch
@@ -0,0 +1,81 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Aikar <[email protected]>
+Date: Sun, 4 Dec 2016 22:06:10 -0500
+Subject: [PATCH] SendSignEvent
+
+
+diff --git a/src/main/java/io/papermc/paper/event/block/SendSignEvent.java b/src/main/java/io/papermc/paper/event/block/SendSignEvent.java
+new file mode 100644
+index 0000000000000000000000000000000000000000..8cc0e1eb7a1a851b3c5ea3e002149b0d96bc5972
+--- /dev/null
++++ b/src/main/java/io/papermc/paper/event/block/SendSignEvent.java
+@@ -0,0 +1,69 @@
++/*
++ * Copyright (c) 2016 Starlis LLC / Daniel Ennis (Aikar) - MIT License
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining
++ * a copy of this software and associated documentation files (the
++ * "Software"), to deal in the Software without restriction, including
++ * without limitation the rights to use, copy, modify, merge, publish,
++ * distribute, sublicense, and/or sell copies of the Software, and to
++ * permit persons to whom the Software is furnished to do so, subject to
++ * the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
++ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
++ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
++ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
++ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++package io.papermc.paper.event.block;
++
++import net.kyori.adventure.text.Component;
++
++import org.bukkit.block.Block;
++import org.bukkit.event.Event;
++import org.bukkit.event.HandlerList;
++import org.jetbrains.annotations.NotNull;
++import org.jetbrains.annotations.Nullable;
++
++import java.util.List;
++
++public abstract class SendSignEvent extends Event {
++
++ /**
++ * @return the Block which is being sent
++ */
++ @NotNull
++ public abstract Block getBlock();
++
++ /**
++ * This collection may be an immutable view
++ *
++ * @return the lines of the sign
++ **/
++ @NotNull
++ public abstract List<Component> getLines();
++
++ /**
++ * @param line the line in which to modify
++ * @param component the component in which to set
++ */
++ public abstract void setLine(int line, @Nullable net.kyori.adventure.text.Component component);
++
++ private static final HandlerList handlers = new HandlerList();
++
++ @NotNull
++ public HandlerList getHandlers() {
++ return handlers;
++ }
++
++ @NotNull
++ public static HandlerList getHandlerList() {
++ return handlers;
++ }
++}
diff --git a/patches/server/0850-SendSignEvent.patch b/patches/server/0850-SendSignEvent.patch
new file mode 100644
index 0000000000..4d340c2aef
--- /dev/null
+++ b/patches/server/0850-SendSignEvent.patch
@@ -0,0 +1,119 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Aikar <[email protected]>
+Date: Mon, 8 Jun 2015 23:55:20 -0400
+Subject: [PATCH] SendSignEvent
+
+
+diff --git a/src/main/java/io/papermc/paper/block/SendSignEventImpl.java b/src/main/java/io/papermc/paper/block/SendSignEventImpl.java
+new file mode 100644
+index 0000000000000000000000000000000000000000..d4fc17586ff4eb07708636ad9ad8c56ea7a882a6
+--- /dev/null
++++ b/src/main/java/io/papermc/paper/block/SendSignEventImpl.java
+@@ -0,0 +1,54 @@
++package io.papermc.paper.block;
++
++import io.papermc.paper.event.block.SendSignEvent;
++
++import net.minecraft.core.BlockPos;
++import net.minecraft.network.chat.Component;
++import net.minecraft.network.chat.TextComponent;
++import net.minecraft.world.level.Level;
++
++import org.bukkit.block.Block;
++import org.jetbrains.annotations.NotNull;
++
++import java.util.Arrays;
++import java.util.List;
++
++import io.papermc.paper.adventure.PaperAdventure;
++
++public class SendSignEventImpl extends SendSignEvent {
++ public final List<net.kyori.adventure.text.Component> lines;
++ public final Component[] filteredMessages;
++ private final Block block;
++
++ public SendSignEventImpl(Level level, BlockPos pos, Component[] messages, Component[] filteredMessages) {
++ this.block = level.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
++ this.lines = Arrays.asList(new net.kyori.adventure.text.Component[messages.length]);
++ for (int i = 0; i < messages.length; i++) {
++ this.lines.set(i, PaperAdventure.asAdventure(messages[i]));
++ }
++
++
++ this.filteredMessages = filteredMessages;
++
++ }
++
++ @NotNull
++ public Block getBlock() {
++ return block;
++ }
++
++ @Override
++ @NotNull
++ public List<net.kyori.adventure.text.Component> getLines() {
++ return lines;
++ }
++
++ public Component[] getFilteredMessages() {
++ return filteredMessages;
++ }
++
++ public void setLine(int line, net.kyori.adventure.text.Component component) {
++ lines.set(line, component != null ? component : net.kyori.adventure.text.Component.empty());
++ filteredMessages[line] = TextComponent.EMPTY;
++ }
++}
+diff --git a/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
+index 6371176fba41218a209ea59b4cafe5b2d4a685fd..8527e3c7d814918539ca47ac002c0761ab5fc8fe 100644
+--- a/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
++++ b/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
+@@ -27,6 +27,7 @@ import net.minecraft.world.phys.Vec3;
+ public class SignBlockEntity extends BlockEntity implements CommandSource { // CraftBukkit - implements
+ private static final boolean CONVERT_LEGACY_SIGNS = Boolean.getBoolean("convertLegacySigns"); // Paper
+
++ private boolean isSending = false; // Paper
+ public static final int LINES = 4;
+ private static final String[] RAW_TEXT_FIELD_NAMES = new String[]{"Text1", "Text2", "Text3", "Text4"};
+ private static final String[] FILTERED_TEXT_FIELD_NAMES = new String[]{"FilteredText1", "FilteredText2", "FilteredText3", "FilteredText4"};
+@@ -54,6 +55,25 @@ public class SignBlockEntity extends BlockEntity implements CommandSource { // C
+ protected void saveAdditional(CompoundTag nbt) {
+ super.saveAdditional(nbt);
+
++ // Paper
++ if (isSending && this.level != null) {
++ var signSendEvent = new io.papermc.paper.block.SendSignEventImpl(this.level, this.worldPosition, this.messages, this.filteredMessages);
++ signSendEvent.callEvent();
++ final java.util.List<net.kyori.adventure.text.Component> lines = signSendEvent.getLines();
++ final java.util.List<Component> lineComponents = io.papermc.paper.adventure.PaperAdventure.asVanilla(lines);
++ final Component[] filteredMessages = signSendEvent.getFilteredMessages();
++ for (int i = 0; i < 4; ++i) {
++ final Component component = lineComponents.get(i);
++ final String json = Component.Serializer.toJson(component);
++ nbt.putString(SignBlockEntity.RAW_TEXT_FIELD_NAMES[i], json);
++ Component ichatbasecomponent1 = filteredMessages[i];
++
++ if (!ichatbasecomponent1.equals(component)) {
++ nbt.putString(SignBlockEntity.FILTERED_TEXT_FIELD_NAMES[i], Component.Serializer.toJson(ichatbasecomponent1));
++ }
++ }
++
++ } else // Paper end
+ for (int i = 0; i < 4; ++i) {
+ Component ichatbasecomponent = this.messages[i];
+ String s = Component.Serializer.toJson(ichatbasecomponent);
+@@ -181,7 +201,14 @@ public class SignBlockEntity extends BlockEntity implements CommandSource { // C
+
+ @Override
+ public ClientboundBlockEntityDataPacket getUpdatePacket() {
++ // Paper start - SignSendEvent
++ this.isSending = true;
++ try {
+ return ClientboundBlockEntityDataPacket.create(this);
++ } finally {
++ this.isSending = false;
++ }
++ // Paper end
+ }
+
+ @Override