Solved Signs just doesn't update...

Discussion in 'Plugin Development' started by IconByte, May 28, 2015.

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

    IconByte

    Hello, I am trying to make minigame with updating arena signs, but the signs just ignores update call (sign.update()).. No errors on console, the chunk is loaded where the sign is, coordinates are right too, just everything should work, but it doesn't.
    Any help? :/

    Code:
        private void updateSign(String arenaName) {
            if (getArena(arenaName.toLowerCase()) != null) {
                Arena arena = ArenaManager.getManager().getArena(arenaName);
                File signsFile = new File("plugins/" + plugin.getDescription().getName() + "/signs.yml");
                YamlConfiguration signsConfig = YamlConfiguration.loadConfiguration(signsFile);
    
                if (signsConfig.contains("signs." + arenaName.toLowerCase() + ".PreviousType") && signsConfig.contains("signs." + arenaName.toLowerCase() + ".PreviousData") && signsConfig.contains("signs." + arenaName.toLowerCase() + ".X") && signsConfig.contains("signs." + arenaName.toLowerCase() + ".Y") && signsConfig.contains("signs." + arenaName.toLowerCase() + ".Z") && signsConfig.contains("signs." + arenaName.toLowerCase() + ".World")) {
                    int X = signsConfig.getInt("signs." + arenaName.toLowerCase() + ".X");
                    int Y = signsConfig.getInt("signs." + arenaName.toLowerCase() + ".Y");
                    int Z = signsConfig.getInt("signs." + arenaName.toLowerCase() + ".Z");
                    World w = Bukkit.getWorld(signsConfig.getString("signs." + arenaName.toLowerCase() + ".World"));
    
                    Block block = w.getBlockAt(X, Y, Z);
                    if (w.getChunkAt(block).isLoaded()) {
                        if (block.getState() instanceof Sign) {
                            org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState();
                            sign.setLine(0, "ยง6[Test]");
                            sign.setLine(1, arenaName.toLowerCase());
                            if (arena.isInGame() == false) {
                                sign.setLine(2, ChatColor.translateAlternateColorCodes('&', translate("WAITING")));
                                if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) {
                                    Sign s = (Sign) block.getState();
                                    Block attachedBlock = block.getRelative(s.getAttachedFace());
                                    attachedBlock.setTypeIdAndData(Material.STAINED_CLAY.getId(), (byte) 5, true);
                                }
                            } else {
                                sign.setLine(2, ChatColor.translateAlternateColorCodes('&', translate("RUNNING")));
                                if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) {
                                    Sign s = (Sign) block.getState();
                                    Block attachedBlock = block.getRelative(s.getAttachedFace());
                                    attachedBlock.setTypeIdAndData(Material.STAINED_CLAY.getId(), (byte) 14, true);
                                }
                            }
                            sign.setLine(3, arena.getPlayers().size() + "/" + arena.getMaxPlayers());
                            sign.update();
                        }
                    }
                }
            }
        }
     
    Last edited: May 28, 2015
  2. Offline

    Agentleader1

    Code:
    sign.update();
    sign.update(true);
     
  3. Offline

    IconByte

    Tried both of them, still ignores/doesn't update the sign.
     
  4. Offline

    Agentleader1

    @IconByte Make sure to get the state of the block, and not the block itself. Or update both block and state.
     
  5. Offline

    IconByte

    On the line 16 I got the state and I am updating it on line 35 also..? I guess I am doing it right..
     
  6. Offline

    caderape

    @IconByte

    Sign s =(Sign) block.getState();
    org.bukkit.block.Sign sign=(org.bukkit.block.Sign) block.getState();

    you import the material and not the block for the fist line.
     
  7. Offline

    IconByte

    Yes, because I wanted the block behind wall_sign and/or the block below sign_post. Sign block import doesn't allow to do it, so I imported material what did it job very well.

    Okay, I got the problem. On the line 15 this if statement returns else:
    Code:
    if(block.getState()instanceof Sign){
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  8. Offline

    I Al Istannen

    @IconByte So you got the fix too? Otherwise that needs to be an instance of"org.bukkit.block.Sign".
     
  9. Offline

    IconByte

    I am getting this error: CraftSign cannot be cast to org.bukkit.material.Sign
    How should I cast it to the correct one..? :/

    Solved! I had to add .getData() after the .getState(), like so:
    Code:
    org.bukkit.material.Sign sign2 = (org.bukkit.material.Sign) block.getState().getData();
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
Thread Status:
Not open for further replies.

Share This Page