diff --git a/src/main/java/com/github/ucchyocean/lc/LunaChatLogger.java b/src/main/java/com/github/ucchyocean/lc/LunaChatLogger.java index f2b557a..c98593e 100644 --- a/src/main/java/com/github/ucchyocean/lc/LunaChatLogger.java +++ b/src/main/java/com/github/ucchyocean/lc/LunaChatLogger.java @@ -10,6 +10,9 @@ import java.io.FileWriter; import java.text.SimpleDateFormat; import java.util.Date; +import org.bukkit.Bukkit; +import org.bukkit.scheduler.BukkitRunnable; + /** * LunaChatロガー * @author ucchy @@ -39,27 +42,35 @@ public class LunaChatLogger { * ログを出力する * @param message ログ内容 */ - public void log(String message) { + public void log(final String message) { checkDir(); - FileWriter writer = null; - try { - writer = new FileWriter(file, true); - String str = lformat.format(new Date()) + "," + message; - writer.write(str + "\r\n"); - writer.flush(); - } catch (Exception e) { - e.printStackTrace(); - } finally { - if ( writer != null ) { + // 以降の処理を、発言処理の負荷軽減のため、非同期実行にする。(see issue #40.) + Bukkit.getScheduler().runTaskAsynchronously(LunaChat.instance, new BukkitRunnable() { + @Override + public void run() { + + FileWriter writer = null; try { - writer.close(); + writer = new FileWriter(file, true); + String str = lformat.format(new Date()) + "," + message; + writer.write(str + "\r\n"); + writer.flush(); } catch (Exception e) { - // do nothing. + e.printStackTrace(); + } finally { + if ( writer != null ) { + try { + writer.close(); + } catch (Exception e) { + // do nothing. + } + } } + } - } + }); } /**