Factions/src/com/massivecraft/factions/cmd/CmdFactionsMotd.java

76 lines
2.1 KiB
Java
Raw Normal View History

2014-10-02 16:12:16 +02:00
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.entity.MPerm;
2014-10-02 16:12:16 +02:00
import com.massivecraft.factions.entity.MPlayer;
2014-10-15 12:05:16 +02:00
import com.massivecraft.factions.event.EventFactionsMotdChange;
2015-05-06 17:04:35 +02:00
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.TypeNullable;
2015-11-06 02:10:29 +01:00
import com.massivecraft.massivecore.command.type.primitive.TypeString;
2016-05-13 12:32:05 +02:00
import com.massivecraft.massivecore.mixin.MixinDisplayName;
2014-10-02 16:12:16 +02:00
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt;
public class CmdFactionsMotd extends FactionsCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsMotd()
{
// Parameters
this.addParameter(TypeNullable.get(TypeString.get()), "new", "read", true).setDesc("the new motd\nif not specified you will just see the current one");
2014-10-02 16:12:16 +02:00
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
2015-05-06 17:04:35 +02:00
public void perform() throws MassiveException
2014-10-02 16:12:16 +02:00
{
// Read
if (!this.argIsSet(0))
2014-10-02 16:12:16 +02:00
{
2015-09-03 09:33:01 +02:00
message(msenderFaction.getMotdMessages());
2014-10-02 16:12:16 +02:00
return;
}
// MPerm
if (!MPerm.getPermMotd().has(msender, msenderFaction, true)) return;
2014-10-02 16:12:16 +02:00
// Args
2015-05-06 17:04:35 +02:00
String target = this.readArg();
2017-05-09 10:59:38 +02:00
target = target.trim();
target = Txt.parse(target);
2014-10-02 16:12:16 +02:00
// Get Old
2017-05-09 10:59:38 +02:00
String old = msenderFaction.getMotd();
2014-10-02 16:12:16 +02:00
// NoChange
if (MUtil.equals(old, target))
{
2017-05-09 10:59:38 +02:00
msg("<i>The motd for %s <i>is already: <h>%s", msenderFaction.describeTo(msender, true), msenderFaction.getMotdDesc());
2014-10-02 16:12:16 +02:00
return;
}
2014-10-15 12:05:16 +02:00
// Event
EventFactionsMotdChange event = new EventFactionsMotdChange(sender, msenderFaction, target);
event.run();
if (event.isCancelled()) return;
target = event.getNewMotd();
2014-10-02 16:12:16 +02:00
// Apply
msenderFaction.setMotd(target);
2019-01-08 17:37:36 +01:00
2014-10-02 16:12:16 +02:00
// Inform
for (MPlayer follower : msenderFaction.getMPlayers())
{
2019-01-08 17:37:36 +01:00
follower.msg("<i>%s <i>changed your faction motd.", MixinDisplayName.get().getDisplayName(sender, follower));
follower.message(msenderFaction.getMotdMessages());
2014-10-02 16:12:16 +02:00
}
}
}