broken-arrow

Untitled

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