2012-03-09 23:09:33 +01:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.Conf;
|
|
|
|
import com.massivecraft.factions.event.FPlayerLeaveEvent;
|
|
|
|
import com.massivecraft.factions.event.FactionDisbandEvent;
|
|
|
|
import com.massivecraft.factions.integration.Econ;
|
|
|
|
import com.massivecraft.factions.FPlayers;
|
|
|
|
import com.massivecraft.factions.Faction;
|
2013-04-09 13:00:09 +02:00
|
|
|
import com.massivecraft.factions.Factions;
|
2012-03-09 23:09:33 +01:00
|
|
|
import com.massivecraft.factions.FPlayer;
|
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;
|
|
|
|
import com.massivecraft.factions.struct.FFlag;
|
|
|
|
import com.massivecraft.factions.struct.FPerm;
|
|
|
|
|
|
|
|
public class CmdDisband extends FCommand
|
|
|
|
{
|
|
|
|
public CmdDisband()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.aliases.add("disband");
|
|
|
|
|
|
|
|
//this.requiredArgs.add("");
|
|
|
|
this.optionalArgs.put("faction", "your");
|
|
|
|
|
2013-04-09 12:56:29 +02:00
|
|
|
this.permission = Perm.DISBAND.node;
|
2012-03-09 23:09:33 +01:00
|
|
|
this.disableOnLock = true;
|
|
|
|
|
|
|
|
senderMustBePlayer = false;
|
|
|
|
senderMustBeMember = false;
|
|
|
|
senderMustBeOfficer = false;
|
|
|
|
senderMustBeLeader = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform()
|
|
|
|
{
|
|
|
|
// The faction, default to your own.. but null if console sender.
|
|
|
|
Faction faction = this.argAsFaction(0, fme == null ? null : myFaction);
|
|
|
|
if (faction == null) return;
|
|
|
|
|
|
|
|
if ( ! FPerm.DISBAND.has(sender, faction, true)) return;
|
|
|
|
|
|
|
|
if (faction.getFlag(FFlag.PERMANENT))
|
|
|
|
{
|
|
|
|
msg("<i>This faction is designated as permanent, so you cannot disband it.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FactionDisbandEvent disbandEvent = new FactionDisbandEvent(me, faction.getId());
|
|
|
|
Bukkit.getServer().getPluginManager().callEvent(disbandEvent);
|
|
|
|
if(disbandEvent.isCancelled()) return;
|
|
|
|
|
|
|
|
// Send FPlayerLeaveEvent for each player in the faction
|
|
|
|
for ( FPlayer fplayer : faction.getFPlayers() )
|
2012-03-13 13:47:54 +01:00
|
|
|
{
|
|
|
|
Bukkit.getServer().getPluginManager().callEvent(new FPlayerLeaveEvent(fplayer, faction, FPlayerLeaveEvent.PlayerLeaveReason.DISBAND));
|
2012-03-09 23:09:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Inform all players
|
|
|
|
for (FPlayer fplayer : FPlayers.i.getOnline())
|
|
|
|
{
|
|
|
|
String who = senderIsConsole ? "A server admin" : fme.describeTo(fplayer);
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Conf.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())+".");
|
2012-03-09 23:09:33 +01:00
|
|
|
|
|
|
|
if (Econ.shouldBeUsed() && ! senderIsConsole)
|
|
|
|
{
|
|
|
|
//Give all the faction's money to the disbander
|
|
|
|
double amount = Econ.getBalance(faction.getAccountId());
|
|
|
|
Econ.transferMoney(fme, faction, fme, amount, false);
|
|
|
|
|
|
|
|
if (amount > 0.0)
|
|
|
|
{
|
|
|
|
String amountString = Econ.moneyString(amount);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|