|
| 1 | +package us.thezircon.play.autopickup.listeners; |
| 2 | + |
| 3 | +import org.bukkit.Bukkit; |
| 4 | +import org.bukkit.Location; |
| 5 | +import org.bukkit.Material; |
| 6 | +import org.bukkit.entity.Entity; |
| 7 | +import org.bukkit.entity.EntityType; |
| 8 | +import org.bukkit.entity.Item; |
| 9 | +import org.bukkit.entity.Player; |
| 10 | +import org.bukkit.event.EventHandler; |
| 11 | +import org.bukkit.event.Listener; |
| 12 | +import org.bukkit.event.block.Action; |
| 13 | +import org.bukkit.event.player.PlayerInteractEvent; |
| 14 | +import org.bukkit.inventory.ItemStack; |
| 15 | +import org.bukkit.scheduler.BukkitRunnable; |
| 16 | +import us.thezircon.play.autopickup.AutoPickup; |
| 17 | + |
| 18 | +public class PlayerInteractEventListener implements Listener { |
| 19 | + |
| 20 | + private static final AutoPickup PLUGIN = AutoPickup.getPlugin(AutoPickup.class); |
| 21 | + |
| 22 | + @EventHandler |
| 23 | + public void onClick(PlayerInteractEvent e) { |
| 24 | + Player player = e.getPlayer(); |
| 25 | + Location loc = e.getClickedBlock().getLocation(); |
| 26 | + if (!PLUGIN.autopickup_list.contains(player)) { |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + if(e.getAction() == Action.RIGHT_CLICK_BLOCK) { |
| 31 | + if(e.getClickedBlock().getType() == Material.SWEET_BERRY_BUSH) { |
| 32 | + new BukkitRunnable() { |
| 33 | + @Override |
| 34 | + public void run() { |
| 35 | + for (Entity entity : loc.getWorld().getNearbyEntities(loc, 1, 1, 1)) { |
| 36 | + if (entity.getType().equals(EntityType.DROPPED_ITEM)) { |
| 37 | + Item item = (Item) entity; |
| 38 | + ItemStack items = item.getItemStack(); |
| 39 | + if (items.getType().equals(Material.SWEET_BERRIES)) { |
| 40 | + if (player.getInventory().firstEmpty()!=-1) { |
| 41 | + player.getInventory().addItem(items); |
| 42 | + item.remove(); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + }.runTaskLater(PLUGIN, 1); |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments