Preventing blocks from being destroyed and replacing them..

Discussion in 'Plugin Development' started by CDMV2, Jan 15, 2012.

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

    CDMV2

    [FORMATTED]

    Thanks to other's member's help I've fixed the blocks spawning in Air and Liquid but now when I someone type /lumos again, I managed to make it so the block disappears, how could I make it so that it out place the old one back?

    Also, sorry btw ;), is there any way I could prevent the player from destroying the block?
     
  2. Offline

    Raeon

    PHP:
    if(underblock.getTypeId() != 0)
    {

    }

    If that's not good enough simply make a for-loop that decreases the Y value, checks if that block isn't air, and turns that block into glowstone instead.

    ~ Raeon
     
  3. Offline

    CDMV2

    Thanks but where do I put that?
     
  4. Offline

    Raeon

    Right under
    PHP:
    Block underblock player.getLocation().getBlock().getRelative(BlockFace.DOWN);
    in the onPlayerMove method, in your player listener.

    ~ Raeon
     
  5. Offline

    CDMV2

    Thanks, works now :) now though, when I type /lumos again I got the glowstone to disappear but who do you make it so the old block appears again?
     
  6. Offline

    randomman159

    Just store the block info before it is replaced with glowstone then when the glowstone moves or lumos is diactivated, it returns the block to how it was before.
     
  7. Offline

    CDMV2

    Lol how?
     
  8. Please don't post all of your classes. No offence but whenever I see someone I do this I just close the tab. You will get much better help if you take some time to format your post. Find the code causing the issue and post that instead of your whole project ;)
     
    CDMV2 likes this.
  9. Offline

    MrMag518

    You need to check if the block under the player is air or liquid, I am on mu phone so I cant give an example atm..
     
  10. Offline

    CDMV2

    Okay, sorry, I didnt even think of that :p

    It's cool thanks, I've fixed it but thanks anyway:)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  11. Code:
    player.sendBlockChange(Location loc, Material material, byte data)
    to set the block

    and
    Code:
    player.sendBlockChange(oldLoc, loc.getBlock().getType(),loc.getBlock().getData())  
    to return the block to its orginal state?
     
Thread Status:
Not open for further replies.

Share This Page