Best way to get messages

Discussion in 'Plugin Development' started by MaTaMoR_, Mar 31, 2015.

Thread Status:
Not open for further replies.
  1. Hi i wanna know which is the best way to get messages from the config, im using this now :

    Code:
    public String getMessage(Messages message) {
        return c(messagesConfig.getString(message.getPath()));
    }
    
    public enum Messages {
    
        NO_PERMISSION("Messages.NoPermission"),
        CONSOLE_SENDER("Messages.ConsoleSender"),
        NO_SELECTION("Messages.NoSelection"),
        WRONG_USAGE("Messages.WrongUsage"),
        NOT_NUMERICAL("Messages.NotNumerical"),
        ID_ALREADY_IN_USE("Messages.IDAlreadyInUse"),
        COMMAND_DONT_EXISTS("Messages.CommandDontExists"),
        ARENA_DONT_EXISTS("Messages.ArenaDontExists");
    
        private final String path;
    
        private Messages(String path) {
            this.path = path;
        }
    
        public String getPath() {
            return path;
        }
    }
    
    player.sendMessage(plugin.Messages().getMessage(Messages.THIS_METHOD_IS_TOO_LONG_AND_SUCKS));
    
    }
    
    So i wanna know how i can get the messages from config but be able to get them like this :

    Code:
    player.sendMessages(Messages.THIS_WAY_IT_ROCKS);
    
     
  2. Offline

    teej107

    @MaTaMoR_ Constants are a good way to save paths to messages. But your preferred way would require a method like this:
    Code:
    public void sendMessage(Player player, Message m)
    or a class of String constants like this:
    Code:
    public class Messages
    {
        public static final String THIS_WAY_IT_ROCKS = "path.to.value";
    }
     
  3. I changed that but still having to use :
    plugin.Messages().getMessage(Messages.THIS_METHOD_IS_TOO_LONG_AND_SUCKS);
    how i can change that ?
     
  4. Offline

    mythbusterma

    Infuzion and timtower like this.
Thread Status:
Not open for further replies.

Share This Page