{Tutorial} Prefixes/MessageManagers! With Enums!

Discussion in 'Resources' started by JPG2000, Oct 29, 2013.

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

    JPG2000

    PRE-NOTE: This is a very simple concept. Very easy to write, and to understand. I just saw a fourm post, that gave people the wrong idea, and it turns out - people don't know how to do this.

    Today, you can have your own MessageManager/Prefixes/Header/What ever you want to call them.

    Anyways, by that, I mean a simple way, when sending a player a message, instead of type "http://dev.bukkit.org/bukkit-plugins/ blablabla', you can easily do: Header.BROADCAST + "Blablabla". Just saves time. [syntax=java]player.sendMessage(Header.BROADCAST + "Broadcast!"); //Instead of player.sendMessage(ChatColor.WHITE + ChatColor.BOLD.toString() + "Broadcast!"); //Obviously, that isn't the best example, sincce the BROADCAST enum is short. But again, its customizable[/syntax] Now, this Enum below, its very simple. Obviously, you won't have the EXACT same Enum - Customize it. You can add 'fields' to the Header, to create your own. You can probably tell from the code, if not, leave a comment ;) Enum class (feel free to customive the fields, I would leave the constructor though): [syntax=java]package com.gameon.medieval.managers; import org.bukkit.ChatColor; /** * * @Author Jake */ public enum Header { //Represents an Negitive Header NEGATIVE(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_RED + ChatColor.BOLD.toString() + "*" + ChatColor.RESET + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY), //Represents a Nutreul Header NUETRAL(ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + ChatColor.BOLD.toString() + "*" + ChatColor.RESET + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY), //Represents a Positive Header POSITIVE(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + ChatColor.BOLD.toString() + "*" + ChatColor.RESET + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY), //Represents a Broadcast Header BROADCAST(ChatColor.WHITE + ChatColor.BOLD.toString()), //Represents a Log header LOG(ChatColor.RED + "[WarfareLogger] " + ChatColor.GRAY); //Prefix that represents the Header private String prefix; //Constructor private Header(String prefix) { this.prefix = prefix; } @Override public String toString() { return this.prefix; } } [/syntax] Enum is pastie: [url]http://pastie.org/8441546[/url] So, in a message, when using a 'field' (LOG, BROADCAST etc), it will add the String as shown above. So, if I send a player a message like so: [syntax=java]player.sendMessage(Header.LOG + "Log message");[/syntax] It would be the same as: [syntax=java]player.sendMessage(ChatColor.RED + "[WarfarePlugin] " + ChatColor.GRAY);[/syntax] So thats basicly it. Its a very small class, yet saves a bunch of time./
     
  2. Offline

    calebbfmv

    Thank you for copying my post.
     
  3. Offline

    JPG2000

    Famous Guy likes this.
Thread Status:
Not open for further replies.

Share This Page