From 43fdc8ae14ba2154a05aaa6b6f75fdf464810a66 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Tue, 13 Sep 2011 13:14:09 -0500 Subject: [PATCH] New command to set a faction as permanent: /f permanent (requires new admin-level permission "factions.setPermanent"). Permanent factions will not be deleted if they have no members, and faction admins of such factions are allowed to leave without a replacement available. Faction admins are also unable to disband their own faction if it is Permanent; only those with the admin-level "factions.disband" permission can disband such a faction while it is set as Permanent. --- src/com/massivecraft/factions/FPlayer.java | 9 ++- src/com/massivecraft/factions/Faction.java | 12 ++++ src/com/massivecraft/factions/Factions.java | 5 ++ .../factions/commands/FCommandDisband.java | 5 ++ .../factions/commands/FCommandHelp.java | 3 +- .../factions/commands/FCommandKick.java | 2 +- .../factions/commands/FCommandPermanent.java | 57 +++++++++++++++++++ .../factions/commands/FCommandShow.java | 4 ++ 8 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 src/com/massivecraft/factions/commands/FCommandPermanent.java diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 8ac986f7..a51f0e6c 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -459,8 +459,9 @@ public class FPlayer { public void leave(boolean makePay) { Faction myFaction = this.getFaction(); + boolean perm = myFaction.isPermanent(); - if (this.getRole() == Role.ADMIN && myFaction.getFPlayers().size() > 1) { + if (!perm && this.getRole() == Role.ADMIN && myFaction.getFPlayers().size() > 1) { sendMessage("You must give the admin role to someone else first."); return; } @@ -496,7 +497,7 @@ public class FPlayer { this.resetFactionData(); - if (myFaction.isNormal() && myFaction.getFPlayers().isEmpty()) { + if (myFaction.isNormal() && !perm && myFaction.getFPlayers().isEmpty()) { // Remove this faction for (FPlayer fplayer : FPlayer.getAllOnline()) { fplayer.sendMessage("The faction "+myFaction.getTag(fplayer)+Conf.colorSystem+" was disbanded."); @@ -687,7 +688,9 @@ public class FPlayer { // -------------------------------------------- // public boolean shouldBeSaved() { - return this.factionId != 0; +// return this.factionId != 0; + // we now need to track all players, so they don't get stuck back into a default faction if factionless; also to keep track of lost power and such + return true; } public static boolean save() { diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index 2d5e83b6..017df0e3 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -34,6 +34,7 @@ public class Faction { private boolean open; private boolean peaceful; private boolean peacefulExplosionsEnabled; + private boolean permanent; private String tag; private String description; private Location home; @@ -50,6 +51,9 @@ public class Faction { this.tag = "???"; this.description = "Default faction description :("; this.lastPlayerLoggedOffTime = 0; + this.peaceful = false; + this.peacefulExplosionsEnabled = false; + this.permanent = false; } // -------------------------------------------- // @@ -132,6 +136,14 @@ public class Faction { peaceful = isPeaceful; } + // "permanent" status can only be set by server admins/moderators/ops, and allows the faction to remain even with 0 members + public boolean isPermanent() { + return permanent; + } + public void setPermanent(boolean isPermanent) { + permanent = isPermanent; + } + public void setPeacefulExplosions(boolean disable) { peacefulExplosionsEnabled = disable; } diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 5bd19217..bd976317 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -120,6 +120,7 @@ public class Factions extends JavaPlugin { commands.add(new FCommandOwnerList()); commands.add(new FCommandPower()); commands.add(new FCommandPeaceful()); + commands.add(new FCommandPermanent()); commands.add(new FCommandRelationAlly()); commands.add(new FCommandRelationEnemy()); commands.add(new FCommandRelationNeutral()); @@ -425,6 +426,10 @@ public class Factions extends JavaPlugin { return hasPerm(sender, "factions.setPeaceful"); } + public static boolean hasPermSetPermanent(CommandSender sender) { + return hasPerm(sender, "factions.setPermanent"); + } + public static boolean hasPermPeacefulExplosionToggle(CommandSender sender) { return hasPerm(sender, "factions.peacefulExplosionToggle"); } diff --git a/src/com/massivecraft/factions/commands/FCommandDisband.java b/src/com/massivecraft/factions/commands/FCommandDisband.java index e91b1e00..2599b063 100644 --- a/src/com/massivecraft/factions/commands/FCommandDisband.java +++ b/src/com/massivecraft/factions/commands/FCommandDisband.java @@ -52,6 +52,11 @@ public class FCommandDisband extends FBaseCommand { } faction = me.getFaction(); + + if (faction.isPermanent() && !Factions.hasPermDisband(sender)) { + sendMessage("Your faction is designated as permanent, so you cannot disband it."); + return; + } } // Inform all players diff --git a/src/com/massivecraft/factions/commands/FCommandHelp.java b/src/com/massivecraft/factions/commands/FCommandHelp.java index 34a40550..8f4a7cf0 100644 --- a/src/com/massivecraft/factions/commands/FCommandHelp.java +++ b/src/com/massivecraft/factions/commands/FCommandHelp.java @@ -140,6 +140,7 @@ public class FCommandHelp extends FBaseCommand { pageLines = new ArrayList(); pageLines.add("Finally some commands for the server admins:"); + pageLines.add( new FCommandBypass().getUseageTemplate() ); pageLines.add( new FCommandSafeclaim().getUseageTemplate() ); pageLines.add( new FCommandAutoSafeclaim().getUseageTemplate() ); pageLines.add( new FCommandSafeunclaimall().getUseageTemplate() ); @@ -151,8 +152,8 @@ public class FCommandHelp extends FBaseCommand { pageLines = new ArrayList(); pageLines.add("More commands for server admins:"); - pageLines.add( new FCommandBypass().getUseageTemplate() ); pageLines.add( new FCommandPeaceful().getUseageTemplate() ); + pageLines.add( new FCommandPermanent().getUseageTemplate() ); pageLines.add("Peaceful factions are protected from PvP and land capture."); pageLines.add( new FCommandLock().getUseageTemplate() ); pageLines.add( new FCommandReload().getUseageTemplate() ); diff --git a/src/com/massivecraft/factions/commands/FCommandKick.java b/src/com/massivecraft/factions/commands/FCommandKick.java index 4b95faf3..a342456f 100644 --- a/src/com/massivecraft/factions/commands/FCommandKick.java +++ b/src/com/massivecraft/factions/commands/FCommandKick.java @@ -71,7 +71,7 @@ public class FCommandKick extends FBaseCommand { yourFaction.deinvite(you); you.resetFactionData(); - if (yourFaction.getFPlayers().isEmpty()) { + if (yourFaction.getFPlayers().isEmpty() && !yourFaction.isPermanent()) { // Remove this faction for (FPlayer fplayer : FPlayer.getAllOnline()) { fplayer.sendMessage("The faction "+yourFaction.getTag(fplayer)+Conf.colorSystem+" was disbanded."); diff --git a/src/com/massivecraft/factions/commands/FCommandPermanent.java b/src/com/massivecraft/factions/commands/FCommandPermanent.java new file mode 100644 index 00000000..680c3cab --- /dev/null +++ b/src/com/massivecraft/factions/commands/FCommandPermanent.java @@ -0,0 +1,57 @@ +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; + + +public class FCommandPermanent extends FBaseCommand { + + public FCommandPermanent() { + aliases.add("permanent"); + + senderMustBePlayer = false; + + requiredParameters.add("faction tag"); + + helpDescription = "Designate a faction as permanent"; + } + + @Override + public boolean hasPermission(CommandSender sender) { + return Factions.hasPermSetPermanent(sender); + } + + @Override + public void perform() { + if( parameters.size() > 0) { + Faction faction = Faction.findByTag(parameters.get(0)); + + if (faction == null) { + sendMessage("No faction found with the tag \"" + parameters.get(0) + "\""); + return; + } + + String change; + if(faction.isPermanent()) { + change = "removed permanent status from"; + faction.setPermanent(false); + } else { + change = "added permanent status to"; + faction.setPermanent(true); + } + // Inform all players + for (FPlayer fplayer : FPlayer.getAllOnline()) { + if (fplayer.getFaction() == faction) { + fplayer.sendMessage(me.getNameAndRelevant(fplayer)+Conf.colorSystem+" has "+change+" your faction."); + } else { + fplayer.sendMessage(me.getNameAndRelevant(fplayer)+Conf.colorSystem+" has "+change+" the faction \"" + faction.getTag(fplayer) + "\"."); + } + } + } + } + +} diff --git a/src/com/massivecraft/factions/commands/FCommandShow.java b/src/com/massivecraft/factions/commands/FCommandShow.java index 4b1b6aa0..363a926e 100644 --- a/src/com/massivecraft/factions/commands/FCommandShow.java +++ b/src/com/massivecraft/factions/commands/FCommandShow.java @@ -70,6 +70,10 @@ public class FCommandShow extends FBaseCommand { sendMessage(Conf.colorChrome+"Joining: "+Conf.colorSystem+(faction.getOpen() ? "no invitation is needed" : "invitation is required")+peaceStatus); sendMessage(Conf.colorChrome+"Land / Power / Maxpower: "+Conf.colorSystem+ faction.getLandRounded()+" / "+faction.getPowerRounded()+" / "+faction.getPowerMaxRounded()); + if (faction.isPermanent()) { + sendMessage(Conf.colorChrome+"This faction is permanent, remaining even with no members."); + } + // show the land value if (Econ.enabled()) { double value = Econ.calculateTotalLandValue(faction.getLandRounded());