package com.massivecraft.factions.cmd; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.Txt; public class CmdFactionsMotd extends FactionsCommand { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // public CmdFactionsMotd() { // Aliases this.addAliases("motd"); // Args this.addOptionalArg("new", "read"); this.setErrorOnToManyArgs(false); // Requirements this.addRequirements(ReqHasPerm.get(Perm.MOTD.node)); } // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @Override public void perform() { // Read if ( ! this.argIsSet(0)) { sendMessage(msenderFaction.getMotdMessages()); return; } // Check Role if ( ! ReqRoleIsAtLeast.get(Rel.OFFICER).apply(sender, this)) { sendMessage(ReqRoleIsAtLeast.get(Rel.OFFICER).createErrorMessage(sender, this)); return; } // Args String target = this.argConcatFrom(0); target = target.trim(); target = Txt.parse(target); // Removal if (target != null && MUtil.set("", "r", "remove", "d", "delete", "del", "e", "erase", "none", "null", "nothing").contains(target)) { target = null; } // Get Old String old = null; if (msenderFaction.hasMotd()) { 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); return; } // Apply msenderFaction.setMotd(target); // Inform for (MPlayer follower : msenderFaction.getMPlayers()) { follower.msg("%s set your faction motd to:\n%s", Mixin.getDisplayName(sender, follower), msenderFaction.getMotd()); } } }