[TUT] Custom Message System!

Discussion in 'Resources' started by calebbfmv, Oct 26, 2013.

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

    calebbfmv

    Have you ever wanted to sendMessage to a player? Of course you have! Have you ever run into having to copy/paste
    Code:
     player.sendMessage(ChatColor.Red + [Plugin] + "Bukkit is awesome!);
    I know I had to, until I created a messaging system!
    Ok first off, you must know what an enum is, if you don't please visit this then come back.
    Here is how I did it, and it works just fine.
    Code:
    public enum MsgType{
            NORMAL(ChatColor.RED + "[BorderPatrol] " + ChatColor.GOLD),
            DENIED(ChatColor.RED + "[BorderPatrol] " + ChatColor.RED),
            ERROR(ChatColor.RED + "[BorderPatrol] " + ChatColor.BOLD),
            LOG("[BorderPatrol] ");
         
            private String prefix;
              
            MsgType(String prefix){
                this.prefix = prefix;
            }
         
            @Override
            public String toString(){
                return this.prefix;
            }    
        }
     
    
    We're done!
    You now have a working messaging system! To use.
    Code:
    sendMessage(MsgType.THING + msg!)
    
     
    PatoTheBest and elraro like this.
  2. Offline

    Ultimate_n00b

    This makes no sense. I feel like you left out a snippet or something.
     
  3. Offline

    calebbfmv

    Ultimate_n00b
    It is kind of that way because I personally wanted to add some more methods, but as I finished I didn't add them.
     
  4. Offline

    Ultimate_n00b

    What you have now, doesn't do anything. It will pop out a lot of errors in eclipse though.
     
    Aengo and MineKayama like this.
  5. Offline

    calebbfmv

    Ultimate_n00b
    Sorry about his guys, my little brother got on and decided to make this little project.
    EDIT:
    Updated to work, how it should
     
    MineKayama likes this.
  6. Offline

    JPG2000

    calebbfmv I dont understand the point of your HashMap. All you need is toString() correct?
     
  7. Offline

    calebbfmv

    JPG2000
    No, because we are storing multiple items, with multiple objects (MsgType, ChatColor)
     
  8. Offline

    Garris0n

    Your little brother made an enum and proceeded to post it on the bukkit forums as a resource on your account? Wow, mine usually just watches TV...
     
  9. Offline

    calebbfmv

    Garris0n
    haha yeah, he is a, special, kid.
     
  10. Offline

    PatoTheBest

    I'm 13, which obviously my brothers don't do anything besides play xbox or watch tv.
     
    ZeusAllMighty11 likes this.
  11. Offline

    JPG2000

    calebbfmv I don't understand your Map. It makes no sense. All you need is the toString() method.
     
  12. Offline

    calebbfmv

    You are quite right my friend. I know I made it this way for a reason a while ago, seems like I don't need it anymore!
     
    JPG2000 likes this.
  13. Offline

    JPG2000

    calebbfmv You never needed it, LOL.

    Anyways, I guess I'll show you my Header enum. Pretty much the same as yours, but more expalnitory. And its short.

    So you in the end you can type:
    Code:java
    1. player.sendMessage(Header.BROADCAST + "This is a broadcast");


    http://pastebin.com/M7BJp8GY
     
  14. Offline

    calebbfmv

    Ours is exactly the same...
     
    JPG2000 likes this.
  15. Offline

    JOPHESTUS

    Nice. Next time I make a plugin, I'm sure this will come in handy : )
     
  16. Offline

    xTrollxDudex

    JOPHESTUS
    When you make a plugin. I'm the mean time, keep hogging likes in the offtopic section ;)
     
    calebbfmv likes this.
Thread Status:
Not open for further replies.

Share This Page