mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-25 09:59:49 -05:00
Do not load chunk in shop init process and deduplicate loading, fix #1360
This commit is contained in:
1 parent
cdf5f8ba56
commit
bd9477e335
4 files changed
+18
-24
No files matched your search
@@ -164,18 +164,17 @@ public class ContainerShop implements Shop {
|
||||
private void initDisplayItem() {
|
||||
Util.ensureThread(false);
|
||||
if (plugin.isDisplay()) {
|
||||
Chunk chunk = getLocation().getChunk();
|
||||
switch (DisplayItem.getNowUsing()) {
|
||||
case REALITEM:
|
||||
this.displayItem = new RealDisplayItem(this, chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
|
||||
this.displayItem = new RealDisplayItem(this);
|
||||
break;
|
||||
case VIRTUALITEM:
|
||||
this.displayItem = new VirtualDisplayItem(this, chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
|
||||
this.displayItem = new VirtualDisplayItem(this);
|
||||
break;
|
||||
default:
|
||||
Util.debugLog(
|
||||
"Warning: Failed to create a ContainerShop displayItem, the type we didn't know, fallback to RealDisplayItem");
|
||||
this.displayItem = new RealDisplayItem(this, chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
|
||||
this.displayItem = new RealDisplayItem(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,15 +52,9 @@ public abstract class DisplayItem {
|
||||
@Nullable
|
||||
protected ItemStack guardedIstack;
|
||||
private boolean pendingRemoval;
|
||||
protected final int chunkX;
|
||||
protected final int chunkZ;
|
||||
protected final String worldName;
|
||||
|
||||
protected DisplayItem(Shop shop, String worldName, int chunkX, int chunkZ) {
|
||||
protected DisplayItem(Shop shop) {
|
||||
this.shop = shop;
|
||||
this.worldName = worldName;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
this.originalItemStack = shop.getItem().clone();
|
||||
if (displayAllowStacks) {
|
||||
//Prevent stack over the normal size
|
||||
|
||||
@@ -50,8 +50,8 @@ public class RealDisplayItem extends DisplayItem {
|
||||
*
|
||||
* @param shop The shop (See Shop)
|
||||
*/
|
||||
RealDisplayItem(@NotNull Shop shop, @NotNull String worldName, int chunkX, int chunkZ) {
|
||||
super(shop, worldName, chunkX, chunkZ);
|
||||
RealDisplayItem(@NotNull Shop shop) {
|
||||
super(shop);
|
||||
// this.displayLoc = shop.getLocation().clone().add(0.5, 1.2, 0.5);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -87,8 +88,8 @@ public class VirtualDisplayItem extends DisplayItem {
|
||||
private AsyncListenerHandler asyncListenerHandler;
|
||||
|
||||
|
||||
public VirtualDisplayItem(@NotNull Shop shop, @NotNull String worldName, int chunkX, int chunkZ) throws RuntimeException {
|
||||
super(shop, worldName, chunkX, chunkZ);
|
||||
public VirtualDisplayItem(@NotNull Shop shop) throws RuntimeException {
|
||||
super(shop);
|
||||
}
|
||||
|
||||
private void initFakeDropItemPacket() {
|
||||
@@ -126,9 +127,11 @@ public class VirtualDisplayItem extends DisplayItem {
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
sendPacketToAll(fakeItemDestroyPacket);
|
||||
unload();
|
||||
isDisplay = false;
|
||||
if (isDisplay) {
|
||||
sendPacketToAll(fakeItemDestroyPacket);
|
||||
unload();
|
||||
isDisplay = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacketToAll(@NotNull PacketContainer packet) {
|
||||
@@ -177,15 +180,16 @@ public class VirtualDisplayItem extends DisplayItem {
|
||||
@Override
|
||||
public void spawn() {
|
||||
Util.ensureThread(false);
|
||||
if (shop.isLeftShop()) {
|
||||
if (shop.isLeftShop() || isDisplay || shop.isDeleted() || !shop.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
//lazy initialize
|
||||
if (!initialized) {
|
||||
initFakeDropItemPacket();
|
||||
}
|
||||
if (shop.isDeleted() || !shop.isLoaded()) {
|
||||
return;
|
||||
if (chunkLocation == null) {
|
||||
Chunk chunk = shop.getLocation().getChunk();
|
||||
chunkLocation = new ShopChunk(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
|
||||
}
|
||||
ShopDisplayItemSpawnEvent shopDisplayItemSpawnEvent = new ShopDisplayItemSpawnEvent(shop, originalItemStack, DisplayType.VIRTUALITEM);
|
||||
plugin.getServer().getPluginManager().callEvent(shopDisplayItemSpawnEvent);
|
||||
@@ -246,9 +250,6 @@ public class VirtualDisplayItem extends DisplayItem {
|
||||
int x = integerStructureModifier.read(0);
|
||||
//chunk z
|
||||
int z = integerStructureModifier.read(1);
|
||||
if (chunkLocation == null) {
|
||||
chunkLocation = new ShopChunk(worldName, chunkX, chunkZ);
|
||||
}
|
||||
if (chunkLocation.isSame(player.getWorld().getName(), x, z)) {
|
||||
packetSenders.add(player.getUniqueId());
|
||||
sendFakeItem(player);
|
||||
|
||||
Reference in new issue
Block a user