@@ -21,22 +21,20 @@ object Serializer {
2121 """ .trimIndent()
2222 }
2323
24- fun deserializeItem (itemNbt : String ): ItemStack ? {
25- return try {
26- val asJsonObject = jsonParser.parse(itemNbt).asJsonObject
24+ fun deserializeItem (itemNbt : String ): ItemStack ? = try {
25+ val asJsonObject = jsonParser.parse(itemNbt).asJsonObject
2726
28- val id = asJsonObject.getAsJsonPrimitive(" id" ).asString
29- val amount = asJsonObject.getAsJsonPrimitive(" Count" ).asInt
30- val nbt = asJsonObject.getAsJsonPrimitive(" tag" ).asString
27+ val id = asJsonObject.getAsJsonPrimitive(" id" ).asString
28+ val amount = asJsonObject.getAsJsonPrimitive(" Count" ).asInt
29+ val nbt = asJsonObject.getAsJsonPrimitive(" tag" ).asString
3130
32- ItemStack (
33- Material .matchMaterial(id)!! ,
34- amount,
35- NBTData .deserialize(nbt)
36- )
37- } catch (exception: Throwable ) {
38- null
39- }
31+ ItemStack (
32+ Material .matchMaterial(id)!! ,
33+ amount,
34+ NBTData .deserialize(nbt)
35+ )
36+ } catch (exception: Throwable ) {
37+ null
4038 }
4139
4240 fun serialize (inventory : Inventory , title : String? = null): String {
@@ -62,33 +60,31 @@ object Serializer {
6260 owner : InventoryHolder ,
6361 inventoryNbt : String ,
6462 title : String? = null
65- ): Inventory ? {
66- return try {
67- val jsonObject = jsonParser.parse(inventoryNbt).asJsonObject
63+ ): Inventory ? = try {
64+ val jsonObject = jsonParser.parse(inventoryNbt).asJsonObject
6865
69- val type = InventoryType .valueOf(
70- jsonObject.getAsJsonPrimitive(" type" ).asString.uppercase()
71- )
72- val size = if (type == InventoryType .CHEST )
73- jsonObject.getAsJsonPrimitive(" size" ).asInt
74- else - 1
75- val resultTitle = if (title == null && jsonObject.has(" title" ))
76- jsonObject.getAsJsonPrimitive(" title" ).asString
77- else title
66+ val type = InventoryType .valueOf(
67+ jsonObject.getAsJsonPrimitive(" type" ).asString.uppercase()
68+ )
69+ val size = if (type == InventoryType .CHEST )
70+ jsonObject.getAsJsonPrimitive(" size" ).asInt
71+ else - 1
72+ val resultTitle = if (title == null && jsonObject.has(" title" ))
73+ jsonObject.getAsJsonPrimitive(" title" ).asString
74+ else title
7875
79- val result = if (type == InventoryType .CHEST )
80- Inventory (owner, size, resultTitle)
81- else
82- Inventory (owner, type, resultTitle)
76+ val result = if (type == InventoryType .CHEST )
77+ Inventory (owner, size, resultTitle)
78+ else
79+ Inventory (owner, type, resultTitle)
8380
84- val items = jsonObject.getAsJsonObject(" Items" )
85- result.apply {
86- for ((slot, item) in items.entrySet()) {
87- setItem(slot.toInt(), deserializeItem(item.toString()))
88- }
81+ val items = jsonObject.getAsJsonObject(" Items" )
82+ result.apply {
83+ for ((slot, item) in items.entrySet()) {
84+ setItem(slot.toInt(), deserializeItem(item.toString()))
8985 }
90- } catch (exception: Throwable ) {
91- null
9286 }
87+ } catch (exception: Throwable ) {
88+ null
9389 }
9490}
0 commit comments