diff --git a/src/Messages.yml b/src/Messages.yml index 5566641..8b0e3b2 100644 --- a/src/Messages.yml +++ b/src/Messages.yml @@ -16,7 +16,8 @@ ChannelNoPermission: '&cYou do not have permission for this channel.' 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}&c{time}' +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}' CommandInvalidArguments: '&cInvalid command: {command} {args}' CommandInvalidArgumentsIgnore: '&cInvalid command: /ignore [player] or /ignore list' CommandMustBeRunByPlayer: '&cThis command must be run by a player.' @@ -54,7 +55,8 @@ 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}' -MutePlayerSpam: '&cYou have been muted for spamming in: {channel_color}{channel_name}&c{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}' MutePlayerSender: '&cMuted player &6{player} &cin: {channel_color}{channel_name}' MutePlayerSenderTime: '&cMuted player &6{player} &cin: {channel_color}{channel_name} &cfor {time} {units}' NoPlayerToReplyTo: '&cYou do not have anyone to reply to.' @@ -76,9 +78,11 @@ 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}.' -UnitsPlural: 'minutes' -UnitsSingular: 'minute' +UnitsMinutePlural: 'minutes' +UnitsMinuteSingular: 'minute' +UnitsSecondPlural: 'seconds' +UnitsSecondSingular: 'second' UnmutePlayerAllPlayer: '&cYou have just been unmuted in all channels.' UnmutePlayerAllSender: '&cUnmuted player &6{player} &cin all channels.' UnmutePlayerPlayer: '&cYou have just been unmuted in: {channel_color}{channel_name}' -UnmutePlayerSender: '&cUnmuted player &6{player} &cin: {channel_color}{channel_name}' \ No newline at end of file +UnmutePlayerSender: '&cUnmuted player &6{player} &cin: {channel_color}{channel_name}' diff --git a/src/mineverse/Aust1n46/chat/MineverseChat.java b/src/mineverse/Aust1n46/chat/MineverseChat.java index 0452978..6ed9d90 100644 --- a/src/mineverse/Aust1n46/chat/MineverseChat.java +++ b/src/mineverse/Aust1n46/chat/MineverseChat.java @@ -1414,4 +1414,4 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener { e.printStackTrace(); } } -} \ No newline at end of file +} diff --git a/src/mineverse/Aust1n46/chat/command/mute/Mute.java b/src/mineverse/Aust1n46/chat/command/mute/Mute.java index 1d2ee8a..245aaf6 100644 --- a/src/mineverse/Aust1n46/chat/command/mute/Mute.java +++ b/src/mineverse/Aust1n46/chat/command/mute/Mute.java @@ -77,9 +77,9 @@ public class Mute extends MineverseCommand { int time = Integer.parseInt(args[2]); if (time > 0) { player.addMute(channel.getName(), datetime + (time * MILLISECONDS_PER_MINUTE)); - String units = LocalizedMessage.UNITS_PLURAL.toString(); + String units = LocalizedMessage.UNITS_MINUTE_PLURAL.toString(); if (time == 1) - units = LocalizedMessage.UNITS_SINGULAR.toString(); + units = LocalizedMessage.UNITS_MINUTE_SINGULAR.toString(); sender.sendMessage(LocalizedMessage.MUTE_PLAYER_SENDER_TIME.toString() .replace("{player}", player.getName()) .replace("{channel_color}", channel.getColor()) @@ -113,4 +113,4 @@ public class Mute extends MineverseCommand { } sender.sendMessage(LocalizedMessage.COMMAND_NO_PERMISSION.toString()); } -} \ No newline at end of file +} diff --git a/src/mineverse/Aust1n46/chat/listeners/ChatListener.java b/src/mineverse/Aust1n46/chat/listeners/ChatListener.java index a618eb5..0588e81 100644 --- a/src/mineverse/Aust1n46/chat/listeners/ChatListener.java +++ b/src/mineverse/Aust1n46/chat/listeners/ChatListener.java @@ -35,6 +35,9 @@ 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) @@ -208,28 +211,30 @@ public class ChatListener implements Listener { Location diff; Boolean filterthis = true; mcp.addListening(eventChannel.getName()); - if(mcp.isMuted(eventChannel.getName())) { - String timedMute = ""; - if(mcp.getMutes().get(eventChannel.getName()).intValue() > 0) { - //Calendar currentDate = Calendar.getInstance(); - //SimpleDateFormat formatter = new SimpleDateFormat("dd:HH:mm:ss"); - //String date = formatter.format(currentDate.getTime()); - //String[] datearray = date.split(":"); - //int datetime = (Integer.parseInt(datearray[0]) * 1440) + (Integer.parseInt(datearray[1]) * 60) + (Integer.parseInt(datearray[2])); - - int time = (int) (System.currentTimeMillis() / 60000); - - String keyword = "minutes"; - int timemark = mcp.getMutes().get(eventChannel.getName()).intValue(); - int remaining = timemark - time; - if(remaining <= 0) remaining = 1; - if(remaining == 1) keyword = "minute"; - timedMute = " for " + remaining + " more " + keyword; + if (mcp.isMuted(eventChannel.getName())) { + if (mcp.getMutes().get(eventChannel.getName()).intValue() > 0) { + int dateTimeMillis = (int) System.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(); + } + 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)); + } + else { + mcp.getPlayer() + .sendMessage(LocalizedMessage.CHANNEL_MUTED.toString() + .replace("{channel_color}", eventChannel.getColor()) + .replace("{channel_name}", eventChannel.getName())); } - mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_MUTED.toString() - .replace("{channel_color}", eventChannel.getColor() + "") - .replace("{channel_name}", eventChannel.getName()) - .replace("{time}", timedMute)); mcp.setQuickChat(false); return; } @@ -251,77 +256,84 @@ public class ChatListener implements Listener { curColor = eventChannel.getChatColor(); bungee = eventChannel.getBungee(); - int time = (int) (System.currentTimeMillis() / 1000); + int dateTimeSeconds = (int) System.currentTimeMillis() / MILLISECONDS_PER_SECOND; if(eventChannel.hasCooldown()) { chCooldown = eventChannel.getCooldown(); } try { - if(mcp.hasCooldown(eventChannel)) { - int timemark = mcp.getCooldowns().get(eventChannel).intValue(); - if(time < timemark) { - int remaining = timemark - time; - String keyword = "seconds"; - if(remaining == 1) keyword = "second"; + if (mcp.hasCooldown(eventChannel)) { + int cooldownTime = mcp.getCooldowns().get(eventChannel).intValue(); + if (dateTimeSeconds < cooldownTime) { + int remainingCooldownTime = cooldownTime - dateTimeSeconds; + String units = LocalizedMessage.UNITS_SECOND_PLURAL.toString(); + if (remainingCooldownTime == 1) { + units = LocalizedMessage.UNITS_SECOND_SINGULAR.toString(); + } mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_COOLDOWN.toString() - .replace("{cooldown}", remaining + "") - .replace("{units}", keyword)); + .replace("{cooldown}", String.valueOf(remainingCooldownTime)).replace("{units}", units)); mcp.setQuickChat(false); bungee = false; return; } } - if(eventChannel.hasCooldown()) { - if(!mcp.getPlayer().hasPermission("venturechat.cooldown.bypass")) { - mcp.addCooldown(eventChannel, time + chCooldown); + if (eventChannel.hasCooldown()) { + if (!mcp.getPlayer().hasPermission("venturechat.cooldown.bypass")) { + mcp.addCooldown(eventChannel, dateTimeSeconds + chCooldown); } } - } - catch(NumberFormatException e) { + } catch (NumberFormatException e) { e.printStackTrace(); } - if(mcp.hasSpam(eventChannel) && plugin.getConfig().getConfigurationSection("antispam").getBoolean("enabled") && !mcp.getPlayer().hasPermission("venturechat.spam.bypass")) { + 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 mutedfor = plugin.getConfig().getConfigurationSection("antispam").getInt("mutetime", 0); - - int datetime = time/60; - if(time < spamtime + plugin.getConfig().getConfigurationSection("antispam").getInt("spamtime")) { - if(spamcount + 1 >= spamtimeconfig) { - mcp.addMute(eventChannel.getName(), datetime + mutedfor); - String timedmute = ""; - if(mutedfor > 0) { - String keyword = "minutes"; - if(mutedfor == 1) keyword = "minute"; - timedmute = " for " + mutedfor + " " + keyword; + int mutedForTime = plugin.getConfig().getConfigurationSection("antispam").getInt("mutetime", 0); + int dateTime = (int) System.currentTimeMillis(); + if (dateTimeSeconds < spamtime + + plugin.getConfig().getConfigurationSection("antispam").getInt("spamtime")) { + if (spamcount + 1 >= spamtimeconfig) { + mcp.addMute(eventChannel.getName(), dateTime + (mutedForTime * MILLISECONDS_PER_MINUTE)); + if (mutedForTime > 0) { + String units = LocalizedMessage.UNITS_MINUTE_PLURAL.toString(); + if (mutedForTime == 1) { + units = LocalizedMessage.UNITS_MINUTE_SINGULAR.toString(); + } + 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)); + } + else { + mcp.getPlayer() + .sendMessage(LocalizedMessage.MUTE_PLAYER_SPAM.toString() + .replace("{channel_color}", eventChannel.getColor()) + .replace("{channel_name}", eventChannel.getName())); } mcp.getSpam().get(eventChannel).set(0, 0); - mcp.getPlayer().sendMessage(LocalizedMessage.MUTE_PLAYER_SPAM.toString() - .replace("{channel_color}", eventChannel.getColor() + "") - .replace("{channel_name}", eventChannel.getName()) - .replace("{time}", timedmute)); mcp.setQuickChat(false); return; - } - else { - if(spamtimeconfig % 2 != 0) spamtimeconfig++; - if(spamcount + 1 == spamtimeconfig / 2) { + } else { + if (spamtimeconfig % 2 != 0) { + spamtimeconfig++; + } + if (spamcount + 1 == spamtimeconfig / 2) { mcp.getPlayer().sendMessage(LocalizedMessage.SPAM_WARNING.toString()); } mcp.getSpam().get(eventChannel).set(0, spamcount + 1); } - } - else { + } else { mcp.getSpam().get(eventChannel).set(0, 1); - mcp.getSpam().get(eventChannel).set(1, time); + mcp.getSpam().get(eventChannel).set(1, dateTimeSeconds); } - } - else { + } else { mcp.addSpam(eventChannel); mcp.getSpam().get(eventChannel).add(0, 1); - mcp.getSpam().get(eventChannel).add(1, time); + mcp.getSpam().get(eventChannel).add(1, dateTimeSeconds); } if(eventChannel.hasDistance()) { @@ -543,4 +555,4 @@ public class ChatListener implements Listener { return; } } -} \ No newline at end of file +} diff --git a/src/mineverse/Aust1n46/chat/localization/LocalizedMessage.java b/src/mineverse/Aust1n46/chat/localization/LocalizedMessage.java index bc98bd8..0a0fa5d 100644 --- a/src/mineverse/Aust1n46/chat/localization/LocalizedMessage.java +++ b/src/mineverse/Aust1n46/chat/localization/LocalizedMessage.java @@ -3,7 +3,7 @@ package mineverse.Aust1n46.chat.localization; import mineverse.Aust1n46.chat.utilities.Format; /** - * Messages configurable in Messages.yml + * Messages configurable in Messages.yml file. */ public enum LocalizedMessage { BLOCK_COMMAND_PLAYER("BlockCommandPlayer"), @@ -24,6 +24,7 @@ public enum LocalizedMessage { CHANNEL_NO_SPEAK_PERMISSIONS("ChannelNoSpeakPermissions"), CHANNEL_PLAYER_LIST_HEADER("ChannelPlayerListHeader"), CHANNEL_MUTED("ChannelMuted"), + CHANNEL_MUTED_TIMED("ChannelMutedTimed"), COMMAND_INVALID_ARGUMENTS("CommandInvalidArguments"), COMMAND_INVALID_ARGUMENTS_IGNORE("CommandInvalidArgumentsIgnore"), COMMAND_MUST_BE_RUN_BY_PLAYER("CommandMustBeRunByPlayer"), @@ -62,6 +63,7 @@ public enum LocalizedMessage { MUTE_PLAYER_PLAYER("MutePlayerPlayer"), MUTE_PLAYER_PLAYER_TIME("MutePlayerPlayerTime"), MUTE_PLAYER_SPAM("MutePlayerSpam"), + MUTE_PLAYER_SPAM_TIME("MutePlayerSpamTime"), MUTE_PLAYER_SENDER("MutePlayerSender"), MUTE_PLAYER_SENDER_TIME("MutePlayerSenderTime"), NO_PLAYER_TO_REPLY_TO("NoPlayerToReplyTo"), @@ -83,8 +85,10 @@ public enum LocalizedMessage { SPY_ON("SpyOn"), UNBLOCK_COMMAND_PLAYER("UnblockCommandPlayer"), UNBLOCK_COMMAND_SENDER("UnblockCommandSender"), - UNITS_PLURAL("UnitsPlural"), - UNITS_SINGULAR("UnitsSingular"), + UNITS_MINUTE_PLURAL("UnitsMinutePlural"), + UNITS_MINUTE_SINGULAR("UnitsMinuteSingular"), + UNITS_SECOND_PLURAL("UnitsSecondPlural"), + UNITS_SECOND_SINGULAR("UnitsSecondSingular"), UNMUTE_PLAYER_ALL_PLAYER("UnmutePlayerAllPlayer"), UNMUTE_PLAYER_ALL_SENDER("UnmutePlayerAllSender"), UNMUTE_PLAYER_PLAYER("UnmutePlayerPlayer"), @@ -100,4 +104,4 @@ public enum LocalizedMessage { public String toString() { return Format.FormatStringAll(Localization.getLocalization().getString(this.message)); } -} \ No newline at end of file +}