Editing Signs

Discussion in 'Plugin Development' started by henne90gen, Jun 30, 2012.

  1. Offline

    henne90gen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Hi everyone!

    I want to edit the text of a sign.
    Basicly I have the coords and the world of a sign in a HashMap.

    So now I want to check if the block at that coords is a sign and then write something on it.
    Can I also check whether the row is at an end?

    Please Help!
  2. Online

    Jacek BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    First get the block and it's state

    Code:
    Block block = world.getBlockAt(x, y, z);
    BlockState state = block.gteState();
    Then to see if it's a sign

    Code:
    if (state instanceof Sign){
        Sign sign = (Sign) state;
    }
    You then have sign.getLines() which will get all 4 lines and sign.getLine(int) which will get a specific lines, there are also corresponding set*() methods :)
  3. Offline

    henne90gen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Is the "world" in
    Code:
    Block block = world.getBlockAt(x, y, z);
    
    the worldname?

    This post has been edited 1 time. It was last edited by henne90gen Jun 30, 2012.
  4. Online

    Jacek BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    No that would just be a string :? It's the world object.
  5. Offline

    henne90gen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I saved only the Worldname into the hashmap can I use that too?
  6. Online

    Jacek BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    You can get the world from that

    Code:
    World world = Bukkit.getServer().getWorld(worldName);
  7. Offline

    henne90gen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Thanks alot I test it.
  8. Offline

    henne90gen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    So another problem occures.

    I thought my code is correct so I tested it. But When I use the command to set the Line of a sign it didnt work! There was nothing to see onto the sign but there is also no error in the console or something like that.

    Here the code:
    Code:
    public boolean ExecuteCmd(Player p, String cmd, String[] args) {
    if (cmd.equalsIgnoreCase("set")){
    StringBuilder news = new StringBuilder();
    for(int i = 1; i < args.length; i++)
                {
                    if(i > 1)
                        news.append(" ");
                    news.append(args[i]);
                }
    String newschecked = news.toString();
    if (newschecked == null) {
    p.sendMessage("Aufschrift kann nicht leer sein!");
    p.sendMessage("Korrekte Verwendung: /signnews set [Aufschrift]");
    } else if (newschecked != null) {
     
    String SignName = "Sign";
    int length = 4;
    for (int i = 0; length < plugin.signs.get(SignName).length; i++) {
    SignName = "Sign" + i;
    }
     
    String[] SignArguments = {plugin.signs.get(SignName)[0], plugin.signs.get(SignName)[1], plugin.signs.get(SignName)[2], plugin.signs.get(SignName)[3], newschecked};
    plugin.signs.put(SignName, SignArguments);
     
    //Koordinaten aus der Hashmap
    int x = new Double(SignArguments[0]).intValue();
    int y = new Double(SignArguments[1]).intValue();
    int z = new Double(SignArguments[2]).intValue();
     
    //Weltname aus der Hashmap in eine Welt umwanden
    World world = Bukkit.getServer().getWorld(plugin.signs.get(SignName)[3]);
     
    //Auf Sign überprüfen
    Block b = world.getBlockAt(x, y, z);
    BlockState state = b.getState();
     
    if (state instanceof Sign) {
    Sign sign = (Sign) state;
    sign.setLine(2, newschecked);
    p.sendMessage("Schild erfolgreich beschriftet!");
     
    } else {
    p.sendMessage("Der Block ist kein Schild!");
    }
    }
    return true;
    }
    return false;
    }
    
    I dont know what to do.

    Please Help!
  9. Offline

    henne90gen

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Does nobody know why that doesnt work???
  10. Offline

    ferrybig

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    you never updating the sign whit BlockState.update();
    yes, you using a block state inside you code

Share This Page