Change chat format

Discussion in 'Plugin Development' started by tomisanhues3, Jun 12, 2015.

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

    tomisanhues3

    Hello, Im currently making a message /msg plugin but im having issues in changing the chat format, im very new at this so if you dont mind explaining would be great
    I want to change the message format, for example, add colors to the message, take a refference on mineplex /msg system

    here is my code

    Code:
    package me.tomisanhues3.essentials;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Essentials extends JavaPlugin {
    
        public static Essentials plugin;
        public static Logger logger = Logger.getLogger("Minecraft");
    
        // Disable
        @Override
        public void onDisable() {
            getLogger().info("essentials has been disabled!");
    
        }
    
        // enable
        @Override
        public void onEnable() {
            getLogger().info("essentials has been invoked!");
        }
    
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd,
                String commandLabel, String[] args) {
            if (commandLabel.equalsIgnoreCase("msg")) {
                if (args.length == 2) {
                    Player player = Bukkit.getServer().getPlayer(args[0]);
                    if (player != null && player.isOnline()) {
                        // get target player -> send target player message
                        player.sendMessage(args[1]);
                      
                    }
                }
            }
            return false;
        }
    }
    
     
  2. Offline

    meguy26

    1.
    Get into the practice of using "cmd.getName().equals("")" instead of commandLabel.equals(), because otherwise aliases will not work.

    2.
    In mincecraft, chat colors are represented as a character code with two characters, the color code symbol, and the color code. To add them to a string, you can do String testRed = ChatColor.RED + "This is red", in addition color codes are an enum, look at ChatColor.

    3.
    If you have no idea what i just said, learn more java.
     
  3. Offline

    tomisanhues3

    I understand, Some is working right now, thank you very much!
     
  4. Offline

    LeePMC

    Dont use cmd.getName() use getCommand() in the main class to put the command code in A seperate class, trust me as you get into multiple commands per plugin it really helps to have listeners and commands in seperate classes, if you want the specifics on how to do this you can 1. Search google 2. Wait untill I get home to make sure I post the correct line of code for you
     
Thread Status:
Not open for further replies.

Share This Page