mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-07 16:57:42 +01:00
SPIGOT-7391: Preserve vanilla sign json where not modified by event
By: md_5 <git@md-5.net>
This commit is contained in:
parent
b68e6ca9c8
commit
289dcffffa
@ -1,12 +1,11 @@
|
|||||||
--- a/net/minecraft/world/level/block/entity/TileEntitySign.java
|
--- a/net/minecraft/world/level/block/entity/TileEntitySign.java
|
||||||
+++ b/net/minecraft/world/level/block/entity/TileEntitySign.java
|
+++ b/net/minecraft/world/level/block/entity/TileEntitySign.java
|
||||||
@@ -31,7 +31,18 @@
|
@@ -31,7 +31,17 @@
|
||||||
import net.minecraft.world.phys.Vec3D;
|
import net.minecraft.world.phys.Vec3D;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
-public class TileEntitySign extends TileEntity {
|
-public class TileEntitySign extends TileEntity {
|
||||||
+// CraftBukkit start
|
+// CraftBukkit start
|
||||||
+import net.minecraft.EnumChatFormat;
|
|
||||||
+import net.minecraft.nbt.NBTBase;
|
+import net.minecraft.nbt.NBTBase;
|
||||||
+import net.minecraft.server.level.EntityPlayer;
|
+import net.minecraft.server.level.EntityPlayer;
|
||||||
+import org.bukkit.block.sign.Side;
|
+import org.bukkit.block.sign.Side;
|
||||||
@ -20,7 +19,7 @@
|
|||||||
|
|
||||||
private static final Logger LOGGER = LogUtils.getLogger();
|
private static final Logger LOGGER = LogUtils.getLogger();
|
||||||
private static final int MAX_TEXT_LINE_WIDTH = 90;
|
private static final int MAX_TEXT_LINE_WIDTH = 90;
|
||||||
@@ -100,7 +111,7 @@
|
@@ -100,7 +110,7 @@
|
||||||
@Override
|
@Override
|
||||||
protected void saveAdditional(NBTTagCompound nbttagcompound) {
|
protected void saveAdditional(NBTTagCompound nbttagcompound) {
|
||||||
super.saveAdditional(nbttagcompound);
|
super.saveAdditional(nbttagcompound);
|
||||||
@ -29,7 +28,7 @@
|
|||||||
Logger logger = TileEntitySign.LOGGER;
|
Logger logger = TileEntitySign.LOGGER;
|
||||||
|
|
||||||
Objects.requireNonNull(logger);
|
Objects.requireNonNull(logger);
|
||||||
@@ -119,7 +130,7 @@
|
@@ -119,7 +129,7 @@
|
||||||
@Override
|
@Override
|
||||||
public void load(NBTTagCompound nbttagcompound) {
|
public void load(NBTTagCompound nbttagcompound) {
|
||||||
super.load(nbttagcompound);
|
super.load(nbttagcompound);
|
||||||
@ -38,7 +37,7 @@
|
|||||||
Logger logger;
|
Logger logger;
|
||||||
|
|
||||||
if (nbttagcompound.contains("front_text")) {
|
if (nbttagcompound.contains("front_text")) {
|
||||||
@@ -173,12 +184,13 @@
|
@@ -173,12 +183,13 @@
|
||||||
public void updateSignText(EntityHuman entityhuman, boolean flag, List<FilteredText> list) {
|
public void updateSignText(EntityHuman entityhuman, boolean flag, List<FilteredText> list) {
|
||||||
if (!this.isWaxed() && entityhuman.getUUID().equals(this.getPlayerWhoMayEdit()) && this.level != null) {
|
if (!this.isWaxed() && entityhuman.getUUID().equals(this.getPlayerWhoMayEdit()) && this.level != null) {
|
||||||
this.updateText((signtext) -> {
|
this.updateText((signtext) -> {
|
||||||
@ -53,7 +52,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +200,8 @@
|
@@ -188,7 +199,8 @@
|
||||||
return this.setText((SignText) unaryoperator.apply(signtext), flag);
|
return this.setText((SignText) unaryoperator.apply(signtext), flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +62,7 @@
|
|||||||
for (int i = 0; i < list.size(); ++i) {
|
for (int i = 0; i < list.size(); ++i) {
|
||||||
FilteredText filteredtext = (FilteredText) list.get(i);
|
FilteredText filteredtext = (FilteredText) list.get(i);
|
||||||
ChatModifier chatmodifier = signtext.getMessage(i, entityhuman.isTextFilteringEnabled()).getStyle();
|
ChatModifier chatmodifier = signtext.getMessage(i, entityhuman.isTextFilteringEnabled()).getStyle();
|
||||||
@@ -200,6 +213,27 @@
|
@@ -200,6 +212,29 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,27 +70,29 @@
|
|||||||
+ Player player = ((EntityPlayer) entityhuman).getBukkitEntity();
|
+ Player player = ((EntityPlayer) entityhuman).getBukkitEntity();
|
||||||
+ String[] lines = new String[4];
|
+ String[] lines = new String[4];
|
||||||
+
|
+
|
||||||
+ for (int j = 0; j < list.size(); ++j) {
|
+ for (int i = 0; i < list.size(); ++i) {
|
||||||
+ lines[j] = CraftChatMessage.fromComponent(signtext.getMessage(j, entityhuman.isTextFilteringEnabled()));
|
+ lines[i] = CraftChatMessage.fromComponent(signtext.getMessage(i, entityhuman.isTextFilteringEnabled()));
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ SignChangeEvent event = new SignChangeEvent(CraftBlock.at(this.level, this.worldPosition), player, lines, (front) ? Side.FRONT : Side.BACK);
|
+ SignChangeEvent event = new SignChangeEvent(CraftBlock.at(this.level, this.worldPosition), player, lines.clone(), (front) ? Side.FRONT : Side.BACK);
|
||||||
+ entityhuman.level().getCraftServer().getPluginManager().callEvent(event);
|
+ entityhuman.level().getCraftServer().getPluginManager().callEvent(event);
|
||||||
+
|
+
|
||||||
+ if (!event.isCancelled()) {
|
+ if (event.isCancelled()) {
|
||||||
+ IChatBaseComponent[] components = org.bukkit.craftbukkit.block.CraftSign.sanitizeLines(event.getLines());
|
+ return originalText;
|
||||||
+ for (int j = 0; j < components.length; j++) {
|
+ }
|
||||||
+ signtext = signtext.setMessage(j, components[j]);
|
+
|
||||||
|
+ IChatBaseComponent[] components = org.bukkit.craftbukkit.block.CraftSign.sanitizeLines(event.getLines());
|
||||||
|
+ for (int i = 0; i < components.length; i++) {
|
||||||
|
+ if (!Objects.equals(lines[i], event.getLine(i))) {
|
||||||
|
+ signtext = signtext.setMessage(i, components[i]);
|
||||||
+ }
|
+ }
|
||||||
+ } else {
|
|
||||||
+ signtext = originalText;
|
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
+
|
+
|
||||||
return signtext;
|
return signtext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,11 +284,37 @@
|
@@ -250,11 +285,37 @@
|
||||||
return flag1;
|
return flag1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +132,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -283,7 +343,7 @@
|
@@ -283,7 +344,7 @@
|
||||||
|
|
||||||
private void markUpdated() {
|
private void markUpdated() {
|
||||||
this.setChanged();
|
this.setChanged();
|
||||||
|
@ -109,7 +109,7 @@ public class CraftSign<T extends TileEntitySign> extends CraftBlockEntityState<T
|
|||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (i < lines.length && lines[i] != null) {
|
if (i < lines.length && lines[i] != null) {
|
||||||
components[i] = IChatBaseComponent.literal("").append(CraftChatMessage.fromString(lines[i])[0]); // SPIGOT-7372: Vanilla wants a literal first
|
components[i] = CraftChatMessage.fromString(lines[i])[0];
|
||||||
} else {
|
} else {
|
||||||
components[i] = IChatBaseComponent.empty();
|
components[i] = IChatBaseComponent.empty();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user