Skip to content

Commit fc33678

Browse files
Fix enderchest shop not working
1 parent 001ba6e commit fc33678

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

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

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,41 +1335,40 @@ public AbstractDisplayItem getDisplayItem() {
13351335
public @Nullable Inventory getInventory() {
13361336
Util.ensureThread(false);
13371337
BlockState state = PaperLib.getBlockState(location.getBlock(), false).getState();
1338-
Inventory inv;
1339-
try {
1340-
if (state.getType() == Material.ENDER_CHEST
1341-
&& plugin.getOpenInvPlugin() != null) { //FIXME: Need better impl
1338+
Inventory inv = null;
1339+
if (state.getType() == Material.ENDER_CHEST && plugin.getOpenInvPlugin() != null) {
1340+
try {//FIXME: Need better impl
1341+
OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(this.getOwner());
13421342
IOpenInv openInv = ((IOpenInv) plugin.getOpenInvPlugin());
1343-
inv = openInv.getSpecialEnderChest(
1344-
Objects.requireNonNull(
1345-
openInv.loadPlayer(
1346-
plugin.getServer().getOfflinePlayer(this.moderator.getOwner()))),
1347-
plugin.getServer().getOfflinePlayer((this.moderator.getOwner())).isOnline())
1348-
.getBukkitInventory();
1343+
Player player = openInv.loadPlayer(offlinePlayer);
1344+
if (player != null) {
1345+
inv = openInv.getSpecialEnderChest(player, offlinePlayer.isOnline()).getBukkitInventory();
1346+
}
1347+
} catch (Exception e) {
1348+
Util.debugLog(e.getMessage());
1349+
return null;
13491350
}
1350-
} catch (Exception e) {
1351-
Util.debugLog(e.getMessage());
1352-
return null;
13531351
}
1354-
InventoryHolder container;
1355-
try {
1356-
container = (InventoryHolder) state;
1357-
inv = container.getInventory();
1358-
} catch (Exception e) {
1359-
if (!createBackup) {
1360-
createBackup = Util.backupDatabase();
1361-
if (createBackup) {
1362-
this.delete(false);
1352+
if (inv == null) {
1353+
InventoryHolder container;
1354+
try {
1355+
container = (InventoryHolder) state;
1356+
inv = container.getInventory();
1357+
} catch (Exception e) {
1358+
if (!createBackup) {
1359+
createBackup = Util.backupDatabase();
1360+
if (createBackup) {
1361+
this.delete(false);
1362+
}
1363+
} else {
1364+
this.delete(true);
13631365
}
1364-
} else {
1365-
this.delete(true);
1366+
plugin.logEvent(new ShopRemoveLog(Util.getNilUniqueId(), "Inventory Invalid", this.saveToInfoStorage()));
1367+
Util.debugLog(
1368+
"Inventory doesn't exist anymore: " + this + " shop was removed.");
1369+
return null;
13661370
}
1367-
plugin.logEvent(new ShopRemoveLog(Util.getNilUniqueId(), "Inventory Invalid", this.saveToInfoStorage()));
1368-
Util.debugLog(
1369-
"Inventory doesn't exist anymore: " + this + " shop was removed.");
1370-
return null;
13711371
}
1372-
13731372
ShopInventoryEvent event = new ShopInventoryEvent(this, inv);
13741373
event.callEvent();
13751374
return event.getInventory();

0 commit comments

Comments
 (0)