Prevent lava to obsidian

Discussion in 'Plugin Development' started by Second_Vynder, Sep 4, 2016.

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

    Second_Vynder

    I have to prevent transform of lava to obsidian when water placed nearby of lava source. My solution is watch when bukkit will be empty and when placed water cancel this. But idk suitable names of events. Thanks for help.
     
  2. Offline

    InstanceofDeath

    idk exactely what you want:

    There is a PlayerBucketEmpty event, which returns
    Player who, Block BlockClicked, BlockFace blockFace, Material bucket, ItemStaxk itemInHand
     
  3. Offline

    HeartandSoul

    Try cancelling the BlockFormEvent
     
    Second_Vynder and Zombie_Striker like this.
  4. Offline

    Zombie_Striker

    @Second_Vynder
    To add onto what @HeartandSoul posted, that BlockFormEvent is called when a block is "formed" (water to stone, lava to obsidian, ect.). What you want to do is check if the formed block is obsidian, and if so, cancel the event.
     
    Second_Vynder likes this.
  5. Offline

    Second_Vynder

    I did so:
    Code:
        @EventHandler
        public void onObsidianForm(BlockFormEvent event) {
            if(event.getBlock().getType() == Material.OBSIDIAN)
                event.setCancelled(true);
        }
    
    But i got nothing. Lava transforms to obsidian.
     
  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    Zombie_Striker

    @Second_Vynder
    If your problem has been solved, mark this thread as solved.
     
  8. Offline

    Second_Vynder

    Offtop (open)
    @Zombie_Striker I know forum's standarts, bro. Yesterday I was not a home and didn't checked code.

    My solution isn't working. Where I am did wrongly:c
    PHP:
        @EventHandler
        
    public void onObsidianForm(BlockGrowEvent event) {
            if(
    event.getNewState().getType() == Material.OBSIDIAN)
                
    event.setCancelled(true);
        }

     
  9. @Second_Vynder
    Well, didn't we agree that the event was called BlockFormEvent, not BlockGrowEvent?
     
    timtower likes this.
  10. Offline

    Second_Vynder

    @AlvinB emm? I tried BlockFormEvent and BlockGrowEvent
    BlockFormEvent (open)

    PHP:
        @EventHandler
        
    public void onObsidianForm(BlockFormEvent event) {
            if(
    event.getBlock().getType() == Material.OBSIDIAN)
                
    event.setCancelled(true);
        }

    BlockGrowEvent (open)

    PHP:
        @EventHandler
        
    public void onObsidianForm(BlockGrowEvent event) {
            if(
    event.getNewState().getType() == Material.OBSIDIAN)
                
    event.setCancelled(true);
        }
     
  11. Offline

    ZP18

    Are you registering the listener?
     
  12. @Second_Vynder
    Well, you forgot the "getNewState()" in the BlockFormEvent one.
     
    CodePlaysMinecraft likes this.
  13. Offline

    Second_Vynder

    @AlvinB @ZP18 Still isn't working.
    Full code (open)

    PHP:
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockFormEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class 
    DisableLavaToObsidian extends JavaPlugin implements Listener{
        @
    Override
        
    public void onEnable(){
            
    Bukkit.getPluginManager().registerEvents(thisthis);
        }
        @
    Override
        
    public void onDisable(){
        
        }
        @
    EventHandler
        
    public void onObsidianForm(BlockFormEvent event) {
            if(
    event.getNewState().getType().equals(Material.OBSIDIAN))
                
    event.setCancelled(true);
        }
      
    }



    May be I need other event? Cuz this didn't working also:
    Show Spoiler

    PHP:
    import org.bukkit.Bukkit;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockFormEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class 
    DisableLavaToObsidian extends JavaPlugin implements Listener{
        @
    Override
        
    public void onEnable(){
            
    Bukkit.getPluginManager().registerEvents(thisthis);
        }
        @
    Override
        
    public void onDisable(){
           
        }
        @
    EventHandler
        
    public void onObsidianForm(BlockFormEvent event) {
                
    event.setCancelled(true);
        }
         
    }

     
    Last edited: Sep 7, 2016
  14. Offline

    timtower Administrator Administrator Moderator

  15. Offline

    ZP18

    That certainly is strange if that doesn't stop it... I think you actually have to use the BlockPhysicsEvent but I'm not 100% sure.
    Yes you should use the == operator instead of .equals() for comparing enumerations but that is not what is causing his code not to work, as he stated.

    @Second_Vynder your best hope is to try different block events, I suggest trying the BlockPhysicsEvent as well as the BlockFromToEvent


    Sent from my iPhone using Tapatalk
     
  16. Well, sure it's not their problem as of now, but it could be later.

    @Second_Vynder The best thing to do now would to check if the event is even being fired in the first place. Try to debug your code.
     
  17. Offline

    ZP18

    Yes I know it would @CodePlaysMinecraft
    Also he made just a plain listener with no checks to cancel the event every time. But it did not stop the obsidian from forming, that's why I suggested trying BlockPhysicsEvent and BlockFromToEvent


    Sent from my iPhone using Tapatalk
     
  18. Offline

    Zombie_Striker

    @Second_Vynder
    What if you try canceling BlockFromToEvent: This event is triggered when a block like water or lava moves to another block. For this, check if the block it is moving to is water, and if so, cancel the event.
     
  19. Offline

    Second_Vynder

    I got nothing again :c
    Show Spoiler

    PHP:
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockFromToEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class 
    DisableLavaToObsidian extends JavaPlugin implements Listener{
        @
    Override
        
    public void onEnable(){
            
    Bukkit.getPluginManager().registerEvents(thisthis);
        }
        @
    Override
        
    public void onDisable(){
           
        }
        @
    EventHandler
        
    public void onObsidianForm(BlockFromToEvent event) {
            
    Block target event.getToBlock();
            
    Material targetMaterial target.getType();
            if(
    targetMaterial == Material.STATIONARY_LAVA || targetMaterial == Material.LAVA){
                
    target.setType(Material.STONE);
                
    event.setCancelled(true);
            }
        }
         
    }
     
  20. Offline

    ZP18

    Have you tried the BlockPhysicsEvent?


    Sent from my iPhone using Tapatalk
     
  21. Offline

    Second_Vynder

    As I know, BlockPhysicsEvent does not works with obsidian
    My test code (open)

    PHP:
        @EventHandler(priority EventPriority.HIGHEST)
        public 
    void onObsidianForm(BlockPhysicsEvent event){
            
    Material block event.getBlock().getType();
            
    Bukkit.broadcastMessage(block.toString());
        }

    When lava transforms to obsidian, I getting nothing about obsidian in the chat (just LAVA or WATER or AIR or STATIONARY_WATER/STATIONARY lava) :c
    And getChangedType also returns STATIONARY_LAVA/STATIONARY_WATER without obsidian.
    Any suggestions, comrades?
     
  22. Offline

    ZP18

    I'll do some tests soon and let you know how I go
     
  23. Offline

    JanTuck

    But if you cancel the event wont the event happen just after again? So the server keeps firing the event? Also players with big enough water to obsidians farms could in theory lag the server?
     
  24. Offline

    Second_Vynder

    Well, when lava has to prevent to obsidian I want to replace lava source on something like stone.
     
  25. Offline

    JanTuck

    I have a project going on so i cant look into this right now but i will sdon if you cant figure it out.

    Sent from Tapatalk
     
    Second_Vynder likes this.
  26. Offline

    Second_Vynder

    I will be grateful for the help.
     
  27. Offline

    JanTuck

    I dont think there is a way to do this.
     
  28. Offline

    ZP18

    Maybe with NMS?


    Sent from my iPhone using Tapatalk
     
  29. Offline

    Whoneedspacee

    I'd say if you don't rid of the water I'd agree with this, someone try deleting the water source as soon as the event gets cancelled and see if that does anything, I'll test this when I get home but can't right now. You could also try setting the material that got turned into obsidian back into lava and see if that helps at all, that's all I can think of that might work right now.
     
  30. Offline

    JanTuck

    The thing is the event doesnt get called. It does not return anything near obsidian then it should be a lava with a specific data tag but that shouldnt be the case.

    Sent from Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page