Factions/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java

91 lines
2.9 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
import org.bukkit.Bukkit;
2013-04-09 13:15:25 +02:00
import com.massivecraft.factions.ConfServer;
2013-04-16 11:05:49 +02:00
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.event.FactionDisbandEvent;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm;
2013-04-09 13:22:23 +02:00
import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction;
2013-04-09 13:00:09 +02:00
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.integration.SpoutFeatures;
2013-04-16 10:11:59 +02:00
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
2013-04-10 13:12:22 +02:00
public class CmdFactionsDisband extends FCommand
{
2013-04-10 13:12:22 +02:00
public CmdFactionsDisband()
{
2013-04-16 10:11:59 +02:00
this.addAliases("disband");
this.addOptionalArg("faction", "you");
2013-04-16 10:11:59 +02:00
this.addRequirements(ReqHasPerm.get(Perm.DISBAND.node));
}
@Override
public void perform()
{
2013-04-16 11:05:49 +02:00
Faction faction = this.arg(0, ARFaction.get(), 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));
}
// Inform all players
2013-04-12 08:56:26 +02:00
for (FPlayer fplayer : FPlayerColl.get().getAllOnline())
{
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));
}
}
2013-04-09 13:15:25 +02:00
if (ConfServer.logFactionDisband)
Factions.get().log("The faction "+faction.getTag()+" ("+faction.getId()+") was disbanded by "+(senderIsConsole ? "console command" : fme.getName())+".");
2013-04-19 09:50:33 +02:00
if (Econ.isEnabled() && ! 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);
Factions.get().log(fme.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getTag()+".");
}
}
faction.detach();
SpoutFeatures.updateTitle(null, null);
SpoutFeatures.updateCape(null, null);
}
}