2012-03-09 23:09:33 +01:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
2013-04-16 11:05:49 +02:00
|
|
|
import com.massivecraft.factions.cmd.arg.ARFaction;
|
2013-04-22 09:37:53 +02:00
|
|
|
import com.massivecraft.factions.entity.FPlayer;
|
2013-04-22 13:03:21 +02:00
|
|
|
import com.massivecraft.factions.entity.FPlayerColls;
|
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;
|
2013-04-22 10:05:03 +02:00
|
|
|
import com.massivecraft.factions.entity.MConf;
|
2013-04-19 12:27:39 +02:00
|
|
|
import com.massivecraft.factions.event.FactionsEventDisband;
|
2013-04-19 14:08:45 +02:00
|
|
|
import com.massivecraft.factions.event.FactionsEventMembershipChange;
|
|
|
|
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
|
2012-03-09 23:09:33 +01:00
|
|
|
import com.massivecraft.factions.integration.Econ;
|
2013-04-09 13:24:55 +02:00
|
|
|
import com.massivecraft.factions.FFlag;
|
|
|
|
import com.massivecraft.factions.FPerm;
|
2013-04-09 13:00:09 +02:00
|
|
|
import com.massivecraft.factions.Factions;
|
2013-04-09 12:56:29 +02:00
|
|
|
import com.massivecraft.factions.Perm;
|
2012-03-09 23:09:33 +01:00
|
|
|
import com.massivecraft.factions.integration.SpoutFeatures;
|
2013-04-16 10:11:59 +02:00
|
|
|
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
2013-04-22 09:37:53 +02:00
|
|
|
import com.massivecraft.mcore.money.Money;
|
2012-03-09 23:09:33 +01:00
|
|
|
|
2013-04-10 13:12:22 +02:00
|
|
|
public class CmdFactionsDisband extends FCommand
|
2012-03-09 23:09:33 +01:00
|
|
|
{
|
2013-04-10 13:12:22 +02:00
|
|
|
public CmdFactionsDisband()
|
2012-03-09 23:09:33 +01:00
|
|
|
{
|
2013-04-16 10:11:59 +02:00
|
|
|
this.addAliases("disband");
|
2012-03-09 23:09:33 +01:00
|
|
|
|
2013-04-16 10:30:21 +02:00
|
|
|
this.addOptionalArg("faction", "you");
|
2012-03-09 23:09:33 +01:00
|
|
|
|
2013-04-16 10:11:59 +02:00
|
|
|
this.addRequirements(ReqHasPerm.get(Perm.DISBAND.node));
|
2012-03-09 23:09:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform()
|
|
|
|
{
|
2013-04-19 12:44:28 +02:00
|
|
|
// Args
|
2013-04-22 13:03:21 +02:00
|
|
|
Faction faction = this.arg(0, ARFaction.get(fme), myFaction);
|
2012-03-09 23:09:33 +01:00
|
|
|
if (faction == null) return;
|
|
|
|
|
2013-04-19 12:44:28 +02:00
|
|
|
// FPerm
|
2012-03-09 23:09:33 +01:00
|
|
|
if ( ! FPerm.DISBAND.has(sender, faction, true)) return;
|
|
|
|
|
2013-04-19 12:44:28 +02:00
|
|
|
// Verify
|
2012-03-09 23:09:33 +01:00
|
|
|
if (faction.getFlag(FFlag.PERMANENT))
|
|
|
|
{
|
|
|
|
msg("<i>This faction is designated as permanent, so you cannot disband it.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-19 12:44:28 +02:00
|
|
|
// Event
|
|
|
|
FactionsEventDisband event = new FactionsEventDisband(me, faction);
|
|
|
|
event.run();
|
|
|
|
if (event.isCancelled()) return;
|
2012-03-09 23:09:33 +01:00
|
|
|
|
2013-04-19 12:44:28 +02:00
|
|
|
// Merged Apply and Inform
|
|
|
|
|
2012-03-09 23:09:33 +01:00
|
|
|
// Send FPlayerLeaveEvent for each player in the faction
|
2013-04-19 14:08:45 +02:00
|
|
|
for (FPlayer fplayer : faction.getFPlayers())
|
2012-03-13 13:47:54 +01:00
|
|
|
{
|
2013-04-22 13:03:21 +02:00
|
|
|
FactionsEventMembershipChange membershipChangeEvent = new FactionsEventMembershipChange(sender, fplayer, FactionColls.get().get(faction).getNone(), MembershipChangeReason.DISBAND);
|
2013-04-19 14:08:45 +02:00
|
|
|
membershipChangeEvent.run();
|
2012-03-09 23:09:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Inform all players
|
2013-04-22 13:03:21 +02:00
|
|
|
for (FPlayer fplayer : FPlayerColls.get().get(fme).getAllOnline())
|
2012-03-09 23:09:33 +01:00
|
|
|
{
|
2013-04-19 15:32:16 +02:00
|
|
|
String who = fme.describeTo(fplayer);
|
2012-03-09 23:09:33 +01:00
|
|
|
if (fplayer.getFaction() == faction)
|
|
|
|
{
|
|
|
|
fplayer.msg("<h>%s<i> disbanded your faction.", who);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fplayer.msg("<h>%s<i> disbanded the faction %s.", who, faction.getTag(fplayer));
|
|
|
|
}
|
|
|
|
}
|
2013-04-22 10:05:03 +02:00
|
|
|
|
|
|
|
if (MConf.get().logFactionDisband)
|
|
|
|
{
|
2013-04-09 13:12:13 +02:00
|
|
|
Factions.get().log("The faction "+faction.getTag()+" ("+faction.getId()+") was disbanded by "+(senderIsConsole ? "console command" : fme.getName())+".");
|
2013-04-22 10:05:03 +02:00
|
|
|
}
|
2012-03-09 23:09:33 +01:00
|
|
|
|
2013-04-22 09:37:53 +02:00
|
|
|
if (Econ.isEnabled(faction))
|
2012-03-09 23:09:33 +01:00
|
|
|
{
|
|
|
|
//Give all the faction's money to the disbander
|
2013-04-22 09:37:53 +02:00
|
|
|
double amount = Money.get(faction);
|
2012-03-09 23:09:33 +01:00
|
|
|
Econ.transferMoney(fme, faction, fme, amount, false);
|
|
|
|
|
|
|
|
if (amount > 0.0)
|
|
|
|
{
|
2013-04-22 09:37:53 +02:00
|
|
|
String amountString = Money.format(faction, amount);
|
2012-03-09 23:09:33 +01:00
|
|
|
msg("<i>You have been given the disbanded faction's bank, totaling %s.", amountString);
|
2013-04-09 13:12:13 +02:00
|
|
|
Factions.get().log(fme.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getTag()+".");
|
2012-03-09 23:09:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
faction.detach();
|
|
|
|
|
2012-05-09 03:24:07 +02:00
|
|
|
SpoutFeatures.updateTitle(null, null);
|
|
|
|
SpoutFeatures.updateCape(null, null);
|
2012-03-09 23:09:33 +01:00
|
|
|
}
|
|
|
|
}
|