Clean up CmdFactionsMotd
Remove unused variable Make use of TypeNullable instead of recreating its functionality
This commit is contained in:
parent
ac7046275d
commit
063dd43f12
@ -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);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -41,14 +42,10 @@ public class CmdFactionsMotd extends FactionsCommand
|
||||
|
||||
// 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("<silver>nothing");
|
||||
|
||||
// NoChange
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -237,15 +237,7 @@ public class Faction extends Entity<Faction> 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<Faction> 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<Faction> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -350,15 +350,7 @@ public class MPlayer extends SenderEntity<MPlayer> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user