From 9e013d6928899c76c227c4adb6ae5aec506f491b Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Sun, 13 Mar 2022 21:22:14 +0000 Subject: trivial refactors, rebase --- patches/api/0356-SendSignEvent.patch | 81 --------------------- patches/api/0374-SendSignEvent.patch | 81 +++++++++++++++++++++ patches/server/0850-SendSignEvent.patch | 120 ------------------------------- patches/server/0878-SendSignEvent.patch | 121 ++++++++++++++++++++++++++++++++ 4 files changed, 202 insertions(+), 201 deletions(-) delete mode 100644 patches/api/0356-SendSignEvent.patch create mode 100644 patches/api/0374-SendSignEvent.patch delete mode 100644 patches/server/0850-SendSignEvent.patch create mode 100644 patches/server/0878-SendSignEvent.patch diff --git a/patches/api/0356-SendSignEvent.patch b/patches/api/0356-SendSignEvent.patch deleted file mode 100644 index d61f8aedea..0000000000 --- a/patches/api/0356-SendSignEvent.patch +++ /dev/null @@ -1,81 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Aikar -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 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/api/0374-SendSignEvent.patch b/patches/api/0374-SendSignEvent.patch new file mode 100644 index 0000000000..c1d2dfcd6b --- /dev/null +++ b/patches/api/0374-SendSignEvent.patch @@ -0,0 +1,81 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar +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..fa188e8bf3965234b2634b01ab1078c2fa76e7be +--- /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<@NotNull Component> lines(); ++ ++ /** ++ * @param line the line in which to modify ++ * @param component the component in which to set ++ */ ++ public abstract void line(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 deleted file mode 100644 index 1145be7bcf..0000000000 --- a/patches/server/0850-SendSignEvent.patch +++ /dev/null @@ -1,120 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Aikar -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 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 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..fba8368c89dc7edeaa5aceb47d59c30b9e1d23fc 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 lines = signSendEvent.getLines(); -+ final java.util.List 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); -@@ -186,7 +206,15 @@ public class SignBlockEntity extends BlockEntity implements CommandSource { // C - - @Override - public CompoundTag getUpdateTag() { -+ // Paper start - SignSendEvent -+ boolean prev = this.isSending; -+ this.isSending = true; -+ try { - return this.saveWithoutMetadata(); -+ } finally { -+ this.isSending = prev; -+ } -+ // Paper end - } - - @Override diff --git a/patches/server/0878-SendSignEvent.patch b/patches/server/0878-SendSignEvent.patch new file mode 100644 index 0000000000..5822edfeb7 --- /dev/null +++ b/patches/server/0878-SendSignEvent.patch @@ -0,0 +1,121 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar +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..9c0ac5fe927728279842d92cc85a0979534f2107 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/block/SendSignEventImpl.java +@@ -0,0 +1,55 @@ ++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 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 lines() { ++ return lines; ++ } ++ ++ public Component[] getFilteredMessages() { ++ return filteredMessages; ++ } ++ ++ @Override ++ public void line(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..3a7d1186a86860cab3fc00f98359d263353d2a3d 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 start ++ 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 lines = signSendEvent.lines(); ++ final java.util.List 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); +@@ -186,7 +206,15 @@ public class SignBlockEntity extends BlockEntity implements CommandSource { // C + + @Override + public CompoundTag getUpdateTag() { ++ // Paper start - SignSendEvent ++ boolean prev = this.isSending; ++ this.isSending = true; ++ try { + return this.saveWithoutMetadata(); ++ } finally { ++ this.isSending = prev; ++ } ++ // Paper end + } + + @Override -- cgit v1.2.3