Don't allow sending messages too fast
The player needs to wait the configured amount of milliseconds between messages #115
This commit is contained in:
parent
661534b92d
commit
03b91d2fdb
3 changed files with 31 additions and 15 deletions
|
@ -51,6 +51,7 @@ public class ChatPlayer extends TBMCPlayerBase {
|
|||
public boolean RainbowPresserColorMode = false;
|
||||
public Color OtherColorMode = null;
|
||||
public boolean ChatOnly = false;
|
||||
public long LastMessageTime = 0L;
|
||||
|
||||
public static final int FlairTimeNonPresser = -1;
|
||||
public static final int FlairTimeCantPress = -2;
|
||||
|
@ -59,8 +60,7 @@ public class ChatPlayer extends TBMCPlayerBase {
|
|||
/**
|
||||
* Gets the player's flair, optionally formatting for Minecraft.
|
||||
*
|
||||
* @param noformats
|
||||
* The MC formatting codes will be only applied if false
|
||||
* @param noformats The MC formatting codes will be only applied if false
|
||||
* @return The flair
|
||||
*/
|
||||
public String GetFormattedFlair(boolean noformats) {
|
||||
|
|
|
@ -134,20 +134,29 @@ public class ChatProcessing {
|
|||
return true;
|
||||
}
|
||||
|
||||
doFunStuff(sender, e, message);
|
||||
|
||||
final String channelidentifier = getChannelID(channel, e.getOrigin());
|
||||
PluginMain.Instance.getServer().getConsoleSender()
|
||||
.sendMessage(String.format("%s <%s§r> %s", channelidentifier, getSenderName(sender, player), message));
|
||||
|
||||
if (Bukkit.getOnlinePlayers().size() == 0) return false; //Don't try to send to nobody (errors on 1.14)
|
||||
|
||||
ChatPlayer mp;
|
||||
if (player != null)
|
||||
mp = TBMCPlayerBase.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||
else //Due to the online player map, getPlayer() can be more efficient than getAs()
|
||||
mp = e.getUser().getAs(ChatPlayer.class); //May be null
|
||||
|
||||
if (mp != null) {
|
||||
if (System.nanoTime() - mp.LastMessageTime < 1000 * component.minTimeBetweenMessages().get()) { //0.1s by default
|
||||
sender.sendMessage("§cYou are sending messages too fast!");
|
||||
return true;
|
||||
}
|
||||
mp.LastMessageTime = System.nanoTime();
|
||||
}
|
||||
|
||||
doFunStuff(sender, e, message);
|
||||
|
||||
final String channelidentifier = getChannelID(channel, e.getOrigin());
|
||||
|
||||
PluginMain.Instance.getServer().getConsoleSender()
|
||||
.sendMessage(String.format("%s <%s§r> %s", channelidentifier, getSenderName(sender, player), message));
|
||||
|
||||
if (Bukkit.getOnlinePlayers().size() == 0) return false; //Don't try to send to nobody (errors on 1.14)
|
||||
|
||||
Color colormode = channel.Color().get();
|
||||
if (mp != null && mp.OtherColorMode != null)
|
||||
colormode = mp.OtherColorMode;
|
||||
|
|
|
@ -34,6 +34,13 @@ public class FormatterComponent extends Component<PluginMain> {
|
|||
return getConfig().getData("notificationPitch", 1.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* The minimum time between messages in milliseconds.
|
||||
*/
|
||||
public ConfigData<Integer> minTimeBetweenMessages() {
|
||||
return getConfig().getData("minTimeBetweenMessages", 100);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
|
|
Loading…
Reference in a new issue