Saber-Factions/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java

97 lines
3.5 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
2014-04-04 20:55:21 +02:00
import com.massivecraft.factions.*;
import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.event.FactionDisbandEvent;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
2014-04-04 20:55:21 +02:00
import org.bukkit.Bukkit;
public class CmdDisband extends FCommand {
public CmdDisband() {
2014-07-01 22:10:18 +02:00
super();
this.aliases.add("disband");
2014-04-04 20:55:21 +02:00
//this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "yours");
2014-07-01 22:10:18 +02:00
this.permission = Permission.DISBAND.node;
this.disableOnLock = true;
2014-04-04 20:55:21 +02:00
2014-07-01 22:10:18 +02:00
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
2014-04-04 20:55:21 +02:00
senderMustBeAdmin = false;
}
@Override
public void perform() {
// The faction, default to your own.. but null if console sender.
2014-07-01 22:10:18 +02:00
Faction faction = this.argAsFaction(0, fme == null ? null : myFaction);
if (faction == null) {
return;
}
2014-04-04 20:55:21 +02:00
boolean isMyFaction = fme == null ? false : faction == myFaction;
if (isMyFaction) {
2014-07-01 22:10:18 +02:00
if (!assertMinRole(Role.ADMIN)) {
return;
}
2014-07-01 21:52:40 +02:00
} else {
2014-04-04 20:55:21 +02:00
if (!Permission.DISBAND_ANY.has(sender, true)) {
return;
}
}
if (!faction.isNormal()) {
2014-07-01 22:10:18 +02:00
msg("<i>You cannot disband the Wilderness, SafeZone, or WarZone.");
return;
}
if (faction.isPermanent()) {
msg("<i>This faction is designated as permanent, so you cannot disband it.");
return;
2014-04-04 20:55:21 +02:00
}
FactionDisbandEvent disbandEvent = new FactionDisbandEvent(me, faction.getId());
2014-07-01 22:10:18 +02:00
Bukkit.getServer().getPluginManager().callEvent(disbandEvent);
if (disbandEvent.isCancelled()) {
return;
}
2014-04-04 20:55:21 +02:00
// Send FPlayerLeaveEvent for each player in the faction
for (FPlayer fplayer : faction.getFPlayers()) {
Bukkit.getServer().getPluginManager().callEvent(new FPlayerLeaveEvent(fplayer, faction, FPlayerLeaveEvent.PlayerLeaveReason.DISBAND));
}
// 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);
2014-07-01 21:52:40 +02:00
} else {
2014-04-04 20:55:21 +02:00
fplayer.msg("<h>%s<i> disbanded the faction %s.", who, faction.getTag(fplayer));
}
2014-07-01 22:10:18 +02:00
}
if (Conf.logFactionDisband) {
2014-04-04 20:55:21 +02:00
P.p.log("The faction " + faction.getTag() + " (" + faction.getId() + ") was disbanded by " + (senderIsConsole ? "console command" : fme.getName()) + ".");
2014-07-01 21:49:42 +02:00
}
2014-04-04 20:55:21 +02: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);
P.p.log(fme.getName() + " has been given bank holdings of " + amountString + " from disbanding " + faction.getTag() + ".");
}
}
2014-04-04 20:55:21 +02:00
faction.detach();
}
}