aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0447-Backport-SPIGOT-5428-Better-handling-of-some-ItemMet.patch
blob: de0b8b8212b91fd9d0cab0526bbfd36f2b1e3ede (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
From af4651f62f0e4ebd4af0dac08b03c94550da301c Mon Sep 17 00:00:00 2001
From: Mathias <mail@mathias.is>
Date: Mon, 16 Dec 2019 19:11:10 +0200
Subject: [PATCH] Backport SPIGOT-5428: Better handling of some ItemMeta


diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
index 2f72f0ce..ffc24634 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java
@@ -53,7 +53,14 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta {
             NBTTagList patterns = entityTag.getList(PATTERNS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
             for (int i = 0; i < Math.min(patterns.size(), 20); i++) {
                 NBTTagCompound p = patterns.getCompound(i);
-                this.patterns.add(new Pattern(DyeColor.getByWoolData((byte) p.getInt(COLOR.NBT)), PatternType.getByIdentifier(p.getString(PATTERN.NBT))));
+                // Paper start - Backport SPIGOT-5428
+                DyeColor color = DyeColor.getByWoolData((byte) p.getInt(COLOR.NBT));
+                PatternType pattern = PatternType.getByIdentifier(p.getString(PATTERN.NBT));
+
+                if (color != null && pattern != null) {
+                    this.patterns.add(new Pattern(color, pattern));
+                }
+                // Paper end
             }
         }
     }
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCharge.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCharge.java
index 267581ec..7adbc4ea 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCharge.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCharge.java
@@ -36,7 +36,13 @@ class CraftMetaCharge extends CraftMetaItem implements FireworkEffectMeta {
         super(tag);
 
         if (tag.hasKey(EXPLOSION.NBT)) {
-            effect = CraftMetaFirework.getEffect(tag.getCompound(EXPLOSION.NBT));
+            // Paper start - Backport SPIGOT-5428
+            try {
+                effect = CraftMetaFirework.getEffect(tag.getCompound(EXPLOSION.NBT));
+            } catch (IllegalArgumentException ex) {
+                // Ignore invalid effects
+            }
+            // Paper end
         }
     }
 
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java
index b82e2fdf..957c144b 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java
@@ -93,7 +93,13 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
         List<FireworkEffect> effects = this.effects = new ArrayList<FireworkEffect>(fireworkEffects.size());
 
         for (int i = 0; i < fireworkEffects.size(); i++) {
-            effects.add(getEffect((NBTTagCompound) fireworkEffects.get(i)));
+            // Paper start - Backport SPIGOT-5428
+            try {
+                effects.add(getEffect((NBTTagCompound) fireworkEffects.get(i)));
+            } catch (IllegalArgumentException ex) {
+                // Ignore invalid effects
+            }
+            // Paper end - Backport SPIGOT-5428
         }
     }
 
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java
index e5b1a730..8a706aba 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java
@@ -66,7 +66,13 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta {
             }
 
             if (display.hasKey(MAP_COLOR.NBT)) {
-                color = Color.fromRGB(display.getInt(MAP_COLOR.NBT));
+                // Paper start - Backport SPIGOT-5428
+                try {
+                    color = Color.fromRGB(display.getInt(MAP_COLOR.NBT));
+                } catch (IllegalArgumentException ex) {
+                    // Invalid colour
+                }
+                // Paper end
             }
         }
     }
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java
index 29fbdcc8..9a7dec54 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java
@@ -62,7 +62,13 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
             type = CraftPotionUtil.toBukkit(tag.getString(DEFAULT_POTION.NBT));
         }
         if (tag.hasKey(POTION_COLOR.NBT)) {
-            color = Color.fromRGB(tag.getInt(POTION_COLOR.NBT));
+            // Paper start - Backport SPIGOT-5428
+            try {
+                color = Color.fromRGB(tag.getInt(POTION_COLOR.NBT));
+            } catch (IllegalArgumentException ex) {
+                // Invalid colour
+            }
+            // Paper end
         }
         if (tag.hasKey(POTION_EFFECTS.NBT)) {
             NBTTagList list = tag.getList(POTION_EFFECTS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
-- 
2.24.1