Factions3/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInvite.java

83 lines
2.6 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
2013-04-16 11:27:03 +02:00
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
2014-09-17 13:29:58 +02:00
import com.massivecraft.factions.cmd.arg.ARMPlayer;
import com.massivecraft.factions.cmd.req.ReqHasFaction;
import com.massivecraft.factions.entity.MPlayer;
2014-06-04 16:47:01 +02:00
import com.massivecraft.factions.event.EventFactionsInvitedChange;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
2013-04-10 13:12:22 +02:00
public class CmdFactionsInvite extends FCommand
{
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
2013-04-10 13:12:22 +02:00
public CmdFactionsInvite()
{
2013-11-11 09:31:04 +01:00
// Aliases
2013-04-16 10:11:59 +02:00
this.addAliases("inv", "invite");
2013-11-11 09:31:04 +01:00
// Args
this.addRequiredArg("player");
this.addOptionalArg("yes/no", "toggle");
2013-11-11 09:31:04 +01:00
// Requirements
2013-04-16 10:11:59 +02:00
this.addRequirements(ReqHasPerm.get(Perm.INVITE.node));
this.addRequirements(ReqHasFaction.get());
this.addRequirements(ReqIsPlayer.get());
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform()
{
// Args
2014-09-17 13:29:58 +02:00
MPlayer mplayer = this.arg(0, ARMPlayer.getAny());
if (mplayer == null) return;
2014-09-17 13:29:58 +02:00
Boolean newInvited = this.arg(1, ARBoolean.get(), !usenderFaction.isInvited(mplayer));
if (newInvited == null) return;
// Allready member?
2014-09-17 13:29:58 +02:00
if (mplayer.getFaction() == usenderFaction)
{
2014-09-17 13:29:58 +02:00
msg("%s<i> is already a member of %s", mplayer.getName(), usenderFaction.getName());
2013-04-16 11:27:03 +02:00
msg("<i>You might want to: " + Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false));
return;
}
// FPerm
if ( ! FPerm.INVITE.has(usender, usenderFaction, true)) return;
// Event
2014-09-17 13:29:58 +02:00
EventFactionsInvitedChange event = new EventFactionsInvitedChange(sender, mplayer, usenderFaction, newInvited);
event.run();
if (event.isCancelled()) return;
newInvited = event.isNewInvited();
// Apply
2014-09-17 13:29:58 +02:00
usenderFaction.setInvited(mplayer, newInvited);
// Inform
if (newInvited)
{
2014-09-17 13:29:58 +02:00
mplayer.msg("%s<i> invited you to %s", usender.describeTo(mplayer, true), usenderFaction.describeTo(mplayer));
usenderFaction.msg("%s<i> invited %s<i> to your faction.", usender.describeTo(usenderFaction, true), mplayer.describeTo(usenderFaction));
}
else
{
2014-09-17 13:29:58 +02:00
mplayer.msg("%s<i> revoked your invitation to <h>%s<i>.", usender.describeTo(mplayer), usenderFaction.describeTo(mplayer));
usenderFaction.msg("%s<i> revoked %s's<i> invitation.", usender.describeTo(usenderFaction), mplayer.describeTo(usenderFaction));
}
}
}