Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-3180

BlockState.update(true,true); not re-applying special block data

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Minor Minor
    • None
    • None

      Step 1: Save the BlockState of a non-blank Sign to a variable

      Step 2: Set the sign block to stone or glass or something

      Step 3: Call the update method on the saved BlockState object and use the force flag

       

      Result expected: The block becomes a sign again and the lines it had are restored

      Result that occurs: The block becomes a sign again but is blank

       

      Code used to test:

      Player player = (Player)sender;
      Block targetBlock = player.getLocation().getBlock().getRelative(BlockFace.NORTH,2);
      targetBlock.setType(Material.SIGN_POST);
      Sign newSign = (Sign)targetBlock.getState();
      newSign.setLine(0, "Test Sign");
      newSign.update(true,true);
      sender.sendMessage(" Placed sign with text.");
      new BukkitRunnable(){public void run(){
         if(targetBlock.getType()==Material.SIGN_POST){
            BlockState oldState = targetBlock.getState();
            targetBlock.setType(Material.GLASS);
            sender.sendMessage(" Overwrote sign with glass.");
            new BukkitRunnable(){public void run(){
               boolean result = oldState.update(true,true);
               sender.sendMessage(" Restored "+oldState.getClass().getSimpleName()+". Update result == "+result);
               BlockState newState = targetBlock.getState();
               if(oldState instanceof Sign && newState instanceof Sign){
                  String[] oldLines = ((Sign)oldState).getLines();
                  String[] newLines = ((Sign)newState).getLines();
                  for(int i = 0; i < 4; i++){
                     sender.sendMessage(" [Line "+(i+1)+"] old: \""+oldLines[i]+"\" new: \""+newLines[i]+"\"");
                  }
               }
            }}.runTaskLater(plugin, 20*3);
         }
      }}.runTaskLater(plugin, 20*3);
      

      Additional Notes:

      • Affects other BlockState types (like chests), not just signs
      • Occurs even without using scheduled tasks
      • Might be related to SPIGOT-1511

      Debug messages from example code:

       

            Unassigned Unassigned
            iPyronic iPyronic
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: