Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -84,6 +87,22 @@ public void onEntityDeath(EntityDeathEvent event) {
final Collection<ItemStack> 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<ItemStack> 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<ItemStack> remaining = InventoryUtils.addItems(killer, drops);

Expand Down
32 changes: 32 additions & 0 deletions src/main/java/net/jadedmc/autopickup/utils/FoodUtils.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
5 changes: 5 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down