package net.deliciousreya.minecraftportal.extensions import com.google.common.collect.ImmutableBiMap import net.deliciousreya.minecraftportal.model.DeserializationException import net.deliciousreya.minecraftportal.proto.PortalSaveDataProtos import org.bukkit.Material import java.lang.IllegalStateException val COLOR_NAME_MAPPING: ImmutableBiMap = ImmutableBiMap.builder() .put("white", Material.WHITE_STAINED_GLASS) .put("red", Material.RED_STAINED_GLASS) .put("orange", Material.ORANGE_STAINED_GLASS) .put("pink", Material.PINK_STAINED_GLASS) .put("yellow", Material.YELLOW_STAINED_GLASS) .put("lime", Material.LIME_STAINED_GLASS) .put("green", Material.GREEN_STAINED_GLASS) .put("lightblue", Material.LIGHT_BLUE_STAINED_GLASS) .put("cyan", Material.CYAN_STAINED_GLASS) .put("blue", Material.BLUE_STAINED_GLASS) .put("magenta", Material.MAGENTA_STAINED_GLASS) .put("purple", Material.PURPLE_STAINED_GLASS) .put("brown", Material.BROWN_STAINED_GLASS) .put("gray", Material.GRAY_STAINED_GLASS) .put("lightgray", Material.LIGHT_GRAY_STAINED_GLASS) .put("black", Material.BLACK_STAINED_GLASS) .build() val COLOR_MAPPING: ImmutableBiMap = ImmutableBiMap.builder() .put(Material.WHITE_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.WHITE) .put(Material.RED_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.RED) .put(Material.ORANGE_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.ORANGE) .put(Material.PINK_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.PINK) .put(Material.YELLOW_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.YELLOW) .put(Material.LIME_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.LIME) .put(Material.GREEN_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.GREEN) .put(Material.LIGHT_BLUE_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.LIGHT_BLUE) .put(Material.CYAN_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.CYAN) .put(Material.BLUE_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.BLUE) .put(Material.MAGENTA_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.MAGENTA) .put(Material.PURPLE_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.PURPLE) .put(Material.BROWN_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.BROWN) .put(Material.GRAY_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.GRAY) .put(Material.LIGHT_GRAY_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.LIGHT_GRAY) .put(Material.BLACK_STAINED_GLASS, PortalSaveDataProtos.Portal.Color.BLACK) .build() val MINERAL_MAPPING: ImmutableBiMap = ImmutableBiMap.builder() .put(Material.COAL_BLOCK, PortalSaveDataProtos.Portal.Mineral.COAL) .put(Material.REDSTONE_BLOCK, PortalSaveDataProtos.Portal.Mineral.REDSTONE) .put(Material.LAPIS_BLOCK, PortalSaveDataProtos.Portal.Mineral.LAPIS) .put(Material.GOLD_BLOCK, PortalSaveDataProtos.Portal.Mineral.GOLD) .put(Material.DIAMOND_BLOCK, PortalSaveDataProtos.Portal.Mineral.DIAMOND) .put(Material.EMERALD_BLOCK, PortalSaveDataProtos.Portal.Mineral.EMERALD) .put(Material.IRON_BLOCK, PortalSaveDataProtos.Portal.Mineral.IRON) .put(Material.QUARTZ_BLOCK, PortalSaveDataProtos.Portal.Mineral.QUARTZ) .put(Material.TERRACOTTA, PortalSaveDataProtos.Portal.Mineral.TERRACOTTA) .put(Material.SMOOTH_RED_SANDSTONE, PortalSaveDataProtos.Portal.Mineral.RED_SANDSTONE) .put(Material.END_STONE_BRICKS, PortalSaveDataProtos.Portal.Mineral.END_STONE) .put(Material.PRISMARINE, PortalSaveDataProtos.Portal.Mineral.PRISMARINE) .put(Material.BRICKS, PortalSaveDataProtos.Portal.Mineral.BRICKS) .put(Material.PURPUR_BLOCK, PortalSaveDataProtos.Portal.Mineral.PURPUR) .put(Material.POLISHED_GRANITE, PortalSaveDataProtos.Portal.Mineral.GRANITE) .put(Material.POLISHED_ANDESITE, PortalSaveDataProtos.Portal.Mineral.ANDESITE) .build() fun Material.toMineralProto(): PortalSaveDataProtos.Portal.Mineral { return MINERAL_MAPPING[this] ?: throw DeserializationException("Not a mineral: $this") } fun Material.toColorProto(): PortalSaveDataProtos.Portal.Color { return COLOR_MAPPING[this] ?: throw DeserializationException("Not a color: $this") } fun PortalSaveDataProtos.Portal.Mineral.toMaterial(): Material { return MINERAL_MAPPING.inverse()[this] ?: throw DeserializationException("Not a material: $this") } fun PortalSaveDataProtos.Portal.Color.toMaterial(): Material { return COLOR_MAPPING.inverse()[this] ?: throw DeserializationException("Not a material: $this") }