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

100 lines
3.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;
2013-04-09 13:00:09 +02:00
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARUPlayer;
2013-04-25 13:25:15 +02:00
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
import com.massivecraft.factions.entity.UPlayer;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
2013-04-22 13:03:21 +02:00
import com.massivecraft.factions.entity.FactionColls;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.UConf;
2013-04-19 14:08:45 +02:00
import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
2013-04-10 13:12:22 +02:00
public class CmdFactionsKick extends FCommand
{
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-25 13:25:15 +02:00
this.addRequirements(ReqFactionsEnabled.get());
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
2013-04-25 17:22:22 +02:00
UPlayer uplayer = this.arg(0, ARUPlayer.getStartAny(sender));
if (uplayer == null) return;
2013-04-19 14:08:45 +02:00
// Validate
if (usender == uplayer)
{
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;
}
if (uplayer.getRole() == Rel.LEADER && !(this.senderIsConsole || usender.isUsingAdminMode()))
{
msg("<b>The leader can not be kicked.");
return;
}
if ( ! UConf.get(uplayer).canLeaveWithNegativePower && uplayer.getPower() < 0)
{
msg("<b>You cannot kick that member until their power is positive.");
return;
}
2013-04-19 14:08:45 +02:00
// FPerm
Faction uplayerFaction = uplayer.getFaction();
if (!FPerm.KICK.has(usender, uplayerFaction, true)) return;
2013-04-19 14:08:45 +02:00
// Event
FactionsEventMembershipChange event = new FactionsEventMembershipChange(sender, uplayer, FactionColls.get().get(uplayer).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
uplayerFaction.msg("%s<i> kicked %s<i> from the faction! :O", usender.describeTo(uplayerFaction, true), uplayer.describeTo(uplayerFaction, true));
uplayer.msg("%s<i> kicked you from %s<i>! :O", usender.describeTo(uplayer, true), uplayerFaction.describeTo(uplayer));
if (uplayerFaction != usenderFaction)
{
usender.msg("<i>You kicked %s<i> from the faction %s<i>!", uplayer.describeTo(usender), uplayerFaction.describeTo(usender));
}
if (MConf.get().logFactionKick)
2013-04-19 14:08:45 +02:00
{
Factions.get().log(usender.getDisplayName() + " kicked " + uplayer.getName() + " from the faction " + uplayerFaction.getName());
2013-04-19 14:08:45 +02:00
}
2013-04-19 14:08:45 +02:00
// Apply
if (uplayer.getRole() == Rel.LEADER)
2013-04-19 14:08:45 +02:00
{
uplayerFaction.promoteNewLeader();
2013-04-19 14:08:45 +02:00
}
uplayerFaction.setInvited(uplayer, false);
uplayer.resetFactionData();
}
}