Support for AdvancedChests was implemented. (#726)

This commit is contained in:
DeadSilenceIV 2025-03-04 09:13:55 -05:00 committed by GitHub
parent 1d294c51c4
commit 170b520b58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 50 additions and 12 deletions

View file

@ -16,6 +16,7 @@ import net.coreprotect.utility.Chat;
public final class CoreProtect extends JavaPlugin { public final class CoreProtect extends JavaPlugin {
private static CoreProtect instance; private static CoreProtect instance;
private boolean advancedChestsEnabled = false;
/** /**
* Get the instance of CoreProtect * Get the instance of CoreProtect
@ -43,6 +44,7 @@ public final class CoreProtect extends JavaPlugin {
instance = this; instance = this;
ConfigHandler.path = this.getDataFolder().getPath() + File.separator; ConfigHandler.path = this.getDataFolder().getPath() + File.separator;
advancedChestsEnabled = getServer().getPluginManager().getPlugin("AdvancedChests") != null;
// Initialize plugin using the initialization service // Initialize plugin using the initialization service
boolean initialized = PluginInitializationService.initializePlugin(this); boolean initialized = PluginInitializationService.initializePlugin(this);
@ -57,4 +59,8 @@ public final class CoreProtect extends JavaPlugin {
public void onDisable() { public void onDisable() {
ShutdownService.safeShutdown(this); ShutdownService.safeShutdown(this);
} }
public boolean isAdvancedChestsEnabled(){
return advancedChestsEnabled;
}
} }

View file

@ -35,6 +35,8 @@ import net.coreprotect.thread.Scheduler;
import net.coreprotect.utility.ItemUtils; import net.coreprotect.utility.ItemUtils;
import net.coreprotect.utility.Util; import net.coreprotect.utility.Util;
import net.coreprotect.utility.Validate; import net.coreprotect.utility.Validate;
import us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI;
import us.lynuxcraft.deadsilenceiv.advancedchests.chest.AdvancedChest;
public final class InventoryChangeListener extends Queue implements Listener { public final class InventoryChangeListener extends Queue implements Listener {
@ -83,21 +85,27 @@ public final class InventoryChangeListener extends Queue implements Listener {
if (containerType != null) { if (containerType != null) {
type = containerType; type = containerType;
} }
} } else {
else {
InventoryHolder inventoryHolder = inventory.getHolder(); InventoryHolder inventoryHolder = inventory.getHolder();
if (inventoryHolder == null) { if (inventoryHolder == null) {
return false; if (CoreProtect.getInstance().isAdvancedChestsEnabled()) {
AdvancedChest<?, ?> advancedChest = AdvancedChestsAPI.getInventoryManager().getAdvancedChest(inventory);
if (advancedChest != null) {
playerLocation = advancedChest.getLocation();
} else {
return false;
}
} else {
return false;
}
} }
if (inventoryHolder instanceof BlockState) { if (inventoryHolder instanceof BlockState) {
BlockState state = (BlockState) inventoryHolder; BlockState state = (BlockState) inventoryHolder;
type = state.getType(); type = state.getType();
if (BlockGroup.CONTAINERS.contains(type)) { if (BlockGroup.CONTAINERS.contains(type)) {
playerLocation = state.getLocation(); playerLocation = state.getLocation();
} }
} } else if (inventoryHolder instanceof DoubleChest) {
else if (inventoryHolder instanceof DoubleChest) {
DoubleChest state = (DoubleChest) inventoryHolder; DoubleChest state = (DoubleChest) inventoryHolder;
playerLocation = state.getLocation(); playerLocation = state.getLocation();
} }
@ -217,6 +225,17 @@ public final class InventoryChangeListener extends Queue implements Listener {
catch (Exception e) { catch (Exception e) {
return; return;
} }
if (location == null && !CoreProtect.getInstance().isAdvancedChestsEnabled()) {
return;
}
if (CoreProtect.getInstance().isAdvancedChestsEnabled()) {
AdvancedChest<?,?> chest = AdvancedChestsAPI.getInventoryManager().getAdvancedChest(inventory);
if (chest != null) {
location = chest.getLocation();
}
}
if (location == null) { if (location == null) {
return; return;
} }
@ -257,6 +276,7 @@ public final class InventoryChangeListener extends Queue implements Listener {
} }
boolean enderChest = false; boolean enderChest = false;
boolean advancedChest;
if (inventoryAction != InventoryAction.MOVE_TO_OTHER_INVENTORY && inventoryAction != InventoryAction.COLLECT_TO_CURSOR && inventoryAction != InventoryAction.UNKNOWN) { if (inventoryAction != InventoryAction.MOVE_TO_OTHER_INVENTORY && inventoryAction != InventoryAction.COLLECT_TO_CURSOR && inventoryAction != InventoryAction.UNKNOWN) {
// Perform this check to prevent triggering onInventoryInteractAsync when a user is just clicking items in their own inventory // Perform this check to prevent triggering onInventoryInteractAsync when a user is just clicking items in their own inventory
Inventory inventory = null; Inventory inventory = null;
@ -277,11 +297,14 @@ public final class InventoryChangeListener extends Queue implements Listener {
InventoryHolder inventoryHolder = inventory.getHolder(); InventoryHolder inventoryHolder = inventory.getHolder();
enderChest = inventory.equals(event.getWhoClicked().getEnderChest()); enderChest = inventory.equals(event.getWhoClicked().getEnderChest());
if ((inventoryHolder == null || !(inventoryHolder instanceof BlockInventoryHolder || inventoryHolder instanceof DoubleChest)) && !enderChest) { advancedChest = isAdvancedChest(inventory);
if ((!(inventoryHolder instanceof BlockInventoryHolder || inventoryHolder instanceof DoubleChest)) && !enderChest && !advancedChest) {
return; return;
} }
} if(advancedChest && event.getSlot() > inventory.getSize() - 10){
else { return;
}
} else {
// Perform standard inventory holder check on primary inventory // Perform standard inventory holder check on primary inventory
Inventory inventory = event.getInventory(); Inventory inventory = event.getInventory();
if (inventory == null) { if (inventory == null) {
@ -290,7 +313,11 @@ public final class InventoryChangeListener extends Queue implements Listener {
InventoryHolder inventoryHolder = inventory.getHolder(); InventoryHolder inventoryHolder = inventory.getHolder();
enderChest = inventory.equals(event.getWhoClicked().getEnderChest()); enderChest = inventory.equals(event.getWhoClicked().getEnderChest());
if ((inventoryHolder == null || !(inventoryHolder instanceof BlockInventoryHolder || inventoryHolder instanceof DoubleChest)) && !enderChest) { advancedChest = isAdvancedChest(inventory);
if ((!(inventoryHolder instanceof BlockInventoryHolder || inventoryHolder instanceof DoubleChest)) && !enderChest && !advancedChest) {
return;
}
if(advancedChest && event.getSlot() > inventory.getSize() - 10){
return; return;
} }
} }
@ -311,7 +338,7 @@ public final class InventoryChangeListener extends Queue implements Listener {
} }
enderChest = inventory.equals(event.getWhoClicked().getEnderChest()); enderChest = inventory.equals(event.getWhoClicked().getEnderChest());
if ((inventoryHolder != null && (inventoryHolder instanceof BlockInventoryHolder || inventoryHolder instanceof DoubleChest)) || enderChest) { if (((inventoryHolder instanceof BlockInventoryHolder || inventoryHolder instanceof DoubleChest)) || enderChest || isAdvancedChest(inventory)) {
movedItem = true; movedItem = true;
} }
@ -382,4 +409,9 @@ public final class InventoryChangeListener extends Queue implements Listener {
HopperPullListener.processHopperPull(location, "#hopper", sourceHolder, destinationHolder, event.getItem()); HopperPullListener.processHopperPull(location, "#hopper", sourceHolder, destinationHolder, event.getItem());
} }
private boolean isAdvancedChest(Inventory inventory) {
return CoreProtect.getInstance().isAdvancedChestsEnabled() && AdvancedChestsAPI.getInventoryManager().getAdvancedChest(inventory) != null;
}
} }

View file

@ -6,7 +6,7 @@ api-version: 1.13
folia-supported: true folia-supported: true
website: http://coreprotect.net website: http://coreprotect.net
author: Intelli author: Intelli
softdepend: [WorldEdit] softdepend: [WorldEdit,AdvancedChests]
description: > description: >
Provides block protection for your server. Provides block protection for your server.
commands: commands: