@@ -20,10 +20,11 @@ import org.json.JSONObject
2020import java.util.*
2121
2222object CosmeticManager {
23- var actions = mapOf (
24- " equip" to mutableSetOf<String >(),
25- " unequip" to mutableSetOf<String >(),
26- " purchase" to mutableSetOf<String >()
23+ var actions = mutableListOf<Actions >()
24+
25+ data class Actions (
26+ var action : String ,
27+ var name : String
2728 )
2829
2930 var previewing = mutableListOf<String >()
@@ -37,9 +38,9 @@ object CosmeticManager {
3738 it.equipped.remove(Minecraft .getMinecraft().thePlayer.uniqueID.toString())
3839 }
3940 if (preview) {
40- previewing.remove(name)
41+ previewing.remove(it. name)
4142 } else {
42- actions[ " unequip" ]
43+ actions.add( Actions ( " unequip" , it.name))
4344 }
4445 }
4546 }
@@ -51,17 +52,19 @@ object CosmeticManager {
5152 cosmetic?.let {
5253 if (BlockWAPIUtils .getCosmetic(it.type).isNotEmpty()) {
5354 BlockWAPIUtils .getCosmetic(it.type).forEach { cosmetic ->
54- unEquipCosmetic(cosmetic.name)
55- previewing.remove(cosmetic.name)
55+ if (cosmetic.equipped.contains(Minecraft .getMinecraft().thePlayer.uniqueID.toString())) {
56+ unEquipCosmetic(cosmetic.name)
57+ previewing.remove(cosmetic.name)
58+ }
5659 }
5760 }
5861 if (! it.equipped.contains(Minecraft .getMinecraft().thePlayer.uniqueID.toString())) {
5962 it.equipped.add(Minecraft .getMinecraft().thePlayer.uniqueID.toString())
6063 }
6164 if (preview) {
62- previewing.add(name)
65+ previewing.add(it. name)
6366 } else {
64- actions[ " equip" ]?.add( name)
67+ actions.add( Actions ( " equip" , it. name) )
6568 }
6669 }
6770 }
@@ -89,34 +92,28 @@ object CosmeticManager {
8992 it.users.add(Minecraft .getMinecraft().thePlayer.uniqueID.toString())
9093 Socket .cachedUser.amountSpent = Socket .cachedUser.amountSpent?.plus(it.cost)
9194 Socket .cachedUser.emeralds = Socket .cachedUser.emeralds.minus(it.cost)
92- actions[ " purchase" ]?.add(cosmeticName )
95+ actions.add( Actions ( " purchase" , it.name) )
9396 }
9497 }
9598 }
9699
97100 fun updateCosmetics () {
98101 Multithreading .runAsync {
99102 for (action in actions) {
100- val list = action.value
101- val func = action.key
102-
103- for (name in list) {
104- val response =
105- NetworkUtils .postString(HYSENTIALS_API + " /cosmetic?name=$name &function=${func} &uuid=${Minecraft .getMinecraft().thePlayer.uniqueID} &key=${Socket .serverId} " )
106- val json = JSONObject (response)
107- if (json.get(" success" ) == false ) {
108- Hysentials .INSTANCE .sendMessage(
109- " &cFailed to $func $name : ${json.get(" message" )} " ,
110- )
111- }
103+ val func = action.action
104+ val name = action.name
105+
106+ val response =
107+ NetworkUtils .postString(HYSENTIALS_API + " /cosmetic?name=$name &function=${func} &uuid=${Minecraft .getMinecraft().thePlayer.uniqueID} &key=${Socket .serverId} " )
108+ val json = JSONObject (response)
109+ if (json.get(" success" ) == false ) {
110+ Hysentials .INSTANCE .sendMessage(
111+ " &cFailed to $func $name : ${json.get(" message" )} " ,
112+ )
112113 }
113114 }
114115 previewing.clear()
115- actions = mapOf (
116- " equip" to mutableSetOf<String >(),
117- " unequip" to mutableSetOf<String >(),
118- " purchase" to mutableSetOf<String >()
119- )
116+ actions = mutableListOf ()
120117 var cosmetics: JsonElement ? =
121118 NetworkUtils .getJsonElement(" $HYSENTIALS_API /cosmetic" , true ) ? : return @runAsync
122119 val `object ` = cosmetics!! .asJsonObject
0 commit comments