Made a Factions.disband() method into the api.

This commit is contained in:
ProSavage 2018-07-20 11:42:47 -05:00
parent 2320fe2586
commit 408725c1d7
3 changed files with 57 additions and 49 deletions

View File

@ -198,6 +198,8 @@ public interface Faction extends EconomyParticipator {
void resetPerms();
void disband(Player disbander);
// -------------------------------
// Relation and relation colors
// -------------------------------

View File

@ -1,14 +1,9 @@
package com.massivecraft.factions.cmd;
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.scoreboards.FTeamWrapper;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
public class CmdDisband extends FCommand {
@ -59,46 +54,8 @@ public class CmdDisband extends FCommand {
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()) {
Bukkit.getServer().getPluginManager().callEvent(new FPlayerLeaveEvent(fplayer, faction, FPlayerLeaveEvent.PlayerLeaveReason.DISBAND));
}
// Inform all players
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
String who = senderIsConsole ? TL.GENERIC_SERVERADMIN.toString() : fme.describeTo(fplayer);
if (fplayer.getFaction() == faction) {
fplayer.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, who);
} else {
fplayer.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, who, faction.getTag(fplayer));
}
}
if (Conf.logFactionDisband) {
//TODO: Format this correctly and translate.
P.p.log("The faction " + faction.getTag() + " (" + faction.getId() + ") was disbanded by " + (senderIsConsole ? "console command" : fme.getName()) + ".");
}
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(TL.COMMAND_DISBAND_HOLDINGS, amountString);
//TODO: Format this correctly and translate
P.p.log(fme.getName() + " has been given bank holdings of " + amountString + " from disbanding " + faction.getTag() + ".");
}
}
Factions.getInstance().removeFaction(faction.getId());
FTeamWrapper.applyUpdates(faction);
//Success
faction.disband(me);
}
@Override

View File

@ -1,9 +1,12 @@
package com.massivecraft.factions.zcore.persist;
import com.massivecraft.factions.*;
import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.event.FactionDisbandEvent;
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.iface.RelationParticipator;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.scoreboards.FTeamWrapper;
import com.massivecraft.factions.struct.BanInfo;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
@ -137,10 +140,8 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
}
public void removeAnnouncements(FPlayer fPlayer) {
if (announcements.containsKey(fPlayer.getId())) {
announcements.remove(fPlayer.getId());
}
}
public ConcurrentHashMap<String, LazyLocation> getWarps() {
return this.warps;
@ -225,6 +226,54 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
}
}
public void disband(Player disbander) {
boolean disbanderIsConsole = disbander == null;
FPlayer fdisbander = FPlayers.getInstance().getByOfflinePlayer(disbander);
FactionDisbandEvent disbandEvent = new FactionDisbandEvent(disbander, this.getId());
Bukkit.getServer().getPluginManager().callEvent(disbandEvent);
if (disbandEvent.isCancelled()) {
return;
}
// Send FPlayerLeaveEvent for each player in the faction
for (FPlayer fplayer : this.getFPlayers()) {
Bukkit.getServer().getPluginManager().callEvent(new FPlayerLeaveEvent(fplayer, this, FPlayerLeaveEvent.PlayerLeaveReason.DISBAND));
}
// Inform all players
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
String who = disbanderIsConsole ? TL.GENERIC_SERVERADMIN.toString() : fdisbander.describeTo(fplayer);
if (fplayer.getFaction() == this) {
fplayer.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, who);
} else {
fplayer.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, who, this.getTag(fplayer));
}
}
if (Conf.logFactionDisband) {
//TODO: Format this correctly and translate.
P.p.log("The faction " + this.getTag() + " (" + this.getId() + ") was disbanded by " + (disbanderIsConsole ? "console command" : fdisbander.getName()) + ".");
}
if (Econ.shouldBeUsed() && !disbanderIsConsole) {
//Give all the faction's money to the disbander
double amount = Econ.getBalance(this.getAccountId());
Econ.transferMoney(fdisbander, this, fdisbander, amount, false);
if (amount > 0.0) {
String amountString = Econ.moneyString(amount);
msg(TL.COMMAND_DISBAND_HOLDINGS, amountString);
//TODO: Format this correctly and translate
P.p.log(fdisbander.getName() + " has been given bank holdings of " + amountString + " from disbanding " + this.getTag() + ".");
}
}
Factions.getInstance().removeFaction(this.getId());
FTeamWrapper.applyUpdates(this);
}
public boolean isBanned(FPlayer player) {
for (BanInfo info : bans) {
if (info.getBanned().equalsIgnoreCase(player.getId())) {