2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-05-08 17:44:00 +02:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
import com.massivecraft.factions.*;
|
2012-03-13 13:58:51 +01:00
|
|
|
import com.massivecraft.factions.event.FPlayerLeaveEvent;
|
|
|
|
import com.massivecraft.factions.event.FactionDisbandEvent;
|
2011-10-05 12:13:54 +02:00
|
|
|
import com.massivecraft.factions.integration.Econ;
|
2014-11-07 19:55:59 +01:00
|
|
|
import com.massivecraft.factions.scoreboards.FTeamWrapper;
|
2011-10-09 14:53:38 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2011-09-13 05:23:44 +02:00
|
|
|
import com.massivecraft.factions.struct.Role;
|
2014-12-08 00:12:52 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2014-04-04 20:55:21 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
|
|
|
|
|
|
|
public class CmdDisband extends FCommand {
|
2014-08-05 17:17:27 +02:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
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-12-08 00:12:52 +01:00
|
|
|
msg(TL.COMMAND_DISBAND_IMMUTABLE.toString());
|
2014-07-01 22:10:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (faction.isPermanent()) {
|
2014-12-08 00:12:52 +01:00
|
|
|
msg(TL.COMMAND_DISBAND_MARKEDPERMANENT.toString());
|
2014-07-01 22:10:18 +02:00
|
|
|
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
|
2014-10-19 07:37:25 +02:00
|
|
|
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
|
2014-12-08 00:12:52 +01:00
|
|
|
String who = senderIsConsole ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fplayer);
|
2014-04-04 20:55:21 +02:00
|
|
|
if (fplayer.getFaction() == faction) {
|
2014-12-08 00:12:52 +01:00
|
|
|
fplayer.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, who);
|
2014-07-01 21:52:40 +02:00
|
|
|
} else {
|
2014-12-08 00:12:52 +01:00
|
|
|
fplayer.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, who, faction.getTag(fplayer));
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
2014-07-01 22:10:18 +02:00
|
|
|
}
|
|
|
|
if (Conf.logFactionDisband) {
|
2014-12-11 17:05:04 +01:00
|
|
|
//TODO: Format this correctly and translate.
|
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);
|
2014-12-08 00:12:52 +01:00
|
|
|
msg(TL.COMMAND_DISBAND_HOLDINGS, amountString);
|
|
|
|
//TODO: Format this correctly and translate
|
2014-04-04 20:55:21 +02:00
|
|
|
P.p.log(fme.getName() + " has been given bank holdings of " + amountString + " from disbanding " + faction.getTag() + ".");
|
|
|
|
}
|
|
|
|
}
|
2011-09-13 05:23:44 +02:00
|
|
|
|
2014-10-19 07:37:25 +02:00
|
|
|
Factions.getInstance().removeFaction(faction.getId());
|
2014-11-07 19:55:59 +01:00
|
|
|
FTeamWrapper.applyUpdates(faction);
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
2015-01-22 00:58:33 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_DISBAND_DESCRIPTION;
|
|
|
|
}
|
2011-05-08 17:44:00 +02:00
|
|
|
}
|