diff --git a/src/main/java/com/github/ucchyocean/lc/PlayerListener.java b/src/main/java/com/github/ucchyocean/lc/PlayerListener.java index 8bc068f..2ca20ac 100644 --- a/src/main/java/com/github/ucchyocean/lc/PlayerListener.java +++ b/src/main/java/com/github/ucchyocean/lc/PlayerListener.java @@ -5,7 +5,9 @@ */ package com.github.ucchyocean.lc; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -39,6 +41,17 @@ public class PlayerListener implements Listener { private static final String LIST_ENDLINE = Resources.get("listEndLine"); private static final String LIST_FORMAT = Resources.get("listFormat"); + private SimpleDateFormat dateFormat; + private SimpleDateFormat timeFormat; + + /** + * コンストラクタ + */ + public PlayerListener() { + dateFormat = new SimpleDateFormat("yyyy/MM/dd"); + timeFormat = new SimpleDateFormat("HH:mm:ss"); + } + /** * プレイヤーのチャットごとに呼び出されるメソッド * @param event チャットイベント @@ -374,6 +387,13 @@ public class PlayerListener implements Listener { format = format.replace("%username", "%1$s"); format = format.replace("%msg", "%2$s"); + if ( format.contains("%date") ) { + format = format.replace("%date", dateFormat.format(new Date())); + } + if ( format.contains("%time") ) { + format = format.replace("%time", timeFormat.format(new Date())); + } + if ( format.contains("%prefix") || format.contains("%suffix") ) { String prefix = ""; diff --git a/src/main/java/com/github/ucchyocean/lc/channel/ChannelImpl.java b/src/main/java/com/github/ucchyocean/lc/channel/ChannelImpl.java index 9bb1a51..c93c2d4 100644 --- a/src/main/java/com/github/ucchyocean/lc/channel/ChannelImpl.java +++ b/src/main/java/com/github/ucchyocean/lc/channel/ChannelImpl.java @@ -5,7 +5,9 @@ */ package com.github.ucchyocean.lc.channel; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -67,6 +69,9 @@ public class ChannelImpl extends Channel { private static final String ERRMSG_MUTED = Resources.get("errmsgMuted"); + private SimpleDateFormat dateFormat; + private SimpleDateFormat timeFormat; + /** ロガー */ private LunaChatLogger logger; @@ -79,6 +84,8 @@ public class ChannelImpl extends Channel { super(name); logger = new LunaChatLogger(name.replace(">", "-")); + dateFormat = new SimpleDateFormat("yyyy/MM/dd"); + timeFormat = new SimpleDateFormat("HH:mm:ss"); } /** @@ -680,6 +687,13 @@ public class ChannelImpl extends Channel { msg = msg.replace("%color", getColorCode()); msg = msg.replace("%to", getPrivateMessageTo()); + if ( msg.contains("%date") ) { + msg = msg.replace("%date", dateFormat.format(new Date())); + } + if ( msg.contains("%time") ) { + msg = msg.replace("%time", timeFormat.format(new Date())); + } + if ( player != null ) { msg = msg.replace("%username", player.getDisplayName()); msg = msg.replace("%player", player.getName()); diff --git a/src/main/resources/config_ja.yml b/src/main/resources/config_ja.yml index b501522..fca65d1 100644 --- a/src/main/resources/config_ja.yml +++ b/src/main/resources/config_ja.yml @@ -59,6 +59,8 @@ formatConstraint: ['%username', '%msg'] # %world : 発言したワールド名 # %prefix : プレフィックス(VaultとPermissionsExが導入されている場合に置き換えられます) # %suffix : サフィックス(VaultとPermissionsExが導入されている場合に置き換えられます) +# %date : 日付 +# %time : 時刻 # %msg : 発言内容(Japanize変換された場合は、Japanize結果を含みます。) defaultFormat: '&f[%color%ch&f]%prefix%username%suffix&a:&f %msg' @@ -86,6 +88,8 @@ maxChannelNameLength: 20 # %world : 発言したワールド名 # %prefix : プレフィックス(VaultとPermissionsExが導入されている場合に置き換えられます) # %suffix : サフィックス(VaultとPermissionsExが導入されている場合に置き換えられます) +# %date : 日付 +# %time : 時刻 # %msg : 発言内容(Japanize変換された場合は、Japanize結果を含みます。) defaultFormatForPrivateMessage: '&7[%player -> %to]&f %msg' @@ -140,6 +144,8 @@ enableNormalChatMessageFormat: true # %world : 発言したワールド名 # %prefix : プレフィックス(VaultとPermissionsExが導入されている場合に置き換えられます) # %suffix : サフィックス(VaultとPermissionsExが導入されている場合に置き換えられます) +# %date : 日付 +# %time : 時刻 # %msg : 発言内容(Japanize変換された場合は、Japanize結果を含みます。) normalChatMessageFormat: '&f%prefix%username%suffix&a:&f %msg'