Chancel Lightlevel Harvest

Discussion in 'Plugin Development' started by Scipione, Jan 20, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Scipione

    Is there any event or possibility to track if a wheat got dropped because the light level was reduces ?

    Thanks for reply :)
     
  2. Offline

    Craftiii4

    I think I get what you mean, I guess play around with the onStructureGrow, onBlockGrow, onBlockFade & OnBlockFromTo events.
     
  3. Offline

    Scipione

    Hm .. thanks for your proposals, but it doesn't in those events is anything i coudl use.
    To be more specific:

    Players are harvesting Wheat as they are removing the torches at night, causing it to drop because of a "too low light level".
    But we are a roleplay server and only farmers can harvest wheat (or mushroom etc..), so they kinda abuse this and i'm currently searching a way to prevent this.

    i'll take any suggestions (;

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  4. Offline

    Craftiii4

    Maybe look into factions code, because I think it has something to prevent this. Not sure though.
     
  5. Offline

    Scipione

    So, i did take a look at the factions code, but they only block player who wanna harvest with water bucket.
    Just to make it more clear, i need to chancel the following:

    Harvest mushrooms with placing torches besides them
    Harvest wheat with destroying torches and reducing light level
    Harvest sugar cain with removing their watersource

    i'll take any suggestions (;

    noone ? i don't need them to stay in place, removing the drop would be enough

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  6. Offline

    Scipione

    lil bump
     
  7. Offline

    RealDope

    Maybe something with ItemSpawnEvent and checking if a nearby torch has recently been broken?
     
  8. Offline

    Scipione

    i'll check that (i'm unsure if i have already or not .. ^^ checked many events) Thanks for your suggestion :)

    alright, got it, thanks (no idea y i forgot ItemSpawnEvent Oo)
    if anyone else is trying:
    Code:java
    1.  
    2. @EventHandler(priority = EventPriority.NORMAL)
    3. public void onItemSpawn(ItemSpawnEvent event) {
    4.  
    5. Entity entity = event.getEntity();
    6.  
    7. if(event.getEntityType() != EntityType.DROPPED_ITEM)
    8. return;
    9.  
    10. Item rawItem= event.getEntity();
    11.  
    12.  
    13. String item = rawItem.getItemStack().getType().name();
    14.  
    15. if(item.equalsIgnoreCase("WHEAT")){
    16. Block block = event.getEntity().getLocation().getBlock();
    17. int lightlevel = block.getLightLevel();
    18.  
    19. if(lightlevel < 9){
    20. event.getEntity().remove();
    21. event.setCancelled(true);
    22. return;
    23. }
    24. }
    25. if(item.equalsIgnoreCase("SEEDS")){
    26. Block block = event.getEntity().getLocation().getBlock();
    27. int lightlevel = block.getLightLevel();
    28. if(lightlevel < 9){
    29. event.getEntity().remove();
    30. event.setCancelled(true);
    31. return;
    32. }
    33. }
    34. if(item.equalsIgnoreCase("BROWN_MUSHROOM")){
    35. Block block = event.getEntity().getLocation().getBlock();
    36. int lightlevel = block.getLightLevel();
    37. if(lightlevel > 12){
    38. event.getEntity().remove();
    39. event.setCancelled(true);
    40. return;
    41. }
    42. }
    43. if(item.equalsIgnoreCase("RED_MUSHROOM")){
    44. Block block = event.getEntity().getLocation().getBlock();
    45. int lightlevel = block.getLightLevel();
    46. if(lightlevel > 12){
    47. event.getEntity().remove();
    48. event.setCancelled(true);
    49. return;
    50. }
    51. }
    52. }
    53.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
Thread Status:
Not open for further replies.

Share This Page