Reuse delay on voiced commands?
Posted: Fri Dec 12, 2014 8:19 am
Havent tried that before, any ideas how to begin, is there an example?
For example after someone has used the command he cant use it again after 30 seconds or something like that.Zoey76 wrote:What do you mean by "reuse delay"?
diff --git a/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java b/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java | |
index f31bf55..ced0f5a 100644 | |
--- a/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java | |
+++ b/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java | |
@@ -18,7 +18,9 @@ | |
*/ | |
package handlers.voicedcommandhandlers; | |
+import java.util.Map; | |
import java.util.StringTokenizer; | |
+import java.util.concurrent.ConcurrentHashMap; | |
import java.util.logging.Level; | |
import com.l2jserver.gameserver.LoginServerThread; | |
@@ -32,6 +34,8 @@ | |
*/ | |
public class ChangePassword implements IVoicedCommandHandler | |
{ | |
+ private static final Map<Integer, Long> REUSES = new ConcurrentHashMap<>(); | |
+ private static final int REUSE = 30 * 60 * 1000; // 30 Min | |
private static final String[] _voicedCommands = | |
{ | |
"changepassword" | |
@@ -77,6 +81,13 @@ | |
return false; | |
} | |
+ final Long timeStamp = REUSES.get(activeChar.getObjectId()); | |
+ if ((timeStamp != null) && ((System.currentTimeMillis() - REUSE) < timeStamp.longValue())) | |
+ { | |
+ activeChar.sendMessage("You cannot change the password so often!"); | |
+ return false; | |
+ } | |
+ REUSES.put(activeChar.getObjectId(), System.currentTimeMillis()); | |
LoginServerThread.getInstance().sendChangePassword(activeChar.getAccountName(), activeChar.getName(), curpass, newpass); | |
} | |
else |
Thats what i needed, thanks.Zoey76 wrote:This is just an example, restart/shutdown will reset reuse and as long as the server is on the memory for this records will be used.Gist by: Zoey76This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
diff --git a/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java b/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java index f31bf55..ced0f5a 100644 --- a/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java +++ b/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java @@ -18,7 +18,9 @@ */ package handlers.voicedcommandhandlers; +import java.util.Map; import java.util.StringTokenizer; +import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import com.l2jserver.gameserver.LoginServerThread; @@ -32,6 +34,8 @@ */ public class ChangePassword implements IVoicedCommandHandler { + private static final Map<Integer, Long> REUSES = new ConcurrentHashMap<>(); + private static final int REUSE = 30 * 60 * 1000; // 30 Min private static final String[] _voicedCommands = { "changepassword" @@ -77,6 +81,13 @@ return false; } + final Long timeStamp = REUSES.get(activeChar.getObjectId()); + if ((timeStamp != null) && ((System.currentTimeMillis() - REUSE) < timeStamp.longValue())) + { + activeChar.sendMessage("You cannot change the password so often!"); + return false; + } + REUSES.put(activeChar.getObjectId(), System.currentTimeMillis()); LoginServerThread.getInstance().sendChangePassword(activeChar.getAccountName(), activeChar.getName(), curpass, newpass); } else