From 3512c4c8e6a4f48198b40d511c99263379e1e05b Mon Sep 17 00:00:00 2001 From: CreedTheFreak Date: Sat, 2 Sep 2017 20:04:16 -0700 Subject: [PATCH 1/2] Started work on implementing the mute reason, and decided to write it to the UserData just like the Ban and TempBan reasons --- .../src/com/earth2me/essentials/UserData.java | 16 ++++++++++++++++ .../essentials/commands/Commandmute.java | 3 +++ 2 files changed, 19 insertions(+) diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 22d1e29b8..e0bed142d 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -73,6 +73,7 @@ public abstract class UserData extends PlayerExtension implements IConf { godmode = _getGodModeEnabled(); muted = _getMuted(); muteTimeout = _getMuteTimeout(); + muteReason = _getMuteReason (); jailed = _getJailed(); jailTimeout = _getJailTimeout(); lastLogin = _getLastLogin(); @@ -491,6 +492,7 @@ public abstract class UserData extends PlayerExtension implements IConf { } private boolean muted; + private String muteReason; public boolean _getMuted() { return config.getBoolean("muted", false); @@ -510,6 +512,20 @@ public abstract class UserData extends PlayerExtension implements IConf { config.save(); } + public String _getMuteReason() { + return config.getString("muteReason"); + } + + public String getMuteReason() { + return muteReason; + } + + public void setMuteReason (String reason) { + muteReason = reason; + config.setProperty ("muteReason", reason); + config.save(); + } + private long muteTimeout; private long _getMuteTimeout() { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java index 5d871c6bb..9cf0969b3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java @@ -52,7 +52,9 @@ public class Commandmute extends EssentialsCommand { if (args.length > 1) { final String time = getFinalArg(args, 1); muteTimestamp = DateUtil.parseDateDiff(time, true); + String muteReason = DateUtil.removeTimePattern (time); user.setMuted(true); + user.setMuteReason (muteReason); } else { user.setMuted(!user.getMuted()); } @@ -70,6 +72,7 @@ public class Commandmute extends EssentialsCommand { user.sendMessage(tl("playerMutedFor", muteTime)); } else { sender.sendMessage(tl("mutedPlayer", user.getDisplayName())); + /** Send the player a message, why they were muted **/ user.sendMessage(tl("playerMuted")); } final String message; From 4ff9fe866604b425c34d578db2a1e025af35fb73 Mon Sep 17 00:00:00 2001 From: CreedTheFreak Date: Sun, 3 Sep 2017 14:41:32 -0700 Subject: [PATCH 2/2] We have added the ability for the Mute to contain a reason, which is stored for the duration of the mute in the user's data file. Currently we need to add in the mute reason code into some other commands such as /afk and /me and /seen ect. We will also need to fix a problem with the reason when we dont add in a time frame for the mute, which should mute the player indefinatly rather then cancelling the mute and throwing a DataFormat exception. --- .../earth2me/essentials/EssentialsPlayerListener.java | 9 ++++++++- Essentials/src/com/earth2me/essentials/User.java | 1 + Essentials/src/com/earth2me/essentials/UserData.java | 8 ++++++-- Essentials/src/messages.properties | 1 + 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 691372f50..71eff6fb7 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -80,7 +80,14 @@ public class EssentialsPlayerListener implements Listener { final User user = ess.getUser(event.getPlayer()); if (user.isMuted()) { event.setCancelled(true); - user.sendMessage(tl("voiceSilenced")); + + if (user.getMuteReason ().equals ("")) { + user.sendMessage(tl("voiceSilenced")); + } + else { + user.sendMessage(tl("voiceSilenced") + tl("muteFormat", user.getMuteReason ())); + } + LOGGER.info(tl("mutedUserSpeaks", user.getName(), event.getMessage())); } try { diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index e9035a8ef..623bce407 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -537,6 +537,7 @@ public class User extends UserData implements Comparable, IMessageRecipien setMuteTimeout(0); sendMessage(tl("canTalkAgain")); setMuted(false); + setMuteReason (""); return true; } } diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index e0bed142d..042d9b2c6 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -521,8 +521,12 @@ public abstract class UserData extends PlayerExtension implements IConf { } public void setMuteReason (String reason) { - muteReason = reason; - config.setProperty ("muteReason", reason); + if (reason.equals("")) { + config.removeProperty ("muteReason"); + } else { + muteReason = reason; + config.setProperty ("muteReason", reason); + } config.save(); } diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 96aa4c9dd..a48d41cf3 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -494,6 +494,7 @@ vanished=\u00a76You are now completely invisible to normal users, and hidden fro versionMismatch=\u00a74Version mismatch\! Please update {0} to the same version. versionMismatchAll=\u00a74Version mismatch\! Please update all Essentials jars to the same version. voiceSilenced=\u00a76Your voice has been silenced\! +muteFormat=\u00a74 Reason: {0} walking=walking warpDeleteError=\u00a74Problem deleting the warp file. warpList={0}