Advertisement
SamWilko

Untitled

Jun 28th, 2022
992
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.65 KB | None
  1.  
  2.  
  3. package me.tvhee.simplepackets;
  4.  
  5. import com.mojang.authlib.GameProfile;
  6. import java.util.UUID;
  7. import me.tvhee.simplepackets.handler.PacketHandler;
  8. import me.tvhee.simplepackets.handler.SimplePacket;
  9. import me.tvhee.simplereflection.MCReflectionUtil;
  10. import me.tvhee.simplereflection.Reflection;
  11. import me.tvhee.simplereflection.ReflectionUtil;
  12. import net.minecraft.network.chat.IChatBaseComponent;
  13. import net.minecraft.network.protocol.status.PacketStatusOutServerInfo;
  14. import org.bukkit.Bukkit;
  15. import org.bukkit.craftbukkit.v1_19_R1.util.CraftChatMessage;
  16.  
  17. public class MyPluginsMain //Extends....
  18. {
  19.     private final SimplePackets simplePackets = new SimplePackets();
  20.  
  21.     public void onLoad()
  22.     {
  23.         simplePackets.onPluginLoad();
  24.     }
  25.  
  26.     public void onEnable()
  27.     {
  28.         simplePackets.onPluginEnable(this);
  29.         simplePackets.addHandler(new PacketHandler(this)
  30.         {
  31.             @Override
  32.             public void onSend(SimplePacket packet)
  33.             {
  34.                 if(!packet.getPacketName().equals("PacketStatusOutServerInfo"))
  35.                     return;
  36.  
  37.                 Class<?> serverPing = MCReflectionUtil.getClass("{nms}.ServerPing", "{nms}.network.protocol.status.ServerPing");
  38.                 Class<?> serverPingPlayerSample = MCReflectionUtil.getClass("{nms}.ServerPing$ServerPingPlayerSample", "{nms}.network.protocol.status.ServerPing$ServerPingPlayerSample");
  39.                 Class<?> serverPingServerData = MCReflectionUtil.getClass("{nms}.ServerPing$ServerData", "{nms}.network.protocol.status.ServerPing$ServerData");
  40.                 Class<?> iChatBaseComponent = MCReflectionUtil.getClass("{nms}.IChatBaseComponent", "{nms}.network.chat.IChatBaseComponent");
  41.                 Class<?> craftChatMessage = MCReflectionUtil.getBukkitClass("{obc}.util.CraftChatMessage");
  42.  
  43.                 Reflection craftChatMessageReflected = new Reflection(craftChatMessage);
  44.                 Reflection serverPingReflected = new Reflection(packet.getPacketReflected().field(serverPing));
  45.  
  46.                 //Motd
  47.                 String motd = craftChatMessageReflected.method("fromComponent", serverPingReflected.field(iChatBaseComponent)).object();
  48.                 serverPingReflected.field(iChatBaseComponent, craftChatMessageReflected.method("toJson", "My Awesome MOTD here").object());
  49.  
  50.                 //Player sample
  51.                 Reflection playerSampleReflected = serverPingReflected.field(serverPingPlayerSample);
  52.                 int maxPlayers = playerSampleReflected.field(1, int.class).object();
  53.                 int onlinePlayers = playerSampleReflected.field(2, int.class).object();
  54.                 GameProfile[] hover = playerSampleReflected.field(GameProfile[].class).object(); //Most likely empty
  55.  
  56.                 playerSampleReflected.field(1, int.class, 5); //5 Max players
  57.                 playerSampleReflected.field(2, int.class, 6); //6 Online players
  58.  
  59.                 GameProfile[] newHover = new GameProfile[2];
  60.                 newHover[0] = new GameProfile(UUID.randomUUID(), "My hover line 1");
  61.                 newHover[1] = new GameProfile(UUID.randomUUID(), "My hover line 2");
  62.                 playerSampleReflected.field(GameProfile[].class, newHover);
  63.  
  64.                 //Server data
  65.                 Reflection serverDataReflected = serverPingReflected.field(serverPingServerData);
  66.                 String protocolNotSupportedLine = serverDataReflected.field(String.class).object();
  67.                 int protocolVersion = serverDataReflected.field(int.class).object();
  68.  
  69.                 serverDataReflected.field(String.class, "My protocol not supported");
  70.                 serverDataReflected.field(int.class, 1); //To make above message visible
  71.  
  72.                 //Favicon
  73.                 String faviconEncoded = serverPingReflected.field(String.class).object();
  74.                 serverPingReflected.field(String.class, new Reflection(Bukkit.loadServerIcon(serverIconFile)).field(String.class));
  75.             }
  76.  
  77.             @Override
  78.             public void onReceive(SimplePacket packet)
  79.             {
  80.             }
  81.         });
  82.     }
  83.  
  84.     public void onDisable()
  85.     {
  86.         simplePackets.onPluginDisable();
  87.     }
  88. }
  89.  
Advertisement
RAW Paste Data Copied
Advertisement