Plant Growth Limitation

Discussion in 'Archived: Plugin Requests' started by Le PHeel, May 24, 2013.

  1. Offline

    Le PHeel

    Is it possible to design a plugin that prevents crops from growing if there are blocks above them? I want a plugin for my server that limits the ability to grow crops unless their is only air above them. The reason for this is that I don't want players to be able to build tiers of farms on top of each other or underground farms, since it doesn't make sense that crops grow without sunlight. I figured the easiest way to limit the capability would be to implement some system in which crops can only grow if there is no block above them.
    I was just wondering if this (or a similar functionality that would accomplish my goal) was possible, and if so, if someone could undertake the project or direct me to something that would accomplish the same function.

    Thank you!
     
  2. Offline

    C0nsole

    Working on this now.

    Here it is.
    If you ever need any updates or anything, PM me. Also, I have not tested this at all so it might not work :p
    Source
    Code:java
    1. package me.C0nsole.NoUndergroundGrowth;
    2.  
    3. import org.bukkit.Location;
    4. import org.bukkit.World;
    5. import org.bukkit.block.Block;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.BlockGrowEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class NoUndergroundGrowth extends JavaPlugin implements Listener{
    12.  
    13. @Override
    14. public void onDisable() {
    15. System.out.println("[NoUndergroundGrowth] v1.0 enabled");
    16. }
    17.  
    18. @Override
    19. public void onEnable() {
    20. System.out.println("[NoUndergroundGrowth] v1.0 disabled");
    21. }
    22.  
    23. @EventHandler
    24. public void onBlockGrow(BlockGrowEvent event){
    25. Block block = event.getBlock();
    26. World world = block.getWorld();
    27. Location loc = block.getLocation();
    28. double y = loc.getY();
    29. double highesty = world.getHighestBlockYAt(loc);
    30. if(highesty > y){
    31. event.setCancelled(true);
    32. }
    33. }
    34.  
    35. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016

Share This Page