add config option to emit inventorypickupevent

This commit is contained in:
Aurora 2020-08-18 12:38:57 +02:00 committed by Brianna
parent 9a9043780f
commit acba79cc6a
2 changed files with 28 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import com.songoda.core.compatibility.CompatibleParticleHandler;
import com.songoda.core.locale.Locale;
import com.songoda.epichoppers.EpicHoppers;
import com.songoda.epichoppers.hopper.Hopper;
import com.songoda.epichoppers.settings.Settings;
import com.songoda.epichoppers.utils.Methods;
import com.songoda.epichoppers.utils.StorageContainerCache;
import org.apache.commons.lang.StringUtils;
@ -15,7 +16,11 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.meta.ItemMeta;
import java.lang.reflect.Method;
@ -72,9 +77,19 @@ public class ModuleSuction extends Module {
&& entity.getLocation().getBlock().getType() != Material.HOPPER)
.map(entity -> (Item) entity)
.collect(Collectors.toSet());
if (itemsToSuck.isEmpty())
return;
boolean filterEndpoint = hopper.getFilter().getEndPoint() != null;
InventoryHolder inventoryHolder = null;
Inventory hopperInventory = null;
if (Settings.EMIT_INVENTORYPICKUPITEMEVENT.getBoolean()) {
inventoryHolder = (InventoryHolder) hopper.getBlock().getState();
hopperInventory = Bukkit.createInventory(inventoryHolder, InventoryType.HOPPER);
}
for (Item item : itemsToSuck) {
ItemStack itemStack = item.getItemStack();
@ -114,6 +129,14 @@ public class ModuleSuction extends Module {
}
}
}
if (Settings.EMIT_INVENTORYPICKUPITEMEVENT.getBoolean()) {
hopperInventory.setContents(hopperCache.cachedInventory);
InventoryPickupItemEvent pickupevent = new InventoryPickupItemEvent(hopperInventory, item);
Bukkit.getPluginManager().callEvent(pickupevent);
if (pickupevent.isCancelled())
continue;
}
// try to add the items to the hopper
int toAdd, added = hopperCache.addAny(itemStack, toAdd = getActualItemAmount(item));

View File

@ -85,6 +85,11 @@ public class Settings {
"Which economy plugin should be used?",
"Supported plugins you have installed: \"" + EconomyManager.getManager().getRegisteredPlugins().stream().collect(Collectors.joining("\", \"")) + "\".");
public static final ConfigSetting EMIT_INVENTORYPICKUPITEMEVENT = new ConfigSetting(config, "Main.Emit InventoryPickupItemEvent", false,
"This event is used by other plugin to modify or monitor the behavior when a hopper picks up items on the ground.",
"However it is a high frequency event and may have an impact on your server performance which is why it is disabled by default.",
"If you absolutely need this enable it but be aware of the potential performance impact.");
public static final ConfigSetting ECO_ICON = new ConfigSetting(config, "Interfaces.Economy Icon", "SUNFLOWER");
public static final ConfigSetting XP_ICON = new ConfigSetting(config, "Interfaces.XP Icon", "EXPERIENCE_BOTTLE");