From 632e2b2d1c5e3fe92482b273f500df92344557a3 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Mon, 12 Sep 2011 22:23:44 -0500 Subject: [PATCH] Faction admins can now disband their own faction using /f disband; note that use of /f disband with another faction specified (/f disband ) still requires the factions.disband permission, but the permission is not required for faction admins disbanding their own faction --- .../factions/commands/FCommandDisband.java | 58 ++++++++++++------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/src/com/massivecraft/factions/commands/FCommandDisband.java b/src/com/massivecraft/factions/commands/FCommandDisband.java index 29832e9d..e91b1e00 100644 --- a/src/com/massivecraft/factions/commands/FCommandDisband.java +++ b/src/com/massivecraft/factions/commands/FCommandDisband.java @@ -1,12 +1,12 @@ package com.massivecraft.factions.commands; -import org.bukkit.command.CommandSender; - import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.SpoutFeatures; +import com.massivecraft.factions.struct.Role; + public class FCommandDisband extends FBaseCommand { @@ -15,37 +15,55 @@ public class FCommandDisband extends FBaseCommand { senderMustBePlayer = false; - requiredParameters.add("faction tag"); + optionalParameters.add("faction tag"); helpDescription = "Disband a faction"; } - @Override - public boolean hasPermission(CommandSender sender) { - return Factions.hasPermDisband(sender); - } - @Override public void perform() { - if( parameters.size() > 0) { - Faction faction = Faction.findByTag(parameters.get(0)); + + Faction faction = null; + + if( parameters.size() > 0) { + faction = Faction.findByTag(parameters.get(0)); if( faction == null || !faction.isNormal()) { - sendMessage("Faction " + parameters.get(0) + "not found"); + sendMessage("Faction \"" + parameters.get(0) + "\" not found"); return; } - // Inform all players - for (FPlayer fplayer : FPlayer.getAllOnline()) { - if (fplayer.getFaction() == faction) { - fplayer.sendMessage(me.getNameAndRelevant(fplayer)+Conf.colorSystem+" disbanded your faction."); - } else { - fplayer.sendMessage(me.getNameAndRelevant(fplayer)+Conf.colorSystem+" disbanded the faction "+faction.getTag(fplayer)+"."); + if ( ! Factions.hasPermDisband(sender)) { + if (me.getFaction() == faction) { + parameters.clear(); + } + else { + sendMessage("You do not have sufficient permission to disband other factions."); + return; } } - Faction.delete( faction.getId() ); - SpoutFeatures.updateAppearances(); } + if (parameters.isEmpty()) { + if ( ! assertHasFaction()) { + return; + } + if ( ! assertMinRole(Role.ADMIN)) { + return; + } + + faction = me.getFaction(); + } + + // Inform all players + for (FPlayer fplayer : FPlayer.getAllOnline()) { + if (fplayer.getFaction() == faction) { + fplayer.sendMessage(me.getNameAndRelevant(fplayer)+Conf.colorSystem+" disbanded your faction."); + } else { + fplayer.sendMessage(me.getNameAndRelevant(fplayer)+Conf.colorSystem+" disbanded the faction "+faction.getTag(fplayer)+"."); + } + } + Faction.delete( faction.getId() ); + SpoutFeatures.updateAppearances(); + } - }