From 408725c1d7333e6d8f7f54c04e091fdad7eb8d20 Mon Sep 17 00:00:00 2001 From: ProSavage Date: Fri, 20 Jul 2018 11:42:47 -0500 Subject: [PATCH] Made a Factions.disband() method into the api. --- .../com/massivecraft/factions/Faction.java | 2 + .../massivecraft/factions/cmd/CmdDisband.java | 49 +---------------- .../factions/zcore/persist/MemoryFaction.java | 55 ++++++++++++++++++- 3 files changed, 57 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index a0ce347a..384c2a4f 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -198,6 +198,8 @@ public interface Faction extends EconomyParticipator { void resetPerms(); + void disband(Player disbander); + // ------------------------------- // Relation and relation colors // ------------------------------- diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java b/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java index 36a3eded..40cc7624 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdDisband.java @@ -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 diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java index eed71f96..c7917340 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -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,9 +140,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { } public void removeAnnouncements(FPlayer fPlayer) { - if (announcements.containsKey(fPlayer.getId())) { - announcements.remove(fPlayer.getId()); - } + announcements.remove(fPlayer.getId()); } public ConcurrentHashMap getWarps() { @@ -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())) {