Set air without sign drop

Discussion in 'Plugin Development' started by AnAwesomeGuy, Oct 25, 2014.

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

    AnAwesomeGuy

    hey so i have been trying to remove a sign block by setting air at it's location. But then it drops the sign instead of removing it. Is there any way of removing a sign by having it's location, and knowing that there is a sign there? i used
    Code:
    Location ls = new Location(world, x, y, z);
    ls.getBlock().setType(Material.AIR);
    world, x, y and z are already defined.
     
  2. Offline

    tovd1234

    You can do it outside of your Plugin easisly (If you have Essentials). Place a block with a sign on it, then use /stoplag and remove the block behind the sign. Once you use /stoplag -c everything will be normal and the sign won't drop (Unless you update it).

    I'm sure you can edit if signs drop or not though.
     
  3. Offline

    AnAwesomeGuy

    No, i don't want my plugin to depend on essentials. And i think that i have to tell the plugin that it's removing a sign. But i don't know how to cast the sign to the location. maybe something like this
    Code:
    Sign sign = (Sign)ls.getBlock();
    sign.setType(Material.AIR);
    But it tells me that it can't cast it.
     
  4. Offline

    RingOfStorms

    That would make the sign turn to air? That is not the goal is it?

    And to set an adjacent block to air and have the sign remain you'll need to set the block to air without physics.

    Code:
    block.setTypeId(0, false);
    
     
  5. Offline

    AnAwesomeGuy

    My goal is to remove the sign without having it drop. The problem with the code i tried above is that it can't be casted to sign.
    Code:
    Sign sign = (Sign) ls.getBlock();
    
    And the
    Code:
    block.setTypeId(0, false);
    
    still makes it drop.
     
  6. Offline

    RingOfStorms

    Oh so you just want to turn the sign itself to air. It is as easy as setting any block to air.

    Code:
    sign.getLocation().getBlock().setType(Material.AIR);
    
    Do note that a Sign is NOT a block. It is a block state. You should really look up what things are in the javadocs rather than blindly guessing that something is a Block. You can find the documentation here.
     
  7. Offline

    AnAwesomeGuy

    1: Yeah forgot to write getState(), thanks for pointing that out.

    2: I don't have a sign, i only have the location of the sign. So i tried to cast it. It can't do that. But when i set air at the location, it drops the sign. So i thought that maybe if i told bukkit that it was removing a sign it would not drop it.
     
  8. Offline

    nopvpgamer

    Location ls = //Your location
    Sign sa = (Sign)ls.getBlock();
    sa.getType().compareTo(Material.AIR);

    Code:java
    1. Location ls = //Your location
    2. Sign sa = (Sign)ls.getBlock();
    3. sa.getType().compareTo(Material.AIR);


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

    mythbusterma

    nopvpgamer

    Did you even read the thread....like at all? You just did EXACTLY what the post three posts above you said not to do. Furthermore, your code does nothing, and has terrible names. Try again.
     
    AnAwesomeGuy likes this.
  10. Offline

    AnAwesomeGuy

    THANKS, can you help me? This code has been bugging me for quite some time now.
     
  11. Offline

    mythbusterma

    AnAwesomeGuy

    You could tey getting the state of the block, setting the state to air, and then updating the state.
     
  12. Offline

    AnAwesomeGuy

    I'm not sure i'm following along. Can you please explain it a bit further?
    Cause what i'm getting from your message is that i should get the state of the block
    Code:
    BlockState b = ls.getBlock().getState();
    I can't use Block since it would require me to cast ls.getBlock().getState(); to Block, which isn't possible. Then set the state to air
    Code:
    b.setType(Material.AIR);
    and then updating the state.
    Code:
    b.update
    But that still drops the sign.

    I also tried this, but it still drops
    Code:
    Block b = (Block)ls.getBlock();
    b.getState().setType(Material.AIR);
    b.getState().update();
     
  13. Offline

    mythbusterma

    AnAwesomeGuy

    I'm not sure if this will work but:

    Block#getState().setType(Material.Air).update()

    Alternatively, you just listen for the sign dropping (ItemDropEvent I believe) and cancel the event.
     
  14. Offline

    AnAwesomeGuy

    You can't put .update() at last. Yes i know i could listen for it, but that would cancel all the other signs that gets dropped, which i don't want.
     
  15. Offline

    mythbusterma

    AnAwesomeGuy

    Sorry, that was my mistake, it should be:

    BlockState state = Block#getState();
    state.setType(Material.AIR);
    state.update();

    And not neccessarily, you would have it listen for when you drop it, and only when the plugin breaks it cancel it.
     
  16. Offline

    CraftCreeper6

    AnAwesomeGuy
    Create a boolean. Set it to true when you set the sign as air. After a tick set it to false.
    Create an ItemDropEvent. If the item is a sign & the boolean value is true. Cancel the drop.
     
  17. Offline

    AnAwesomeGuy

    Thanks CraftCreeper6 & mythbusterma :)
    This is my code for reference.
    Outside of the void
    Code:
    boolean sd = false;
    In my void that i will call at some point.
    Code:
    Location l = new Location(world, x, y, z);
    sd = true
    Block b = l.getBlock();
    b.setType(Material.AIR);
    new BukkitRunnable() {
        @Override
        public void run() {
            sd = false;
        }
    }.runTaskLater(main.plugin, 1);
    And then i have the itemspawnevent.
    Code:
    @EventHandler
    public void onItemDrop(ItemSpawnEvent e) {
        if(spawn.getmanager().sd == true) {
            e.setCancelled(true);
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page