Solved Setting Sign lines not working

Discussion in 'Spigot Plugin Development' started by NightFighter989, Jul 9, 2018.

  1. I'm creating a plugin which has the ability to join a lobby through a sign, The code is called and the Replace() function is called but the Sign just doesn't update. And the Block is correct as I tested it by setting the block to a bookshelf and it overrides the sign. I've done quite a lot of testing and it just doesn't work. (also the click event doesn't work but I can probably do that my self)
    the main bit I need help with is Update().
    Code (Java):
    class Sign{
        public org.bukkit.block.Sign blk;
        public String Command;
        public String[] sign_text;
        private int players;
        public room rm;
        int loby;
        room_type type;
        String[] Og_text;
    public Sign(int Loby,room_type type ,Location loc,String[] msg) {
        rm = room_controller.get().get_room(Loby, type);
        Block b =main.wrd.getBlockAt(loc);
        blk = (org.bukkit.block.Sign)b.getState();
        this.loby = Loby;
        this.type = type;
        this.Og_text = msg;
        Sign_Controller.get().add(this);
    }
    public void onPlayerInteract(PlayerInteractEvent event) {
        if(event.getAction()== Action.RIGHT_CLICK_BLOCK)
            if(event.getClickedBlock().getLocation()== blk.getBlock().getLocation()) {
                rm = room_controller.get().get_room(loby, type);
                if(rm != null) {
                    if(rm.Join(event.getPlayer())) {
                        return;
                    }else {
                        player_controller.get().send_message(main.Ls, event.getPlayer(), rm.ID);
                    }
                }
                else {
                    rm = room_controller.get().new_room(type, loby);
                    rm.Join(event.getPlayer());
                }
            }
    }
    public void update() {
        players = player_controller.get().get_players(rm.ID).size();
        ArrayList<String> tmp = Replace(Og_text);
        for(int x = 0;x<tmp.size();x++) {
            blk.setLine(x, tmp.get(x));
        }
        blk.update(true);
    }
    public ArrayList<String> Replace(String[] msg) {
        ArrayList<String> s = new ArrayList<String>();
        for(int g = 0;g<msg.length;g++) {
            String p = msg[g];
            p = p.replaceAll("@",Integer.toString(players));
            p = ChatColor.translateAlternateColorCodes('&', p);
            s.add(p);
        }
        return s;
    }
    }
     
     
  2. JanTuck

    Supporter

    This is not python so please follow java naming conventions
     
    • Winner Winner x 3
  3. Strahan

    Benefactor

    ...and lobby is spelled lobby, not loby :)

    Your even't isn't working because you forgot @EventHandler before the event. Also, I do not see anything calling the update function. The function itself is a bit unnecessarily bulky and doesn't have error control.
     
    • Like Like x 1
  4. I put up this thread to get help with the problem not a criticism of my naming standards. the event is not handled directly I have a controller that calls all the events in the Signs. and the update function is also called externally upon the sign text being changed or the someone joining the lobby (I fixed the Player Interact thing btw it now works, the only thing in my plugin that doesn't work is updating of the Sign)
     
  5. Benz56

    Moderator Supporter

    Adding to what @Strahan posted.
    You also forgot to implement Listener in your Sign class and I'm guessing you haven't registered it as well.

    Adding to what @JanTuck posted.
    You're posting in a forum consisting of Java developers mainly. Your naming conventions make it a lot more challenging for us to actually provide you with any help as what we expect to be a variable is actually a class in your case etc. Following the Java standard will not only help us but also help yourself in the long run as other peoples code will follow the standard Java naming conventions.
     
  6. As I put in the other post I am using another class to call the event in the class and as it says in the original post I DONT WANT TO FIX THE EVENT I WANT HELP TO FIX UPDATE()
    plus I don't know java naming convention as I am self-taught so sorry.
     
  7. anyway I fixed the event now (no thanks to any of you) for anyone who is wanting to fix this again in the future, what I did was give spigot the event to run (you will see in code in Update)
    Code (Java):
    package Org.ArcadeMaster.NFBGR;
    import java.util.ArrayList;
    import java.util.logging.Level;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    class Sign{
        public org.bukkit.block.Sign blk;
        public String Command;
        public String[] sign_text;
        private int players;
        public room rm;
        int loby;
        room_type type;
        String[] Og_text;
    public Sign(int Loby,room_type type ,Location loc,String[] msg) {
        rm = room_controller.get().get_room(Loby, type);
        Block b =main.wrd.getBlockAt(loc);
        blk = (org.bukkit.block.Sign)b.getState();
        this.loby = Loby;
        this.type = type;
        this.Og_text = msg;
    }
    public void onPlayerInteract(PlayerInteractEvent event) {
        if(event.getAction()== Action.RIGHT_CLICK_BLOCK)
            if(event.getClickedBlock().getLocation().getBlockX()== blk.getBlock().getLocation().getBlockX() && event.getClickedBlock().getLocation().getBlockY()== blk.getBlock().getLocation().getBlockY() && event.getClickedBlock().getLocation().getBlockZ()== blk.getBlock().getLocation().getBlockZ()) {
                rm = room_controller.get().get_room(loby, type);
                if(rm != null) {
                    if(rm.Join(event.getPlayer())) {
                        return;
                    }else {
                        player_controller.get().send_message(main.Ls, event.getPlayer(), rm.ID);
                    }
                }
                else {
                    rm = room_controller.get().new_room(type, loby);
                    rm.Join(event.getPlayer());
                }
            }
    }
    public void update() {
        players = player_controller.get().get_players(rm.ID).size();
        String[] tmp = Replace(Og_text);
        for(int x = 0;x<tmp.length;x++) {
            blk.setLine(x, tmp[x]);
        }
        main.plg.getServer().getPluginManager().callEvent(new SignChangeEvent(blk.getBlock(), null, tmp));
        blk.update();
    }
    public String[] Replace(String[] msg) {
        String[] s = msg;
        for(int g = 0;g<msg.length;g++) {
            s[g] = s[g].replaceAll("@",Integer.toString(players));
            s[g] = ChatColor.translateAlternateColorCodes('&', s[g]);
        }
        return s;
    }
    }
     
     
  8. I was self-taught as well (assuming you consider using the help of good ol' Google self-taught) and my naming conventions are fine. Not to one-up, but knowing Java should be the start behind knowing naming conventions, not who taught you or how you learned it.
    The only one to blame for not receiving proper help is yourself. You were given tips, so make sure you make use of them or the same thing may happen again when you need the help and really can't figure it out :p
     
    • Agree Agree x 2
  9. Strahan

    Benefactor

    1. Getting snotty just means in the future when you need help, someone with the answer may recall this thread and be like fuck that kid.
    2. While some pointers have no bearing on your problem, it doesn't mean they aren't valid and helpful.
    3. With your level of experience and quality of code you are producing, please resist the urge to post code for others to use.
     
    • Agree Agree x 1
    • Winner Winner x 1
  10. JanTuck

    Supporter

    Just... stop Why? What? Why? Why again?
     
    • Like Like x 1
  11. I mean @EventHandler :p, I'm tired >.<
     
    • Funny Funny x 1