From 2642f9b344917de873d7e10075eb024f94f0b445 Mon Sep 17 00:00:00 2001 From: Thinkofdeath Date: Thu, 23 Jul 2015 20:50:53 +0100 Subject: [PATCH] SPIGOT-1068: Limit the number of patterns on banners --- nms-patches/TileEntityBanner.patch | 26 +++++++++++++++++++ .../inventory/CraftMetaBanner.java | 4 +-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 nms-patches/TileEntityBanner.patch diff --git a/nms-patches/TileEntityBanner.patch b/nms-patches/TileEntityBanner.patch new file mode 100644 index 0000000000..f8cd7bc283 --- /dev/null +++ b/nms-patches/TileEntityBanner.patch @@ -0,0 +1,26 @@ +--- a/net/minecraft/server/TileEntityBanner.java ++++ b/net/minecraft/server/TileEntityBanner.java +@@ -20,6 +20,11 @@ + + if (nbttagcompound.hasKey("Patterns")) { + this.patterns = (NBTTagList) nbttagcompound.getList("Patterns", 10).clone(); ++ // CraftBukkit start ++ while (this.patterns.size() > 20) { ++ this.patterns.a(20); // PAIL Rename remove ++ } ++ // CraftBukkit end + } + + if (nbttagcompound.hasKeyOfType("Base", 99)) { +@@ -54,6 +59,11 @@ + super.a(nbttagcompound); + this.color = nbttagcompound.getInt("Base"); + this.patterns = nbttagcompound.getList("Patterns", 10); ++ // CraftBukkit start ++ while (this.patterns.size() > 20) { ++ this.patterns.a(20); // PAIL Rename remove ++ } ++ // CraftBukkit end + this.h = null; + this.i = null; + this.j = null; diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java index 994b9aaac8..80f9ffa9bb 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java @@ -50,8 +50,8 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta { if (entityTag.hasKey(PATTERNS.NBT)) { NBTTagList patterns = entityTag.getList(PATTERNS.NBT, 10); - for (int i = 0; i < patterns.size(); i++) { - NBTTagCompound p = (NBTTagCompound) patterns.get(i); + for (int i = 0; i < Math.min(patterns.size(), 20); i++) { + NBTTagCompound p = patterns.get(i); this.patterns.add(new Pattern(DyeColor.getByDyeData((byte) p.getInt(COLOR.NBT)), PatternType.getByIdentifier(p.getString(PATTERN.NBT)))); } }