rendered paste bodyIndex: java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
===================================================================
--- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 1245)
+++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (working copy)
@@ -30,6 +30,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
+import java.util.logging.Logger;
import javolution.util.FastList;
import javolution.util.FastMap;
@@ -348,6 +349,8 @@
private boolean _inJail = false;
private long _jailTimer = 0;
+ private boolean _chatBanned = false;
+ private long _chatBanTimer = 0;
private ScheduledFuture _jailTask;
/** Olympiad */
@@ -511,7 +514,6 @@
private boolean _isGm;
private int _accessLevel;
- private boolean _chatBanned = false; // Chat Banned
private ScheduledFuture _chatUnbanTask = null;
private boolean _messageRefusal = false; // message refusal mode
private boolean _dietMode = false; // ignore weight penalty
@@ -638,6 +640,7 @@
_reference = reference;
_sendMessage = sendMessage;
}
+ @SuppressWarnings("synthetic-access")
public void run()
{
try
@@ -646,7 +649,8 @@
}
catch (Throwable t)
{
- _log.log(Level.WARNING, "", t);
+ Logger logger = _log;
+ logger.log(Level.WARNING, "", t);
}
}
}
@@ -5988,6 +5992,8 @@
statement.setString(55, getName());
statement.setLong(56, getDeathPenaltyBuffLevel());
statement.setInt(57, getObjectId());
+ statement.setInt(58, isChatBanned() ? 1 : 0);
+ statement.setLong(59, getChatBanTimer());
statement.execute();
statement.close();
@@ -5996,7 +6002,7 @@
finally { try { con.close(); } catch (Exception e) {} }
}
- private void storeCharSub()
+ private void storeCharSub()
{
java.sql.Connection con = null;
@@ -7934,36 +7940,6 @@
return _race[i];
}
- public void setChatBanned(boolean isBanned)
- {
- _chatBanned = isBanned;
-
- if (isChatBanned())
- sendMessage("You have been chat banned by a server admin.");
- else
- {
- sendMessage("Your chat ban has been lifted.");
- if (_chatUnbanTask != null)
- _chatUnbanTask.cancel(false);
- _chatUnbanTask = null;
- }
- sendPacket(new EtcStatusUpdate(this));
- }
-
- public boolean isChatBanned()
- {
- return _chatBanned;
- }
-
- public void setChatUnbanTask(ScheduledFuture task)
- {
- _chatUnbanTask = task;
- }
- public ScheduledFuture getChatUnbanTask()
- {
- return _chatUnbanTask;
- }
-
public boolean getMessageRefusal()
{
return _messageRefusal;
@@ -8660,6 +8636,8 @@
// jail task
updateJailState();
+ // chat ban task
+ updateChatBanState();
if (_isInvul)
sendMessage("Entering world in Invulnerable mode.");
@@ -9750,6 +9728,99 @@
_queuedSkill = new SkillDat(queuedSkill, ctrlPressed, shiftPressed);
}
+ public boolean isChatBanned()
+ {
+ return _chatBanned;
+ }
+
+ public void setChatBanned(boolean state)
+ {
+ _chatBanned = state;
+
+ }
+ public void setChatBanned(boolean state, int delayInMinutes)
+ {
+ _chatBanned = state;
+ _chatBanTimer = delayInMinutes;
+ //Remove the task if any
+ stopChatUnbanTask(false);
+
+ if (_chatBanned)
+ {
+ if (delayInMinutes > 0)
+ {
+ _chatBanTimer = delayInMinutes * 60000L; // in millisec
+
+ // start the countdown
+ _chatUnbanTask = ThreadPoolManager.getInstance().scheduleGeneral(new ChatUnbanTask(this), _chatBanTimer);
+ sendMessage("You have been chat banned by a server admin for "+delayInMinutes+" minutes.");
+ }
+ }
+ else
+ {
+ sendMessage("Your chat ban has been lifted.");
+ }
+ sendPacket(new EtcStatusUpdate(this));
+ storeCharBase();
+ }
+
+ public long getChatBanTimer()
+ {
+ return _chatBanTimer;
+ }
+
+ public void setChatBanTimer(long time)
+ {
+ _chatBanTimer = time;
+ }
+
+ private void updateChatBanState()
+ {
+ if (isChatBanned())
+ {
+ // If chat ban time is elapsed, player can talk :P
+ if (_chatBanTimer > 0)
+ {
+ // restart the countdown
+ _chatUnbanTask = ThreadPoolManager.getInstance().scheduleGeneral(new ChatUnbanTask(this), _chatBanTimer);
+ sendMessage("You are still chat banned for "+Math.round(_chatBanTimer/60000)+" minutes.");
+ }
+ }
+ }
+
+ public void stopChatUnbanTask(boolean save)
+ {
+ if (_chatUnbanTask != null)
+ {
+ if (save)
+ {
+ long delay = _chatUnbanTask.getDelay(TimeUnit.MILLISECONDS);
+ if (delay < 0)
+ delay = 0;
+ setChatBanTimer(delay);
+ }
+ _chatUnbanTask.cancel(false);
+ _chatUnbanTask = null;
+ }
+ }
+
+ private class ChatUnbanTask implements Runnable
+ {
+ L2PcInstance _player;
+ protected long _startedAt;
+
+ protected ChatUnbanTask(L2PcInstance player)
+ {
+ _player = player;
+ _startedAt = System.currentTimeMillis();
+ }
+
+ public void run()
+ {
+ _player.setChatBanned(false, 0);
+ }
+ }
+
public boolean isInJail()
{
return _inJail;