Commits

md_5 authored 0a1c89e4b1c
SPIGOT-7212: Allow negative firework power
No tags

src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java

Modified
46 46 @Specific(To.NBT)
47 47 static final ItemMetaKey EXPLOSION_TYPE = new ItemMetaKey("Type");
48 48 @Specific(To.NBT)
49 49 static final ItemMetaKey EXPLOSION_TRAIL = new ItemMetaKey("Trail");
50 50 @Specific(To.NBT)
51 51 static final ItemMetaKey EXPLOSION_FLICKER = new ItemMetaKey("Flicker");
52 52 @Specific(To.NBT)
53 53 static final ItemMetaKey EXPLOSION_FADE = new ItemMetaKey("FadeColors");
54 54
55 55 private List<FireworkEffect> effects;
56 - private int power;
56 + private Integer power;
57 57
58 58 CraftMetaFirework(CraftMetaItem meta) {
59 59 super(meta);
60 60
61 61 if (!(meta instanceof CraftMetaFirework)) {
62 62 return;
63 63 }
64 64
65 65 CraftMetaFirework that = (CraftMetaFirework) meta;
66 66
73 73
74 74 CraftMetaFirework(NBTTagCompound tag) {
75 75 super(tag);
76 76
77 77 if (!tag.contains(FIREWORKS.NBT)) {
78 78 return;
79 79 }
80 80
81 81 NBTTagCompound fireworks = tag.getCompound(FIREWORKS.NBT);
82 82
83 - power = 0xff & fireworks.getByte(FLIGHT.NBT);
83 + power = (int) fireworks.getByte(FLIGHT.NBT);
84 84
85 85 if (!fireworks.contains(EXPLOSIONS.NBT)) {
86 86 return;
87 87 }
88 88
89 89 NBTTagList fireworkEffects = fireworks.getList(EXPLOSIONS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
90 90 List<FireworkEffect> effects = this.effects = new ArrayList<FireworkEffect>(fireworkEffects.size());
91 91
92 92 for (int i = 0; i < fireworkEffects.size(); i++) {
93 93 try {
174 174 default:
175 175 throw new IllegalArgumentException("Unknown effect type " + nbt);
176 176 }
177 177 }
178 178
179 179 CraftMetaFirework(Map<String, Object> map) {
180 180 super(map);
181 181
182 182 Integer power = SerializableMeta.getObject(Integer.class, map, FLIGHT.BUKKIT, true);
183 183 if (power != null) {
184 - setPower(power);
184 + this.power = power;
185 185 }
186 186
187 187 Iterable<?> effects = SerializableMeta.getObject(Iterable.class, map, EXPLOSIONS.BUKKIT, true);
188 188 safelyAddEffects(effects);
189 189 }
190 190
191 191 @Override
192 192 public boolean hasEffects() {
193 193 return !(effects == null || effects.isEmpty());
194 194 }
227 227 for (FireworkEffect effect : this.effects) {
228 228 effects.add(getExplosion(effect));
229 229 }
230 230
231 231 if (effects.size() > 0) {
232 232 fireworks.put(EXPLOSIONS.NBT, effects);
233 233 }
234 234 }
235 235
236 236 if (hasPower()) {
237 - fireworks.putByte(FLIGHT.NBT, (byte) power);
237 + fireworks.putByte(FLIGHT.NBT, power.byteValue());
238 238 }
239 239 }
240 240
241 241 static void addColors(NBTTagCompound compound, ItemMetaKey key, List<Color> colors) {
242 242 if (colors.isEmpty()) {
243 243 return;
244 244 }
245 245
246 246 final int[] colorArray = new int[colors.size()];
247 247 int i = 0;
260 260 @Override
261 261 boolean isEmpty() {
262 262 return super.isEmpty() && isFireworkEmpty();
263 263 }
264 264
265 265 boolean isFireworkEmpty() {
266 266 return !(hasEffects() || hasPower());
267 267 }
268 268
269 269 boolean hasPower() {
270 - return power != 0;
270 + return power != null && power != 0;
271 271 }
272 272
273 273 @Override
274 274 boolean equalsCommon(CraftMetaItem meta) {
275 275 if (!super.equalsCommon(meta)) {
276 276 return false;
277 277 }
278 278
279 279 if (meta instanceof CraftMetaFirework) {
280 280 CraftMetaFirework that = (CraftMetaFirework) meta;

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut