Beispiel #1
0
 public static void init(PluginBase plg) {
   plugin = plg;
   language = plg.getConfig().getNested("general.language", "english");
   debugMode = plg.getConfig().getNested("general.debug-mode", false);
   initMessages();
   saveMessages();
   LNG_CONFIG.debug(Message.values().length, language, true, debugMode);
 }
Beispiel #2
0
  /**
   * This is my favorite debug routine :) I use it everywhere to print out variable values
   *
   * @param s - array of any object that you need to print out. Example: Message.BC ("variable
   *     1:",var1,"variable 2:",var2)
   */
  public static void BC(Object... s) {
    if (!debugMode) return;
    if (s.length == 0) return;

    StringBuilder sb =
        new StringBuilder("&3[").append(plugin.getDescription().getName()).append("]&f ");
    for (Object str : s) sb.append(str.toString()).append(" ");
    plugin.getServer().broadcastMessage(TextFormat.colorize(sb.toString().trim()));
  }
Beispiel #3
0
 private static void saveMessages() {
   File f = new File(plugin.getDataFolder() + File.separator + language + ".lng");
   Config lng = new Config(f, Config.YAML);
   for (Message key : Message.values()) lng.set(key.name().toLowerCase(), key.message);
   try {
     lng.save();
   } catch (Exception e) {
     LNG_SAVE_FAIL.log();
     if (debugMode) e.printStackTrace();
     return;
   }
 }
Beispiel #4
0
 private static void initMessages() {
   copyLanguage();
   Config lng = null;
   try {
     File f = new File(plugin.getDataFolder() + File.separator + language + ".lng");
     lng = new Config(f, Config.YAML);
   } catch (Exception e) {
     LNG_LOAD_FAIL.log();
     if (debugMode) e.printStackTrace();
     return;
   }
   for (Message key : Message.values())
     key.initMessage((String) lng.get(key.name().toLowerCase(), key.message));
 }
Beispiel #5
0
 public static boolean debugMessage(Object... s) {
   if (debugMode) plugin.getLogger().info(TextFormat.clean(join(s)));
   return true;
 }
Beispiel #6
0
 private static boolean copyLanguage() {
   return plugin.saveResource("lang/" + language + ".lng", language + ".lng", false);
 }
Beispiel #7
0
 /**
  * Send message to all players or to players with defined permission
  *
  * @param permission
  * @param s
  * @return Examples: Message.MSG_BROADCAST.broadcast ("pluginname.broadcast"); // send message to
  *     all players with permission "pluginname.broadcast" Message.MSG_BROADCAST.broadcast (null);
  *     // send message to all players
  */
 public boolean broadcast(String permission, Object... s) {
   for (Player player : plugin.getServer().getOnlinePlayers().values()) {
     if (permission == null || player.hasPermission(permission)) print(player, s);
   }
   return true;
 }
Beispiel #8
0
 /**
  * Same as log, but will printout nothing if debug mode is disabled
  *
  * @param s
  * @return
  */
 public boolean debug(Object... s) {
   if (debugMode) plugin.getLogger().info(TextFormat.clean(getText(s)));
   return true;
 }
Beispiel #9
0
 /**
  * Send current message to log files
  *
  * @param s
  * @return — always returns true. Examples: Message.ERROR_MESSAGE.log(variable1); // just print
  *     in log return Message.ERROR_MESSAGE.log(variable1); // print in log and return value true
  */
 public boolean log(Object... s) {
   plugin.getLogger().info(getText(s));
   return true;
 }