Filled BetterServerMessage

Discussion in 'Archived: Plugin Requests' started by Maddin, May 10, 2013.

  1. Offline

    Maddin

    Suggested name: BetterServerMessage

    What I want: To simply change the way the 'say xy' command in the console is being displayed.
    Example:
    Normal: [Server] Message
    How it could be: [Admin]: Message

    Ideas for commands: No commands needed for this plugin.

    Ideas for permissions: No permissions needed for this plugin.
     
  2. Offline

    Kodfod

    Here you go!

    https://dl.dropboxusercontent.com/u/35900863/consolename.jar

    Will create a config:

    Code:
    console:
      name: '&2[Server]'
      color: '&4'
    It also supports colors inside the message

    [​IMG]

    edit: source:

    Main (open)

    Code:java
    1. package us.kodfod.console;
    2.  
    3. import java.io.File;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Main extends JavaPlugin {
    11.  
    12. public void onDisable(){
    13. }
    14. public void onEnable(){
    15. if (!new File(this.getDataFolder().pathSeparator+"config.yml").exists()) {
    16. Config.load(this);
    17. saveConfig();
    18. } else {
    19. }
    20. }
    21. @Override
    22. public boolean onCommand(CommandSender sender, Command cmd,String label, String[] args) {
    23. if (cmd.getName().equalsIgnoreCase("say")) {
    24. if (args.length > 0) {
    25. if (sender.hasPermission("cosole.say")) {
    26. String nargs = "";
    27. for (int i = 0; i < args.length; i++) {
    28. nargs = nargs + " "+ args[i];
    29. }
    30. String name = getConfig().getString("console.name");
    31. String color = getConfig().getString("console.color");
    32. String cname = ChatColor.translateAlternateColorCodes('&', name);
    33. String cargs = ChatColor.translateAlternateColorCodes('&', color+nargs);
    34. Bukkit.broadcastMessage(cname+":"+cargs);
    35. return true;
    36. } else {
    37. sender.sendMessage(ChatColor.RED+"You do not have permissions for this!");
    38. return true;
    39. }
    40. } else {
    41. return false;
    42. }
    43. }
    44. return false;
    45. }
    46.  
    47. }[/i]



    Config (open)

    Code:java
    1.  
    2.  
    3. import java.lang.reflect.Field;
    4. import java.lang.reflect.Modifier;
    5. import org.bukkit.configuration.file.FileConfiguration;
    6. import org.bukkit.plugin.Plugin;
    7.  
    8. public class Config {
    9.  
    10. public static String console_name = "&2[Server]";
    11. public static String console_color = "&4";
    12.  
    13. public static void load(Plugin plugin) {
    14. FileConfiguration conf = plugin.getConfig();
    15. for (Field field : Config.class.getDeclaredFields()) {
    16. if (Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers())) {
    17. String path = field.getName().replaceAll("_", ".");
    18. try {
    19. if (conf.isSet(path)) {
    20. field.set(null, conf.get(path));
    21. } else {
    22. conf.set(path, field.get(null));
    23. }
    24. } catch (IllegalAccessException ex) {
    25. ex.getCause().printStackTrace();
    26. }
    27. }
    28. }
    29. plugin.saveConfig();
    30. }
    31. }

     
    Maddin likes this.
  3. Offline

    Maddin

    Thanks a lot :D
     

Share This Page