Fix other grow states

This commit is contained in:
Leon Grünewald 2025-03-29 12:24:13 +01:00
parent 4382a0e9b0
commit 76b4c17f57
2 changed files with 17 additions and 1 deletions

View file

@ -31,15 +31,17 @@ public class BlockSpreadEventListener implements Listener {
@EventHandler
public void onBlockSpread(BlockSpreadEvent e) {
// log.info("BlockSpreadEvent: " + e.getBlock().getType().name());
switch (e.getSource().getType()) {
case Material.KELP:
this.onKelpSpread(e);
break;
case Material.BAMBOO:
case Material.BAMBOO_SAPLING:
this.onBambooSpread(e);
break;
default:
log.info("BlockSpreadEvent: Source " + e.getSource().getType());
// log.info("BlockSpreadEvent: Source " + e.getSource().getType());
break;
}
}

View file

@ -1,4 +1,6 @@
package de.doggoat.growableRebalance.listeners;
import de.doggoat.growableRebalance.PlantUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
@ -6,6 +8,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.plugin.java.JavaPlugin;
import java.lang.reflect.Array;
import java.util.logging.Logger;
import java.util.Arrays;
import java.util.List;
@ -25,6 +29,16 @@ public class GrowthEventListener implements Listener {
@EventHandler
public void onStructureGrow(StructureGrowEvent e) {
Player p = e.getPlayer();
Location ground = PlantUtils.getSingleBlockGround(e.getLocation());
if (unreplaceableBlocks.contains(ground.getBlock().getType())) {
e.setCancelled(true);
if (p != null) {
p.sendMessage("You cannot grow " + e.getLocation().getBlock().getType() + " on " + ground.getBlock().getType());
}
return;
}
List<BlockState> forbiddenBlocks = e.getBlocks().stream()
.filter(blockState -> unreplaceableBlocks.contains(blockState.getBlock().getType()))
.filter(blockState -> dirtBlocks.contains(blockState.getType()))