Fix some fireworks colors and NPE of there is no NBT (#650)

Adds Bukkit colors and an additional NPE check
This commit is contained in:
rtm516 2020-05-25 22:57:10 +01:00 committed by GitHub
parent 6b68bbb413
commit d0545c57c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 6 deletions

View file

@ -25,8 +25,6 @@
package org.geysermc.connector.entity; package org.geysermc.connector.entity;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
@ -36,7 +34,6 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.CompoundTagBuilder;
import com.nukkitx.protocol.bedrock.data.EntityData; import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.FireworkColor; import org.geysermc.connector.utils.FireworkColor;
@ -57,6 +54,11 @@ public class FireworkEntity extends Entity {
if (entityMetadata.getId() == 7) { if (entityMetadata.getId() == 7) {
ItemStack item = (ItemStack) entityMetadata.getValue(); ItemStack item = (ItemStack) entityMetadata.getValue();
CompoundTag tag = item.getNbt(); CompoundTag tag = item.getNbt();
if (tag == null) {
return;
}
CompoundTag fireworks = tag.get("Fireworks"); CompoundTag fireworks = tag.get("Fireworks");
CompoundTagBuilder fireworksBuilder = CompoundTagBuilder.builder(); CompoundTagBuilder fireworksBuilder = CompoundTagBuilder.builder();

View file

@ -29,6 +29,7 @@ package org.geysermc.connector.utils;
import lombok.Getter; import lombok.Getter;
public enum FireworkColor { public enum FireworkColor {
// Vanilla colors
BLACK((byte) 0, 1973019), BLACK((byte) 0, 1973019),
RED((byte) 1, 11743532), RED((byte) 1, 11743532),
GREEN((byte) 2, 3887386), GREEN((byte) 2, 3887386),
@ -44,7 +45,27 @@ public enum FireworkColor {
LIGHT_BLUE((byte) 12, 6719955), LIGHT_BLUE((byte) 12, 6719955),
MAGENTA((byte) 13, 12801229), MAGENTA((byte) 13, 12801229),
ORANGE((byte) 14, 15435844), ORANGE((byte) 14, 15435844),
WHITE((byte) 15, 15790320); WHITE((byte) 15, 15790320),
// Bukkit colors
// https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Color.html
BUKKIT_WHITE((byte) 15, 0xFFFFFF),
BUKKIT_SILVER((byte) 7, 0xC0C0C0),
BUKKIT_GRAY((byte) 8, 0x808080),
BUKKIT_BLACK((byte) 0, 0x000000),
BUKKIT_RED((byte) 1, 0xFF0000),
BUKKIT_MAROON((byte) 1, 0x800000), // No perfect map but this is as close as it can be
BUKKIT_YELLOW((byte) 11, 0xFFFF00),
BUKKIT_OLIVE((byte) 2, 0x808000), // No perfect map but this is as close as it can be
BUKKIT_LIME((byte) 10, 0x00FF00),
BUKKIT_GREEN((byte) 2, 0x008000),
BUKKIT_AQUA((byte) 12, 0x00FFFF),
BUKKIT_TEAL((byte) 6, 0x008080),
BUKKIT_BLUE((byte) 4, 0x0000FF),
BUKKIT_NAVY((byte) 4, 0x000080), // No perfect map but this is as close as it can be
BUKKIT_FUCHSIA((byte) 9, 0xFF00FF), // No perfect map but this is as close as it can be
BUKKIT_PURPLE((byte) 5, 0x800080),
BUKKIT_ORANGE((byte) 14, 0xFFA500);
private static final FireworkColor[] VALUES = values(); private static final FireworkColor[] VALUES = values();
@ -65,7 +86,7 @@ public enum FireworkColor {
} }
} }
return null; return WHITE;
} }
public static FireworkColor fromBedrockID(int id) { public static FireworkColor fromBedrockID(int id) {
@ -75,6 +96,6 @@ public enum FireworkColor {
} }
} }
return null; return WHITE;
} }
} }