Advertisement
SamWilko

Untitled

Jun 28th, 2022
902
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.02 KB | None
  1.  
  2. Save New Duplicate & Edit Just Text
  3. 1
  4. 2
  5. 3
  6. 4
  7. 5
  8. 6
  9. 7
  10. 8
  11. 9
  12. 10
  13. 11
  14. 12
  15. 13
  16. 14
  17. 15
  18. 16
  19. 17
  20. 18
  21. 19
  22. 20
  23. 21
  24. 22
  25. 23
  26. 24
  27. 25
  28. 26
  29. 27
  30. 28
  31. 29
  32. 30
  33. 31
  34. 32
  35. 33
  36. 34
  37. 35
  38. 36
  39. 37
  40. 38
  41. 39
  42. 40
  43. 41
  44. 42
  45. 43
  46. 44
  47. 45
  48. 46
  49. 47
  50. 48
  51. 49
  52. 50
  53. 51
  54. 52
  55. 53
  56. 54
  57. 55
  58. 56
  59. 57
  60. 58
  61. 59
  62. 60
  63. 61
  64. 62
  65. 63
  66. 64
  67. 65
  68. 66
  69. 67
  70. 68
  71. 69
  72. 70
  73. 71
  74. 72
  75. 73
  76. 74
  77. 75
  78. 76
  79. 77
  80. 78
  81. 79
  82. 80
  83. 81
  84. 82
  85. 83
  86. 84
  87. 85
  88. 86
  89. 87
  90. package me.tvhee.simplepackets;
  91.  
  92. import com.mojang.authlib.GameProfile;
  93. import java.util.UUID;
  94. import me.tvhee.simplepackets.handler.PacketHandler;
  95. import me.tvhee.simplepackets.handler.SimplePacket;
  96. import me.tvhee.simplereflection.MCReflectionUtil;
  97. import me.tvhee.simplereflection.Reflection;
  98. import me.tvhee.simplereflection.ReflectionUtil;
  99. import net.minecraft.network.chat.IChatBaseComponent;
  100. import net.minecraft.network.protocol.status.PacketStatusOutServerInfo;
  101. import org.bukkit.Bukkit;
  102. import org.bukkit.craftbukkit.v1_19_R1.util.CraftChatMessage;
  103.  
  104. public class MyPluginsMain //Extends....
  105. {
  106.     private final SimplePackets simplePackets = new SimplePackets();
  107.  
  108.     public void onLoad()
  109.     {
  110.         simplePackets.onPluginLoad();
  111.     }
  112.  
  113.     public void onEnable()
  114.     {
  115.         simplePackets.onPluginEnable(this);
  116.         simplePackets.addHandler(new PacketHandler(this)
  117.         {
  118.             @Override
  119.             public void onSend(SimplePacket packet)
  120.             {
  121.                 if(!packet.getPacketName().equals("PacketStatusOutServerInfo"))
  122.                     return;
  123.  
  124.                 Class<?> serverPing = MCReflectionUtil.getClass("{nms}.ServerPing", "{nms}.network.protocol.status.ServerPing");
  125.                 Class<?> serverPingPlayerSample = MCReflectionUtil.getClass("{nms}.ServerPing$ServerPingPlayerSample", "{nms}.network.protocol.status.ServerPing$ServerPingPlayerSample");
  126.                 Class<?> serverPingServerData = MCReflectionUtil.getClass("{nms}.ServerPing$ServerData", "{nms}.network.protocol.status.ServerPing$ServerData");
  127.                 Class<?> iChatBaseComponent = MCReflectionUtil.getClass("{nms}.IChatBaseComponent", "{nms}.network.chat.IChatBaseComponent");
  128.                 Class<?> craftChatMessage = MCReflectionUtil.getBukkitClass("{obc}.util.CraftChatMessage");
  129.  
  130.                 Reflection craftChatMessageReflected = new Reflection(craftChatMessage);
  131.                 Reflection serverPingReflected = new Reflection(packet.getPacketReflected().field(serverPing));
  132.  
  133.                 //Motd
  134.                 String motd = craftChatMessageReflected.method("fromComponent", serverPingReflected.field(iChatBaseComponent)).object();
  135.                 serverPingReflected.field(iChatBaseComponent, craftChatMessageReflected.method("toJson", "My Awesome MOTD here").object());
  136.  
  137.                 //Player sample
  138.                 Reflection playerSampleReflected = serverPingReflected.field(serverPingPlayerSample);
  139.                 int maxPlayers = playerSampleReflected.field(1, int.class).object();
  140.                 int onlinePlayers = playerSampleReflected.field(2, int.class).object();
  141.                 GameProfile[] hover = playerSampleReflected.field(GameProfile[].class).object(); //Most likely empty
  142.  
  143.                 playerSampleReflected.field(1, int.class, 5); //5 Max players
  144.                 playerSampleReflected.field(2, int.class, 6); //6 Online players
  145.  
  146.                 GameProfile[] newHover = new GameProfile[2];
  147.                 newHover[0] = new GameProfile(UUID.randomUUID(), "My hover line 1");
  148.                 newHover[1] = new GameProfile(UUID.randomUUID(), "My hover line 2");
  149.                 playerSampleReflected.field(GameProfile[].class, newHover);
  150.  
  151.                 //Server data
  152.                 Reflection serverDataReflected = serverPingReflected.field(serverPingServerData);
  153.                 String protocolNotSupportedLine = serverDataReflected.field(String.class).object();
  154.                 int protocolVersion = serverDataReflected.field(int.class).object();
  155.  
  156.                 serverDataReflected.field(String.class, "My protocol not supported");
  157.                 serverDataReflected.field(int.class, 1); //To make above message visible
  158.  
  159.                 //Favicon
  160.                 String faviconEncoded = serverPingReflected.field(String.class).object();
  161.                 serverPingReflected.field(String.class, new Reflection(Bukkit.loadServerIcon(serverIconFile)).field(String.class));
  162.             }
  163.  
  164.             @Override
  165.             public void onReceive(SimplePacket packet)
  166.             {
  167.             }
  168.         });
  169.     }
  170.  
  171.     public void onDisable()
  172.     {
  173.         simplePackets.onPluginDisable();
  174.     }
  175. }
  176.  
Advertisement
RAW Paste Data Copied
Advertisement