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

98 lines
3.0 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
2013-04-09 13:00:09 +02:00
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
2014-09-17 13:29:58 +02:00
import com.massivecraft.factions.cmd.arg.ARMPlayer;
import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf;
2014-06-04 16:47:01 +02:00
import com.massivecraft.factions.event.EventFactionsMembershipChange;
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
2014-06-21 19:03:39 +02:00
import com.massivecraft.massivecore.util.IdUtil;
2014-09-18 13:41:20 +02:00
public class CmdFactionsKick extends FactionsCommand
{
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
2013-04-10 13:12:22 +02:00
public CmdFactionsKick()
{
2013-11-11 09:31:04 +01:00
// Aliases
2013-04-16 10:11:59 +02:00
this.addAliases("kick");
2013-11-11 09:31:04 +01:00
// Args
this.addRequiredArg("player");
2013-11-11 09:31:04 +01:00
// Requirements
2013-04-16 10:11:59 +02:00
this.addRequirements(ReqHasPerm.get(Perm.KICK.node));
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform()
2013-04-19 14:08:45 +02:00
{
// Arg
2014-09-17 13:29:58 +02:00
MPlayer mplayer = this.arg(0, ARMPlayer.getAny());
if (mplayer == null) return;
2013-04-19 14:08:45 +02:00
// Validate
2014-09-18 13:41:20 +02:00
if (msender == mplayer)
{
2011-10-10 13:40:24 +02:00
msg("<b>You cannot kick yourself.");
2013-04-16 11:27:03 +02:00
msg("<i>You might want to: %s", Factions.get().getOuterCmdFactions().cmdFactionsLeave.getUseageTemplate(false));
return;
}
2014-09-18 13:41:20 +02:00
if (mplayer.getRole() == Rel.LEADER && !(this.senderIsConsole || msender.isUsingAdminMode()))
{
msg("<b>The leader can not be kicked.");
return;
}
2014-09-17 13:29:58 +02:00
if ( ! MConf.get().canLeaveWithNegativePower && mplayer.getPower() < 0)
{
msg("<b>You cannot kick that member until their power is positive.");
return;
}
// MPerm
2014-09-17 13:29:58 +02:00
Faction mplayerFaction = mplayer.getFaction();
if ( ! MPerm.getKick().has(msender, mplayerFaction, true)) return;
2013-04-19 14:08:45 +02:00
// Event
2014-09-17 13:29:58 +02:00
EventFactionsMembershipChange event = new EventFactionsMembershipChange(sender, mplayer, FactionColl.get().getNone(), MembershipChangeReason.KICK);
2013-04-19 14:08:45 +02:00
event.run();
2012-03-02 02:16:45 +01:00
if (event.isCancelled()) return;
2013-04-19 14:08:45 +02:00
// Inform
2014-09-18 13:41:20 +02:00
mplayerFaction.msg("%s<i> kicked %s<i> from the faction! :O", msender.describeTo(mplayerFaction, true), mplayer.describeTo(mplayerFaction, true));
mplayer.msg("%s<i> kicked you from %s<i>! :O", msender.describeTo(mplayer, true), mplayerFaction.describeTo(mplayer));
if (mplayerFaction != msenderFaction)
{
2014-09-18 13:41:20 +02:00
msender.msg("<i>You kicked %s<i> from the faction %s<i>!", mplayer.describeTo(msender), mplayerFaction.describeTo(msender));
}
if (MConf.get().logFactionKick)
2013-04-19 14:08:45 +02:00
{
2014-09-18 13:41:20 +02:00
Factions.get().log(msender.getDisplayName(IdUtil.getConsole()) + " kicked " + mplayer.getName() + " from the faction " + mplayerFaction.getName());
2013-04-19 14:08:45 +02:00
}
2013-04-19 14:08:45 +02:00
// Apply
2014-09-17 13:29:58 +02:00
if (mplayer.getRole() == Rel.LEADER)
2013-04-19 14:08:45 +02:00
{
2014-09-17 13:29:58 +02:00
mplayerFaction.promoteNewLeader();
2013-04-19 14:08:45 +02:00
}
2014-09-17 13:29:58 +02:00
mplayerFaction.setInvited(mplayer, false);
mplayer.resetFactionData();
}
}