diff --git a/src/main/java/net/jadedmc/autopickup/listeners/EntityDeathListener.java b/src/main/java/net/jadedmc/autopickup/listeners/EntityDeathListener.java index 30de339..58ca549 100644 --- a/src/main/java/net/jadedmc/autopickup/listeners/EntityDeathListener.java +++ b/src/main/java/net/jadedmc/autopickup/listeners/EntityDeathListener.java @@ -25,7 +25,9 @@ package net.jadedmc.autopickup.listeners; import net.jadedmc.autopickup.AutoPickupPlugin; +import net.jadedmc.autopickup.utils.FoodUtils; import net.jadedmc.autopickup.utils.InventoryUtils; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -36,6 +38,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.List; /** * This listens to the EntityDeathEvent event, which is called every time an entity dies. @@ -84,6 +87,22 @@ public void onEntityDeath(EntityDeathEvent event) { final Collection drops = new ArrayList<>(event.getDrops()); event.getDrops().clear(); + // if auto-cook is enabled, all items are cooked and given to the player. + if (plugin.getConfigManager().getConfig().getBoolean("Settings.auto-cook")){ + if (plugin.getConfigManager().getConfig().getBoolean("RequirePermission") && killer.hasPermission("autopickup.use.autocook")){ + List drop = new ArrayList<>(drops); + drop.replaceAll(itemStack -> { + Material cookedMaterial = FoodUtils.getCookedVersion(itemStack.getType()); + if (cookedMaterial != null) { + return new ItemStack(cookedMaterial, itemStack.getAmount()); + } + return itemStack; + }); + drops.clear(); + drops.addAll(drop); + } + } + // Adds the item caught to the player's inventory. final Collection remaining = InventoryUtils.addItems(killer, drops); diff --git a/src/main/java/net/jadedmc/autopickup/utils/FoodUtils.java b/src/main/java/net/jadedmc/autopickup/utils/FoodUtils.java new file mode 100644 index 0000000..67b75d3 --- /dev/null +++ b/src/main/java/net/jadedmc/autopickup/utils/FoodUtils.java @@ -0,0 +1,32 @@ +package net.jadedmc.autopickup.utils; + +import org.bukkit.Material; + +public class FoodUtils { + + /** + * It gives the cooked version of the items according to their type. + * For now, only animal species have been added actively. + */ + public static Material getCookedVersion(Material rawMaterial) { + switch (rawMaterial) { + case BEEF: + return Material.COOKED_BEEF; + case CHICKEN: + return Material.COOKED_CHICKEN; + case PORKCHOP: + return Material.COOKED_PORKCHOP; + case MUTTON: + return Material.COOKED_MUTTON; + case RABBIT: + return Material.COOKED_RABBIT; + case COD: + return Material.COOKED_COD; + case SALMON: + return Material.COOKED_SALMON; + default: + return null; + } + } + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3d4f0ed..71a8149 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,6 +4,11 @@ AutoPickup: Fishing: true Mobs: true +# Toggle true if you want to open automatic cook. +# This feature requires the permission autopickup.use.autocook +Settings: + auto-cook: true + # Set if Auto Pickup should require permissions to use. # If true, requires the permission autopickup.use RequirePermission: false