Skip to content

Commit 8972a5e

Browse files
committed
We want to not drop just the seeds.
1 parent 2eded79 commit 8972a5e

File tree

3 files changed

+26
-119
lines changed

3 files changed

+26
-119
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = "com.github.sarhatabaot.farmassistreboot"
10-
version = "1.4.7"
10+
version = "1.4.8.1"
1111

1212
dependencies {
1313
compileOnly(libs.spigot.api)

build.gradle.kts~

-118
This file was deleted.

src/main/java/com/github/sarhatabaot/farmassistreboot/listeners/BlockBreakListener.java

+25
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
package com.github.sarhatabaot.farmassistreboot.listeners;
22

3+
import com.cryptomorin.xseries.XMaterial;
34
import com.github.sarhatabaot.farmassistreboot.Crop;
45
import com.github.sarhatabaot.farmassistreboot.FarmAssistReboot;
56
import com.github.sarhatabaot.farmassistreboot.Util;
67
import com.github.sarhatabaot.farmassistreboot.messages.Debug;
78
import com.github.sarhatabaot.farmassistreboot.messages.Permissions;
9+
import org.bukkit.Location;
810
import org.bukkit.Material;
11+
import org.bukkit.World;
912
import org.bukkit.block.Block;
1013
import org.bukkit.block.data.Ageable;
1114
import org.bukkit.entity.Player;
1215
import org.bukkit.event.EventHandler;
1316
import org.bukkit.event.EventPriority;
1417
import org.bukkit.event.Listener;
1518
import org.bukkit.event.block.BlockBreakEvent;
19+
import org.bukkit.inventory.ItemStack;
1620
import org.jetbrains.annotations.NotNull;
1721

22+
import java.util.ArrayList;
23+
import java.util.Collection;
24+
import java.util.stream.Collectors;
25+
1826
public class BlockBreakListener implements Listener {
1927
private final FarmAssistReboot plugin;
2028

@@ -65,6 +73,17 @@ private boolean hasMaterialPermission(@NotNull BlockBreakEvent event) {
6573
return event.getPlayer().hasPermission(Permissions.BASE_PERMISSION + event.getBlock().getType().name());
6674
}
6775

76+
public void dropItemsNaturally(Location location, Collection<ItemStack> items) {
77+
World world = location.getWorld();
78+
if (world == null) return;
79+
80+
for (ItemStack item : items) {
81+
if (item == null || item.getType() == Material.AIR) continue;
82+
world.dropItemNaturally(location, item);
83+
}
84+
}
85+
86+
6887
private void applyReplant(@NotNull BlockBreakEvent event) {
6988
final Material material = event.getBlock().getType();
7089
final Player player = event.getPlayer();
@@ -77,6 +96,12 @@ private void applyReplant(@NotNull BlockBreakEvent event) {
7796
}
7897

7998
if (Util.checkNoDrops(player)) {
99+
final XMaterial seed = Crop.valueOf(material.name()).getSeed();
100+
final Collection<ItemStack> items = event.getBlock().getDrops().stream()
101+
.filter(itemStack -> itemStack.getType() != seed.get())
102+
.collect(Collectors.toList());
103+
104+
dropItemsNaturally(event.getBlock().getLocation(), items);
80105
event.setDropItems(false);
81106
}
82107

0 commit comments

Comments
 (0)