|
22 | 22 | import com.volmit.adapt.api.adaptation.SimpleAdaptation; |
23 | 23 | import com.volmit.adapt.util.*; |
24 | 24 | import lombok.NoArgsConstructor; |
25 | | -import net.minecraft.network.protocol.game.PacketPlayOutCollect; |
26 | 25 | import org.bukkit.Bukkit; |
27 | 26 | import org.bukkit.Material; |
28 | 27 | import org.bukkit.Sound; |
29 | | -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; |
30 | 28 | import org.bukkit.entity.Entity; |
31 | 29 | import org.bukkit.entity.Item; |
32 | 30 | import org.bukkit.entity.Player; |
@@ -118,9 +116,20 @@ private double getRange(double factor) { |
118 | 116 |
|
119 | 117 | public void sendCollected(Player plr, Item item) { |
120 | 118 | try { |
121 | | - PacketPlayOutCollect packet = new PacketPlayOutCollect(item.getEntityId(), plr.getEntityId(), item.getItemStack().getAmount()); |
122 | | - for (Entity i : plr.getWorld().getNearbyEntities(plr.getLocation(), 8, 8, 8, entity -> entity instanceof Player player)) { |
123 | | - ((CraftPlayer) i).getHandle().b.a(packet); |
| 119 | + String nmstag = Bukkit.getServer().getClass().getCanonicalName().split("\\Q.\\E")[3]; |
| 120 | + Class<?> c = Class.forName("net.minecraft.server." + nmstag + ".PacketPlayOutCollect"); |
| 121 | + Class<?> p = Class.forName("net.minecraft.server." + nmstag + ".EntityPlayer"); |
| 122 | + Class<?> pk = Class.forName("net.minecraft.server." + nmstag + ".Packet"); |
| 123 | + Object v = c.getConstructor().newInstance(); |
| 124 | + new V(v).set("a", item.getEntityId()); |
| 125 | + new V(v).set("b", plr.getEntityId()); |
| 126 | + new V(v).set("c", item.getItemStack().getAmount()); |
| 127 | + |
| 128 | + for (Entity i : plr.getWorld().getNearbyEntities(plr.getLocation(), 8, 8, 8)) { |
| 129 | + if (i instanceof Player) { |
| 130 | + Object pconnect = new V(new V(i).invoke("getHandle")).get("playerConnection"); |
| 131 | + pconnect.getClass().getMethod("sendPacket", pk).invoke(pconnect, v); |
| 132 | + } |
124 | 133 | } |
125 | 134 | } catch (Exception e) { |
126 | 135 | Adapt.error("Failed to send collected packet"); |
|
0 commit comments