From d555c1b081f5e6838b95eef2526028c7901adfa1 Mon Sep 17 00:00:00 2001 From: delbertina Date: Sat, 2 Dec 2017 19:46:46 -0600 Subject: [PATCH 1/2] Added method hasMuteReason in UserData. --- Essentials/src/com/earth2me/essentials/UserData.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 6bcbcfa73..85b98dcbb 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -536,6 +536,10 @@ public abstract class UserData extends PlayerExtension implements IConf { config.save(); } + public boolean hasMuteReason(){ + return getMuteReason().equals(""); + } + private long muteTimeout; private long _getMuteTimeout() { From 849b329213a541f14720bf1260ba8183d30c8c05 Mon Sep 17 00:00:00 2001 From: delbertina Date: Sat, 2 Dec 2017 20:35:44 -0600 Subject: [PATCH 2/2] Changed if else blocks to ternary operators. Not sure if way to avoid weird empty string usage. --- .../src/com/earth2me/essentials/commands/Commandafk.java | 8 ++------ .../src/com/earth2me/essentials/commands/Commandmail.java | 8 ++------ .../src/com/earth2me/essentials/commands/Commandme.java | 8 ++------ .../src/com/earth2me/essentials/commands/Commandr.java | 8 ++------ .../src/com/earth2me/essentials/commands/Commandseen.java | 8 ++------ .../com/earth2me/essentials/commands/Commandwhois.java | 8 ++------ 6 files changed, 12 insertions(+), 36 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java index 2d78628a3..0206dd00e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java @@ -51,12 +51,8 @@ public class Commandafk extends EssentialsCommand { private void toggleAfk(User sender, User user, String message) throws Exception { if (message != null && sender != null) { if (sender.isMuted()) { - if (sender.getMuteReason ().equals ("")) { - throw new Exception(tl("voiceSilenced")); - } - else { - throw new Exception(tl("voiceSilenced") + tl("muteReason", sender.getMuteReason ())); - } + throw new Exception(tl("voiceSilenced") + (sender.hasMuteReason() ? + tl("muteReason", sender.getMuteReason()) : "")); } if (!sender.isAuthorized("essentials.afk.message")) { throw new Exception(tl("noPermToAFKMessage")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index b69568497..5e4e5bbf3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -48,12 +48,8 @@ public class Commandmail extends EssentialsCommand { } if (user.isMuted()) { - if (user.getMuteReason ().equals ("")) { - throw new Exception(tl("voiceSilenced")); - } - else { - throw new Exception(tl("voiceSilenced") + tl("muteReason", user.getMuteReason ())); - } + throw new Exception(tl("voiceSilenced") + (user.hasMuteReason() ? + tl("muteReason", user.getMuteReason()) : "")); } User u = getPlayer(server, args[1], true, true); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/com/earth2me/essentials/commands/Commandme.java index 40796abf6..f41f09d0e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java @@ -24,12 +24,8 @@ public class Commandme extends EssentialsCommand { @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { if (user.isMuted()) { - if (user.getMuteReason ().equals ("")) { - throw new Exception(tl("voiceSilenced")); - } - else { - throw new Exception(tl("voiceSilenced") + tl("muteReason", user.getMuteReason ())); - } + throw new Exception(tl("voiceSilenced") + (user.hasMuteReason() ? + tl("muteReason", user.getMuteReason()) : "")); } if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java index 0542581d2..9b997ca1f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java @@ -28,12 +28,8 @@ public class Commandr extends EssentialsCommand { User user = ess.getUser(sender.getPlayer()); if (user.isMuted()) { - if (user.getMuteReason ().equals ("")) { - throw new Exception(tl("voiceSilenced")); - } - else { - throw new Exception(tl("voiceSilenced") + tl("muteReason", user.getMuteReason ())); - } + throw new Exception(tl("voiceSilenced") + (user.hasMuteReason() ? + tl("muteReason", user.getMuteReason()) : "")); } message = FormatUtil.formatMessage(user, "essentials.msg", message); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java index cbd83c2fb..41a8f0501 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java @@ -117,12 +117,8 @@ public class Commandseen extends EssentialsCommand { sender.sendMessage(tl("whoisJail", (user.getJailTimeout() > 0 ? DateUtil.formatDateDiff(user.getJailTimeout()) : tl("true")))); } if (user.isMuted()) { - if (user.getMuteReason ().equals ("")) { - sender.sendMessage(tl("whoisMuted", (user.getMuteTimeout() > 0 ? DateUtil.formatDateDiff(user.getMuteTimeout()) : tl("true")))); - } - else { - sender.sendMessage(tl("whoisMuted", (user.getMuteTimeout() > 0 ? DateUtil.formatDateDiff(user.getMuteTimeout()) : tl("true"))) + tl("muteReason", user.getMuteReason ())); - } + throw new Exception(tl("whoisMuted", (user.getMuteTimeout() > 0 ? DateUtil.formatDateDiff(user.getMuteTimeout()) : tl("true"))) + (user.hasMuteReason() ? + tl("muteReason", user.getMuteReason()) : "")); } final String location = user.getGeoLocation(); if (location != null && (!(sender.isPlayer()) || ess.getUser(sender.getPlayer()).isAuthorized("essentials.geoip.show"))) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java index 1db31e831..d9598f77c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java @@ -56,12 +56,8 @@ public class Commandwhois extends EssentialsCommand { sender.sendMessage(tl("whoisAFK", tl("false"))); } sender.sendMessage(tl("whoisJail", (user.isJailed() ? user.getJailTimeout() > 0 ? DateUtil.formatDateDiff(user.getJailTimeout()) : tl("true") : tl("false")))); - if (user.getMuteReason ().equals ("")) { - sender.sendMessage(tl("whoisMuted", (user.isMuted() ? user.getMuteTimeout() > 0 ? DateUtil.formatDateDiff(user.getMuteTimeout()) : tl("true") : tl("false")))); - } - else { - sender.sendMessage(tl("whoisMuted", (user.isMuted() ? user.getMuteTimeout() > 0 ? DateUtil.formatDateDiff(user.getMuteTimeout()) : tl("true") : tl("false"))+ tl("muteReason", user.getMuteReason ()))); - } + throw new Exception(tl("voiceSilenced") + (user.hasMuteReason() ? + tl("muteReason", user.getMuteReason()) : "")); } @Override