broken-arrow

Untitled

Sep 17th, 2021
697
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. import lombok.SneakyThrows;
  4. import net.minecraft.server.v1_16_R3.*;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Material;
  7. import org.bukkit.Server;
  8. import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
  9. import org.bukkit.entity.Player;
  10.  
  11. import java.lang.reflect.Constructor;
  12. import java.lang.reflect.InvocationTargetException;
  13. import java.lang.reflect.Method;
  14.  
  15. public class UpdateTittleContainers {
  16.  
  17.  
  18.     @SneakyThrows
  19.     public static void update(Player p, String title, Material container, int inventorySize) {
  20.         Containers<?> inventoryType = null;
  21.         EntityPlayer ep = ((CraftPlayer) p).getHandle();
  22.         IChatBaseComponent icbc = IChatBaseComponent.ChatSerializer.b("'" + title + "'");
  23.  
  24.         if (container == Material.HOPPER)
  25.             inventoryType = Containers.HOPPER;
  26.         if (container == Material.CHEST)
  27.             inventoryType = inventorySize == 9 ? Containers.GENERIC_9X1 : inventorySize == 9 * 2 ?
  28.                     Containers.GENERIC_9X2 : inventorySize == 9 * 3 ? Containers.GENERIC_9X3 : inventorySize == 9 * 4 ?
  29.                     Containers.GENERIC_9X4 : inventorySize == 9 * 5 ? Containers.GENERIC_9X5 : null;
  30.  
  31.         if (inventoryType != null) {
  32.             PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(ep.activeContainer.windowId, inventoryType, icbc);
  33.             ep.playerConnection.sendPacket((Packet<?>) packet);
  34.             ep.updateInventory(ep.activeContainer);
  35.         }
  36.         versionCheck(Bukkit.getServer(), p);
  37.     }
  38.  
  39.     public static void versionCheck(Server server, Player p) {
  40.         String version = server.getVersion();
  41.         int start = version.indexOf("MC: ") + 4;
  42.         int end = version.length() - 1;
  43.         System.out.println(version.substring(start, end));
  44.         System.out.println(Bukkit.getServer().getClass().getPackageName().split("\\.")[3]);
  45.         String title = "Testar";
  46.         try {
  47.             EntityPlayer ep = ((CraftPlayer) p).getHandle();
  48.             IChatBaseComponent icbc = IChatBaseComponent.ChatSerializer.b("'" + title + "'");
  49.  
  50.             Class<?> exemple = Class.forName("net.minecraft.server.v1_16_R3.Containers");
  51.             Class<?> exemplee = Class.forName("net.minecraft.server.v1_16_R3.Container");
  52.             Class<?> tests155 = Class.forName("net.minecraft.server.v1_16_R3.EntityPlayer");
  53.             Class<?> testshuman = Class.forName("net.minecraft.server.v1_16_R3.EntityHuman");
  54.  
  55.  
  56.             int windowId = exemplee.getDeclaredField("windowId").getInt("windowId");
  57.  
  58.             Class<?> tests1 = Class.forName("net.minecraft.server.v1_16_R3.IChatBaseComponent");
  59.  
  60.             Class<?> chatCompenent = Class.forName("net.minecraft.server.v1_16_R3.IChatBaseComponent$ChatSerializer");
  61.             Method declaredMethodChat = chatCompenent.getDeclaredMethod("b", String.class);
  62.             Object inventoryTittle = declaredMethodChat.invoke(null, "'" + title + "'");
  63.  
  64.  
  65.             Object inventoryType = exemple.getDeclaredField("HOPPER").get("HOPPER");
  66.  
  67.             Class<?> tests = Class.forName("net.minecraft.server.v1_16_R3.PacketPlayOutOpenWindow");
  68.             Constructor<?> tesst = tests.getDeclaredConstructor(int.class, exemple, tests1);
  69.             Object methods = tesst.newInstance(ep.activeContainer.windowId, inventoryType, inventoryTittle);
  70.  
  71.             System.out.println("windows    ");
  72.             PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(ep.activeContainer.windowId, (Containers<?>) inventoryType, icbc);
  73.             ep.playerConnection.sendPacket((Packet<?>) methods);
  74.             ep.updateInventory(ep.activeContainer);
  75.             System.out.println(inventoryType);
  76.             //System.out.println(Arrays.toString(new String[]{exemple.getDeclaredField("GENERIC_9X1").toString()}));
  77.  
  78.         } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InstantiationException | InvocationTargetException e) {
  79.             e.printStackTrace();
  80.         }
  81.     }
  82. }
  83.  
RAW Paste Data