diff options
author | Shane Freeder <[email protected]> | 2022-03-13 21:22:14 +0000 |
---|---|---|
committer | Shane Freeder <[email protected]> | 2022-03-13 21:23:59 +0000 |
commit | 9e013d6928899c76c227c4adb6ae5aec506f491b (patch) | |
tree | 4c8f0b224bcc09b6ba23d3992433d924dd5474d1 /patches/server/0878-SendSignEvent.patch | |
parent | 6ff60b33a647e9a35ddf37f3ab33901211ac5f64 (diff) | |
download | Paper-9e013d6928899c76c227c4adb6ae5aec506f491b.tar.gz Paper-9e013d6928899c76c227c4adb6ae5aec506f491b.zip |
trivial refactors, rebasefeature/SignSendEvent
Diffstat (limited to 'patches/server/0878-SendSignEvent.patch')
-rw-r--r-- | patches/server/0878-SendSignEvent.patch | 121 |
1 files changed, 121 insertions, 0 deletions
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 <[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..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<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> 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<net.kyori.adventure.text.Component> lines = signSendEvent.lines(); ++ 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); +@@ -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 |