mirror of
https://github.com/Aust1n46/VentureChat.git
synced 2025-05-23 02:19:05 +00:00
Overhauled mute system.
Improved timed muting. Added new arg parser for mute duration. Fixed cooldown overflow issue. Fixed timed mutes not expiring properly issue. Updated data file format to properly use yml formatting. Properly sync timed mutes over BungeeCord.
This commit is contained in:
parent
87b49cec2b
commit
241fe7a319
@ -8,7 +8,7 @@ BungeeToggleOn: '&6You are now receiving BungeeCord chat.'
|
||||
ClearChatSender: '&aCleared the server chat.'
|
||||
ClearChatServer: '&aYour chat has been cleared.'
|
||||
ChannelCannotMute: '&cYou cannot mute players in this channel: {channel_color}{channel_name}'
|
||||
ChannelCooldown: '&c{cooldown} {units} of cooldown remaining.'
|
||||
ChannelCooldown: '&c{cooldown} of cooldown remaining.'
|
||||
ChannelList: '{channel_color}{channel_name} : {channel_alias}'
|
||||
ChannelListHeader: '&6Channel List : Alias'
|
||||
ChannelListWithPermissions: '{channel_color}{channel_name} : {channel_alias} - Permission Required'
|
||||
@ -17,7 +17,7 @@ ChannelNoPermissionView: '&cYou do not have permission to look at this channel.'
|
||||
ChannelNoSpeakPermissions: '&cYou do not have permission to speak in this channel.'
|
||||
ChannelPlayerListHeader: '&6Players in Channel: {channel_color}{channel_name}'
|
||||
ChannelMuted: '&cYou are muted in this channel: {channel_color}{channel_name}'
|
||||
ChannelMutedTimed: '&cYou are muted in this channel: {channel_color}{channel_name}&c for {time} more {units}'
|
||||
ChannelMutedTimed: '&cYou are muted in this channel: {channel_color}{channel_name}&c for {time}'
|
||||
CommandInvalidArguments: '&cInvalid command: {command} {args}'
|
||||
CommandInvalidArgumentsIgnore: '&cInvalid command: /ignore [player] or /ignore list'
|
||||
CommandMustBeRunByPlayer: '&cThis command must be run by a player.'
|
||||
@ -54,11 +54,11 @@ MustListenOneChannel: '&cYou need to be listening on at least one channel, setti
|
||||
MutePlayerAllPlayer: '&cYou have just been muted in all channels.'
|
||||
MutePlayerAllSender: '&cMuted player &6{player} &cin all channels.'
|
||||
MutePlayerPlayer: '&cYou have just been muted in: {channel_color}{channel_name}'
|
||||
MutePlayerPlayerTime: '&cYou have just been muted in: {channel_color}{channel_name} &cfor {time} {units}'
|
||||
MutePlayerPlayerTime: '&cYou have just been muted in: {channel_color}{channel_name} &cfor {time}'
|
||||
MutePlayerSpam: '&cYou have been muted for spamming in: {channel_color}{channel_name}'
|
||||
MutePlayerSpamTime: '&cYou have been muted for spamming in: {channel_color}{channel_name} &cfor {time} {units}'
|
||||
MutePlayerSpamTime: '&cYou have been muted for spamming in: {channel_color}{channel_name} &cfor {time}'
|
||||
MutePlayerSender: '&cMuted player &6{player} &cin: {channel_color}{channel_name}'
|
||||
MutePlayerSenderTime: '&cMuted player &6{player} &cin: {channel_color}{channel_name} &cfor {time} {units}'
|
||||
MutePlayerSenderTime: '&cMuted player &6{player} &cin: {channel_color}{channel_name} &cfor {time}'
|
||||
NoPlayerToReplyTo: '&cYou do not have anyone to reply to.'
|
||||
NotificationsOff: '&aYou are no longer receiving notifications.'
|
||||
NotificationsOn: '&aYou are now receiving notifications.'
|
||||
@ -78,6 +78,10 @@ SpyOff: '&6You are no longer spying.'
|
||||
SpyOn: '&6You are now spying.'
|
||||
UnblockCommandPlayer: '&cYou have been unblocked from entering command {command}.'
|
||||
UnblockCommandSender: '&cUnblocked player &6{player} &cfrom entering command {command}.'
|
||||
UnitsDayPlural: 'days'
|
||||
UnitsDaySingular: 'day'
|
||||
UnitsHourPlural: 'hours'
|
||||
UnitsHourSingular: 'hour'
|
||||
UnitsMinutePlural: 'minutes'
|
||||
UnitsMinuteSingular: 'minute'
|
||||
UnitsSecondPlural: 'seconds'
|
||||
|
@ -377,25 +377,27 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
@Override
|
||||
public void run() {
|
||||
for (MineverseChatPlayer p : MineverseChatAPI.getOnlineMineverseChatPlayers()) {
|
||||
int time = Format.currentTimeMillis();
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
Iterator<String> iterator = p.getMutes().keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ChatChannel channel = ChatChannel.getChannel(iterator.next());
|
||||
int timemark = p.getMutes().get(channel.getName());
|
||||
if (timemark == 0) {
|
||||
continue;
|
||||
}
|
||||
if (getConfig().getString("loglevel", "info").equals("debug")) {
|
||||
System.out.println(time + " " + timemark);
|
||||
}
|
||||
if (time >= timemark) {
|
||||
iterator.remove();
|
||||
if (p.isOnline()) {
|
||||
String channelName = iterator.next();
|
||||
if(ChatChannel.isChannel(channelName)) {
|
||||
ChatChannel channel = ChatChannel.getChannel(channelName);
|
||||
long timemark = p.getMutes().get(channelName);
|
||||
if (timemark == 0) {
|
||||
continue;
|
||||
}
|
||||
if (getConfig().getString("loglevel", "info").equals("debug")) {
|
||||
System.out.println(currentTimeMillis + " " + timemark);
|
||||
}
|
||||
if (currentTimeMillis >= timemark) {
|
||||
iterator.remove();
|
||||
p.getPlayer().sendMessage(LocalizedMessage.UNMUTE_PLAYER_PLAYER.toString()
|
||||
.replace("{player}", p.getName()).replace("{channel_color}", channel.getColor())
|
||||
.replace("{channel_name}", channel.getName()));
|
||||
} else {
|
||||
p.setModified(true);
|
||||
.replace("{channel_name}", channelName));
|
||||
if(channel.getBungee()) {
|
||||
MineverseChat.getInstance().synchronize(p, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -405,7 +407,7 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
.sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Updating Player Mutes"));
|
||||
}
|
||||
}
|
||||
}, 0L, 1200L); // one minute interval
|
||||
}, 0L, 60L); // three second interval
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -567,6 +569,7 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
ChatChannel channel = ChatChannel.getChannel(c);
|
||||
if(channel.getBungee()) {
|
||||
out.writeUTF(channel.getName());
|
||||
out.writeLong(mcp.getMutes().get(c));
|
||||
}
|
||||
}
|
||||
int ignoreCount = 0;
|
||||
@ -807,9 +810,10 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
// System.out.println(sizeB + " mute size");
|
||||
for(int b = 0; b < sizeB; b++) {
|
||||
String ch = msgin.readUTF();
|
||||
long muteTime = msgin.readLong();
|
||||
// System.out.println(ch);
|
||||
if(ChatChannel.isChannel(ch)) {
|
||||
p.addMute(ch, 0);
|
||||
p.addMute(ch, muteTime);
|
||||
}
|
||||
}
|
||||
// System.out.println(msgin.available() + " available before");
|
||||
@ -942,7 +946,7 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
||||
Set<UUID> ignores = new HashSet<UUID>();
|
||||
Set<String> listening = new HashSet<String>();
|
||||
listening.add(current.getName());
|
||||
HashMap<String, Integer> mutes = new HashMap<String, Integer>();
|
||||
HashMap<String, Long> mutes = new HashMap<String, Long>();
|
||||
Set<String> blockedCommands = new HashSet<String>();
|
||||
String jsonFormat = "Default";
|
||||
s = new MineverseChatPlayer(uuid, name, current, ignores, listening, mutes, blockedCommands, false, null, true, true, name, jsonFormat, false, false, false, true, true);
|
||||
|
@ -22,7 +22,7 @@ public class MineverseChatPlayer {
|
||||
private ChatChannel currentChannel;
|
||||
private Set<UUID> ignores;
|
||||
private Set<String> listening;
|
||||
private HashMap<String, Integer> mutes;
|
||||
private HashMap<String, Long> mutes;
|
||||
private Set<String> blockedCommands;
|
||||
private boolean host;
|
||||
private UUID party;
|
||||
@ -38,9 +38,9 @@ public class MineverseChatPlayer {
|
||||
private boolean quickChat;
|
||||
private ChatChannel quickChannel;
|
||||
private UUID replyPlayer;
|
||||
private HashMap<ChatChannel, Integer> cooldowns;
|
||||
private HashMap<ChatChannel, Long> cooldowns;
|
||||
private boolean partyChat;
|
||||
private HashMap<ChatChannel, List<Integer>> spam;
|
||||
private HashMap<ChatChannel, List<Long>> spam;
|
||||
private boolean modified;
|
||||
private List<ChatMessage> messages;
|
||||
private String jsonFormat;
|
||||
@ -50,14 +50,7 @@ public class MineverseChatPlayer {
|
||||
private boolean messageToggle;
|
||||
private boolean bungeeToggle;
|
||||
|
||||
//buttons variable no longer used
|
||||
//mail variable no longer used
|
||||
@Deprecated
|
||||
public MineverseChatPlayer(UUID uuid, String name, ChatChannel currentChannel, Set<UUID> ignores, Set<String> listening, HashMap<String, Integer> mutes, Set<String> blockedCommands, List<String> mail, boolean host, UUID party, boolean filter, boolean notifications, String nickname, String jsonFormat, boolean spy, boolean commandSpy, boolean rangedSpy, boolean buttons, boolean messageToggle, boolean bungeeToggle) {
|
||||
this(uuid, name, currentChannel, ignores, listening, mutes, blockedCommands, host, party, filter, notifications, nickname, jsonFormat, spy, commandSpy, rangedSpy, messageToggle, bungeeToggle);
|
||||
}
|
||||
|
||||
public MineverseChatPlayer(UUID uuid, String name, ChatChannel currentChannel, Set<UUID> ignores, Set<String> listening, HashMap<String, Integer> mutes, Set<String> blockedCommands, boolean host, UUID party, boolean filter, boolean notifications, String nickname, String jsonFormat, boolean spy, boolean commandSpy, boolean rangedSpy, boolean messageToggle, boolean bungeeToggle) {
|
||||
public MineverseChatPlayer(UUID uuid, String name, ChatChannel currentChannel, Set<UUID> ignores, Set<String> listening, HashMap<String, Long> mutes, Set<String> blockedCommands, boolean host, UUID party, boolean filter, boolean notifications, String nickname, String jsonFormat, boolean spy, boolean commandSpy, boolean rangedSpy, boolean messageToggle, boolean bungeeToggle) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.currentChannel = currentChannel;
|
||||
@ -84,8 +77,8 @@ public class MineverseChatPlayer {
|
||||
this.modified = false;
|
||||
this.messages = new ArrayList<ChatMessage>();
|
||||
this.jsonFormat = jsonFormat;
|
||||
this.cooldowns = new HashMap<ChatChannel, Integer>();
|
||||
this.spam = new HashMap<ChatChannel, List<Integer>>();
|
||||
this.cooldowns = new HashMap<ChatChannel, Long>();
|
||||
this.spam = new HashMap<ChatChannel, List<Long>>();
|
||||
this.messageToggle = messageToggle;
|
||||
this.bungeeToggle = bungeeToggle;
|
||||
}
|
||||
@ -214,11 +207,11 @@ public class MineverseChatPlayer {
|
||||
this.listening.clear();
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getMutes() {
|
||||
public HashMap<String, Long> getMutes() {
|
||||
return this.mutes;
|
||||
}
|
||||
|
||||
public boolean addMute(String channel, int time) {
|
||||
public boolean addMute(String channel, long time) {
|
||||
if(channel != null && time >= 0) {
|
||||
mutes.put(channel, time);
|
||||
return true;
|
||||
@ -412,11 +405,11 @@ public class MineverseChatPlayer {
|
||||
this.partyChat = partyChat;
|
||||
}
|
||||
|
||||
public HashMap<ChatChannel, Integer> getCooldowns() {
|
||||
public HashMap<ChatChannel, Long> getCooldowns() {
|
||||
return this.cooldowns;
|
||||
}
|
||||
|
||||
public boolean addCooldown(ChatChannel channel, int time) {
|
||||
public boolean addCooldown(ChatChannel channel, long time) {
|
||||
if(channel != null && time > 0) {
|
||||
cooldowns.put(channel, time);
|
||||
return true;
|
||||
@ -436,7 +429,7 @@ public class MineverseChatPlayer {
|
||||
return channel != null && this.cooldowns != null ? this.cooldowns.containsKey(channel) : false;
|
||||
}
|
||||
|
||||
public HashMap<ChatChannel, List<Integer>> getSpam() {
|
||||
public HashMap<ChatChannel, List<Long>> getSpam() {
|
||||
return this.spam;
|
||||
}
|
||||
|
||||
@ -446,7 +439,7 @@ public class MineverseChatPlayer {
|
||||
|
||||
public boolean addSpam(ChatChannel channel) {
|
||||
if(channel != null) {
|
||||
spam.put(channel, new ArrayList<Integer>());
|
||||
spam.put(channel, new ArrayList<Long>());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -9,14 +9,14 @@ import java.util.UUID;
|
||||
public class SynchronizedMineverseChatPlayer {
|
||||
private UUID uuid;
|
||||
private Set<String> listening;
|
||||
private HashMap<String, Integer> mutes;
|
||||
private HashMap<String, Long> mutes;
|
||||
private Set<UUID> ignores;
|
||||
private int messagePackets;
|
||||
private List<String> messageData = new ArrayList<String>();
|
||||
private boolean spy;
|
||||
private boolean messageToggle;
|
||||
|
||||
public SynchronizedMineverseChatPlayer(UUID uuid, Set<String> listening, HashMap<String, Integer> mutes, Set<UUID> ignores, boolean spy, boolean messageToggle) {
|
||||
public SynchronizedMineverseChatPlayer(UUID uuid, Set<String> listening, HashMap<String, Long> mutes, Set<UUID> ignores, boolean spy, boolean messageToggle) {
|
||||
this.uuid = uuid;
|
||||
this.listening = listening;
|
||||
this.mutes = mutes;
|
||||
@ -61,15 +61,15 @@ public class SynchronizedMineverseChatPlayer {
|
||||
return this.ignores;
|
||||
}
|
||||
|
||||
public void addMute(String channel) {
|
||||
this.mutes.put(channel, 0);
|
||||
public void addMute(String channel, long muteTime) {
|
||||
this.mutes.put(channel, muteTime);
|
||||
}
|
||||
|
||||
public void removeMute(String channel) {
|
||||
this.mutes.remove(channel);
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getMutes() {
|
||||
public HashMap<String, Long> getMutes() {
|
||||
return this.mutes;
|
||||
}
|
||||
|
||||
|
@ -423,7 +423,7 @@ public class MineverseChatBungee extends Plugin implements Listener {
|
||||
UUID uuid = UUID.fromString(in.readUTF());
|
||||
SynchronizedMineverseChatPlayer smcp = MineverseChatAPI.getSynchronizedMineverseChatPlayer(uuid);
|
||||
if(smcp == null) {
|
||||
smcp = new SynchronizedMineverseChatPlayer(uuid, new HashSet<String>(), new HashMap<String, Integer>(), new HashSet<UUID>(), false, true);
|
||||
smcp = new SynchronizedMineverseChatPlayer(uuid, new HashSet<String>(), new HashMap<String, Long>(), new HashSet<UUID>(), false, true);
|
||||
MineverseChatAPI.addSynchronizedMineverseChatPlayerToMap(smcp);
|
||||
}
|
||||
out.writeUTF("Sync");
|
||||
@ -440,6 +440,7 @@ public class MineverseChatBungee extends Plugin implements Listener {
|
||||
for(String channel : smcp.getMutes().keySet()) {
|
||||
//System.out.println(channel);
|
||||
out.writeUTF(channel);
|
||||
out.writeLong(smcp.getMutes().get(channel));
|
||||
}
|
||||
//System.out.println(smcp.isSpy() + " spy value");
|
||||
//System.out.println(out.size() + " size before");
|
||||
@ -459,7 +460,7 @@ public class MineverseChatBungee extends Plugin implements Listener {
|
||||
UUID uuid = UUID.fromString(in.readUTF());
|
||||
SynchronizedMineverseChatPlayer smcp = MineverseChatAPI.getSynchronizedMineverseChatPlayer(uuid);
|
||||
if(smcp == null) {
|
||||
smcp = new SynchronizedMineverseChatPlayer(uuid, new HashSet<String>(), new HashMap<String, Integer>(), new HashSet<UUID>(), false, true);
|
||||
smcp = new SynchronizedMineverseChatPlayer(uuid, new HashSet<String>(), new HashMap<String, Long>(), new HashSet<UUID>(), false, true);
|
||||
MineverseChatAPI.addSynchronizedMineverseChatPlayerToMap(smcp);
|
||||
}
|
||||
smcp.getListening().clear();
|
||||
@ -474,8 +475,9 @@ public class MineverseChatBungee extends Plugin implements Listener {
|
||||
//System.out.println(size + " mutes");
|
||||
for(int b = 0; b < sizeM; b++) {
|
||||
String mute = in.readUTF();
|
||||
long muteTime = in.readLong();
|
||||
//System.out.println(mute);
|
||||
smcp.addMute(mute);
|
||||
smcp.addMute(mute, muteTime);
|
||||
}
|
||||
int sizeI = in.read();
|
||||
for(int c = 0; c < sizeI; c++) {
|
||||
|
@ -11,7 +11,6 @@ import mineverse.Aust1n46.chat.localization.LocalizedMessage;
|
||||
import mineverse.Aust1n46.chat.utilities.Format;
|
||||
|
||||
public class Mute extends MineverseCommand {
|
||||
private static final int MILLISECONDS_PER_MINUTE = 60000;
|
||||
|
||||
public Mute(String name) {
|
||||
super(name);
|
||||
@ -74,24 +73,22 @@ public class Mute extends MineverseCommand {
|
||||
}
|
||||
if (channel.isMutable()) {
|
||||
try {
|
||||
int datetime = Format.currentTimeMillis();
|
||||
int time = Integer.parseInt(args[2]);
|
||||
long datetime = System.currentTimeMillis();
|
||||
long time = Format.parseTimeStringToMillis(args[2]);
|
||||
if (time > 0) {
|
||||
player.addMute(channel.getName(), datetime + (time * MILLISECONDS_PER_MINUTE));
|
||||
String units = LocalizedMessage.UNITS_MINUTE_PLURAL.toString();
|
||||
if (time == 1)
|
||||
units = LocalizedMessage.UNITS_MINUTE_SINGULAR.toString();
|
||||
player.addMute(channel.getName(), datetime + time);
|
||||
String timeString = Format.parseTimeStringFromMillis(time);
|
||||
sender.sendMessage(LocalizedMessage.MUTE_PLAYER_SENDER_TIME.toString()
|
||||
.replace("{player}", player.getName())
|
||||
.replace("{channel_color}", channel.getColor())
|
||||
.replace("{channel_name}", channel.getName()).replace("{time}", time + "")
|
||||
.replace("{units}", units));
|
||||
.replace("{channel_name}", channel.getName())
|
||||
.replace("{time}", timeString));
|
||||
if (player.isOnline())
|
||||
player.getPlayer()
|
||||
.sendMessage(LocalizedMessage.MUTE_PLAYER_PLAYER_TIME.toString()
|
||||
.replace("{channel_color}", channel.getColor())
|
||||
.replace("{channel_name}", channel.getName())
|
||||
.replace("{time}", time + "").replace("{units}", units));
|
||||
.replace("{time}", timeString));
|
||||
else
|
||||
player.setModified(true);
|
||||
if (channel.getBungee()) {
|
||||
|
@ -52,11 +52,11 @@ public class BungeePlayerData {
|
||||
String channel = l.nextToken();
|
||||
listening.add(channel);
|
||||
}
|
||||
HashMap<String, Integer> mutes = new HashMap<String, Integer>();
|
||||
HashMap<String, Long> mutes = new HashMap<String, Long>();
|
||||
StringTokenizer m = new StringTokenizer(playerData.getString(uuidString + ".mutes"), ",");
|
||||
while(m.hasMoreTokens()) {
|
||||
String[] parts = m.nextToken().split(":");
|
||||
mutes.put(parts[0], Integer.parseInt(parts[1]));
|
||||
mutes.put(parts[0], Long.parseLong(parts[1]));
|
||||
}
|
||||
HashSet<UUID> ignores = new HashSet<UUID>();
|
||||
StringTokenizer n = new StringTokenizer(playerData.getString(uuidString + ".ignores"), ",");
|
||||
@ -115,11 +115,11 @@ public class BungeePlayerData {
|
||||
String channel = l.nextToken();
|
||||
listening.add(channel);
|
||||
}
|
||||
HashMap<String, Integer> mutes = new HashMap<String, Integer>();
|
||||
HashMap<String, Long> mutes = new HashMap<String, Long>();
|
||||
StringTokenizer m = new StringTokenizer(bungeePlayerDataFileConfiguration.getString("mutes"), ",");
|
||||
while(m.hasMoreTokens()) {
|
||||
String[] parts = m.nextToken().split(":");
|
||||
mutes.put(parts[0], Integer.parseInt(parts[1]));
|
||||
mutes.put(parts[0], Long.parseLong(parts[1]));
|
||||
}
|
||||
HashSet<UUID> ignores = new HashSet<UUID>();
|
||||
StringTokenizer n = new StringTokenizer(bungeePlayerDataFileConfiguration.getString("ignores"), ",");
|
||||
|
@ -14,6 +14,7 @@ import java.util.StringTokenizer;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
@ -64,7 +65,7 @@ public class PlayerData {
|
||||
listening.add(channel);
|
||||
}
|
||||
}
|
||||
HashMap<String, Integer> mutes = new HashMap<String, Integer>();
|
||||
HashMap<String, Long> mutes = new HashMap<String, Long>();
|
||||
StringTokenizer m = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("mutes"), ",");
|
||||
while(m.hasMoreTokens()) {
|
||||
String[] parts = m.nextToken().split(":");
|
||||
@ -73,7 +74,7 @@ public class PlayerData {
|
||||
Bukkit.getConsoleSender().sendMessage("[VentureChat] Null Mute Time: " + parts[0] + " " + name);
|
||||
continue;
|
||||
}
|
||||
mutes.put(ChatChannel.getChannel(parts[0]).getName(), Integer.parseInt(parts[1]));
|
||||
mutes.put(ChatChannel.getChannel(parts[0]).getName(), Long.parseLong(parts[1]));
|
||||
}
|
||||
}
|
||||
Set<String> blockedCommands = new HashSet<String>();
|
||||
@ -160,18 +161,24 @@ public class PlayerData {
|
||||
listening.add(channel);
|
||||
}
|
||||
}
|
||||
HashMap<String, Integer> mutes = new HashMap<String, Integer>();
|
||||
StringTokenizer m = new StringTokenizer(playerDataFileYamlConfiguration.getString("mutes"), ",");
|
||||
while(m.hasMoreTokens()) {
|
||||
String[] parts = m.nextToken().split(":");
|
||||
if(ChatChannel.isChannel(parts[0])) {
|
||||
if(parts[1].equals("null")) {
|
||||
Bukkit.getConsoleSender().sendMessage("[VentureChat] Null Mute Time: " + parts[0] + " " + name);
|
||||
continue;
|
||||
}
|
||||
mutes.put(ChatChannel.getChannel(parts[0]).getName(), Integer.parseInt(parts[1]));
|
||||
}
|
||||
HashMap<String, Long> mutes = new HashMap<String, Long>();
|
||||
// StringTokenizer m = new StringTokenizer(playerDataFileYamlConfiguration.getString("mutes"), ",");
|
||||
// while(m.hasMoreTokens()) {
|
||||
// String[] parts = m.nextToken().split(":");
|
||||
// if(ChatChannel.isChannel(parts[0])) {
|
||||
// if(parts[1].equals("null")) {
|
||||
// Bukkit.getConsoleSender().sendMessage("[VentureChat] Null Mute Time: " + parts[0] + " " + name);
|
||||
// continue;
|
||||
// }
|
||||
// mutes.put(ChatChannel.getChannel(parts[0]).getName(), Long.parseLong(parts[1]));
|
||||
// }
|
||||
// }
|
||||
ConfigurationSection muteSection = playerDataFileYamlConfiguration.getConfigurationSection("mutes");
|
||||
for(String channelName : muteSection.getKeys(false)) {
|
||||
ConfigurationSection channelSection = muteSection.getConfigurationSection(channelName);
|
||||
mutes.put(channelName, channelSection.getLong("time"));
|
||||
}
|
||||
|
||||
Set<String> blockedCommands = new HashSet<String>();
|
||||
StringTokenizer b = new StringTokenizer(playerDataFileYamlConfiguration.getString("blockedcommands"), ",");
|
||||
while(b.hasMoreTokens()) {
|
||||
@ -225,11 +232,6 @@ public class PlayerData {
|
||||
ChatChannel c = ChatChannel.getChannel(channel);
|
||||
listening += c.getName() + ",";
|
||||
}
|
||||
String mutes = "";
|
||||
for(String channel : mcp.getMutes().keySet()) {
|
||||
ChatChannel c = ChatChannel.getChannel(channel);
|
||||
mutes += c.getName() + ":" + mcp.getMutes().get(c.getName()) + ",";
|
||||
}
|
||||
String blockedCommands = "";
|
||||
for(String s : mcp.getBlockedCommands()) {
|
||||
blockedCommands += s + ",";
|
||||
@ -238,13 +240,13 @@ public class PlayerData {
|
||||
listening = listening.substring(0, listening.length() - 1);
|
||||
}
|
||||
playerDataFileYamlConfiguration.set("listen", listening);
|
||||
if(mutes.length() > 0) {
|
||||
mutes = mutes.substring(0, mutes.length() - 1);
|
||||
}
|
||||
playerDataFileYamlConfiguration.set("mutes", mutes);
|
||||
if(blockedCommands.length() > 0) {
|
||||
blockedCommands = blockedCommands.substring(0, blockedCommands.length() - 1);
|
||||
|
||||
ConfigurationSection muteSection = playerDataFileYamlConfiguration.createSection("mutes");
|
||||
for(String channelName : mcp.getMutes().keySet()) {
|
||||
ConfigurationSection channelSection = muteSection.createSection(channelName);
|
||||
channelSection.set("time", mcp.getMutes().get(channelName));
|
||||
}
|
||||
|
||||
playerDataFileYamlConfiguration.set("blockedcommands", blockedCommands);
|
||||
playerDataFileYamlConfiguration.set("host", mcp.isHost());
|
||||
playerDataFileYamlConfiguration.set("party", mcp.hasParty() ? mcp.getParty().toString() : "");
|
||||
|
@ -35,9 +35,6 @@ import mineverse.Aust1n46.chat.versions.VersionHandler;
|
||||
|
||||
//This class listens to chat through the chat event and handles the bulk of the chat channels and formatting.
|
||||
public class ChatListener implements Listener {
|
||||
private static final int MILLISECONDS_PER_MINUTE = 60000;
|
||||
private static final int MILLISECONDS_PER_SECOND = 1000;
|
||||
|
||||
private MineverseChat plugin = MineverseChat.getInstance();
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
@ -213,22 +210,19 @@ public class ChatListener implements Listener {
|
||||
Boolean filterthis = true;
|
||||
mcp.addListening(eventChannel.getName());
|
||||
if (mcp.isMuted(eventChannel.getName())) {
|
||||
if (mcp.getMutes().get(eventChannel.getName()).intValue() > 0) {
|
||||
int dateTimeMillis = Format.currentTimeMillis();
|
||||
String units = LocalizedMessage.UNITS_MINUTE_PLURAL.toString();
|
||||
int muteTimeMillis = mcp.getMutes().get(eventChannel.getName()).intValue();
|
||||
int remainingMuteTime = (muteTimeMillis - dateTimeMillis) / MILLISECONDS_PER_MINUTE;
|
||||
if (remainingMuteTime <= 0) {
|
||||
remainingMuteTime = 1;
|
||||
}
|
||||
if (remainingMuteTime == 1) {
|
||||
units = LocalizedMessage.UNITS_MINUTE_SINGULAR.toString();
|
||||
if (mcp.getMutes().get(eventChannel.getName()).longValue() > 0) {
|
||||
long dateTimeMillis = System.currentTimeMillis();
|
||||
long muteTimeMillis = mcp.getMutes().get(eventChannel.getName()).longValue();
|
||||
long remainingMuteTime = muteTimeMillis - dateTimeMillis;
|
||||
if (remainingMuteTime < 1000) {
|
||||
remainingMuteTime = 1000;
|
||||
}
|
||||
String timeString = Format.parseTimeStringFromMillis(remainingMuteTime);
|
||||
mcp.getPlayer()
|
||||
.sendMessage(LocalizedMessage.CHANNEL_MUTED_TIMED.toString()
|
||||
.replace("{channel_color}", eventChannel.getColor())
|
||||
.replace("{channel_name}", eventChannel.getName())
|
||||
.replace("{time}", String.valueOf(remainingMuteTime)).replace("{units}", units));
|
||||
.replace("{time}", timeString));
|
||||
}
|
||||
else {
|
||||
mcp.getPlayer()
|
||||
@ -240,7 +234,6 @@ public class ChatListener implements Listener {
|
||||
return;
|
||||
}
|
||||
Double chDistance = (double) 0;
|
||||
int chCooldown = 0;
|
||||
String curColor = "";
|
||||
if(eventChannel.hasPermission() && !mcp.getPlayer().hasPermission(eventChannel.getPermission())) {
|
||||
mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_NO_PERMISSION.toString());
|
||||
@ -257,22 +250,20 @@ public class ChatListener implements Listener {
|
||||
curColor = eventChannel.getChatColor();
|
||||
bungee = eventChannel.getBungee();
|
||||
|
||||
int dateTimeSeconds = Format.currentTimeMillis() / MILLISECONDS_PER_SECOND;
|
||||
long dateTimeSeconds = System.currentTimeMillis() / Format.MILLISECONDS_PER_SECOND;
|
||||
|
||||
int chCooldown = 0;
|
||||
if(eventChannel.hasCooldown()) {
|
||||
chCooldown = eventChannel.getCooldown();
|
||||
}
|
||||
try {
|
||||
if (mcp.hasCooldown(eventChannel)) {
|
||||
int cooldownTime = mcp.getCooldowns().get(eventChannel).intValue();
|
||||
long cooldownTime = mcp.getCooldowns().get(eventChannel).longValue();
|
||||
if (dateTimeSeconds < cooldownTime) {
|
||||
int remainingCooldownTime = cooldownTime - dateTimeSeconds;
|
||||
String units = LocalizedMessage.UNITS_SECOND_PLURAL.toString();
|
||||
if (remainingCooldownTime == 1) {
|
||||
units = LocalizedMessage.UNITS_SECOND_SINGULAR.toString();
|
||||
}
|
||||
long remainingCooldownTime = cooldownTime - dateTimeSeconds;
|
||||
String cooldownString = Format.parseTimeStringFromMillis(remainingCooldownTime * Format.MILLISECONDS_PER_SECOND);
|
||||
mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_COOLDOWN.toString()
|
||||
.replace("{cooldown}", String.valueOf(remainingCooldownTime)).replace("{units}", units));
|
||||
.replace("{cooldown}", cooldownString));
|
||||
mcp.setQuickChat(false);
|
||||
bungee = false;
|
||||
return;
|
||||
@ -289,25 +280,23 @@ public class ChatListener implements Listener {
|
||||
|
||||
if (mcp.hasSpam(eventChannel) && plugin.getConfig().getConfigurationSection("antispam").getBoolean("enabled")
|
||||
&& !mcp.getPlayer().hasPermission("venturechat.spam.bypass")) {
|
||||
int spamcount = mcp.getSpam().get(eventChannel).get(0);
|
||||
int spamtime = mcp.getSpam().get(eventChannel).get(1);
|
||||
int spamtimeconfig = plugin.getConfig().getConfigurationSection("antispam").getInt("spamnumber");
|
||||
int mutedForTime = plugin.getConfig().getConfigurationSection("antispam").getInt("mutetime", 0);
|
||||
int dateTime = Format.currentTimeMillis();
|
||||
long spamcount = mcp.getSpam().get(eventChannel).get(0);
|
||||
long spamtime = mcp.getSpam().get(eventChannel).get(1);
|
||||
long spamtimeconfig = plugin.getConfig().getConfigurationSection("antispam").getLong("spamnumber");
|
||||
String mutedForTime = plugin.getConfig().getConfigurationSection("antispam").getString("mutetime", "0");
|
||||
long dateTime = System.currentTimeMillis();
|
||||
if (dateTimeSeconds < spamtime
|
||||
+ plugin.getConfig().getConfigurationSection("antispam").getInt("spamtime")) {
|
||||
+ plugin.getConfig().getConfigurationSection("antispam").getLong("spamtime")) {
|
||||
if (spamcount + 1 >= spamtimeconfig) {
|
||||
if (mutedForTime > 0) {
|
||||
mcp.addMute(eventChannel.getName(), dateTime + (mutedForTime * MILLISECONDS_PER_MINUTE));
|
||||
String units = LocalizedMessage.UNITS_MINUTE_PLURAL.toString();
|
||||
if (mutedForTime == 1) {
|
||||
units = LocalizedMessage.UNITS_MINUTE_SINGULAR.toString();
|
||||
}
|
||||
long time = Format.parseTimeStringToMillis(mutedForTime);
|
||||
if (time > 0) {
|
||||
mcp.addMute(eventChannel.getName(), dateTime + time);
|
||||
String timeString = Format.parseTimeStringFromMillis(time);
|
||||
mcp.getPlayer()
|
||||
.sendMessage(LocalizedMessage.MUTE_PLAYER_SPAM_TIME.toString()
|
||||
.replace("{channel_color}", eventChannel.getColor())
|
||||
.replace("{channel_name}", eventChannel.getName())
|
||||
.replace("{time}", String.valueOf(mutedForTime)).replace("{units}", units));
|
||||
.replace("{time}", timeString));
|
||||
}
|
||||
else {
|
||||
mcp.addMute(eventChannel.getName(), 0);
|
||||
@ -316,7 +305,7 @@ public class ChatListener implements Listener {
|
||||
.replace("{channel_color}", eventChannel.getColor())
|
||||
.replace("{channel_name}", eventChannel.getName()));
|
||||
}
|
||||
mcp.getSpam().get(eventChannel).set(0, 0);
|
||||
mcp.getSpam().get(eventChannel).set(0, 0L);
|
||||
mcp.setQuickChat(false);
|
||||
return;
|
||||
} else {
|
||||
@ -329,12 +318,12 @@ public class ChatListener implements Listener {
|
||||
mcp.getSpam().get(eventChannel).set(0, spamcount + 1);
|
||||
}
|
||||
} else {
|
||||
mcp.getSpam().get(eventChannel).set(0, 1);
|
||||
mcp.getSpam().get(eventChannel).set(0, 1L);
|
||||
mcp.getSpam().get(eventChannel).set(1, dateTimeSeconds);
|
||||
}
|
||||
} else {
|
||||
mcp.addSpam(eventChannel);
|
||||
mcp.getSpam().get(eventChannel).add(0, 1);
|
||||
mcp.getSpam().get(eventChannel).add(0, 1L);
|
||||
mcp.getSpam().get(eventChannel).add(1, dateTimeSeconds);
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class LoginListener implements Listener {
|
||||
Set<UUID> ignores = new HashSet<UUID>();
|
||||
Set<String> listening = new HashSet<String>();
|
||||
listening.add(current.getName());
|
||||
HashMap<String, Integer> mutes = new HashMap<String, Integer>();
|
||||
HashMap<String, Long> mutes = new HashMap<String, Long>();
|
||||
Set<String> blockedCommands = new HashSet<String>();
|
||||
String jsonFormat = "Default";
|
||||
mcp = new MineverseChatPlayer(uuid, name, current, ignores, listening, mutes, blockedCommands, false, null, true, true, name, jsonFormat, false, false, false, true, true);
|
||||
|
@ -85,6 +85,10 @@ public enum LocalizedMessage {
|
||||
SPY_ON("SpyOn"),
|
||||
UNBLOCK_COMMAND_PLAYER("UnblockCommandPlayer"),
|
||||
UNBLOCK_COMMAND_SENDER("UnblockCommandSender"),
|
||||
UNITS_DAY_PLURAL("UnitsDayPlural"),
|
||||
UNITS_DAY_SINGULAR("UnitsDaySingular"),
|
||||
UNITS_HOUR_PLURAL("UnitsHourPlural"),
|
||||
UNITS_HOUR_SINGULAR("UnitsHourSingular"),
|
||||
UNITS_MINUTE_PLURAL("UnitsMinutePlural"),
|
||||
UNITS_MINUTE_SINGULAR("UnitsMinuteSingular"),
|
||||
UNITS_SECOND_PLURAL("UnitsSecondPlural"),
|
||||
|
@ -21,6 +21,7 @@ import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import mineverse.Aust1n46.chat.MineverseChat;
|
||||
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
|
||||
import mineverse.Aust1n46.chat.json.JsonFormat;
|
||||
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
|
||||
import mineverse.Aust1n46.chat.versions.VersionHandler;
|
||||
|
||||
/**
|
||||
@ -39,6 +40,11 @@ public class Format {
|
||||
private static final Pattern LEGACY_CHAT_COLOR_PATTERN = Pattern.compile(
|
||||
"(?<!(&x(&[a-fA-F0-9]){5}))(?<!(&x(&[a-fA-F0-9]){4}))(?<!(&x(&[a-fA-F0-9]){3}))(?<!(&x(&[a-fA-F0-9]){2}))(?<!(&x(&[a-fA-F0-9]){1}))(?<!(&x))(&)([0-9a-fA-F])");
|
||||
|
||||
public static final long MILLISECONDS_PER_DAY = 86400000;
|
||||
public static final long MILLISECONDS_PER_HOUR = 3600000;
|
||||
public static final long MILLISECONDS_PER_MINUTE = 60000;
|
||||
public static final long MILLISECONDS_PER_SECOND = 1000;
|
||||
|
||||
/**
|
||||
* Converts a message to Minecraft JSON formatting while applying the
|
||||
* {@link JsonFormat} from the config.
|
||||
@ -700,7 +706,134 @@ public class Format {
|
||||
return getInstance().getConfig().getBoolean("underlineurls", true);
|
||||
}
|
||||
|
||||
public static int currentTimeMillis() {
|
||||
return (int) (System.currentTimeMillis() % Integer.MAX_VALUE);
|
||||
public static String parseTimeStringFromMillis(long millis) {
|
||||
String timeString = "";
|
||||
if(millis >= Format.MILLISECONDS_PER_DAY) {
|
||||
long numberOfDays = millis / Format.MILLISECONDS_PER_DAY;
|
||||
millis -= Format.MILLISECONDS_PER_DAY * numberOfDays;
|
||||
|
||||
String units = LocalizedMessage.UNITS_DAY_PLURAL.toString();
|
||||
if (numberOfDays == 1) {
|
||||
units = LocalizedMessage.UNITS_DAY_SINGULAR.toString();
|
||||
}
|
||||
timeString += numberOfDays + " " + units + " ";
|
||||
}
|
||||
|
||||
if(millis >= Format.MILLISECONDS_PER_HOUR) {
|
||||
long numberOfHours = millis / Format.MILLISECONDS_PER_HOUR;
|
||||
millis -= Format.MILLISECONDS_PER_HOUR * numberOfHours;
|
||||
|
||||
String units = LocalizedMessage.UNITS_HOUR_PLURAL.toString();
|
||||
if (numberOfHours == 1) {
|
||||
units = LocalizedMessage.UNITS_HOUR_SINGULAR.toString();
|
||||
}
|
||||
timeString += numberOfHours + " " + units + " ";
|
||||
}
|
||||
|
||||
if(millis >= Format.MILLISECONDS_PER_MINUTE) {
|
||||
long numberOfMinutes = millis / Format.MILLISECONDS_PER_MINUTE;
|
||||
millis -= Format.MILLISECONDS_PER_MINUTE * numberOfMinutes;
|
||||
|
||||
String units = LocalizedMessage.UNITS_MINUTE_PLURAL.toString();
|
||||
if (numberOfMinutes == 1) {
|
||||
units = LocalizedMessage.UNITS_MINUTE_SINGULAR.toString();
|
||||
}
|
||||
timeString += numberOfMinutes + " " + units + " ";
|
||||
}
|
||||
|
||||
if(millis >= Format.MILLISECONDS_PER_SECOND) {
|
||||
long numberOfSeconds = millis / Format.MILLISECONDS_PER_SECOND;
|
||||
millis -= Format.MILLISECONDS_PER_SECOND * numberOfSeconds;
|
||||
|
||||
String units = LocalizedMessage.UNITS_SECOND_PLURAL.toString();
|
||||
if (numberOfSeconds == 1) {
|
||||
units = LocalizedMessage.UNITS_SECOND_SINGULAR.toString();
|
||||
}
|
||||
timeString += numberOfSeconds + " " + units;
|
||||
}
|
||||
return timeString.trim();
|
||||
}
|
||||
|
||||
public static long parseTimeStringToMillis(String timeInput) {
|
||||
long millis = 0L;
|
||||
timeInput = timeInput.toLowerCase();
|
||||
char validChars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'd', 'h', 'm', 's' };
|
||||
if(containsInvalidChars(validChars, timeInput)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
long countDayTokens = timeInput.chars().filter(ch -> ch == 'd').count();
|
||||
long countHourTokens = timeInput.chars().filter(ch -> ch == 'h').count();
|
||||
long countMinuteTokens = timeInput.chars().filter(ch -> ch == 'm').count();
|
||||
long countSecondTokens = timeInput.chars().filter(ch -> ch == 's').count();
|
||||
if(countDayTokens > 1 || countHourTokens > 1 || countMinuteTokens > 1 || countSecondTokens > 1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int indexOfSecondToken = timeInput.indexOf("s");
|
||||
int indexOfMinuteToken = timeInput.indexOf("m");
|
||||
int indexOfHourToken = timeInput.indexOf("h");
|
||||
int indexOfDayToken = timeInput.indexOf("d");
|
||||
if(indexOfDayToken != -1) {
|
||||
if((indexOfHourToken != -1 && indexOfHourToken < indexOfDayToken) || (indexOfMinuteToken != -1 && indexOfMinuteToken < indexOfDayToken) || (indexOfSecondToken != -1 && indexOfSecondToken < indexOfDayToken)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if(indexOfHourToken != -1) {
|
||||
if((indexOfMinuteToken != -1 && indexOfMinuteToken < indexOfHourToken) || (indexOfSecondToken != -1 && indexOfSecondToken < indexOfHourToken)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if(indexOfMinuteToken != -1) {
|
||||
if((indexOfSecondToken != -1 && indexOfSecondToken < indexOfMinuteToken)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if(indexOfDayToken != -1) {
|
||||
int numberOfDays = Integer.parseInt(timeInput.substring(0, indexOfDayToken));
|
||||
timeInput = timeInput.substring(indexOfDayToken + 1);
|
||||
millis += MILLISECONDS_PER_DAY * numberOfDays;
|
||||
}
|
||||
if(timeInput.length() > 0) {
|
||||
indexOfHourToken = timeInput.indexOf("h");
|
||||
if(indexOfHourToken != -1) {
|
||||
int numberOfHours = Integer.parseInt(timeInput.substring(0, indexOfHourToken));
|
||||
timeInput = timeInput.substring(indexOfHourToken + 1);
|
||||
millis += MILLISECONDS_PER_HOUR * numberOfHours;
|
||||
}
|
||||
}
|
||||
if(timeInput.length() > 0) {
|
||||
indexOfMinuteToken = timeInput.indexOf("m");
|
||||
if(indexOfMinuteToken != -1) {
|
||||
int numberOfMinutes = Integer.parseInt(timeInput.substring(0, indexOfMinuteToken));
|
||||
timeInput = timeInput.substring(indexOfMinuteToken + 1);
|
||||
millis += MILLISECONDS_PER_MINUTE * numberOfMinutes;
|
||||
}
|
||||
}
|
||||
if(timeInput.length() > 0) {
|
||||
indexOfSecondToken = timeInput.indexOf("s");
|
||||
if(indexOfSecondToken != -1) {
|
||||
int numberOfSeconds = Integer.parseInt(timeInput.substring(0, indexOfSecondToken));
|
||||
timeInput = timeInput.substring(indexOfSecondToken + 1);
|
||||
millis += MILLISECONDS_PER_SECOND * numberOfSeconds;
|
||||
}
|
||||
}
|
||||
return millis;
|
||||
}
|
||||
|
||||
private static boolean containsInvalidChars(char[] validChars, String validate) {
|
||||
for(char c : validate.toCharArray()) {
|
||||
boolean isValidChar = false;
|
||||
for(char v : validChars) {
|
||||
if(c == v) {
|
||||
isValidChar = true;
|
||||
}
|
||||
}
|
||||
if(!isValidChar) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user