Sign not updating

Discussion in 'Plugin Development' started by MoseMister, Sep 1, 2016.

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

    MoseMister

    Is it just me, or am I missing something?
    The sign is created but the text is not showing. I have debugged and I found out that the sign data is being set correctly (as in sign.getLine(1) even after the update). I have tried putting a delay on the setting of the lines. All the is there, but its just not updating.

    public class SignSnapshot{

    Location LOC_OF_SIGN;
    int MATERIAL;
    byte DATA;
    String LINE1, LINE2, LINE3, LINE4;

    public SignSnapshot(Sign sign){
    LOC_OF_SIGN = sign.getLocation();
    MATERIAL = sign.getType();
    DATA = sign.getData().getData();
    LINE1 = sign.getLine(0);
    LINE2 = sign.getLine(1);
    LINE3 = sign.getLine(2);
    LINE4 = sign.getLine(3);
    }

    public Location resetSign(){
    Block block = LOC_OF_SIGN.getBlock();
    block.setTypeAndData(MATERIAL, DATA, false);
    Sign sign = (Sign)block.getState();
    sign.setLine(0, LINE1);
    sign.setLine(1, LINE2);
    sign.setLine(2, LINE3);
    sign.setLine(3, LINE4);
    sign.update();
    //I have also tried 'sign.update(true)' but that doesnt work
    }
     
    Last edited: Sep 1, 2016
  2. Offline

    Zombie_Striker

    You forgot to specify which lines you are setting. Add the line number (0 through 3) to the parameters aswell.
     
  3. Offline

    MoseMister

    Sorry, it is like that on my actual computer (i had to manually copy and paste it due to the issues with my laptop at that point in time).

    P.S no errors in console, if that was a issue that i was having, eclipse would have said something as well as bukkit throwing a error. But like I said, not the case.
     
    Last edited: Sep 1, 2016
  4. Offline

    InstanceofDeath

    pls pls only name static final variables UPPERCASE.
    (java automaticly switches enums at Runtime into abstract classes with static final vars)
    Thats because most people write enum vars uppercase
     
  5. Offline

    MoseMister

    sorry its a bad habbit I got into a long time ago, been trying to break it
     
  6. @MoseMister
    Please give us the actual code you're actually using. The code posted above would not even come close to passing a compiler.
     
    bwfcwalshy likes this.
  7. Offline

    MoseMister

    Location BLOCK;
    Material MATERIAL;
    byte DATA;
    String LINE1;
    String LINE2;
    String LINE3;
    String LINE4;

    public SignSnapshot(Sign sign) {
    BLOCK = sign.getLocation();
    MATERIAL = sign.getType();
    DATA = sign.getData().getData();
    LINE1 = sign.getLine(0);
    LINE2 = sign.getLine(1);
    LINE3 = sign.getLine(2);
    LINE4 = sign.getLine(3);
    }

    @Override
    public void clearInventory(){
    return;
    }

    @Override
    public void setInventory(Location loc){
    Block block = loc.getBlock();
    if (block.getState() instanceof Sign) {
    System.out.println(
    "putting sign data on: " + LINE1 + ", " + LINE2 + ", " + LINE3 + ", " + LINE4);
    Sign sign = (Sign) block.getState();
    sign.setLine(0, LINE1);
    sign.setLine(1, LINE2);
    sign.setLine(2, LINE3);
    sign.setLine(3, "Test");
    sign.update();
    }
    }

    public void setBlock(Location loc){
    Block block = loc.getBlock();
    loc.getBlock().setType(MATERIAL);
    block.setData(DATA, false);
    setInventory(loc);
    }
     
  8. Offline

    kameronn

    @MoseMister
    In your void, is everything else working but the setting the sign? For example putting System.out.println("test") outside the if statement. Also your checking if the block is instanceof Sign, but I'm pretty sure that Wall_Sign and Sign are considered two different blocks, so make sure you sign isnt on a wall
     
  9. Offline

    MoseMister

    The setting of the sign works, its the setting of the text on the sign. I have debugged the code and it all runs (including the if statement of instanceof Sign - if you check that the state is instanceof of a sign, then it means it can be a wall sign or a standing sign). I have checked that it is actually setting into the state after the update and it does. It just seems like it doesnt update the text on the sign
     
  10. Offline

    kameronn

    @MoseMister
    well, thats really weird, I put the same exact thing you put into my idea, and it work for me, try putting the method we're your calling it
     
  11. Offline

    MoseMister

    Ok, so I have rewritten it to see if I would naturally rewrite it..... still the same issue (but setting the inventory on a furnace works fine).

    Here is the new code. (PS. with FurnaceSnapshot and SignSnapshot when I pasted them in, the format was destroyed, it lacked spaces and had 3 new lines for every 1 ... not sure why, I have tried to put them all where they were though)

    Code:
    public class BlockSnapshot {
      
        Material MATERIAL;
        MaterialData DATA;
        Location LOCATION;
      
        protected BlockSnapshot(Block block){
            MATERIAL = block.getType();
            DATA = block.getState().getData();
            LOCATION = block.getLocation();
        }
      
        protected BlockSnapshot(BlockState state){
            MATERIAL = state.getType();
            DATA = state.getData();
            LOCATION = state.getLocation();
        }
      
        public Material getMaterial(){
            return MATERIAL;
        }
      
        public MaterialData getData(){
            return DATA;
        }
      
        public Location getLocation(){
            return LOCATION;
        }
      
        public Block placeBlock(){
            return placeBlock(LOCATION);
        }
      
        @SuppressWarnings("deprecation")
        public Block placeBlock(Location loc){
            return placeBlock(loc, DATA.getData());
        }
      
        @SuppressWarnings("deprecation")
        public Block placeBlock(Location loc, byte data){
            Block block = loc.getBlock();
            block.setType(MATERIAL);
            block.setData(DATA.getData(), false);
            if(this instanceof InventoryBlockSnapshot){
                ((InventoryBlockSnapshot)this).setInventory(loc);
            }
            return block;
        }
      
        public static class SpecialSnapshot extends BlockSnapshot {
    
            protected SpecialSnapshot(Block block) {
                super(block);
            }
          
            protected SpecialSnapshot(BlockState block) {
                super(block);
            }
          
        }
      
        public interface InventoryBlockSnapshot{
            public void setInventory(Location loc);
            public void clearInventory();
        }
      
        public static BlockSnapshot createSnapshot(Block block){
            return createSnapshot(block.getState());
        }
      
        public static BlockSnapshot createSnapshot(BlockState state){
            if(state instanceof Furnace){
                return new FurnaceSnapshot((Furnace)state);
            }else if(state instanceof Sign){
                return new SignSnapshot((Sign)state);
            }else{
                return new BlockSnapshot(state);
            }
        }
    
    }
    
    Code:
    public class FurnaceSnapshot extends SpecialSnapshot implements BlockSnapshot.InventoryBlockSnapshot{
    
      ItemStack FUEL, RESULT, ITEM;
    
      public FurnaceSnapshot (Furnace state){
        super(state);
        FurnaceInventory inv = state.getInventory();
        FUEL = inv.getFuel();
        RESULT = inv.getResult();
        ITEM = inv.getSmelting();
      }
    
      @Override
      public void setInventory (Location loc){
        BlockState state = loc.getBlock().getState();
        if(state instanceof Furnace){
          Furnace furnace = (Furnace)state;
          FurnaceInventory inv = furnace.getInventory();
          inv.setFuel(FUEL);
          inv.setResult(RESULT);
          inv.setSmelting(ITEM);
        }
      }
    
      @Override
      public void clearInventory(){
        BlockState state = LOCATION.getBlock().getState();
        if(state instanceof InventoryHolder){
          InventoryHolder holder = (InventoryHolder)state;
          holder.getInventory().clear();
        }
      }
    }
    
    Code:
    public class SignSnapshot extends SpecialSnapshot implements BlockSnapshot.InventoryBlockSnapshot{
    
      String LINE1, LINE2, LINE3, LINE4;
    
      public SignSnapshot(Signstate){
        super(state);
        LINE1 = state.getLine(0);
        LINE2 = state.getLine(1);
        LINE3 = state.getLine(2);
        LINE4 = state.getLine(3);
      }
    
      @Override
      public void setInventory(Locationloc){
        System.out.println("sign set inventory");
        BlockState state=loc.getBlock().getState();
        if(state instanceof Sign){
          System.out.println("state instanceof sign");
          Sign sign = (Sign)state;
          sign.setLine(0, LINE1);
          sign.setLine(1, LINE2);
          sign.setLine(2, LINE3);
          sign.setLine(3, LINE4);
          sign.update();
        }
      }
    
      @Override
      public void clearInventory(){
      }
    }
    
     
  12. @MoseMister Youre changing your code but not changing the bad habits, you say you are trying to break it but the names are still the same yet other code is being changed. Maybe you should try a bit harder to break that habit. Just a thought.
     
    Zombie_Striker likes this.
  13. Offline

    MoseMister

    Thanks. I have actually been typing it lowercase in the rest of the code. Still doesnt fix the issue though
     
  14. Offline

    MoseMister

    I found the issue ... sort of. The code works fine in Minecraft 1.9.4, however after building a brand new version of craftbukkit 1.10.2 the signs still didn't work, so it seems to be a issue on the craftbukkit side more then anything. Is there a new way to modify signs that I don't know about?
     
  15. Offline

    Zombie_Striker

    @MoseMister
    Since the methods are not deprecated, that should still be the way to change signs.

    Can you change the signs to some other string? Try replacing "LINE1" with "Test". If that fixes it, your issue is that the LINES are broken. If not, then try using Player.sendSignChage() to send the change. If that still does not work, the packet for sign change has been broken. If it fixes your problem, your setLine methods are broken.
     
  16. @MoseMister I have no research on this topic, however I did look into it a long time ago. I would recommend looping through all players and sending a sing change if all else fails.
     
  17. Offline

    MoseMister

    I can not change the line to anything. Im yet to test Player.sendSignChange however i really dont want to, due to the fact when a player connects it will not show, not only that but when checking for the sign again i need to check if the plugin has sent the player the lines or something a long those lines.

    Due to the fact it works on 1.9.4 (the exact same code) i doubt that my setLine method code is broken and it is probably something to do with Bukkit, im yet to test someone else code that sets sign lines without the SignChangeEvent to make sure 100% that its not just me, but like I said, its doubtful that thats the case

    @TheEnderCrafter9 thanks for the suggestion but @Zombie_Striker already suggested it (just above your comment) and like I said in the paragraph above, I really dont want to do it that way
     
Thread Status:
Not open for further replies.

Share This Page