From 063dd43f1273ff873220bac6ad7e0224e8783b1d Mon Sep 17 00:00:00 2001 From: TheComputerGeek2 Date: Fri, 21 Apr 2017 11:12:41 -0700 Subject: [PATCH] Clean up CmdFactionsMotd Remove unused variable Make use of TypeNullable instead of recreating its functionality --- .../factions/cmd/CmdFactionsMotd.java | 25 +++++------- .../massivecraft/factions/entity/Faction.java | 40 +++++++++---------- .../massivecraft/factions/entity/MPlayer.java | 10 +---- 3 files changed, 30 insertions(+), 45 deletions(-) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMotd.java b/src/com/massivecraft/factions/cmd/CmdFactionsMotd.java index e7f1a81c..a6b1c567 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMotd.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMotd.java @@ -1,10 +1,11 @@ package com.massivecraft.factions.cmd; +import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.event.EventFactionsMotdChange; -import com.massivecraft.massivecore.MassiveCore; import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.TypeNullable; import com.massivecraft.massivecore.command.type.primitive.TypeString; import com.massivecraft.massivecore.mixin.MixinDisplayName; import com.massivecraft.massivecore.util.MUtil; @@ -19,7 +20,7 @@ public class CmdFactionsMotd extends FactionsCommand public CmdFactionsMotd() { // Parameters - this.addParameter(TypeString.get(), "new", "read", true); + this.addParameter(TypeNullable.get(TypeString.get()), "new", "read", true); } // -------------------------------------------- // @@ -30,25 +31,21 @@ public class CmdFactionsMotd extends FactionsCommand public void perform() throws MassiveException { // Read - if ( ! this.argIsSet(0)) + if (!this.argIsSet(0)) { message(msenderFaction.getMotdMessages()); return; } // MPerm - if ( ! MPerm.getPermMotd().has(msender, msenderFaction, true)) return; + if (!MPerm.getPermMotd().has(msender, msenderFaction, true)) return; // Args String target = this.readArg(); - target = target.trim(); - target = Txt.parse(target); - // Removal - if (target != null && MassiveCore.NOTHING_REMOVE.contains(target)) - { - target = null; - } + // Clean input + target = Faction.clean(target); + target = Txt.parse(target); // Get Old String old = null; @@ -57,14 +54,10 @@ public class CmdFactionsMotd extends FactionsCommand old = msenderFaction.getMotd(); } - // Target Desc - String targetDesc = target; - if (targetDesc == null) targetDesc = Txt.parse("nothing"); - // NoChange if (MUtil.equals(old, target)) { - msg("The motd for %s is already: %s", msenderFaction.describeTo(msender, true), target); + msg("The motd for %s is already: %s", msenderFaction.describeTo(msender, true), old == null ? Txt.parse("none") : old); return; } diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 693518ac..af6f7603 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -237,15 +237,7 @@ public class Faction extends Entity implements FactionsParticipator public void setDescription(String description) { // Clean input - String target = description; - if (target != null) - { - target = target.trim(); - if (target.isEmpty()) - { - target = null; - } - } + String target = clean(description); // Detect Nochange if (MUtil.equals(this.description, target)) return; @@ -270,22 +262,14 @@ public class Faction extends Entity implements FactionsParticipator public String getMotd() { - if (this.hasMotd()) return Txt.parse(this.motd); + if (this.hasMotd()) return this.motd; return NOMOTD; } - public void setMotd(String description) + public void setMotd(String motd) { // Clean input - String target = description; - if (target != null) - { - target = target.trim(); - if (target.isEmpty()) - { - target = null; - } - } + String target = clean(motd); // Detect Nochange if (MUtil.equals(this.motd, target)) return; @@ -1203,4 +1187,20 @@ public class Faction extends Entity implements FactionsParticipator return MixinMessage.get().msgPredicate(new PredicateCommandSenderFaction(this), msgs); } + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + // FIXME this probably needs to be moved elsewhere + public static String clean(String message) + { + String target = message; + if (target == null) return null; + + target = target.trim(); + if (target.isEmpty()) target = null; + + return target; + } + } diff --git a/src/com/massivecraft/factions/entity/MPlayer.java b/src/com/massivecraft/factions/entity/MPlayer.java index 6e52fc4e..3e10a404 100644 --- a/src/com/massivecraft/factions/entity/MPlayer.java +++ b/src/com/massivecraft/factions/entity/MPlayer.java @@ -350,15 +350,7 @@ public class MPlayer extends SenderEntity implements FactionsParticipat public void setTitle(String title) { // Clean input - String target = title; - if (target != null) - { - target = target.trim(); - if (target.length() == 0) - { - target = null; - } - } + String target = Faction.clean(title); // Detect Nochange if (MUtil.equals(this.title, target)) return;