Skip to content

Commit

Permalink
feat: block spread event for optimize-growable-farms like bamboo
Browse files Browse the repository at this point in the history
  • Loading branch information
alvindimas05 committed Jan 18, 2025
1 parent 6aeba13 commit 3aa5914
Showing 1 changed file with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.player.PlayerInteractEvent;

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -57,17 +58,27 @@ private static void runTask() {
private static final List<BlockFace> growablefaces = Arrays.asList(BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH,
BlockFace.SOUTH, BlockFace.DOWN, BlockFace.UP);

@EventHandler(priority = EventPriority.HIGHEST)
public void onGrowableGrow(BlockGrowEvent e) {
public <T> void onGrowableGrow(T e) {
if (!Main.config.getBoolean("microfeatures.optimize-growable-farms.enable")) {
return;
}

if (e.isCancelled()) {
return;
BlockState b = null;
if(e instanceof BlockGrowEvent){
if (((BlockGrowEvent) e).isCancelled()) {
return;
}

b = ((BlockGrowEvent) e).getNewState();
}
if(e instanceof BlockSpreadEvent){
if (((BlockSpreadEvent) e).isCancelled()) {
return;
}

BlockState b = e.getNewState();
b = ((BlockSpreadEvent) e).getNewState();
}
assert b != null;

Material mat = b.getType();

Expand Down Expand Up @@ -95,6 +106,16 @@ public void onGrowableGrow(BlockGrowEvent e) {

}

@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockGrow(BlockGrowEvent e) {
onGrowableGrow(e);
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockSpread(BlockSpreadEvent e) {
onGrowableGrow(e);
}

private static Map<Player, Integer> intervals = new WeakHashMap<>();

@EventHandler(priority = EventPriority.HIGHEST)
Expand Down

0 comments on commit 3aa5914

Please sign in to comment.