Cancelling a mega redwood grow event and creating a redwood grow event

Discussion in 'Spigot Plugin Development' started by Roree, Jun 27, 2016.

  1. Code (Java):
        @EventHandler (priority = EventPriority.MONITOR)
        public void spruceGrow(StructureGrowEvent e) {
            if (e.getSpecies() == TreeType.MEGA_REDWOOD && !e.isCancelled()) {
                e.setCancelled(true);
                //Bukkit.broadcastMessage("mega redwood");
                //Bukkit.broadcastMessage(e.getLocation().getBlockX() + "|" + e.getLocation().getBlockY() + "|" + e.getLocation().getBlockZ());
                List<BlockState> blocks = new ArrayList<BlockState>();
                blocks.add(e.getLocation().getBlock().getState());
                if (e.isFromBonemeal()) {
                    this.getServer().getPluginManager().callEvent(new StructureGrowEvent(e.getLocation(), TreeType.REDWOOD, true, e.getPlayer(), blocks));
                } else {
                    this.getServer().getPluginManager().callEvent(new StructureGrowEvent(e.getLocation(), TreeType.REDWOOD, false, e.getPlayer(), blocks));
                }
            }
        }
    My code does nothing at all, any ideas?
     
  2. You could simplify this by replacing the if/else with this:
    Code (Java):
    this.getServer().getPluginManager().callEvent(new StructureGrowEvent(e.getLocation(), TreeType.REDWOOD, e.isFromBonemeal(), e.getPlayer(), blocks));
    Anyway, did you register the class as a listener?
     
  3. Yeah I didn't think about that, and yes I did, the debug messages displayed when they weren't comments