Skip to content

Commit 4d80cdd

Browse files
committed
Rewrite VirtualDisplayItem
1 parent c60a72c commit 4d80cdd

File tree

12 files changed

+999
-507
lines changed

12 files changed

+999
-507
lines changed

quickshop-bukkit/src/main/java/com/ghostchu/quickshop/QuickShop.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import com.ghostchu.quickshop.shop.controlpanel.SimpleShopControlPanel;
4444
import com.ghostchu.quickshop.shop.controlpanel.SimpleShopControlPanelManager;
4545
import com.ghostchu.quickshop.shop.display.AbstractDisplayItem;
46-
import com.ghostchu.quickshop.shop.display.VirtualDisplayItem;
46+
import com.ghostchu.quickshop.shop.display.virtual.VirtualDisplayItemManager;
4747
import com.ghostchu.quickshop.shop.inventory.BukkitInventoryWrapperManager;
4848
import com.ghostchu.quickshop.shop.signhooker.SignHooker;
4949
import com.ghostchu.quickshop.util.*;
@@ -238,6 +238,9 @@ public class QuickShop implements QuickShopAPI, Reloadable {
238238
@Getter
239239
private BungeeListener bungeeListener;
240240
private RankLimiter rankLimiter;
241+
@Nullable
242+
@Getter
243+
private VirtualDisplayItemManager virtualDisplayItemManager;
241244

242245
public QuickShop(QuickShopBukkit javaPlugin, Logger logger, Platform platform) {
243246
this.javaPlugin = javaPlugin;
@@ -626,7 +629,11 @@ public final void onEnable() {
626629
registerCommunicationChannels();
627630
new QSConfigurationReloadEvent(javaPlugin).callEvent();
628631
load3rdParty();
632+
try (PerfMonitor ignored = new PerfMonitor("Self Test")) {
633+
runtimeCheck(EnvCheckEntry.Stage.AFTER_ON_ENABLE);
634+
}
629635
logger.info("QuickShop Loaded! " + enableTimer.stopAndGetTimePassed() + " ms.");
636+
630637
}
631638

632639
private void loadErrorReporter() {
@@ -660,6 +667,7 @@ private void loadVirtualDisplayItem() {
660667
Plugin protocolLibPlugin = Bukkit.getPluginManager().getPlugin("ProtocolLib");
661668
if (protocolLibPlugin != null && protocolLibPlugin.isEnabled()) {
662669
logger.info("Successfully loaded ProtocolLib support!");
670+
virtualDisplayItemManager = new VirtualDisplayItemManager(this);
663671
if (getConfig().getBoolean("shop.per-player-shop-sign")) {
664672
signHooker = new SignHooker(this);
665673
logger.info("Successfully registered per-player shop sign!");
@@ -957,9 +965,9 @@ public final void onDisable() {
957965
logger.info("Cleaning up shop manager...");
958966
shopManager.clear();
959967
}
960-
if (AbstractDisplayItem.getNowUsing() == DisplayType.VIRTUALITEM) {
968+
if (AbstractDisplayItem.getNowUsing() == DisplayType.VIRTUALITEM && virtualDisplayItemManager != null) {
961969
logger.info("Cleaning up display manager...");
962-
VirtualDisplayItem.VirtualDisplayItemManager.unload();
970+
virtualDisplayItemManager.unload();
963971
}
964972
if (logWatcher != null) {
965973
logger.info("Stopping log watcher...");

quickshop-bukkit/src/main/java/com/ghostchu/quickshop/shop/ContainerShop.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.ghostchu.quickshop.shop.datatype.ShopSignPersistentDataType;
2323
import com.ghostchu.quickshop.shop.display.AbstractDisplayItem;
2424
import com.ghostchu.quickshop.shop.display.RealDisplayItem;
25-
import com.ghostchu.quickshop.shop.display.VirtualDisplayItem;
2625
import com.ghostchu.quickshop.util.MsgUtil;
2726
import com.ghostchu.quickshop.util.Util;
2827
import com.ghostchu.quickshop.util.logger.Log;
@@ -357,7 +356,7 @@ public void checkDisplay() {
357356
} else {
358357
this.displayItem = switch (AbstractDisplayItem.getNowUsing()) {
359358
case REALITEM -> new RealDisplayItem(this);
360-
default -> new VirtualDisplayItem(this);
359+
default -> plugin.getVirtualDisplayItemManager().createVirtualDisplayItem(this);
361360
};
362361
}
363362
} catch (Error anyError) {

quickshop-bukkit/src/main/java/com/ghostchu/quickshop/shop/display/AbstractDisplayItem.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import com.ghostchu.simplereloadlib.Reloadable;
1414
import com.google.common.collect.Lists;
1515
import com.google.gson.JsonSyntaxException;
16-
import lombok.Getter;
17-
import lombok.Setter;
1816
import org.bukkit.Bukkit;
1917
import org.bukkit.Location;
2018
import org.bukkit.entity.Entity;
@@ -31,9 +29,6 @@
3129
public abstract class AbstractDisplayItem implements Reloadable {
3230

3331
protected static final QuickShop PLUGIN = QuickShop.getInstance();
34-
@Setter
35-
@Getter
36-
private static volatile boolean isNotSupportVirtualItem = false;
3732
protected final ItemStack originalItemStack;
3833
protected final Shop shop;
3934
@Nullable
@@ -54,15 +49,7 @@ protected AbstractDisplayItem(Shop shop) {
5449
*/
5550
@NotNull
5651
public static DisplayType getNowUsing() {
57-
DisplayType displayType = DisplayType.fromID(PLUGIN.getConfig().getInt("shop.display-type"));
58-
//Falling back to RealDisplayItem when VirtualDisplayItem is unsupported
59-
if (isNotSupportVirtualItem && displayType == DisplayType.VIRTUALITEM) {
60-
PLUGIN.getConfig().set("shop.display-type", 0);
61-
PLUGIN.getJavaPlugin().saveConfig();
62-
PLUGIN.logger().warn("Falling back to RealDisplayItem because {} type is unsupported.", displayType.name());
63-
return DisplayType.REALITEM;
64-
}
65-
return displayType;
52+
return DisplayType.fromID(PLUGIN.getConfig().getInt("shop.display-type"));
6653
}
6754

6855
/**
@@ -332,4 +319,13 @@ public ReloadResult reloadModule() {
332319
*/
333320
public abstract void spawn();
334321

322+
/**
323+
* Gets the shop that display holding
324+
*
325+
* @return The shop that display holding
326+
*/
327+
@NotNull
328+
public Shop getShop() {
329+
return shop;
330+
}
335331
}

0 commit comments

Comments
 (0)