1111import com .fasterxml .jackson .databind .ser .std .StdSerializer ;
1212
1313import java .io .IOException ;
14+ import java .util .Optional ;
1415
1516public class XSeriesSerialSupplier {
1617
@@ -28,7 +29,7 @@ public XMaterialSerializer() {
2829
2930 @ Override
3031 public void serialize (XMaterial xMaterial , JsonGenerator jsonGenerator , SerializerProvider serializerProvider ) throws IOException {
31- jsonGenerator .writeString (xMaterial .toString ());
32+ jsonGenerator .writeString (xMaterial .name ());
3233 }
3334 }
3435
@@ -44,8 +45,12 @@ public XMaterialDeserializer() {
4445 @ Override
4546 public XMaterial deserialize (JsonParser jsonParser , DeserializationContext deserializationContext ) throws IOException , JacksonException {
4647 JsonNode node = jsonParser .getCodec ().readTree (jsonParser );
47- String xMaterial = node .toString ();
48- return XMaterial .matchXMaterial (xMaterial ).get ();
48+ String xMaterial = node .toString ().replace ("\" " , "" );
49+ Optional <XMaterial > optional = XMaterial .matchXMaterial (xMaterial );
50+ if (!optional .isPresent ()){
51+ IridiumCore .getInstance ().getLogger ().warning ("Could not deserialize " +xMaterial +" to a Material, defaulting to AIR" );
52+ }
53+ return optional .orElse (XMaterial .AIR );
4954 }
5055 }
5156
@@ -60,7 +65,7 @@ public XPotionSerializer() {
6065
6166 @ Override
6267 public void serialize (XPotion xPotion , JsonGenerator jsonGenerator , SerializerProvider serializerProvider ) throws IOException {
63- jsonGenerator .writeString (xPotion .toString ());
68+ jsonGenerator .writeString (xPotion .name ());
6469 }
6570 }
6671
@@ -76,8 +81,12 @@ public XPotionDeserializer() {
7681 @ Override
7782 public XPotion deserialize (JsonParser jsonParser , DeserializationContext deserializationContext ) throws IOException , JacksonException {
7883 JsonNode node = jsonParser .getCodec ().readTree (jsonParser );
79- String xPotion = node .toString ();
80- return XPotion .of (xPotion ).get ();
84+ String xPotion = node .toString ().replace ("\" " , "" );
85+ Optional <XPotion > optional = XPotion .of (xPotion );
86+ if (!optional .isPresent ()){
87+ IridiumCore .getInstance ().getLogger ().warning ("Could not deserialize " +xPotion +" to a Potion, defaulting to LUCK" );
88+ }
89+ return optional .orElse (XPotion .LUCK );
8190 }
8291 }
8392
@@ -92,7 +101,7 @@ public XEnchantmentSerializer() {
92101
93102 @ Override
94103 public void serialize (XEnchantment xEnchantment , JsonGenerator jsonGenerator , SerializerProvider serializerProvider ) throws IOException {
95- jsonGenerator .writeString (xEnchantment .toString ());
104+ jsonGenerator .writeString (xEnchantment .name ());
96105 }
97106 }
98107
@@ -108,8 +117,12 @@ public XEnchantmentDeserializer() {
108117 @ Override
109118 public XEnchantment deserialize (JsonParser jsonParser , DeserializationContext deserializationContext ) throws IOException , JacksonException {
110119 JsonNode node = jsonParser .getCodec ().readTree (jsonParser );
111- String xEnchantment = node .toString ();
112- return XEnchantment .of (xEnchantment ).get ();
120+ String xEnchantment = node .toString ().replace ("\" " , "" );
121+ Optional <XEnchantment > optional = XEnchantment .of (xEnchantment );
122+ if (!optional .isPresent ()){
123+ IridiumCore .getInstance ().getLogger ().warning ("Could not deserialize " +xEnchantment +" to an Enchantment, defaulting to WIND_BURST" );
124+ }
125+ return optional .orElse (XEnchantment .WIND_BURST );
113126 }
114127 }
115128
@@ -124,7 +137,7 @@ public XBiomeSerializer() {
124137
125138 @ Override
126139 public void serialize (XBiome xBiome , JsonGenerator jsonGenerator , SerializerProvider serializerProvider ) throws IOException {
127- jsonGenerator .writeString (xBiome .toString ());
140+ jsonGenerator .writeString (xBiome .name ());
128141 }
129142 }
130143
@@ -140,8 +153,12 @@ public XBiomeDeserializer() {
140153 @ Override
141154 public XBiome deserialize (JsonParser jsonParser , DeserializationContext deserializationContext ) throws IOException , JacksonException {
142155 JsonNode node = jsonParser .getCodec ().readTree (jsonParser );
143- String xBiome = node .toString ();
144- return XBiome .of (xBiome ).get ();
156+ String xBiome = node .toString ().replace ("\" " , "" );
157+ Optional <XBiome > optional = XBiome .of (xBiome );
158+ if (!optional .isPresent ()){
159+ IridiumCore .getInstance ().getLogger ().warning ("Could not deserialize " +xBiome +" to a Biome, defaulting to Plains" );
160+ }
161+ return optional .orElse (XBiome .PLAINS );
145162 }
146163 }
147164
@@ -156,7 +173,7 @@ public XSoundSerializer() {
156173
157174 @ Override
158175 public void serialize (XSound xSound , JsonGenerator jsonGenerator , SerializerProvider serializerProvider ) throws IOException {
159- jsonGenerator .writeString (xSound .toString ());
176+ jsonGenerator .writeString (xSound .name ());
160177 }
161178 }
162179
@@ -172,8 +189,12 @@ public XSoundDeserializer() {
172189 @ Override
173190 public XSound deserialize (JsonParser jsonParser , DeserializationContext deserializationContext ) throws IOException , JacksonException {
174191 JsonNode node = jsonParser .getCodec ().readTree (jsonParser );
175- String xSound = node .toString ();
176- return XSound .of (xSound ).get ();
192+ String xSound = node .toString ().replace ("\" " , "" );
193+ Optional <XSound > optional = XSound .of (xSound );
194+ if (!optional .isPresent ()){
195+ IridiumCore .getInstance ().getLogger ().warning ("Could not deserialize " +xSound +" to a Sound, defaulting to ENTITY_PLAYER_LEVELUP" );
196+ }
197+ return optional .orElse (XSound .ENTITY_PLAYER_LEVELUP );
177198 }
178199 }
179200
@@ -188,7 +209,7 @@ public XEntityTypeSerializer() {
188209
189210 @ Override
190211 public void serialize (XEntityType xEntityType , JsonGenerator jsonGenerator , SerializerProvider serializerProvider ) throws IOException {
191- jsonGenerator .writeString (xEntityType .toString ());
212+ jsonGenerator .writeString (xEntityType .name ());
192213 }
193214 }
194215
@@ -204,8 +225,12 @@ public XEntityTypeDeserializer() {
204225 @ Override
205226 public XEntityType deserialize (JsonParser jsonParser , DeserializationContext deserializationContext ) throws IOException , JacksonException {
206227 JsonNode node = jsonParser .getCodec ().readTree (jsonParser );
207- String xEntityType = node .toString ();
208- return XEntityType .of (xEntityType ).get ();
228+ String xEntityType = node .toString ().replace ("\" " , "" );
229+ Optional <XEntityType > optional = XEntityType .of (xEntityType );
230+ if (!optional .isPresent ()){
231+ IridiumCore .getInstance ().getLogger ().warning ("Could not deserialize " +xEntityType +" to an EntityType, defaulting to WOLF" );
232+ }
233+ return optional .orElse (XEntityType .WOLF );
209234 }
210235 }
211236}
0 commit comments