Problem by updating a sign

Discussion in 'Spigot Plugin Development' started by goebel123, May 4, 2015.

  1. Hello peeps,
    currently I'm trying to update a sign by a normal java method. The method gets fired by the SignChangeEvent.
    Here's the code:
    Code (Text):
        public void onSignChange(SignChangeEvent e) {
            Player p = e.getPlayer();
            if (e.getLine(0).equalsIgnoreCase("kostenlos")) {
                if (p.hasPermission(freesigns.getConfig().getString("freesigns.permissions.erstellen"))) {
                    int maxvalue = Integer.parseInt(freesigns.getConfig().getString("freesigns.signs.maxvalue"));
                    maxvalue = maxvalue +1;
                    freesigns.getConfig().set("freesigns.signs.maxvalue", maxvalue);
                    Double x = e.getBlock().getLocation().getX();
                    Double y = e.getBlock().getLocation().getY();
                    Double z = e.getBlock().getLocation().getZ();
                    freesigns.getConfig().set("freesigns.signs." + maxvalue + ".locs.x", x);
                    freesigns.getConfig().set("freesigns.signs." + maxvalue + ".locs.y", y);
                    freesigns.getConfig().set("freesigns.signs." + maxvalue + ".locs.z", z);
                    String id = e.getLine(1);
                    freesigns.getConfig().set("freesigns.signs." + maxvalue + ".itemId", id);
                    freesigns.getConfig().set("freesigns.signs." + maxvalue + ".loaded", false);
                    freesigns.getConfig().set("freesigns.signs." + maxvalue + ".paused", false);
    And the method:
    Code (Text):
    public void reloadSignsList() {
            int maxvalue = Integer.parseInt(this.getConfig().getString("freesigns.signs.maxvalue"));
            Sign sign = null;
            if (maxvalue != 0) {
                for (int i = 1; i <= maxvalue; i++) {
                    if (!this.getConfig().getBoolean("freesigns.signs." + i + ".loaded")) {
                        if (!this.getConfig().getBoolean("freesigns.signs." + i + ".paused")) {
                            Double x = Double.parseDouble(this.getConfig().getString("freesigns.signs." + i + ".locs.x"));
                            Double y = Double.parseDouble(this.getConfig().getString("freesigns.signs." + i + ".locs.y"));
                            Double z = Double.parseDouble(this.getConfig().getString("freesigns.signs." + i + ".locs.z"));
                            Location loc = new Location(Bukkit.getWorld(this.getConfig().getString("freesigns.defaultworld")), x, y, z);
                            Block b = loc.getBlock();
                            if (b.getState() instanceof Sign) {
                                sign = (Sign) loc.getBlock().getState();
                                sign.setLine(0, "§0[§cKostenlos§0]");
                                sign.setLine(1, ChatColor.RED + this.getConfig().getString("freesigns.signs." + i + ".itemId"));
                                this.getConfig().set("freesigns.signs." + i + ".loaded", true);
                    } else {
                        System.out.println("Schild " + i + "bereits geladen, daher übersprungen.");
            } else {
                System.err.println("Keine Schilder vorhanden, daher wurde die SignsList nicht gereloaded.");
    I guess you already saw the debug code, so here is the consolelog:
    And finally the plugin config:
    The problem is that the sign doesn't update its text. I'm using the 1.8 Spigot version, however the version ain't the problem, cause another pl does update the signs well. I also tried to use sign.update(true); or b.getState().update(); etc. I hope you can help me solving this bug.
  2. Vik1395


    Code (Text):
    Try using the command on top before and after you change the lines. What does it print?
  3. after changing it says the same stuff like above and before "kostenlos"
  4. have you tried doing something like:

    Code (Text):
    new BukkitRunnable() {
        public void run() {
    (ofc, you need to replace "this.plugin" with your plugin's instance)
    instead of just doing:

    Code (Text):

    my guess is you tried to run
    Code (Text):
    but after you invoke that, onSignChagne() method finishes and sign information that is held in SighChangeEvent (e) will be used to update the sign again... so you put the original sign back on the sign..

    So, what I put up there is to schedule
    Code (Text):
    to be executed after onSignChange() method is completed.
  5. Vik1395


    If it is just one line that you need to change, you can try returning that particular string to the onSignChangeEvent and then just use
    Code (Text):
    e.setLine(1, newstring);
    Its also safer to use ChatColor.x instead of §x