Solved Having trouble with sendBlockChange

Discussion in 'Plugin Development' started by 0ct0berBkkitPlgins, Dec 8, 2015.

Thread Status:
Not open for further replies.
  1. Hello, so I'm having some trouble getting sendBlockChange to work. What I want is to render a block as air to a certain player in my plugin. This is normally achieved with
    Code:
    (player).sendBlockChange(location, material, data);
    . Here is my code. b is a clicked block in a playerinteractevent, and p is the player. The code DOES run, as I checked to ensure all my conditions are met
    Code:
    p.sendMessage("success");
    . I've also suppressed deprecation thats caused by data still being a magic value. Yet nothing happens to the block... Can someone help? The purpose is to render one block in a wall invisible to the user, and let them walk through it like a ghost. If there is any other way of achieving this or if I need to send a packet differently, that would be fine too.

    Here is my code (Note: I tried this without chunk refresh before and nothing happened. The chunk refresh was a supposed solution I found, but it didn't solve the problem).
    Code:
                        p.sendBlockChange(b.getLocation(), Material.AIR, (byte) 0);
    
                        p.sendMessage("success");
    
                        p.getWorld().refreshChunk(p.getLocation().getChunk().getX(), p.getLocation().getChunk().getZ());
    
                          getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    
                          {
    
                            public void run() {
    
                                p.sendBlockChange(b.getLocation(), b.getType(), b.getData());
    
                                p.getWorld().refreshChunk(p.getLocation().getChunk().getX(), p.getLocation().getChunk().getZ());
    
                            }
    
                          }
    
                          , ticks);
    
                    }
    
    There are no console errors. Once again, the final code is being ran. The player receives the "success" message. "ticks" is 60.
     
    Last edited: Dec 8, 2015
  2. Offline

    mcdorli

    Your signature is perfect for this. I don't need to say anything.
     
  3. I'm confused. I said that I have tested everything and the code is being ran...?
     
  4. Offline

    mcdorli

    Console errors? BTW.: You should follow the java naming and code style conventions, don't use GNU type brackets. It doesn't make any difference, but look.
     
  5. I'm not familiar with that. Also, please note that I wouldn't make this post without following my own guidelines if that is my signature. Your posts are pointless here. If you have an answer, please say it. Telling me to follow my own regular guidelines isn't helpful.
    I would not state that there aren't console errors, because it is assumed by my signature that I would have checked that.
     
  6. Offline

    Zombie_Striker

    This is your problem. You're sending a packet that turns a block (lets say stone) into (lets say wood). After you send that, this method says "This is stone, lets make sure the player knows this is stone". Remove this line.
     
  7. Thanks for your help. However, I had tried that before... My new code is here, and it hasn't fixed the problem:
    Code:
                        p.sendBlockChange(b.getLocation(), Material.STONE, (byte) 0);
    
                        p.sendMessage("success");
    
                          getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    
                          {
    
                            public void run() {
    
                                p.sendBlockChange(b.getLocation(), b.getType(), b.getData());
    
                            }
    
                          }
    
                          , 60L);
    
                    }
    
                }
    
            }
    
        }
    
    }
    Any other ideas?
    Is there any better way to do this since it's deprecated? I think this could be done with just regular packets, but I'm a little confused on how packets work and I'm not really wanting to look through that. Once again, I'm receiving the "success" message and no errors.

    Edit: Every once and a while I'll see stone for a split second when using it. Removed the runnable to test, still had the same thing.

    Edit: @Zombie_Striker

    Turns out that right clicking the blocks was causing them to update for the player. I fixed this by making the block disappear one tick later. Now it works.
     
    Last edited: Dec 8, 2015
Thread Status:
Not open for further replies.

Share This Page