package com.massivecraft.factions.cmd; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.req.ReqFactionsEnabled; import com.massivecraft.factions.entity.UPlayer; import com.massivecraft.factions.entity.UPlayerColls; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.FactionColls; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.event.EventFactionsDisband; import com.massivecraft.factions.event.EventFactionsMembershipChange; import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.util.Txt; public class CmdFactionsDisband extends FCommand { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // public CmdFactionsDisband() { // Aliases this.addAliases("disband"); // Args this.addOptionalArg("faction", "you"); // Requirements this.addRequirements(ReqFactionsEnabled.get()); this.addRequirements(ReqHasPerm.get(Perm.DISBAND.node)); } // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @Override public void perform() { // Args Faction faction = this.arg(0, ARFaction.get(usender), usenderFaction); if (faction == null) return; // FPerm if ( ! FPerm.DISBAND.has(usender, faction, true)) return; // Verify if (faction.getFlag(FFlag.PERMANENT)) { msg("This faction is designated as permanent, so you cannot disband it."); return; } // Event EventFactionsDisband event = new EventFactionsDisband(me, faction); event.run(); if (event.isCancelled()) return; // Merged Apply and Inform // Run event for each player in the faction for (UPlayer uplayer : faction.getUPlayers()) { EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(sender, uplayer, FactionColls.get().get(faction).getNone(), MembershipChangeReason.DISBAND); membershipChangeEvent.run(); } // Inform all players for (UPlayer uplayer : UPlayerColls.get().get(usender).getAllOnline()) { String who = usender.describeTo(uplayer); if (uplayer.getFaction() == faction) { uplayer.msg("%s disbanded your faction.", who); } else { uplayer.msg("%s disbanded the faction %s.", who, faction.getName(uplayer)); } } if (MConf.get().logFactionDisband) { Factions.get().log(Txt.parse("The faction %s (%s) was disbanded by %s.", faction.getName(), faction.getId(), usender.getDisplayName())); } faction.detach(); } }