Skip to content

Commit 099c92a

Browse files
PotatoCraft-Studio#255 Try to send remove entity item packet after sending item
1 parent 33e536a commit 099c92a

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@
4646
import org.maxgamer.quickshop.util.GameVersion;
4747
import org.maxgamer.quickshop.util.Util;
4848

49-
import java.util.*;
49+
import java.util.ArrayList;
50+
import java.util.Collection;
51+
import java.util.Collections;
52+
import java.util.Iterator;
53+
import java.util.List;
54+
import java.util.Map;
55+
import java.util.Objects;
56+
import java.util.Optional;
57+
import java.util.Set;
58+
import java.util.UUID;
5059
import java.util.concurrent.ConcurrentHashMap;
5160
import java.util.concurrent.ConcurrentSkipListSet;
5261
import java.util.concurrent.atomic.AtomicBoolean;
@@ -87,7 +96,7 @@ private void load() {
8796
chunkLocation = new SimpleShopChunk(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
8897
VirtualDisplayItemManager.put(chunkLocation, this);
8998
if (Util.isLoaded(shop.getLocation())) {
90-
//Let nearby player can saw fake item
99+
//Let nearby player can see the fake item
91100
Collection<Entity> entityCollection = shop.getLocation().getWorld().getNearbyEntities(shop.getLocation(), PLUGIN.getServer().getViewDistance() * 16, shop.getLocation().getWorld().getMaxHeight(), PLUGIN.getServer().getViewDistance() * 16);
92101
for (Entity entity : entityCollection) {
93102
if (entity instanceof Player) {
@@ -219,6 +228,10 @@ private void unload() {
219228
VirtualDisplayItemManager.remove(chunkLocation, this);
220229
}
221230

231+
public void sendDestroyFakeItemPacket(@NotNull Player player) {
232+
sendPacket(player, fakeItemDestroyPacket);
233+
}
234+
222235
public void sendFakeItem(@NotNull Player player) {
223236
sendPacket(player, fakeItemSpawnPacket);
224237
sendPacket(player, fakeItemMetaPacket);
@@ -322,8 +335,12 @@ public void onPacketSending(@NotNull PacketEvent event) {
322335
if (!target.shop.isLoaded() || !target.isDisplay || target.shop.isLeftShop()) {
323336
continue;
324337
}
325-
target.packetSenders.add(player.getUniqueId());
326-
target.sendFakeItem(player);
338+
if (target.packetSenders.add(player.getUniqueId())) {
339+
target.sendFakeItem(player);
340+
} else {
341+
target.sendDestroyFakeItemPacket(player);
342+
target.sendFakeItem(player);
343+
}
327344
}
328345
return targetList;
329346
});
@@ -463,7 +480,7 @@ private static PacketContainer createFakeItemMetaPacket(int entityID, ItemStack
463480
}
464481

465482
private static PacketContainer createFakeItemVelocityPacket(int entityID) {
466-
//And, create a entity velocity packet to make it at a proper location (otherwise it will fly randomly)
483+
//And, create an entity velocity packet to make it at a proper location (otherwise it will fly randomly)
467484
PacketContainer fakeItemVelocityPacket = PROTOCOL_MANAGER.createPacket(PacketType.Play.Server.ENTITY_VELOCITY);
468485
fakeItemVelocityPacket.getIntegers()
469486
//Entity ID
@@ -488,11 +505,11 @@ private static PacketContainer createFakeItemDestroyPacket(int entityID) {
488505
//1.17+
489506
MinecraftVersion minecraftVersion = PROTOCOL_MANAGER.getMinecraftVersion();
490507
if (minecraftVersion.getMajor() == 1 && minecraftVersion.getMinor() == 17 && minecraftVersion.getBuild() == 0) {
491-
//On 1.17, just need to write a int
508+
//On 1.17, just need to write an int
492509
//Entity to remove
493510
fakeItemDestroyPacket.getIntegers().write(0, entityID);
494511
} else {
495-
//On 1.17.1 (may be 1.17.1+? it's enough, Mojang, stop the changes), we need add the int list
512+
//On 1.17.1 (maybe 1.17.1+? it's enough, Mojang, stop the changes), we need add the int list
496513
//Entity to remove
497514
try {
498515
fakeItemDestroyPacket.getIntLists().write(0, Collections.singletonList(entityID));

0 commit comments

Comments
 (0)