Prefix

Discussion in 'Plugin Development' started by ryandv, Jun 19, 2017.

Thread Status:
Not open for further replies.
  1. What is this: This is a class that I have made for you to easy make prefixes. This works with permissions but you can do it on a lot of other ways. Its easy to use please leave a comment to say what I can improve to this class or something else.

    Why: I have make It so you can learn how to do prefixes



    Code:
    
    
    package listeners;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    
    public class Prefix implements Listener{
      
    
        /*
         * This class is made by ryandv1.
         * My Profile on Bukkit: https://dev.bukkit.org/members/ryandv1
         *
         * This is made to learn how to do prefixes.
         * Please don't claim this class ass your own (but you are fre to use it)
         * If you use it please put my name somewhere
         */
      
        @EventHandler
        public void onchat(AsyncPlayerChatEvent e){
            Player p = e.getPlayer(); // Getting the player
    
            String s = e.getMessage(); //getting the Player Message
    
            if(p.hasPermission("green")){ // This is the Permission that the player needs to have this prefix
          e.setFormat(ChatColor.GREEN + "[Green]" + ChatColor.AQUA + p.getName() + ChatColor.WHITE + s);
                // this is the format in the chat that s is The String what we defined before
    
            }else if(p.hasPermission("yellow")){
        e.setFormat(ChatColor.YELLOW + "[Yellow]" + ChatColor.BLUE + p.getName() + ChatColor.WHITE + s);
          
    }else if(p.hasPermission("red")){
                e.setFormat(ChatColor.RED + "[Red]" + ChatColor.RED + p.getName() + ChatColor.WHITE + s);
              
            }
        }
    
    }
     
    Last edited: Jun 19, 2017
  2. Offline

    Zombie_Striker

    @ryandv
    Are you asking for help fixing the code, or are you posting this to let other members use? If the latter, click report and ask for this to be moved to Resources.

    1. For resouces, you do not need the package in the class as the user will provide their package when they copy it.
    2. If you do not want other people using your code, choose a lisence or add a message at the top saying all rights reserved.
    3. Variable names should be descriptive. You should not have single-character variable names unless they are temporary (Like for For loops): p should be 'player', and s should be something like "message" or atleast "msg"
     
  3. Offline

    PhantomUnicorns

    You should've made this a util before I did :p, here is the link. @ryandv
     
Thread Status:
Not open for further replies.

Share This Page