Skip to content

Instantly share code, notes, and snippets.

@jan-krueger
Last active December 31, 2015 03:28
Show Gist options
  • Save jan-krueger/7927411 to your computer and use it in GitHub Desktop.
Save jan-krueger/7927411 to your computer and use it in GitHub Desktop.
Here is my code for a small MessageManager. You can send Messages to a Player or you can log errors or messages in the console. It's realy simple to use.
package <your-package>;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
public class MessageManager {
private static MessageManager instance = new MessageManager();
public String prefix = "myprefix";
public enum MessageType {
INFO(ChatColor.GRAY),
GOOD(ChatColor.GOLD),
BAD(ChatColor.RED),
NORMAL(ChatColor.RESET);
private ChatColor color;
MessageType(ChatColor color) {
this.color = color;
}
public ChatColor getColor() {
return color;
}
}
public enum LogType {
INFO(ChatColor.YELLOW),
GOOD(ChatColor.GREEN),
BAD(ChatColor.RED),
SEVERE(ChatColor.DARK_RED);
private ChatColor color;
LogType(ChatColor color) {
this.color = color;
}
public ChatColor getColor() {
return color;
}
}
private MessageManager() {}
public static MessageManager getInstance() {
return instance;
}
public void message(CommandSender sender, MessageType type, String... messages) {
for(String m : messages) {
sender.sendMessage(prefix + type.getColor() + m);
}
}
public void log(LogType type, String... messages) {
for(String m : messages) {
Bukkit.getConsoleSender().sendMessage(prefix + type.getColor() + m);
}
}
public void log(LogType type, StackTraceElement[] stackTrace) {
for(StackTraceElement st : stackTrace) {
Bukkit.getConsoleSender().sendMessage(prefix + type.getColor() + st);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment