Paper/nms-patches/TileEntitySign.patch

122 Zeilen
5.1 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/TileEntitySign.java
+++ b/net/minecraft/server/TileEntitySign.java
2020-06-25 02:00:00 +02:00
@@ -1,9 +1,10 @@
package net.minecraft.server;
2019-04-23 04:00:00 +02:00
import com.mojang.brigadier.exceptions.CommandSyntaxException;
2020-06-25 02:00:00 +02:00
+import java.util.UUID;
2019-04-23 04:00:00 +02:00
import javax.annotation.Nullable;
-public class TileEntitySign extends TileEntity {
+public class TileEntitySign extends TileEntity implements ICommandListener { // CraftBukkit - implements
2020-06-25 02:00:00 +02:00
public final IChatBaseComponent[] lines;
public boolean isEditable;
@@ -29,6 +30,12 @@
nbttagcompound.setString("Text" + (i + 1), s);
}
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
+ if (Boolean.getBoolean("convertLegacySigns")) {
+ nbttagcompound.setBoolean("Bukkit.isConverted", true);
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
2020-06-25 02:00:00 +02:00
nbttagcompound.setString("Color", this.color.c());
2016-05-10 13:47:39 +02:00
return nbttagcompound;
}
2020-06-25 02:00:00 +02:00
@@ -39,18 +46,38 @@
super.load(iblockdata, nbttagcompound);
2019-05-14 02:00:00 +02:00
this.color = EnumColor.a(nbttagcompound.getString("Color"), EnumColor.BLACK);
+ // CraftBukkit start - Add an option to convert signs correctly
+ // This is done with a flag instead of all the time because
+ // we have no way to tell whether a sign is from 1.7.10 or 1.8
2015-02-26 23:41:06 +01:00
+
+ boolean oldSign = Boolean.getBoolean("convertLegacySigns") && !nbttagcompound.getBoolean("Bukkit.isConverted");
2015-02-26 23:41:06 +01:00
+
for (int i = 0; i < 4; ++i) {
String s = nbttagcompound.getString("Text" + (i + 1));
2020-06-25 02:00:00 +02:00
- IChatMutableComponent ichatmutablecomponent = IChatBaseComponent.ChatSerializer.a(s.isEmpty() ? "\"\"" : s);
+ if (s != null && s.length() > 2048) {
+ s = "\"\"";
+ }
2019-04-23 04:00:00 +02:00
+
+ try {
2020-06-25 02:00:00 +02:00
+ IChatMutableComponent ichatmutablecomponent = IChatBaseComponent.ChatSerializer.a(s.isEmpty() ? "\"\"" : s);
2018-07-15 02:00:00 +02:00
- if (this.world instanceof WorldServer) {
- try {
2020-06-25 02:00:00 +02:00
- this.lines[i] = ChatComponentUtils.filterForDisplay(this.a((EntityPlayer) null), ichatmutablecomponent, (Entity) null, 0);
2018-07-15 02:00:00 +02:00
- } catch (CommandSyntaxException commandsyntaxexception) {
2015-02-26 23:41:06 +01:00
+ if (oldSign) {
+ lines[i] = org.bukkit.craftbukkit.util.CraftChatMessage.fromString(s)[0];
+ continue;
+ }
+ // CraftBukkit end
+
2018-07-15 02:00:00 +02:00
+ if (this.world instanceof WorldServer) {
+ try {
2020-06-25 02:00:00 +02:00
+ this.lines[i] = ChatComponentUtils.filterForDisplay(this.a((EntityPlayer) null), ichatmutablecomponent, (Entity) null, 0);
2018-07-15 02:00:00 +02:00
+ } catch (CommandSyntaxException commandsyntaxexception) {
2020-06-25 02:00:00 +02:00
+ this.lines[i] = ichatmutablecomponent;
2018-07-15 02:00:00 +02:00
+ }
+ } else {
2020-06-25 02:00:00 +02:00
this.lines[i] = ichatmutablecomponent;
2018-07-15 02:00:00 +02:00
}
- } else {
2020-06-25 02:00:00 +02:00
- this.lines[i] = ichatmutablecomponent;
2016-02-29 22:32:46 +01:00
+ } catch (com.google.gson.JsonParseException jsonparseexception) {
+ this.lines[i] = new ChatComponentText(s);
}
2019-12-10 23:00:00 +01:00
this.g[i] = null;
2020-06-25 02:00:00 +02:00
@@ -111,11 +138,37 @@
2019-04-23 04:00:00 +02:00
return true;
}
2018-07-15 02:00:00 +02:00
+ // CraftBukkit start
+ @Override
2020-06-25 02:00:00 +02:00
+ public void sendMessage(IChatBaseComponent ichatbasecomponent, UUID uuid) {}
2019-04-23 04:00:00 +02:00
+
+ @Override
2018-07-15 02:00:00 +02:00
+ public org.bukkit.command.CommandSender getBukkitSender(CommandListenerWrapper wrapper) {
2018-12-13 01:00:00 +01:00
+ return wrapper.getEntity() != null ? wrapper.getEntity().getBukkitSender(wrapper) : new org.bukkit.craftbukkit.command.CraftBlockCommandSender(wrapper, this);
2018-07-15 02:00:00 +02:00
+ }
2019-04-23 04:00:00 +02:00
+
+ @Override
+ public boolean shouldSendSuccess() {
+ return false;
+ }
+
+ @Override
+ public boolean shouldSendFailure() {
+ return false;
+ }
+
+ @Override
+ public boolean shouldBroadcastCommands() {
+ return false;
+ }
2018-07-15 02:00:00 +02:00
+ // CraftBukkit end
+
public CommandListenerWrapper a(@Nullable EntityPlayer entityplayer) {
String s = entityplayer == null ? "Sign" : entityplayer.getDisplayName().getString();
Object object = entityplayer == null ? new ChatComponentText("Sign") : entityplayer.getScoreboardDisplayName();
2019-04-23 04:00:00 +02:00
2020-06-25 02:00:00 +02:00
- return new CommandListenerWrapper(ICommandListener.DUMMY, Vec3D.a((BaseBlockPosition) this.position), Vec2F.a, (WorldServer) this.world, 2, s, (IChatBaseComponent) object, this.world.getMinecraftServer(), entityplayer);
2019-04-23 04:00:00 +02:00
+ // CraftBukkit - this
2020-06-25 02:00:00 +02:00
+ return new CommandListenerWrapper(this, Vec3D.a((BaseBlockPosition) this.position), Vec2F.a, (WorldServer) this.world, 2, s, (IChatBaseComponent) object, this.world.getMinecraftServer(), entityplayer);
2019-04-23 04:00:00 +02:00
}
2019-05-14 02:00:00 +02:00
public EnumColor getColor() {
2020-06-25 02:00:00 +02:00
@@ -126,7 +179,7 @@
if (enumcolor != this.getColor()) {
this.color = enumcolor;
this.update();
- this.world.notify(this.getPosition(), this.getBlock(), this.getBlock(), 3);
+ if (this.world != null) this.world.notify(this.getPosition(), this.getBlock(), this.getBlock(), 3); // CraftBukkit - skip notify if world is null (SPIGOT-5122)
return true;
} else {
return false;