Join Event Help

Discussion in 'Spigot Plugin Development' started by dyenxunit, Jun 6, 2015.

  1. I have no clue why when the player joins it doesnt get their custom name like [Owner] dyenxunit has Joined the game. I have tried getting their custom display name too Can someone assist with this. There is no error code etheir. The [Owner] dyenxunit only shows up when i leave the game.

    Another Question i have is how do i replace everything in the config that starts with & with §.

    Code (Text):
    @EventHandler
        public void SJE (PlayerJoinEvent e){
            Player p = e.getPlayer();
            if(p.hasPermission("SJE.CustomJoin")){
                e.setJoinMessage("%Player% has joined the game".replace("%Player%", p.getName());
        }
    }
     
     
    #1 dyenxunit, Jun 6, 2015
    Last edited: Jun 6, 2015
  2. What are you trying to do? Do you want to set a prefix for their name? Or set their name? Because right now, all your doing is setting the join message when they join the server. Also, please fix your braces, I cannot read your code.
     
  3. What im trying to do is get their customDisplay name so persay if i was to join my custom name would be [Owner] dyenxunit joined the game but it only shows up as dyenxunit has joined the game but when i leave it says [Owner] dyenxunit has left the game
     
  4. The plugin controlling the prefix hasnt run its code yet. You need to delay your code to give the other plugin time to run. This means you will have to delete the join message (so one doesnt appear) and then later run your own faked join message (using broadcast, or similar).
     
  5. getDisplayName() or getCustomName().
     
  6. Tried both None of them worked
     
  7. With a delay task ?
     
  8. Another Question i have is how do i replace everything in the config that starts with & with §.
     
  9. You need a toColors method for that. Here's the one I use:
    Code (Text):

    public static String toColors(String s){
        if(s == null) return null;
        return s.replaceAll("&([0-9a-f])", "\u00A7$1");
    }
     
     
  10. It actually does things a little differently (more efficiently).

    Code (Text):

        public static String translateAlternateColorCodes(char altColorChar, String textToTranslate) {
            char[] b = textToTranslate.toCharArray();
            for (int i = 0; i < b.length - 1; i++) {
                if (b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i+1]) > -1) {
                    b[i] = ChatColor.COLOR_CHAR;
                    b[i+1] = Character.toLowerCase(b[i+1]);
                }
            }
            return new String(b);
        }
     
    ;)
     
  11. @Fccardiff ChatColor.translateAlternateColorCodes('&', string);...
     
  12. Hehe, see above.
     
  13. Well, uh, the other guy beat you to it. Haha

    Anyways, off-topic. He already has the answer.
     
  14. ERRRM which one do i use ? Sorry like i have said many times im still a newbie coder :(
     
  15. Use the one from the API.
     
  16. Yep - use translateAlternateColorCodes - it's better, I just forgot about the method.
     
  17. @dyenxunit You can use that code if you want but it's easier just to do this;
    Code (Text):
    ChatColor.translateAlternateColorCodes('&', string);