Solved Code not working and no errors

Discussion in 'Spigot Plugin Development' started by ZevoGaems, Jun 6, 2017.

Thread Status:
Not open for further replies.
  1. I have this part of my plugin that t is supposed to make it so when a player joins if they have a rank it adds it to their name in tab, but it won't work when the player joins. Here is what I have
    Code (Text):
        @EventHandler
        public void onPlayerJoinEvent(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            if(getConfig().getString("ranked player." + p.getUniqueId()) != null) {
                String rank = getConfig().getString("ranked player." + p.getUniqueId() + ".rank");
                if(rank.equals("Owner")) {
                    p.setPlayerListName(ChatColor.GRAY + "[" + ChatColor.DARK_RED + ChatColor.BOLD + "Owner" + ChatColor.RESET + ChatColor.GRAY + "]" + ChatColor.RESET + " " + p.getName());
                }
                if(rank.equals("Admin")) {
                    p.setPlayerListName(ChatColor.GRAY + "[" + ChatColor.RED + ChatColor.BOLD + "Admin" + ChatColor.RESET + ChatColor.GRAY + "]" + ChatColor.RESET + " " + p.getName());
                }
                if(rank.equals("Dev")) {
                    p.setPlayerListName(ChatColor.GRAY + "[" + ChatColor.DARK_PURPLE + ChatColor.BOLD + "Dev" + ChatColor.RESET + ChatColor.GRAY + "]" + ChatColor.RESET + " " + p.getName());
                }
                if(rank.equals("Builder")) {
                    p.setPlayerListName(ChatColor.GRAY + "[" + ChatColor.BLUE + ChatColor.BOLD + "Builder" + ChatColor.RESET + ChatColor.GRAY + "]" + ChatColor.RESET + " " + p.getName());
                }
                if(rank.equals("Mod")) {
                    p.setPlayerListName(ChatColor.GRAY + "[" + ChatColor.GREEN + ChatColor.BOLD + "Mod" + ChatColor.RESET + ChatColor.GRAY + "]" + ChatColor.RESET + " " + p.getName());
                }

                if(rank.equals("Trainee")) {
                    p.setPlayerListName(ChatColor.GRAY + "[" + ChatColor.GREEN + ChatColor.BOLD + "Trainee" + ChatColor.RESET + ChatColor.GRAY + "]" + ChatColor.RESET + " " + p.getName());
                }
            }
        }
     
  2. Is there anything in the console when the player joins?
     
  3. Nothing that regards my plugin but I do still have groupmanager and I don't know if that effects it.
     
  4. Where is this if(rank.---) stuff coming from? Are you depending on another plugin? If so, that is probably the reason.
     
  5. Its not another plugin its actually part of my plugin. The other code that, that is coming from is...
    Code (Text):
            if(cmd.getName().equalsIgnoreCase("rank")) {
                if(!sender.hasPermission("minegrid.rank")) {
                    sender.sendMessage(ChatColor.RED + "Requested Permission Level \n OWNER");
                } else if(args.length != 2) {
                    sender.sendMessage(ChatColor.RED + "Usage, /rank (player) (rank)");
                } else if(args.length == 2) {
                    String p1 = args[0];
                    Player p = Bukkit.getPlayer(p1);
                    String pname = p.getName();
                    String rank = args[1];
                    if(rank.equals("Owner")) {
                        Bukkit.broadcast(ChatColor.RED + sender.getName() + " has promoted " + pname + " to Owner!", "minegrid.notify");
                        getConfig().set("ranked player." + p.getUniqueId() + ".rank", "Owner");
                        saveConfig();
                        p.setPlayerListName(ChatColor.GRAY + "[" + ChatColor.DARK_RED + ChatColor.BOLD + "Owner" + ChatColor.RESET + ChatColor.GRAY + "]" + ChatColor.RESET + " " + p.getName());
                    }
                    if(rank.equals("Admin")) {
                        Bukkit.broadcast(ChatColor.RED + sender.getName() + " has promoted " + pname + " to Admin!", "minegrid.notify");
                        getConfig().set("ranked player." + p.getUniqueId() + ".rank", "Admin");
                        saveConfig();
                        p.setPlayerListName(ChatColor.GRAY + "[" + ChatColor.RED + ChatColor.BOLD + "Admin" + ChatColor.RESET + ChatColor.GRAY + "]" + ChatColor.RESET + " " + p.getName());
                    }
                    if(rank.equals("Dev")) {
                        Bukkit.broadcast(ChatColor.RED + sender.getName() + " has promoted " + pname + " to Dev!", "minegrid.notify");
                        getConfig().set("ranked player." + p.getUniqueId() + ".rank", "Dev");
                        saveConfig();
                        p.setPlayerListName(ChatColor.GRAY + "[" + ChatColor.DARK_PURPLE + ChatColor.BOLD + "Dev" + ChatColor.RESET + ChatColor.GRAY + "]" + ChatColor.RESET + " " + p.getName());
                    }
                    if(rank.equals("Builder")) {
                        Bukkit.broadcast(ChatColor.RED + sender.getName() + " has promoted " + pname + " to Builder!", "minegrid.notify");
                        getConfig().set("ranked player." + p.getUniqueId() + ".rank", "Builder");
                        saveConfig();
                        p.setPlayerListName(ChatColor.GRAY + "[" + ChatColor.BLUE + ChatColor.BOLD + "Builder" + ChatColor.RESET + ChatColor.GRAY + "]" + ChatColor.RESET + " " + p.getName());
                    }
                    if(rank.equals("Mod")) {
                        Bukkit.broadcast(ChatColor.RED + sender.getName() + " has promoted " + pname + " to Mod!", "minegrid.notify");
                        getConfig().set("ranked player." + p.getUniqueId() + ".rank", "Mod");
                        saveConfig();
                        p.setPlayerListName(ChatColor.GRAY + "[" + ChatColor.GREEN + ChatColor.BOLD + "Mod" + ChatColor.RESET + ChatColor.GRAY + "]" + ChatColor.RESET + " " + p.getName());
                    }

                    if(rank.equals("Trainee")) {
                        Bukkit.broadcast(ChatColor.RED + sender.getName() + " has promoted " + pname + " to Trainee!", "minegrid.notify");
                        getConfig().set("ranked player." + p.getUniqueId() + ".rank", "Trainee");
                        saveConfig();
                        p.setPlayerListName(ChatColor.GRAY + "[" + ChatColor.GREEN + ChatColor.BOLD + "Trainee" + ChatColor.RESET + ChatColor.GRAY + "]" + ChatColor.RESET + " " + p.getName());
                    }
                    }
                }
     
  6. I know this isn't aimed at helping your question, but from what your doing a switch statement would be better and could benefit you.
     
  7. Will it fix it?
     
  8. No, I was just suggesting it as if you have more ranks this will work better than lots of if and else statements.
     
  9. Did you register the event?
     
  10. Did you register your events in onEnable()? If you forget to do that, you won't get any errors in the console, but your @EventHandler annotation will mean nothing.
     
  11. To help use fix your problem you can add some debug messages in the onjoin method. Using System.out.printIn(message)
    This will display a message in the console. If you don't get any messages in console then the event is not firing, if so check if you have registered your events I need your onEnable
     
  12. I did register it here
    Code (Text):

        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
     
     
  13. ok, is the plugin loading in it's whole. Is it showing up in the plugin list?

    EDIT you are not allowed to use spaces in YML. instead you should use a . that causing the issue zi guess
     
  14. In that case, try what @NoahNok said:
     
  15. I added it and I joined back and it registered all of them. It got all the way to the owner part.
     
  16. Maybe the problem is that the names you put in your tab list are above the limit. The character limit in the tab list is 16 characters, but from what I can see, if your IGN is the same as your Spigot username, you're trying to set the tab list name to 17 characters (for the Owner rank, at least). So, if the console messages really show and your code is working, it must mean your name is too long.

    Try putting the first letter or two of each rank instead of the full rank name and see what happens.
     
  17. Ok I tried the first thing and added the debug thing and they all showed up. I don't think it is the IGN thing becuse my ign is Flauw and when you do /rank Flauw Owner it shows the rank then fine but when you join then it doesn't
     
  18. Delay the method with a task by a tick.
     
    • Agree Agree x 1
  19. Please don't get mad at me for asking but I have been having alot of trouble with the timer, delay, and task thing. How would I create a delay for my plugin?
     
  20. Use a BukkitRunnable.
     
Thread Status:
Not open for further replies.