Merge pull request #5 from feature/chatslow to master
* commit '9ef0ea629c57b148d815b93a455f9817ce512960': Added changes from master to Chat Chat Slow Command
This commit is contained in:
commit
4c4ba34d39
@ -7,7 +7,9 @@ import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
@ -17,6 +19,7 @@ import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.chat.command.ChatSlowCommand;
|
||||
import mineplex.core.preferences.PreferencesManager;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
@ -57,9 +60,10 @@ public class Chat extends MiniPlugin
|
||||
//private String _authName = "";
|
||||
private String _serverName;
|
||||
|
||||
private int _chatSlow = 0;
|
||||
private long _silenced = 0;
|
||||
|
||||
private NautHashMap<String, String> _playerLastMessage = new NautHashMap<String, String>();
|
||||
private HashMap<UUID, MessageData> _playerLastMessage = new HashMap<UUID, MessageData>();
|
||||
|
||||
public Chat(JavaPlugin plugin, CoreClientManager clientManager, PreferencesManager preferences, String serverName)
|
||||
{
|
||||
@ -84,6 +88,23 @@ public class Chat extends MiniPlugin
|
||||
{
|
||||
addCommand(new SilenceCommand(this));
|
||||
addCommand(new BroadcastCommand(this));
|
||||
addCommand(new ChatSlowCommand(this));
|
||||
}
|
||||
|
||||
public void setChatSlow(int seconds, boolean inform)
|
||||
{
|
||||
if (seconds < 0)
|
||||
seconds = 0;
|
||||
|
||||
_chatSlow = seconds;
|
||||
|
||||
if (inform)
|
||||
{
|
||||
if (seconds == 0)
|
||||
UtilServer.broadcast(F.main("Chat", "Chat Slow is now disabled"));
|
||||
else
|
||||
UtilServer.broadcast(F.main("Chat", "Chat slow is now enabled with a cooldown of " + F.time(seconds + " seconds")));
|
||||
}
|
||||
}
|
||||
|
||||
public void Silence(long duration, boolean inform)
|
||||
@ -290,17 +311,26 @@ public class Chat extends MiniPlugin
|
||||
UtilPlayer.message(sender, F.main("Chat", "You are sending messages too fast."));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else if (!_clientManager.Get(sender).GetRank().Has(Rank.MODERATOR) &&
|
||||
_playerLastMessage.containsKey(sender.getName()) &&
|
||||
_playerLastMessage.get(sender.getName()).equalsIgnoreCase(event.getMessage()))
|
||||
else if (_playerLastMessage.containsKey(sender.getUniqueId()))
|
||||
{
|
||||
UtilPlayer.message(sender, F.main("Chat", "You can't repeat the same message."));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_playerLastMessage.put(sender.getName(), event.getMessage());
|
||||
MessageData lastMessage = _playerLastMessage.get(sender.getUniqueId());
|
||||
long chatSlowTime = 1000L * _chatSlow;
|
||||
long timeDiff = System.currentTimeMillis() - lastMessage.getTimeSent();
|
||||
if (timeDiff < chatSlowTime && !_clientManager.Get(sender).GetRank().Has(Rank.HELPER))
|
||||
{
|
||||
UtilPlayer.message(sender, F.main("Chat", "Chat slow enabled. Please wait " + F.time(UtilTime.convertString(chatSlowTime - timeDiff, 1, UtilTime.TimeUnit.FIT))));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else if (!_clientManager.Get(sender).GetRank().Has(Rank.MODERATOR) &&
|
||||
lastMessage.getMessage().equalsIgnoreCase(event.getMessage()))
|
||||
{
|
||||
UtilPlayer.message(sender, F.main("Chat", "You can't repeat the same message."));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!event.isCancelled())
|
||||
_playerLastMessage.put(sender.getUniqueId(), new MessageData(event.getMessage()));
|
||||
}
|
||||
|
||||
public String hasher(JSONArray hasharray, String message)
|
||||
@ -530,6 +560,6 @@ public class Chat extends MiniPlugin
|
||||
@EventHandler
|
||||
public void playerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
_playerLastMessage.remove(event.getPlayer().getName());
|
||||
_playerLastMessage.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package mineplex.core.chat;
|
||||
|
||||
public class MessageData
|
||||
{
|
||||
private String _message;
|
||||
private long _timeSent;
|
||||
|
||||
public MessageData(String message)
|
||||
{
|
||||
this(message, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public MessageData(String message, long timeSent)
|
||||
{
|
||||
_message = message;
|
||||
_timeSent = timeSent;
|
||||
}
|
||||
|
||||
public String getMessage()
|
||||
{
|
||||
return _message;
|
||||
}
|
||||
|
||||
public long getTimeSent()
|
||||
{
|
||||
return _timeSent;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package mineplex.core.chat.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.chat.Chat;
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
|
||||
public class ChatSlowCommand extends CommandBase<Chat>
|
||||
{
|
||||
public ChatSlowCommand(Chat plugin)
|
||||
{
|
||||
super(plugin, Rank.SNR_MODERATOR, "chatslow");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
if (args != null && args.length == 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
int seconds = Integer.parseInt(args[0]);
|
||||
|
||||
if (seconds < 0)
|
||||
{
|
||||
UtilPlayer.message(caller, F.main("Chat", "Seconds must be a positive integer"));
|
||||
return;
|
||||
}
|
||||
|
||||
Plugin.setChatSlow(seconds, true);
|
||||
UtilPlayer.message(caller, F.main("Chat", "Set chat slow to " + F.time(seconds + " seconds")));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
showUsage(caller);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
showUsage(caller);
|
||||
}
|
||||
}
|
||||
|
||||
private void showUsage(Player caller)
|
||||
{
|
||||
UtilPlayer.message(caller, F.main("Chat", "Usage: /chatslow <seconds>"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user