package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.arg.ARUPlayer; import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.event.EventFactionsMembershipChange; import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.util.IdUtil; public class CmdFactionsKick extends FCommand { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // public CmdFactionsKick() { // Aliases this.addAliases("kick"); // Args this.addRequiredArg("player"); // Requirements this.addRequirements(ReqHasPerm.get(Perm.KICK.node)); } // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @Override public void perform() { // Arg MPlayer uplayer = this.arg(0, ARUPlayer.getAny()); if (uplayer == null) return; // Validate if (usender == uplayer) { msg("You cannot kick yourself."); msg("You might want to: %s", Factions.get().getOuterCmdFactions().cmdFactionsLeave.getUseageTemplate(false)); return; } if (uplayer.getRole() == Rel.LEADER && !(this.senderIsConsole || usender.isUsingAdminMode())) { msg("The leader can not be kicked."); return; } if ( ! MConf.get().canLeaveWithNegativePower && uplayer.getPower() < 0) { msg("You cannot kick that member until their power is positive."); return; } // FPerm Faction uplayerFaction = uplayer.getFaction(); if (!FPerm.KICK.has(usender, uplayerFaction, true)) return; // Event EventFactionsMembershipChange event = new EventFactionsMembershipChange(sender, uplayer, FactionColl.get().getNone(), MembershipChangeReason.KICK); event.run(); if (event.isCancelled()) return; // Inform uplayerFaction.msg("%s kicked %s from the faction! :O", usender.describeTo(uplayerFaction, true), uplayer.describeTo(uplayerFaction, true)); uplayer.msg("%s kicked you from %s! :O", usender.describeTo(uplayer, true), uplayerFaction.describeTo(uplayer)); if (uplayerFaction != usenderFaction) { usender.msg("You kicked %s from the faction %s!", uplayer.describeTo(usender), uplayerFaction.describeTo(usender)); } if (MConf.get().logFactionKick) { Factions.get().log(usender.getDisplayName(IdUtil.getConsole()) + " kicked " + uplayer.getName() + " from the faction " + uplayerFaction.getName()); } // Apply if (uplayer.getRole() == Rel.LEADER) { uplayerFaction.promoteNewLeader(); } uplayerFaction.setInvited(uplayer, false); uplayer.resetFactionData(); } }