Solved Blank sign

Discussion in 'Plugin Development' started by sudoman281, Jul 30, 2016.

Thread Status:
Not open for further replies.
  1. I am trying to make plugin, that will allow you to copy sign. Copying text to my variables is ok, but problem is pasting it on another sign. I have read a lot of articles so I tried to do delayed task onSignChange, but still not working :/ Here is my code: http://pastebin.com/h6LL0eG1. What is happening recorded here:
     
  2. Offline

    Zombie_Striker

    @sudoman281
    These are global variables, meaning when one player tried to copy a sign, every single player on the server can copy the sign as well. This also means that there can only be one player and one sign that can be changed at a time. This is where custom objects and Maps would come in handy
    A) Bukkit logs your plugins for you. no need to send two messages.
    B) Because of A, you can remove this whole method.
    Every new statement should have their own line. Do not stack statements.
    Only return true when the command worked as planned. If something goes wrong, return false.
    Do not compare booleans for an if statement. No need to turn a boolean into a boolean. Remove the "== true".
    A) Use BukkitRunnables instead of schedulers
    B) This should be done inside the event (I.e remove the delayed task). Use event.setLine(line , "message") to change the lines for signs.
     
  3. @Zombie_Striker thank you very much for your advice :) But please can you simply tell me, where is the problem, that the text on signs is not appearing? Thank you.
     
  4. Offline

    Zombie_Striker

    @sudoman281
     
  5. @Zombie_Striker so now this is in my code:
    Code:
    @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            if (event.getAction() == Action.RIGHT_CLICK_BLOCK && enabled) {
                if(event.getClickedBlock().getState() instanceof Sign) {
                    if(copyMode == true) {
                        Sign sign = (Sign) event.getClickedBlock().getState();
                        l1 = sign.getLine(0);
                        //l2 = sign.getLine(1);
                        l3 = sign.getLine(2);
                        l4 = sign.getLine(3);
                        copyMode = false;
                        event.getPlayer().sendMessage(ChatColor.GREEN + "Copy mode disabled. Now rightclick on blank sign.");
                    } else {
                        Sign sign = (Sign) event.getClickedBlock().getState();
                        sign.setLine(0, l1);
                        sign.setLine(1, "Ahoj");
                        sign.setLine(2, l3);
                        sign.setLine(3, l4);
                        sign.update(true);
                    }
                }
            }
        }
       
         @EventHandler
         public void onSignChange(SignChangeEvent event) {
              if(enabled == true) {
                  Sign sign = (Sign) event.getBlock().getState();
                  event.setLine(0, l1);
                  event.setLine(1, "Ahoj");
                  event.setLine(2, l3);
                  event.setLine(3, l4);
                  sign.update(true);
              }
         }
    But still not working :/
     
  6. Offline

    Zombie_Striker

    @sudoman281
    Don't use Sign.setLine(). Use event.getLine()
     
  7. Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page