diff --git a/src/org/mcteam/factions/FPlayer.java b/src/org/mcteam/factions/FPlayer.java index ba1a4a54..a5eae29e 100644 --- a/src/org/mcteam/factions/FPlayer.java +++ b/src/org/mcteam/factions/FPlayer.java @@ -44,6 +44,9 @@ public class FPlayer { private long lastPowerUpdateTime; private long lastLoginTime; private transient boolean mapAutoUpdating; + private transient boolean autoClaimEnabled; + private transient boolean autoSafeZoneEnabled; + private transient boolean autoWarZoneEnabled; private boolean factionChatting; // -------------------------------------------- // @@ -129,6 +132,45 @@ public class FPlayer { return lastLoginTime; } + public boolean autoClaimEnabled() { + if (this.factionId == 0) + return false; + return autoClaimEnabled; + } + public void enableAutoClaim(boolean enabled) { + this.autoClaimEnabled = enabled; + if (enabled) { + this.autoSafeZoneEnabled = false; + this.autoWarZoneEnabled = false; + } + } + + public boolean autoSafeZoneEnabled() { + if (this.factionId == 0) + return false; + return autoSafeZoneEnabled; + } + public void enableAutoSafeZone(boolean enabled) { + this.autoSafeZoneEnabled = enabled; + if (enabled) { + this.autoClaimEnabled = false; + this.autoWarZoneEnabled = false; + } + } + + public boolean autoWarZoneEnabled() { + if (this.factionId == 0) + return false; + return autoWarZoneEnabled; + } + public void enableAutoWarZone(boolean enabled) { + this.autoWarZoneEnabled = enabled; + if (enabled) { + this.autoClaimEnabled = false; + this.autoSafeZoneEnabled = false; + } + } + public void setLastLoginTime(long lastLoginTime) { this.lastLoginTime = lastLoginTime; this.lastPowerUpdateTime = lastLoginTime; @@ -395,6 +437,77 @@ public class FPlayer { } } + public boolean attemptClaim(boolean notifyFailure) { + // notifyFailure is false if called by auto-claim; not need to notify on every failure for it + // return value is false on failure, true on success + + Faction myFaction = getFaction(); + FLocation flocation = new FLocation(this); + Faction otherFaction = Board.getFactionAt(flocation); + + if (myFaction == otherFaction) { + if (notifyFailure) + sendMessage("You already own this land."); + return false; + } + + if (this.getRole().value < Role.MODERATOR.value) { + sendMessage("You must be "+Role.MODERATOR+" to claim land."); + return false; + } + + if (Conf.worldsNoClaiming.contains(flocation.getWorldName())) { + sendMessage("Sorry, this world has land claiming disabled."); + return false; + } + + if (otherFaction.isSafeZone()) { + if (notifyFailure) + sendMessage("You can not claim a Safe Zone."); + return false; + } + else if (otherFaction.isWarZone()) { + if (notifyFailure) + sendMessage("You can not claim a War Zone."); + return false; + } + + if (myFaction.getLandRounded() >= myFaction.getPowerRounded()) { + sendMessage("You can't claim more land! You need more power!"); + return false; + } + + if (otherFaction.getRelation(this) == Relation.ALLY) { + if (notifyFailure) + sendMessage("You can't claim the land of your allies."); + return false; + } + + if (otherFaction.isNone()) { + myFaction.sendMessage(this.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some new land :D"); + } else { //if (otherFaction.isNormal()) { + + if ( ! otherFaction.hasLandInflation()) { + // TODO more messages WARN current faction most importantly + sendMessage(this.getRelationColor(otherFaction)+otherFaction.getTag()+Conf.colorSystem+" owns this land and is strong enough to keep it."); + return false; + } + + if ( ! Board.isBorderLocation(flocation)) { + sendMessage("You must start claiming land at the border of the territory."); + return false; + } + + // ASDF claimed some of your land 450 blocks NNW of you. + // ASDf claimed some land from FACTION NAME + otherFaction.sendMessage(this.getNameAndRelevant(otherFaction)+Conf.colorSystem+" stole some of your land :O"); + myFaction.sendMessage(this.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some land from "+otherFaction.getTag(myFaction)); + } + + Board.setFactionAt(myFaction, flocation); + return true; + } + // -------------------------------------------- // // Messages // -------------------------------------------- // diff --git a/src/org/mcteam/factions/Factions.java b/src/org/mcteam/factions/Factions.java index ab6b11e6..e9f1133c 100644 --- a/src/org/mcteam/factions/Factions.java +++ b/src/org/mcteam/factions/Factions.java @@ -69,6 +69,9 @@ public class Factions extends JavaPlugin { // Add the commands commands.add(new FCommandHelp()); commands.add(new FCommandAdmin()); + commands.add(new FCommandAutoClaim()); + commands.add(new FCommandAutoSafeclaim()); + commands.add(new FCommandAutoWarclaim()); commands.add(new FCommandBypass()); commands.add(new FCommandChat()); commands.add(new FCommandClaim()); diff --git a/src/org/mcteam/factions/commands/FCommandAutoClaim.java b/src/org/mcteam/factions/commands/FCommandAutoClaim.java new file mode 100644 index 00000000..23921c9c --- /dev/null +++ b/src/org/mcteam/factions/commands/FCommandAutoClaim.java @@ -0,0 +1,67 @@ +package org.mcteam.factions.commands; + +import org.mcteam.factions.Conf; +import org.mcteam.factions.FLocation; +import org.mcteam.factions.Faction; +import org.mcteam.factions.struct.Role; + +public class FCommandAutoClaim extends FBaseCommand { + + public FCommandAutoClaim() { + aliases.add("autoclaim"); + + optionalParameters.add("on|off"); + + helpDescription = "Auto-claim land as you walk around"; + } + + @Override + public void perform() { + if ( ! assertHasFaction()) { + return; + } + + if( isLocked() ) { + sendLockMessage(); + return; + } + + // default: toggle existing value + boolean enable = !me.autoClaimEnabled(); + + // if on|off is specified, use that instead + if (parameters.size() > 0) + enable = parseBool(parameters.get(0)); + + me.enableAutoClaim(enable); + + if (!enable) { + sendMessage("Auto-claiming of land disabled."); + return; + } + + Faction myFaction = me.getFaction(); + FLocation flocation = new FLocation(me); + + if ( ! assertMinRole(Role.MODERATOR)) { + me.enableAutoClaim(false); + return; + } + + if (Conf.worldsNoClaiming.contains(flocation.getWorldName())) { + sendMessage("Sorry, this world has land claiming disabled."); + me.enableAutoClaim(false); + return; + } + + if (myFaction.getLandRounded() >= myFaction.getPowerRounded()) { + sendMessage("You can't claim more land! You need more power!"); + me.enableAutoClaim(false); + return; + } + + sendMessage("Auto-claiming of land enabled."); + me.attemptClaim(false); + } + +} diff --git a/src/org/mcteam/factions/commands/FCommandAutoSafeclaim.java b/src/org/mcteam/factions/commands/FCommandAutoSafeclaim.java new file mode 100644 index 00000000..78d8fda3 --- /dev/null +++ b/src/org/mcteam/factions/commands/FCommandAutoSafeclaim.java @@ -0,0 +1,54 @@ +package org.mcteam.factions.commands; + +import org.bukkit.command.CommandSender; +import org.mcteam.factions.Board; +import org.mcteam.factions.FLocation; +import org.mcteam.factions.Faction; +import org.mcteam.factions.Factions; + +public class FCommandAutoSafeclaim extends FBaseCommand { + + public FCommandAutoSafeclaim() { + aliases.add("autosafe"); + + optionalParameters.add("on|off"); + + helpDescription = "Auto-claim land for the safezone"; + } + + @Override + public boolean hasPermission(CommandSender sender) { + return Factions.hasPermManageSafeZone(sender); + } + + @Override + public void perform() { + + if( isLocked() ) { + sendLockMessage(); + return; + } + + boolean enable = !me.autoSafeZoneEnabled(); + + if (parameters.size() > 0) + enable = parseBool(parameters.get(0)); + + me.enableAutoSafeZone(enable); + + if (!enable) { + sendMessage("Auto-claiming of safe zone disabled."); + return; + } + + sendMessage("Auto-claiming of safe zone enabled."); + + FLocation playerFlocation = new FLocation(me); + + if (!Board.getFactionAt(playerFlocation).isSafeZone()) { + Board.setFactionAt(Faction.getSafeZone(), playerFlocation); + sendMessage("This land is now a safe zone."); + } + } + +} diff --git a/src/org/mcteam/factions/commands/FCommandAutoWarclaim.java b/src/org/mcteam/factions/commands/FCommandAutoWarclaim.java new file mode 100644 index 00000000..6fa7abf3 --- /dev/null +++ b/src/org/mcteam/factions/commands/FCommandAutoWarclaim.java @@ -0,0 +1,54 @@ +package org.mcteam.factions.commands; + +import org.bukkit.command.CommandSender; +import org.mcteam.factions.Board; +import org.mcteam.factions.FLocation; +import org.mcteam.factions.Faction; +import org.mcteam.factions.Factions; + +public class FCommandAutoWarclaim extends FBaseCommand { + + public FCommandAutoWarclaim() { + aliases.add("autowar"); + + optionalParameters.add("on|off"); + + helpDescription = "Auto-claim land for the warzone"; + } + + @Override + public boolean hasPermission(CommandSender sender) { + return Factions.hasPermManageWarZone(sender); + } + + @Override + public void perform() { + + if( isLocked() ) { + sendLockMessage(); + return; + } + + boolean enable = !me.autoWarZoneEnabled(); + + if (parameters.size() > 0) + enable = parseBool(parameters.get(0)); + + me.enableAutoWarZone(enable); + + if (!enable) { + sendMessage("Auto-claiming of war zone disabled."); + return; + } + + sendMessage("Auto-claiming of war zone enabled."); + + FLocation playerFlocation = new FLocation(me); + + if (!Board.getFactionAt(playerFlocation).isWarZone()) { + Board.setFactionAt(Faction.getWarZone(), playerFlocation); + sendMessage("This land is now a war zone."); + } + } + +} diff --git a/src/org/mcteam/factions/commands/FCommandClaim.java b/src/org/mcteam/factions/commands/FCommandClaim.java index 663feaf2..3c1c6efc 100644 --- a/src/org/mcteam/factions/commands/FCommandClaim.java +++ b/src/org/mcteam/factions/commands/FCommandClaim.java @@ -1,12 +1,5 @@ package org.mcteam.factions.commands; -import org.mcteam.factions.Board; -import org.mcteam.factions.Conf; -import org.mcteam.factions.FLocation; -import org.mcteam.factions.Faction; -import org.mcteam.factions.struct.Relation; -import org.mcteam.factions.struct.Role; - public class FCommandClaim extends FBaseCommand { public FCommandClaim() { @@ -25,66 +18,7 @@ public class FCommandClaim extends FBaseCommand { return; } - Faction myFaction = me.getFaction(); - FLocation flocation = new FLocation(me); - Faction otherFaction = Board.getFactionAt(flocation); - - if (myFaction == otherFaction) { - sendMessage("You already own this land."); - return; - } - - if ( ! assertMinRole(Role.MODERATOR)) { - return; - } - - - if (Conf.worldsNoClaiming.contains(flocation.getWorldName())) { - sendMessage("Sorry, this world has land claiming disabled."); - return; - } - - if (otherFaction.isSafeZone()) { - sendMessage("You can not claim a Safe Zone."); - return; - } - else if (otherFaction.isWarZone()) { - sendMessage("You can not claim a War Zone."); - return; - } - - if (myFaction.getLandRounded() >= myFaction.getPowerRounded()) { - sendMessage("You can't claim more land! You need more power!"); - return; - } - - if (otherFaction.getRelation(me) == Relation.ALLY) { - sendMessage("You can't claim the land of your allies."); - return; - } - - if (otherFaction.isNone()) { - myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some new land :D"); - } else { //if (otherFaction.isNormal()) { - - if ( ! otherFaction.hasLandInflation()) { - // TODO more messages WARN current faction most importantly - sendMessage(me.getRelationColor(otherFaction)+otherFaction.getTag()+Conf.colorSystem+" owns this land and is strong enough to keep it."); - return; - } - - if ( ! Board.isBorderLocation(flocation)) { - sendMessage("You must start claiming land at the border of the territory."); - return; - } - - // ASDF claimed some of your land 450 blocks NNW of you. - // ASDf claimed some land from FACTION NAME - otherFaction.sendMessage(me.getNameAndRelevant(otherFaction)+Conf.colorSystem+" stole some of your land :O"); - myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" claimed some land from "+otherFaction.getTag(myFaction)); - } - - Board.setFactionAt(myFaction, flocation); + me.attemptClaim(true); } } diff --git a/src/org/mcteam/factions/commands/FCommandHelp.java b/src/org/mcteam/factions/commands/FCommandHelp.java index c19a16b9..f4e37f0c 100644 --- a/src/org/mcteam/factions/commands/FCommandHelp.java +++ b/src/org/mcteam/factions/commands/FCommandHelp.java @@ -64,9 +64,9 @@ public class FCommandHelp extends FBaseCommand { helpPages.add(pageLines); pageLines = new ArrayList(); - pageLines.add( "Create a faction using these two commands:" ); pageLines.add( new FCommandCreate().getUseageTemplate() ); pageLines.add( new FCommandDescription().getUseageTemplate() ); + pageLines.add( new FCommandTag().getUseageTemplate() ); pageLines.add( "You might want to close it and use invitations:" ); pageLines.add( new FCommandOpen().getUseageTemplate() ); pageLines.add( new FCommandInvite().getUseageTemplate() ); @@ -77,9 +77,9 @@ public class FCommandHelp extends FBaseCommand { pageLines = new ArrayList(); pageLines.add( new FCommandClaim().getUseageTemplate() ); + pageLines.add( new FCommandAutoClaim().getUseageTemplate() ); pageLines.add( new FCommandUnclaim().getUseageTemplate() ); pageLines.add( new FCommandUnclaimall().getUseageTemplate() ); - pageLines.add( new FCommandTag().getUseageTemplate() ); pageLines.add( new FCommandKick().getUseageTemplate() ); pageLines.add( new FCommandMod().getUseageTemplate() ); pageLines.add( new FCommandAdmin().getUseageTemplate() ); @@ -127,16 +127,18 @@ public class FCommandHelp extends FBaseCommand { pageLines.add("Finally some commands for the server admins:"); pageLines.add( new FCommandVersion().getUseageTemplate() ); pageLines.add( new FCommandSafeclaim().getUseageTemplate() ); + pageLines.add( new FCommandAutoSafeclaim().getUseageTemplate() ); pageLines.add( new FCommandSafeunclaimall().getUseageTemplate() ); pageLines.add( new FCommandWarclaim().getUseageTemplate() ); + pageLines.add( new FCommandAutoWarclaim().getUseageTemplate() ); pageLines.add( new FCommandWarunclaimall().getUseageTemplate() ); - pageLines.add( new FCommandWorldNoClaim().getUseageTemplate() ); - pageLines.add( new FCommandWorldNoPowerLoss().getUseageTemplate() ); pageLines.add( new FCommandBypass().getUseageTemplate() ); helpPages.add(pageLines); pageLines = new ArrayList(); pageLines.add("More commands for server admins:"); + pageLines.add( new FCommandWorldNoClaim().getUseageTemplate() ); + pageLines.add( new FCommandWorldNoPowerLoss().getUseageTemplate() ); pageLines.add( new FCommandLock().getUseageTemplate() ); pageLines.add( new FCommandReload().getUseageTemplate() ); pageLines.add( new FCommandSaveAll().getUseageTemplate() ); diff --git a/src/org/mcteam/factions/commands/FCommandSafeclaim.java b/src/org/mcteam/factions/commands/FCommandSafeclaim.java index c5bce0d5..bb31eeb1 100644 --- a/src/org/mcteam/factions/commands/FCommandSafeclaim.java +++ b/src/org/mcteam/factions/commands/FCommandSafeclaim.java @@ -47,7 +47,7 @@ public class FCommandSafeclaim extends FBaseCommand { } else { Board.setFactionAt(Faction.getSafeZone(), playerFlocation); - sendMessage("This land is now a safe zone"); + sendMessage("This land is now a safe zone."); } } diff --git a/src/org/mcteam/factions/commands/FCommandWarclaim.java b/src/org/mcteam/factions/commands/FCommandWarclaim.java index 4e2b6133..3e6b9024 100644 --- a/src/org/mcteam/factions/commands/FCommandWarclaim.java +++ b/src/org/mcteam/factions/commands/FCommandWarclaim.java @@ -47,7 +47,7 @@ public class FCommandWarclaim extends FBaseCommand { } else { Board.setFactionAt(Faction.getWarZone(), playerFlocation); - sendMessage("This land is now a war zone"); + sendMessage("This land is now a war zone."); } } diff --git a/src/org/mcteam/factions/listeners/FactionsPlayerListener.java b/src/org/mcteam/factions/listeners/FactionsPlayerListener.java index 6d8b7bc3..931a4733 100644 --- a/src/org/mcteam/factions/listeners/FactionsPlayerListener.java +++ b/src/org/mcteam/factions/listeners/FactionsPlayerListener.java @@ -25,6 +25,7 @@ import org.mcteam.factions.FLocation; import org.mcteam.factions.FPlayer; import org.mcteam.factions.Faction; import org.mcteam.factions.Factions; +import org.mcteam.factions.struct.Role; import org.mcteam.factions.util.TextUtil; @@ -164,6 +165,50 @@ public class FactionsPlayerListener extends PlayerListener{ me.sendFactionHereMessage(); } } + + if (me.autoClaimEnabled()) { + Faction myFaction = me.getFaction(); + FLocation flocation = new FLocation(me); + + if (me.getRole().value < Role.MODERATOR.value) { + me.sendMessage("You must be "+Role.MODERATOR+" to claim land."); + me.enableAutoClaim(false); + } + else if (Conf.worldsNoClaiming.contains(flocation.getWorldName())) { + me.sendMessage("Sorry, this world has land claiming disabled."); + me.enableAutoClaim(false); + } + else if (myFaction.getLandRounded() >= myFaction.getPowerRounded()) { + me.sendMessage("You can't claim more land! You need more power!"); + me.enableAutoClaim(false); + } + else + me.attemptClaim(false); + } + else if (me.autoSafeZoneEnabled()) { + if (!Factions.hasPermManageSafeZone((CommandSender)me)) { + me.enableAutoSafeZone(false); + } else { + FLocation playerFlocation = new FLocation(me); + + if (!Board.getFactionAt(playerFlocation).isSafeZone()) { + Board.setFactionAt(Faction.getSafeZone(), playerFlocation); + me.sendMessage("This land is now a safe zone."); + } + } + } + else if (me.autoWarZoneEnabled()) { + if (!Factions.hasPermManageWarZone((CommandSender)me)) { + me.enableAutoWarZone(false); + } else { + FLocation playerFlocation = new FLocation(me); + + if (!Board.getFactionAt(playerFlocation).isWarZone()) { + Board.setFactionAt(Faction.getWarZone(), playerFlocation); + me.sendMessage("This land is now a war zone."); + } + } + } } @Override