Saber-Factions/src/org/mcteam/factions/commands/FCommandHome.java
Brettflan b490c5f196 Laundry list of changes for 1.2.0 release:
/f map now has a nifty faction name key  (LexManos)
There are now War Zones; these work similar to Safe Zones, except PvP is enabled and monsters are not blocked  (Brettflan)
Players now only regenerate power while actually online  (Brettflan)
New command available to prevent power loss in specific worlds  (Brettflan)
New command available to prevent faction land claims in specific worlds (doesn't affect safezone and warzone claims)  (Brettflan)
New command to unclaim all safezone areas  (Brettflan)
Players are now prevented from using /f home if an enemy is nearby, and the players isn't in a safezone or their own faction territory  (Brettflan)
New option to make membership default to closed for newly created factions  (Brettflan)
When an admin has bypass mode enabled (/f bypass), they can now unclaim any faction land they're standing on  (Brettflan)
2011-05-29 16:28:29 -05:00

76 lines
2.2 KiB
Java

package org.mcteam.factions.commands;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.mcteam.factions.Board;
import org.mcteam.factions.Conf;
import org.mcteam.factions.Faction;
import org.mcteam.factions.FLocation;
import org.mcteam.factions.FPlayer;
import org.mcteam.factions.struct.Relation;
import org.mcteam.factions.struct.Role;
public class FCommandHome extends FBaseCommand {
public FCommandHome() {
aliases.add("home");
helpDescription = "Teleport to the faction home";
}
public void perform() {
if ( ! assertHasFaction()) {
return;
}
if ( ! Conf.homesEnabled) {
me.sendMessage("Sorry, Faction homes are disabled on this server.");
return;
}
Faction myFaction = me.getFaction();
if ( ! myFaction.hasHome()) {
me.sendMessage("You faction does not have a home. " + (me.getRole().value < Role.MODERATOR.value ? " Ask your leader to:" : "You should:"));
me.sendMessage(new FCommandSethome().getUseageTemplate());
return;
}
Faction faction = Board.getFactionAt(new FLocation(player.getLocation()));
// 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();
World w = loc.getWorld();
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
for (Player p : player.getServer().getOnlinePlayers())
{
if (p == null || !p.isOnline() || p.isDead() || p == player || p.getWorld() != w)
continue;
FPlayer fp = FPlayer.get(p);
if (me.getRelation(fp) != Relation.ENEMY)
continue;
Location l = p.getLocation();
int dx = Math.abs(x - l.getBlockX());
int dy = Math.abs(y - l.getBlockY());
int dz = Math.abs(z - l.getBlockZ());
int delta = dx + dy + dz;
if (delta > Conf.homesTeleportAllowedEnemyDistance)
continue;
me.sendMessage("You cannot teleport to your faction home while an enemy is within " + Conf.homesTeleportAllowedEnemyDistance + " blocks of you.");
return;
}
}
player.teleport(myFaction.getHome());
}
}