Angel Ernesto Rangel Hernandez

Create a plugin that automatically plants a sapling after a tree is cut down.

Kodari AI
KodariOct 7 at 11:53 am 1
AutoReforestation
Automatically plants a sapling whenever a tree is chopped down. Listens for tree-felling events, detects the tree type, and spawns the corresponding sapling at the felled location. Configurable to require an axe, respect player permissions, and toggle per-world. Includes cooldown prevention to avoid replanting in the same spot repeatedly, and supports all vanilla tree species including oak, spruce, birch, jungle, acacia, and dark oak.
  • Add the plugin entry point and listener.

  • Detect the tree’s base log and map its species to the matching sapling.

  • Replant one tick after the break, only if the spot is still empty and the soil is suitable.

Created SaplingReplant. It replants the matching sapling or mangrove propagule after the base log is broken, provided the spot is still empty and the ground is suitable.

Kodari can make mistakes. Review important code before using.
Files
src
Code
3 88
src/main/java/com/kodari/saplingreplant/SaplingReplantPlugin.java
package com.kodari.saplingreplant;

import org.bukkit.plugin.java.JavaPlugin;

public final class SaplingReplantPlugin extends JavaPlugin {
    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(new TreeReplantListener(this), this);
    }
}