From 56cbf54c98ed951932043dda0b084a4ff9354d8b Mon Sep 17 00:00:00 2001 From: Brettflan Date: Sun, 19 Jun 2011 03:56:21 -0500 Subject: [PATCH] Added options to require faction homes to be set only inside the faction's own territory ("homesMustBeInClaimedTerritory", default is true) and to optionally prevent teleporting to the faction home if the player is in enemy territory ("homesTeleportAllowedFromEnemyTerritory", default is true thus not prevented) Made commands which reference player names (like /f admin ) allow for partial name matches Optimized a couple of things, and updated help text to indicate /f unclaim works for safe/war zones --- src/org/mcteam/factions/Conf.java | 2 ++ src/org/mcteam/factions/FPlayer.java | 9 +++++++-- src/org/mcteam/factions/Faction.java | 2 +- src/org/mcteam/factions/commands/FCommandHelp.java | 3 ++- src/org/mcteam/factions/commands/FCommandHome.java | 5 +++++ src/org/mcteam/factions/commands/FCommandSethome.java | 7 ++++++- 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/org/mcteam/factions/Conf.java b/src/org/mcteam/factions/Conf.java index 292f9245..c24ec42f 100644 --- a/src/org/mcteam/factions/Conf.java +++ b/src/org/mcteam/factions/Conf.java @@ -61,7 +61,9 @@ public class Conf { public static double autoLeaveAfterDaysOfInactivity = 14; public static boolean homesEnabled = true; + public static boolean homesMustBeInClaimedTerritory = true; public static boolean homesTeleportToOnDeath = true; + public static boolean homesTeleportAllowedFromEnemyTerritory = true; public static double homesTeleportAllowedEnemyDistance = 32; public static boolean disablePVPForFactionlessPlayers = false; diff --git a/src/org/mcteam/factions/FPlayer.java b/src/org/mcteam/factions/FPlayer.java index a5eae29e..6b29c06b 100644 --- a/src/org/mcteam/factions/FPlayer.java +++ b/src/org/mcteam/factions/FPlayer.java @@ -393,7 +393,11 @@ public class FPlayer { public boolean isInOthersTerritory() { int idHere = Board.getIdAt(new FLocation(this)); - return idHere != 0 && idHere != this.factionId; + return idHere > 0 && idHere != this.factionId; + } + + public boolean isInEnemyTerritory() { + return Board.getFactionAt(new FLocation(this)).getRelation(this) == Relation.ENEMY; } public void sendFactionHereMessage() { @@ -557,7 +561,8 @@ public class FPlayer { public static FPlayer find(String playername) { for (Entry entry : instances.entrySet()) { - if (entry.getKey().equalsIgnoreCase(playername)) { +// if (entry.getKey().equalsIgnoreCase(playername)) { + if (entry.getKey().startsWith(playername)) { return entry.getValue(); } } diff --git a/src/org/mcteam/factions/Faction.java b/src/org/mcteam/factions/Faction.java index 376be4cb..4e97e95d 100644 --- a/src/org/mcteam/factions/Faction.java +++ b/src/org/mcteam/factions/Faction.java @@ -156,7 +156,7 @@ public class Faction { } public Relation getRelation(Faction otherFaction) { - if (otherFaction.isNone() || this.isNone()) { + if (!otherFaction.isNormal() || !this.isNormal()) { return Relation.NEUTRAL; } if (otherFaction.equals(this)) { diff --git a/src/org/mcteam/factions/commands/FCommandHelp.java b/src/org/mcteam/factions/commands/FCommandHelp.java index 3c1c17b3..f74fe5d9 100644 --- a/src/org/mcteam/factions/commands/FCommandHelp.java +++ b/src/org/mcteam/factions/commands/FCommandHelp.java @@ -132,11 +132,12 @@ public class FCommandHelp extends FBaseCommand { pageLines.add( new FCommandWarclaim().getUseageTemplate() ); pageLines.add( new FCommandAutoWarclaim().getUseageTemplate() ); pageLines.add( new FCommandWarunclaimall().getUseageTemplate() ); - pageLines.add( new FCommandBypass().getUseageTemplate() ); + pageLines.add("Note: /f unclaim works on safe/war zones as well."); helpPages.add(pageLines); pageLines = new ArrayList(); pageLines.add("More commands for server admins:"); + pageLines.add( new FCommandBypass().getUseageTemplate() ); pageLines.add( new FCommandWorldNoClaim().getUseageTemplate() ); pageLines.add( new FCommandWorldNoPowerLoss().getUseageTemplate() ); pageLines.add( new FCommandLock().getUseageTemplate() ); diff --git a/src/org/mcteam/factions/commands/FCommandHome.java b/src/org/mcteam/factions/commands/FCommandHome.java index 87f2a900..896a5e8f 100644 --- a/src/org/mcteam/factions/commands/FCommandHome.java +++ b/src/org/mcteam/factions/commands/FCommandHome.java @@ -39,6 +39,11 @@ public class FCommandHome extends FBaseCommand { Faction faction = Board.getFactionAt(new FLocation(player.getLocation())); + if (!Conf.homesTeleportAllowedFromEnemyTerritory && me.isInEnemyTerritory()) { + me.sendMessage("You cannot teleport to your faction home while in the territory of an enemy faction."); + return; + } + // if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby if (Conf.homesTeleportAllowedEnemyDistance > 0 && ! faction.isSafeZone() && ! me.isInOwnTerritory()) { Location loc = player.getLocation(); diff --git a/src/org/mcteam/factions/commands/FCommandSethome.java b/src/org/mcteam/factions/commands/FCommandSethome.java index b4700545..3bb2f2dd 100644 --- a/src/org/mcteam/factions/commands/FCommandSethome.java +++ b/src/org/mcteam/factions/commands/FCommandSethome.java @@ -1,7 +1,9 @@ package org.mcteam.factions.commands; +import org.mcteam.factions.Board; import org.mcteam.factions.Conf; import org.mcteam.factions.Faction; +import org.mcteam.factions.FLocation; import org.mcteam.factions.struct.Role; public class FCommandSethome extends FBaseCommand { @@ -31,7 +33,10 @@ public class FCommandSethome extends FBaseCommand { return; } - // TODO may only be inside faction territory + if (Conf.homesMustBeInClaimedTerritory && !me.isInOwnTerritory()) { + me.sendMessage("Sorry, your faction home can only be set inside your own claimed territory."); + return; + } Faction myFaction = me.getFaction(); myFaction.setHome(player.getLocation());