Clean up CmdFactionsMotd

Remove unused variable

Make use of TypeNullable instead of recreating its functionality
This commit is contained in:
TheComputerGeek2 2017-04-21 11:12:41 -07:00 committed by Olof Larsson
parent ac7046275d
commit 063dd43f12
3 changed files with 30 additions and 45 deletions

View File

@ -1,10 +1,11 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.event.EventFactionsMotdChange; import com.massivecraft.factions.event.EventFactionsMotdChange;
import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.TypeNullable;
import com.massivecraft.massivecore.command.type.primitive.TypeString; import com.massivecraft.massivecore.command.type.primitive.TypeString;
import com.massivecraft.massivecore.mixin.MixinDisplayName; import com.massivecraft.massivecore.mixin.MixinDisplayName;
import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.MUtil;
@ -19,7 +20,7 @@ public class CmdFactionsMotd extends FactionsCommand
public CmdFactionsMotd() public CmdFactionsMotd()
{ {
// Parameters // Parameters
this.addParameter(TypeString.get(), "new", "read", true); this.addParameter(TypeNullable.get(TypeString.get()), "new", "read", true);
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -41,14 +42,10 @@ public class CmdFactionsMotd extends FactionsCommand
// Args // Args
String target = this.readArg(); String target = this.readArg();
target = target.trim();
target = Txt.parse(target);
// Removal // Clean input
if (target != null && MassiveCore.NOTHING_REMOVE.contains(target)) target = Faction.clean(target);
{ target = Txt.parse(target);
target = null;
}
// Get Old // Get Old
String old = null; String old = null;
@ -57,14 +54,10 @@ public class CmdFactionsMotd extends FactionsCommand
old = msenderFaction.getMotd(); old = msenderFaction.getMotd();
} }
// Target Desc
String targetDesc = target;
if (targetDesc == null) targetDesc = Txt.parse("<silver>nothing");
// NoChange // NoChange
if (MUtil.equals(old, target)) if (MUtil.equals(old, target))
{ {
msg("<i>The motd for %s <i>is already: <h>%s", msenderFaction.describeTo(msender, true), target); msg("<i>The motd for %s <i>is already: <h>%s", msenderFaction.describeTo(msender, true), old == null ? Txt.parse("<silver>none") : old);
return; return;
} }

View File

@ -237,15 +237,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
public void setDescription(String description) public void setDescription(String description)
{ {
// Clean input // Clean input
String target = description; String target = clean(description);
if (target != null)
{
target = target.trim();
if (target.isEmpty())
{
target = null;
}
}
// Detect Nochange // Detect Nochange
if (MUtil.equals(this.description, target)) return; if (MUtil.equals(this.description, target)) return;
@ -270,22 +262,14 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
public String getMotd() public String getMotd()
{ {
if (this.hasMotd()) return Txt.parse(this.motd); if (this.hasMotd()) return this.motd;
return NOMOTD; return NOMOTD;
} }
public void setMotd(String description) public void setMotd(String motd)
{ {
// Clean input // Clean input
String target = description; String target = clean(motd);
if (target != null)
{
target = target.trim();
if (target.isEmpty())
{
target = null;
}
}
// Detect Nochange // Detect Nochange
if (MUtil.equals(this.motd, target)) return; if (MUtil.equals(this.motd, target)) return;
@ -1203,4 +1187,20 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
return MixinMessage.get().msgPredicate(new PredicateCommandSenderFaction(this), msgs); 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;
}
} }

View File

@ -350,15 +350,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
public void setTitle(String title) public void setTitle(String title)
{ {
// Clean input // Clean input
String target = title; String target = Faction.clean(title);
if (target != null)
{
target = target.trim();
if (target.length() == 0)
{
target = null;
}
}
// Detect Nochange // Detect Nochange
if (MUtil.equals(this.title, target)) return; if (MUtil.equals(this.title, target)) return;