|
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; |
25 | 26 | import org.bukkit.Bukkit; |
26 | 27 | import org.bukkit.Material; |
27 | 28 | import org.bukkit.Sound; |
| 29 | +import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; |
28 | 30 | import org.bukkit.entity.Entity; |
29 | 31 | import org.bukkit.entity.Item; |
30 | 32 | import org.bukkit.entity.Player; |
@@ -116,20 +118,9 @@ private double getRange(double factor) { |
116 | 118 |
|
117 | 119 | public void sendCollected(Player plr, Item item) { |
118 | 120 | try { |
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 | | - } |
| 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); |
133 | 124 | } |
134 | 125 | } catch (Exception e) { |
135 | 126 | Adapt.error("Failed to send collected packet"); |
|
0 commit comments