New command to set a faction as permanent: /f permanent <faction tag> (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.

This commit is contained in:
Brettflan 2011-09-13 13:14:09 -05:00
parent 249846d6ae
commit 43fdc8ae14
8 changed files with 92 additions and 5 deletions

View File

@ -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() {

View File

@ -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;
}

View File

@ -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");
}

View File

@ -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

View File

@ -140,6 +140,7 @@ public class FCommandHelp extends FBaseCommand {
pageLines = new ArrayList<String>();
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<String>();
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() );

View File

@ -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.");

View File

@ -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) + "\".");
}
}
}
}
}

View File

@ -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());