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

70 lines
2.1 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.FPlayer;
2013-04-16 11:27:03 +02:00
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
2013-04-16 11:05:49 +02:00
import com.massivecraft.factions.cmd.arg.ARFPlayer;
import com.massivecraft.factions.event.FactionsEventInvitedChange;
import com.massivecraft.mcore.cmd.arg.ARBoolean;
2013-04-16 10:11:59 +02:00
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
2013-04-10 13:12:22 +02:00
public class CmdFactionsInvite extends FCommand
{
2013-04-10 13:12:22 +02:00
public CmdFactionsInvite()
{
2013-04-16 10:11:59 +02:00
this.addAliases("inv", "invite");
this.addRequiredArg("player");
this.addOptionalArg("yes/no", "toggle");
2013-04-16 10:11:59 +02:00
this.addRequirements(ReqHasPerm.get(Perm.INVITE.node));
this.addRequirements(ReqIsPlayer.get());
}
@Override
public void perform()
{
// Args
FPlayer fplayer = this.arg(0, ARFPlayer.getStartAny());
if (fplayer == null) return;
Boolean newInvited = this.arg(1, ARBoolean.get(), !myFaction.isInvited(fplayer));
if (newInvited == null) return;
// Allready member?
if (fplayer.getFaction() == myFaction)
{
msg("%s<i> is already a member of %s", fplayer.getName(), myFaction.getTag());
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(sender, myFaction, true)) return;
// Event
FactionsEventInvitedChange event = new FactionsEventInvitedChange(sender, fplayer, myFaction, newInvited);
event.run();
if (event.isCancelled()) return;
newInvited = event.isNewInvited();
// Apply
myFaction.setInvited(fplayer, newInvited);
// Inform
if (newInvited)
{
fplayer.msg("%s<i> invited you to %s", fme.describeTo(fplayer, true), myFaction.describeTo(fplayer));
myFaction.msg("%s<i> invited %s<i> to your faction.", fme.describeTo(myFaction, true), fplayer.describeTo(myFaction));
}
else
{
fplayer.msg("%s<i> revoked your invitation to <h>%s<i>.", fme.describeTo(fplayer), myFaction.describeTo(fplayer));
myFaction.msg("%s<i> revoked %s's<i> invitation.", fme.describeTo(myFaction), fplayer.describeTo(myFaction));
}
}
}