How do i make colored join messages?

Discussion in 'Plugin Development' started by FalconLetsPlay, May 10, 2021.

Thread Status:
Not open for further replies.
  1. Offline

    FalconLetsPlay

    I just made a join message plugin and want to make them colored. Here's my code:
    Code:
    package de.falconletsplay.joinmessages;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public final class JoinMessages extends JavaPlugin implements Listener {
    
        @Override
        public void onEnable() {
            // Plugin startup logic
            getServer().getPluginManager().registerEvents(this, this);
        }
    
        @Override
        public void onDisable() {
            // Plugin shutdown logic
        }
    
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e){
            Player p  = e.getPlayer();
            e.setJoinMessage("Hallo :) viel Spass auf dem Server! " + p.getName());
        }
    
        @EventHandler
        public void onPlayerQuit(PlayerQuitEvent e){
            Player p = e.getPlayer();
            e.setQuitMessage(":c Schade, dass du gehen musst " + p.getName());
        }
    }
     
  2. Offline

    davidclue

  3. Offline

    Newdel

    You can either use the ChatColor enum or use the color code directly (§1, §2, §a,§b, ...)
     
  4. Offline

    FalconLetsPlay

    thank u

    ok so now the color problem is solved but how do i remove these little as with some kind of accent on them?
     
    Last edited: May 11, 2021
  5. Offline

    Kars

    You are going to have to be more specific.
     
  6. Offline

    FalconLetsPlay

    i cant post screenshots for some reason
     
  7. Offline

    timtower Administrator Administrator Moderator

    Then post a link to one
     
  8. Offline

    FalconLetsPlay

    2021-05-11_18.29.10.png
     

    Attached Files:

  9. Offline

    Newdel

  10. Offline

    FalconLetsPlay

    Code:
      @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e){
            Player p  = e.getPlayer();
            e.setJoinMessage("§e§l Hallo :) viel Spass auf dem Server! " + p.getName());
        }
    
        @EventHandler
        public void onPlayerQuit(PlayerQuitEvent e){
            Player p = e.getPlayer();
            e.setQuitMessage("§e§l :c Schade, dass du gehen musst " + p.getName());
        }
     
  11. Offline

    Newdel

    That's either not the current code, another plugin is adding those weird symbols or...dunno. Maybe it's the version? No idea why the minecraft version would do this but just in case: Which version are you using?
     
  12. Offline

    FalconLetsPlay

    Im using 1.15.2
     
  13. Offline

    davidclue

    Just use the method I sent you previously and it will solve all your problems...
     
  14. Offline

    Newdel

    The method literally replaces the symbol you give it with '§'
     
  15. Offline

    FalconLetsPlay

    it literally only gives me errors
     
  16. Offline

    timtower Administrator Administrator Moderator

    Then show the errors.
     
  17. Offline

    KarimAKL

    Yes, but it uses the unicode (\u00a7), not the actual character. The problem is probably encoding.
     
    davidclue likes this.
  18. Offline

    Newdel

    Good point. But wouldn't that lead to weird symbols WITHOUT the color code being interpreted? Seems stupid that the output would be "ħeÄ$l" like in OPs case but just in case...
    @FalconLetsPlay what's the error when you use ChatColor.alternateColorCodes() and try to use ChatColor.YELLOW + ChatColor.BOLD + "..."
     
  19. Offline

    FalconLetsPlay

    thank u but now im getting the problem
    and the same with the leave part, and i honestly dont understand it
     
  20. Offline

    KarimAKL

    @Newdel Converting '§' from UTF-8 to ASCII results in 'Â'.

    @FalconLetsPlay You cannot concatenate ChatColor, but you can use ChatColor.YELLOW.toString() + ChatColor.BOLD.toString().

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 12, 2021
    Newdel likes this.
  21. Offline

    FalconLetsPlay

    thank u that was the solution to my problem
     
    KarimAKL likes this.
  22. Offline

    TheDepressedOne

    @FalconLetsPlay Please mark thread as solved to cleanup forums. Thanks!
     
Thread Status:
Not open for further replies.

Share This Page