SHARE
TWEET

Untitled

a guest Jul 17th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package mc.utopia.plugin.advancements
  2.  
  3. import java.lang.reflect.Field
  4.  
  5. typealias PacketPlayOutAdvancements = net.minecraft.server.v1_14_R1.PacketPlayOutAdvancements
  6. typealias SerializedAdvancement = net.minecraft.server.v1_14_R1.Advancement.SerializedAdvancement
  7. typealias MinecraftKey = net.minecraft.server.v1_14_R1.MinecraftKey
  8. typealias AdvancementProgress = net.minecraft.server.v1_14_R1.AdvancementProgress
  9. typealias AdvancementDisplay = net.minecraft.server.v1_14_R1.AdvancementDisplay
  10. typealias IChatBaseComponent = net.minecraft.server.v1_14_R1.IChatBaseComponent
  11. typealias ChatSerializer = net.minecraft.server.v1_14_R1.IChatBaseComponent.ChatSerializer
  12.  
  13. fun PacketPlayOutAdvancements(
  14.     clear: Boolean,
  15.     advancements: Map<MinecraftKey, SerializedAdvancement>,
  16.     remove: Set<MinecraftKey>,
  17.     progresses: Map<MinecraftKey, AdvancementProgress>
  18. ) = PacketPlayOutAdvancements().apply {
  19.     this.clear = clear
  20.     this.advancements = advancements
  21.     this.remove = remove
  22.     this.progresses = progresses
  23. }
  24.  
  25. var PacketPlayOutAdvancements.clear
  26.     get() = getPrivateFieldValue<Boolean>("a")
  27.     set(value) = setPrivateFieldValue("a", value)
  28. var PacketPlayOutAdvancements.advancements
  29.     get() = getPrivateFieldValue<Map<MinecraftKey, SerializedAdvancement>>("b")
  30.     set(value) = setPrivateFieldValue("b", value)
  31. var PacketPlayOutAdvancements.remove
  32.     get() = getPrivateFieldValue<Set<MinecraftKey>>("c")
  33.     set(value) = setPrivateFieldValue("c", value)
  34. var PacketPlayOutAdvancements.progresses
  35.     get() = getPrivateFieldValue<Map<MinecraftKey, AdvancementProgress>>("d")
  36.     set(value) = setPrivateFieldValue("d", value)
  37.  
  38. var SerializedAdvancement.display
  39.     get() = getPrivateFieldValue<AdvancementDisplay>("c")
  40.     set(value) = setPrivateFieldValue("c", value)
  41.  
  42. var AdvancementDisplay.title
  43.     get() = getPrivateFieldValue<IChatBaseComponent>("a")
  44.     set(value) = setPrivateFieldValue("a", value)
  45. var AdvancementDisplay.description
  46.     get() = getPrivateFieldValue<IChatBaseComponent>("b")
  47.     set(value) = setPrivateFieldValue("b", value)
  48.  
  49. private inline fun <reified T> Any.getPrivateFieldValue(fieldName: String): T {
  50.     return javaClass.getPrivateField(fieldName)[this] as T
  51. }
  52.  
  53. private fun Any.setPrivateFieldValue(fieldName: String, value: Any?) {
  54.     javaClass.getPrivateField(fieldName)[this] = value
  55. }
  56.  
  57. private fun Class<*>.getPrivateField(name: String): Field = javaClass.getDeclaredField(name).apply {
  58.     isAccessible = true
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top