/**
   * @see me.happypikachu.BattleTags.listeners.BattleTagsListener#getRelation(java.lang.String,
   *     java.lang.String)
   */
  @Override
  public ChatColor getRelation(String viewer, String seen) {
    Faction pFaction = FPlayers.i.get(viewer).getFaction();
    Faction npFaction = FPlayers.i.get(seen).getFaction();

    return pFaction.getColorTo(npFaction);
  }
 @Override
 public void onPlayerQuit(PlayerQuitEvent event) {
   // Make sure player's power is up to date when they log off.
   FPlayer me = FPlayer.get(event.getPlayer());
   me.getPower();
   Faction myFaction = me.getFaction();
   if (myFaction != null) {
     myFaction.memberLoggedOff();
   }
 }
 @Override
 public boolean isExplosionsEnabled(Location loc) {
   Faction faction = Board.getFactionAt(new FLocation(loc));
   if (ChatColor.stripColor(faction.getTag()).equalsIgnoreCase("safezone")
       || ChatColor.stripColor(faction.getTag()).equalsIgnoreCase("warzone")) {
     // ObsidianDestroyer.debug("Factions18x.isExplosionsEnabled: false");
     return false;
   }
   // ObsidianDestroyer.debug("Factions18x.isExplosionsEnabled: " +
   // faction.getFlag(FFlag.EXPLOSIONS));
   return faction.getFlag(FFlag.EXPLOSIONS);
 }
Example #4
0
  @Override
  public void perform() {
    String tag = this.argAsString(0);

    // TODO does not first test cover selfcase?
    if (Factions.i.isTagTaken(tag)
        && !MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag())) {
      msg("<b>That tag is already taken");
      return;
    }

    ArrayList<String> errors = new ArrayList<String>();
    errors.addAll(Factions.validateTag(tag));
    if (errors.size() > 0) {
      sendMessage(errors);
      return;
    }

    // if economy is enabled, they're not on the bypass list, and this command has a cost set, make
    // sure they can pay
    if (!canAffordCommand(Conf.econCostTag, "to change the faction tag")) return;

    // trigger the faction rename event (cancellable)
    FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag);
    Bukkit.getServer().getPluginManager().callEvent(renameEvent);
    if (renameEvent.isCancelled()) return;

    // then make 'em pay (if applicable)
    if (!payForCommand(
        Conf.econCostTag, "to change the faction tag", "for changing the faction tag")) return;

    String oldtag = myFaction.getTag();
    myFaction.setTag(tag);

    // Inform
    myFaction.msg(
        "%s<i> changed your faction tag to %s",
        fme.describeTo(myFaction, true), myFaction.getTag(myFaction));
    for (Faction faction : Factions.i.get()) {
      if (faction == myFaction) {
        continue;
      }
      faction.msg(
          "<i>The faction %s<i> changed their name to %s.",
          fme.getColorTo(faction) + oldtag, myFaction.getTag(faction));
    }

    if (Conf.spoutFactionTagsOverNames) {
      SpoutFeatures.updateAppearances(myFaction);
    }
  }
 @Override
 public boolean isFactionOffline(Location loc) {
   Faction faction = Board.getFactionAt(new FLocation(loc));
   if (faction.isNone()) {
     return false;
   } else if ((ChatColor.stripColor(faction.getTag()).equalsIgnoreCase("wilderness")
       || ChatColor.stripColor(faction.getTag()).equalsIgnoreCase("safezone")
       || ChatColor.stripColor(faction.getTag()).equalsIgnoreCase("warzone"))) {
     // ObsidianDestroyer.debug("Factions18x.isFactionOffline: false");
     return false;
   }
   // ObsidianDestroyer.debug("Factions18x.isFactionOffline: " +
   // faction.hasOfflineExplosionProtection());
   return faction.hasOfflineExplosionProtection();
 }
Example #6
0
  @Override
  public void perform() {
    Faction forFaction = this.argAsFaction(0, myFaction);
    if (forFaction == null || forFaction == fme.getAutoClaimFor()) {
      fme.setAutoClaimFor(null);
      msg("<i>Auto-claiming of land disabled.");
      return;
    }

    if (!FPerm.TERRITORY.has(fme, forFaction, true)) return;

    fme.setAutoClaimFor(forFaction);

    msg("<i>Now auto-claiming land for <h>%s<i>.", forFaction.describeTo(fme));
    fme.attemptClaim(forFaction, me.getLocation(), true);
  }
  private void doOwnerList(
      FPlayer player, SpoutPlayer sPlayer, FLocation here, Faction factionHere) {
    // ----------
    // Owner list
    // ----------
    if (Conf.spoutTerritoryDisplayPosition > 0
        && Conf.spoutTerritoryDisplaySize > 0
        && Conf.spoutTerritoryOwnersShow
        && Conf.ownedAreasEnabled) {
      GenericLabel label;
      if (ownerLabels.containsKey(player.getName())) label = ownerLabels.get(player.getName());
      else {
        label = new GenericLabel();
        label
            .setWidth(1)
            .setHeight(1); // prevent Spout's questionable new "no default size" warning
        label.setScale(Conf.spoutTerritoryDisplaySize);
        label.setY((int) (10 * Conf.spoutTerritoryDisplaySize));
        sPlayer.getMainScreen().attachWidget(P.p, label);
        ownerLabels.put(player.getName(), label);
      }

      String msg = "";

      if (player.getFaction() == factionHere) {
        msg = factionHere.getOwnerListString(here);

        if (!msg.isEmpty()) msg = Conf.ownedLandMessage + msg;
      }

      label.setText(msg);
      alignLabel(label, msg);
      label.setDirty(true);
    }
  }
Example #8
0
  @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);
  }
  public boolean canPlayerUseBlock(Player player, Block block) {

    if (Conf.adminBypassPlayers.contains(player.getName())) {
      return true;
    }

    Material material = block.getType();
    FLocation loc = new FLocation(block);
    Faction otherFaction = Board.getFactionAt(loc);

    // no door/chest/whatever protection in wilderness, war zones, or safe zones
    if (!otherFaction.isNormal()) {
      return true;
    }

    // We only care about some material types.
    if (otherFaction.hasPlayersOnline()) {
      if (!Conf.territoryProtectedMaterials.contains(material)) {
        return true;
      }
    } else {
      if (!Conf.territoryProtectedMaterialsWhenOffline.contains(material)) {
        return true;
      }
    }

    FPlayer me = FPlayer.get(player);
    Faction myFaction = me.getFaction();
    Relation rel = myFaction.getRelation(otherFaction);
    boolean ownershipFail =
        Conf.ownedAreasEnabled
            && Conf.ownedAreaProtectMaterials
            && !otherFaction.playerHasOwnershipRights(me, loc);

    // You may use any block unless it is another faction's territory...
    if (rel.isNeutral()
        || (rel.isEnemy() && Conf.territoryEnemyProtectMaterials)
        || (rel.isAlly() && Conf.territoryAllyProtectMaterials)) {
      me.sendMessage(
          "You can't use "
              + TextUtil.getMaterialName(material)
              + " in the territory of "
              + otherFaction.getTag(myFaction));
      return false;
    }
    // Also cancel if player doesn't have ownership rights for this claim
    else if (rel.isMember() && ownershipFail && !Factions.hasPermOwnershipBypass(player)) {
      me.sendMessage(
          "You can't use "
              + TextUtil.getMaterialName(material)
              + " in this territory, it is owned by: "
              + myFaction.getOwnerListString(loc));
      return false;
    }

    return true;
  }
  @Override
  public void onMessageToChannel(CAPIMessageToChannelEvent event) {
    if (event.isCancelled()) return;
    if (!myChannelIds.contains(event.getChannel().getId())) return;

    Player me = event.getMe();
    FPlayer fme = FPlayers.i.get(me);
    Faction myFaction = fme.getFaction();

    if (event.getChannel().getId().equals("faction") && myFaction.isNormal()) {
      event.getThem().addAll(myFaction.getOnlinePlayers());
    } else if (event.getChannel().getId().equals("allies")) {
      for (Player somePlayer : Bukkit.getServer().getOnlinePlayers()) {
        FPlayer someFPlayer = FPlayers.i.get(somePlayer);
        if (someFPlayer.getRelationTo(fme).isAtLeast(Rel.ALLY)) {
          event.getThem().add(somePlayer);
        }
      }
    }
  }
Example #11
0
  public Faction findFaction(String factionName, boolean defaultToMine) {
    // First we search faction names
    Faction faction = Faction.findByTag(factionName);
    if (faction != null) {
      return faction;
    }

    // Next we search player names
    FPlayer fp = FPlayer.find(factionName);
    if (fp != null) {
      return fp.getFaction();
    }

    if (defaultToMine && sender instanceof Player) {
      return me.getFaction();
    }

    sendMessage(Conf.colorSystem + "No faction or player \"" + factionName + "\" was found");
    return null;
  }
Example #12
0
  @Override
  public void perform() {

    if (isLocked()) {
      sendLockMessage();
      return;
    }

    String tag = parameters.get(0);

    if (me.hasFaction()) {
      sendMessage("You must leave your current faction first.");
      return;
    }

    if (Faction.isTagTaken(tag)) {
      sendMessage("That tag is already in use.");
      return;
    }

    ArrayList<String> tagValidationErrors = Faction.validateTag(tag);
    if (tagValidationErrors.size() > 0) {
      sendMessage(tagValidationErrors);
      return;
    }

    // if economy is enabled, they're not on the bypass list, and this command has a cost set, make
    // 'em pay
    if (!payForCommand(Conf.econCostCreate)) {
      return;
    }

    Faction faction = Faction.create();
    faction.setTag(tag);
    me.setRole(Role.ADMIN);
    me.setFaction(faction);

    for (FPlayer follower : FPlayer.getAllOnline()) {
      follower.sendMessage(
          me.getNameAndRelevant(follower)
              + Conf.colorSystem
              + " created a new faction "
              + faction.getTag(follower));
    }

    sendMessage("You should now: " + new FCommandDescription().getUseageTemplate());
  }
 @Override
 public boolean isPvpEnabledAt(Location location) {
   FLocation flocation = new FLocation(location);
   Faction faction = Board.getFactionAt(flocation);
   return faction.getFlag(FFlag.PVP);
 }
  @SuppressWarnings("deprecation")
  public static String getSafeZone(Player p) {
    if (tekkitrestrict.config.getBoolean("UseSafeZones")) {
      if (!TRPermHandler.hasPermission(p, "safezone", "bypass", "")) {
        if (tekkitrestrict.getInstance().getServer().getPluginManager().isPluginEnabled("Towny")
            && depends.contains("towny")) {
          /*
           * com.palmergames.bukkit.towny.Towny tapp =
           * (com.palmergames.bukkit
           * .towny.Towny)tekkitrestrict.getInstance
           * ().getServer().getPluginManager().getPlugin("Towny");
           * com.palmergames.bukkit.towny.object.PlayerCache c =
           * tapp.getCache(p);
           * if(!tapp.getTownyUniverse().isWilderness(p.getWorld
           * ().getHighestBlockAt(p.getLocation()))){ return "towny";
           * }
           */
          Block cb = p.getWorld().getHighestBlockAt(p.getLocation());
          boolean hasperm =
              com.palmergames.bukkit.towny.utils.PlayerCacheUtil.getCachePermission(
                  p,
                  p.getLocation(),
                  cb.getTypeId(),
                  com.palmergames.bukkit.towny.object.TownyPermission.ActionType.DESTROY);
          TownBlockStatus tbs =
              com.palmergames.bukkit.towny.utils.PlayerCacheUtil.getTownBlockStatus(
                  p, WorldCoord.parseWorldCoord(p.getLocation()));
          // boolean ls = tbs != TownBlockStatus.UNCLAIMED_ZONE && tbs != TownBlockStatus.WARZONE &&
          // tbs != TownBlockStatus.UNKOWN;
          if (!hasperm) {
            // tekkitrestrict.log.info("towny");
            return "towny+";
          }
        }
        // tekkitrestrict.log.info("deb");
        if (tekkitrestrict.getInstance().getServer().getPluginManager().isPluginEnabled("Factions")
            && depends.contains("factions")) {
          // if(!com.massivecraft.factions.listeners.FactionsPlayerListener.canPlayerUseBlock(p,
          // p.getWorld().getHighestBlockAt(p.getLocation()), true)){
          // Location cccc =
          // p.getWorld().getHighestBlockAt(p.getLocation()).getLocation();

          com.massivecraft.factions.FLocation ccc =
              new com.massivecraft.factions.FLocation(p.getPlayer());
          com.massivecraft.factions.Faction f = com.massivecraft.factions.Board.getFactionAt(ccc);
          String name = p.getPlayer().getName();

          com.massivecraft.factions.FPlayer me = com.massivecraft.factions.FPlayers.i.get(name);
          if (!com.massivecraft.factions.Conf.playersWhoBypassAllProtection.contains(name)) {
            /*if (me.getFaction() != null && f != null && !me.hasAdminMode()) {
            	if ((me.getFaction().getTag() != f.getTag())
            			&& !f.isNone()) {
            		// tekkitrestrict.log.info("factions");

            	}
            }*/
            if (!FPerm.BUILD.has(me, ccc)) {
              return "factions+" + f.getTag();
            }
          }
        }

        if (tekkitrestrict
                .getInstance()
                .getServer()
                .getPluginManager()
                .isPluginEnabled("PreciousStones")
            && depends.contains("preciousstones")) {
          net.sacredlabyrinth.Phaed.PreciousStones.PreciousStones ps =
              (net.sacredlabyrinth.Phaed.PreciousStones.PreciousStones)
                  tekkitrestrict
                      .getInstance()
                      .getServer()
                      .getPluginManager()
                      .getPlugin("PreciousStones");
          Block fblock = p.getWorld().getBlockAt(p.getLocation());

          Field field =
              ps.getForceFieldManager()
                  .getEnabledSourceField(fblock.getLocation(), FieldFlag.CUBOID);
          // tekkitrestrict.log.info("a");
          if (field != null) {
            // tekkitrestrict.log.info("b");
            boolean allowed = ps.getForceFieldManager().isApplyToAllowed(field, p.getName());
            if (!allowed || field.hasFlag(FieldFlag.APPLY_TO_ALL)) {
              // if (field.getSettings().canGrief(fblock.getTypeId()))
              // return;
              // tekkitrestrict.log.info("c");
              return "preciousstones";
            }
          }
        }

        if (tekkitrestrict
                .getInstance()
                .getServer()
                .getPluginManager()
                .isPluginEnabled("GriefPrevention")
            && depends.contains("griefprevention")) {
          me.ryanhamshire.GriefPrevention.GriefPrevention pl =
              (me.ryanhamshire.GriefPrevention.GriefPrevention)
                  tekkitrestrict
                      .getInstance()
                      .getServer()
                      .getPluginManager()
                      .getPlugin("GriefPrevention");
          Claim claim = pl.dataStore.getClaimAt(p.getLocation(), false, null);
          if (claim != null) {
            String noAccessReason = claim.allowAccess(p);
            if (noAccessReason != null) {
              return "griefprevention";
            }
          }
        }

        return getXYZSafeZone(p.getLocation(), p.getWorld().getName());
      } else {
        return "";
      }
    }
    return "";
  }
  private void doLabels(FPlayer player, SpoutPlayer sPlayer, boolean notify) {
    FLocation here = player.getLastStoodAt();
    Faction factionHere = Board.getFactionAt(here);
    String tag = factionHere.getColorTo(player).toString() + factionHere.getTag();

    // ----------------------
    // Main territory display
    // ----------------------
    if (Conf.spoutTerritoryDisplayPosition > 0 && Conf.spoutTerritoryDisplaySize > 0) {
      GenericLabel label;
      if (territoryLabels.containsKey(player.getName()))
        label = territoryLabels.get(player.getName());
      else {
        label = new GenericLabel();
        label
            .setWidth(1)
            .setHeight(1); // prevent Spout's questionable new "no default size" warning
        label.setScale(Conf.spoutTerritoryDisplaySize);

        sPlayer.getMainScreen().attachWidget(P.p, label);
        territoryLabels.put(player.getName(), label);
      }

      String msg = tag;

      if (Conf.spoutTerritoryDisplayShowDescription && !factionHere.getDescription().isEmpty())
        msg += " - " + factionHere.getDescription();

      label.setText(msg);
      alignLabel(label, msg);
      label.setDirty(true);
    }

    // -----------------------
    // Fading territory notice
    // -----------------------
    if (notify && Conf.spoutTerritoryNoticeShow && Conf.spoutTerritoryNoticeSize > 0) {
      NoticeLabel label;
      if (territoryChangeLabels.containsKey(player.getName()))
        label = territoryChangeLabels.get(player.getName());
      else {
        label = new NoticeLabel(Conf.spoutTerritoryNoticeLeaveAfterSeconds);
        label
            .setWidth(1)
            .setHeight(1); // prevent Spout's questionable new "no default size" warning
        label.setScale(Conf.spoutTerritoryNoticeSize);
        label.setY(Conf.spoutTerritoryNoticeTop);
        sPlayer.getMainScreen().attachWidget(P.p, label);
        territoryChangeLabels.put(player.getName(), label);
      }

      String msg = tag;

      if (Conf.spoutTerritoryNoticeShowDescription && !factionHere.getDescription().isEmpty())
        msg += " - " + factionHere.getDescription();

      label.setText(msg);
      alignLabel(label, msg, 2);
      label.resetNotice();
      label.setDirty(true);
    }

    // and owner list, of course
    doOwnerList(player, sPlayer, here, factionHere);
  }
 @Override
 public boolean isFactionAtPower(Location loc) {
   Faction faction = Board.getFactionAt(new FLocation(loc));
   return faction.getPower() >= faction.getLandRounded();
 }
Example #17
0
  @Override
  public void perform() {
    Faction faction = this.argAsFaction(0);
    if (faction == null) return;

    FPlayer fplayer = this.argAsBestFPlayerMatch(1, fme, false);
    boolean samePlayer = fplayer == fme;

    if (!samePlayer && !Permission.JOIN_OTHERS.has(sender, false)) {
      msg("<b>You do not have permission to move other players into a faction.");
      return;
    }

    if (faction == fplayer.getFaction()) {
      msg(
          "<b>%s %s already a member of %s",
          fplayer.describeTo(fme, true), (samePlayer ? "are" : "is"), faction.getTag(fme));
      return;
    }

    if (Conf.factionMemberLimit > 0 && faction.getFPlayers().size() >= Conf.factionMemberLimit) {
      msg(
          " <b>!<white> The faction %s is at the limit of %d members, so %s cannot currently join.",
          faction.getTag(fme), Conf.factionMemberLimit, fplayer.describeTo(fme, false));
      return;
    }

    if (fplayer.hasFaction()) {
      msg(
          "<b>%s must leave %s current faction first.",
          fplayer.describeTo(fme, true), (samePlayer ? "your" : "their"));
      return;
    }

    if (!Conf.canLeaveWithNegativePower && fplayer.getPower() < 0) {
      msg(
          "<b>%s cannot join a faction with a negative power level.",
          fplayer.describeTo(fme, true));
      return;
    }

    if (!(faction.getOpen()
        || faction.isInvited(fplayer)
        || fme.hasAdminMode()
        || Permission.JOIN_ANY.has(sender, false))) {
      msg("<i>This faction requires invitation.");
      if (samePlayer)
        faction.msg("%s<i> tried to join your faction.", fplayer.describeTo(faction, true));
      return;
    }

    // if economy is enabled, they're not on the bypass list, and this command has a cost set, make
    // sure they can pay
    if (samePlayer && !canAffordCommand(Conf.econCostJoin, "to join a faction")) return;

    // trigger the join event (cancellable)
    FPlayerJoinEvent joinEvent =
        new FPlayerJoinEvent(
            FPlayers.i.get(me), faction, FPlayerJoinEvent.PlayerJoinReason.COMMAND);
    Bukkit.getServer().getPluginManager().callEvent(joinEvent);
    if (joinEvent.isCancelled()) return;

    // then make 'em pay (if applicable)
    if (samePlayer
        && !payForCommand(Conf.econCostJoin, "to join a faction", "for joining a faction")) return;

    fme.setRole(
        Conf
            .factionRankDefault); // They have just joined a faction, start them out on the lowest
                                  // rank (default config).

    if (!samePlayer)
      fplayer.msg(
          "<i>%s moved you into the faction %s.",
          fme.describeTo(fplayer, true), faction.getTag(fplayer));
    faction.msg("<i>%s joined your faction.", fplayer.describeTo(faction, true));
    fme.msg("<i>%s successfully joined %s.", fplayer.describeTo(fme, true), faction.getTag(fme));

    fplayer.resetFactionData();
    fplayer.setFaction(faction);

    faction.deinvite(fplayer);

    if (Conf.logFactionJoin) {
      if (samePlayer) P.p.log("%s joined the faction %s.", fplayer.getName(), faction.getTag());
      else
        P.p.log(
            "%s moved the player %s into the faction %s.",
            fme.getName(), fplayer.getName(), faction.getTag());
    }
  }
Example #18
0
  @Override
  public void perform() {
    // TODO: Hide this command on help also.
    if (!Conf.homesEnabled) {
      this.fme.msg("<b>Sorry, Faction homes are disabled on this server.");
      return;
    }

    if (!Conf.homesTeleportCommandEnabled) {
      this.fme.msg(
          "<b>Sorry, the ability to teleport to Faction homes is disabled on this server.");
      return;
    }

    if (!this.myFaction.hasHome()) {
      this.fme.msg(
          "<b>Your faction does not have a home. "
              + (this.fme.getRole().isLessThan(Rel.OFFICER)
                  ? "<i> Ask your leader to:"
                  : "<i>You should:"));
      this.fme.sendMessage(this.p.cmdBase.cmdSethome.getUseageTemplate());
      return;
    }

    if (!Conf.homesTeleportAllowedFromEnemyTerritory && this.fme.isInEnemyTerritory()) {
      this.fme.msg(
          "<b>You cannot teleport to your faction home while in the territory of an enemy faction.");
      return;
    }

    if (!Conf.homesTeleportAllowedFromDifferentWorld
        && this.me.getWorld().getUID() != this.myFaction.getHome().getWorld().getUID()) {
      this.fme.msg("<b>You cannot teleport to your faction home while in a different world.");
      return;
    }

    final Faction faction = Board.getFactionAt(new FLocation(this.me.getLocation()));
    final Location loc = this.me.getLocation().clone();

    // 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.getFlag(FFlag.PVP)
        && (!this.fme.isInOwnTerritory()
            || this.fme.isInOwnTerritory() && !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory)) {
      final World w = loc.getWorld();
      final double x = loc.getX();
      final double y = loc.getY();
      final double z = loc.getZ();

      for (final Player p : this.me.getServer().getOnlinePlayers()) {
        if (p == null || !p.isOnline() || p.isDead() || p == this.me || p.getWorld() != w) {
          continue;
        }

        final FPlayer fp = FPlayers.i.get(p);
        if (this.fme.getRelationTo(fp) != Rel.ENEMY) {
          continue;
        }

        final Location l = p.getLocation();
        final double dx = Math.abs(x - l.getX());
        final double dy = Math.abs(y - l.getY());
        final double dz = Math.abs(z - l.getZ());
        final double max = Conf.homesTeleportAllowedEnemyDistance;

        // box-shaped distance check
        if (dx > max || dy > max || dz > max) {
          continue;
        }

        this.fme.msg(
            "<b>You cannot teleport to your faction home while an enemy is within "
                + Conf.homesTeleportAllowedEnemyDistance
                + " blocks of you.");
        return;
      }
    }
    Location home = this.myFaction.getHome();

    if (home.clone().getBlock().getType() != Material.AIR
        || home.clone().add(0, 1, 0).getBlock().getType() != Material.AIR) {
      home.clone().getBlock().setType(Material.AIR);
      home.clone().add(0, 1, 0).getBlock().setType(Material.AIR);
      home.clone().add(0, 2, 0).getBlock().setType(Material.STONE);
    }

    // if Essentials teleport handling is enabled and available, pass the teleport off to it (for
    // delay and cooldown)
    if (EssentialsFeatures.handleTeleport(this.me, this.myFaction.getHome())) return;

    // if economy is enabled, they're not on the bypass list, and this command has a cost set, make
    // 'em pay
    if (!this.payForCommand(
        Conf.econCostHome,
        "to teleport to your faction home",
        "for teleporting to your faction home")) return;

    // Create a smoke effect
    if (Conf.homesTeleportCommandSmokeEffectEnabled) {
      final List<Location> smokeLocations = new ArrayList<Location>();
      smokeLocations.add(loc);
      smokeLocations.add(loc.add(0, 1, 0));
      smokeLocations.add(this.myFaction.getHome());
      smokeLocations.add(this.myFaction.getHome().clone().add(0, 1, 0));
      SmokeUtil.spawnCloudRandom(smokeLocations, 3f);
    }

    this.me.teleport(this.myFaction.getHome());
  }
  @Override
  public void perform() {
    // TODO: Hide this command on help also.
    if (!Conf.homesEnabled) {
      fme.msg("<b>Sorry, Faction homes are disabled on this server.");
      return;
    }

    if (!Conf.homesTeleportCommandEnabled) {
      fme.msg("<b>Sorry, the ability to teleport to Faction homes is disabled on this server.");
      return;
    }

    if (!myFaction.hasHome()) {
      fme.msg(
          "<b>You faction does not have a home. "
              + (fme.getRole().value < Role.MODERATOR.value
                  ? "<i> Ask your leader to:"
                  : "<i>You should:"));
      fme.sendMessage(p.cmdBase.cmdSethome.getUseageTemplate());
      return;
    }

    if (!Conf.homesTeleportAllowedFromEnemyTerritory && fme.isInEnemyTerritory()) {
      fme.msg(
          "<b>You cannot teleport to your faction home while in the territory of an enemy faction.");
      return;
    }

    if (!Conf.homesTeleportAllowedFromDifferentWorld
        && me.getWorld().getUID() != myFaction.getHome().getWorld().getUID()) {
      fme.msg("<b>You cannot teleport to your faction home while in a different world.");
      return;
    }

    Faction faction = Board.getFactionAt(new FLocation(me.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()
        && (!fme.isInOwnTerritory()
            || (fme.isInOwnTerritory() && !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory))) {
      Location loc = me.getLocation();
      World w = loc.getWorld();
      double x = loc.getX();
      double y = loc.getY();
      double z = loc.getZ();

      for (Player p : me.getServer().getOnlinePlayers()) {
        if (p == null || !p.isOnline() || p.isDead() || p == fme || p.getWorld() != w) continue;

        FPlayer fp = FPlayers.i.get(p);
        if (fme.getRelationTo(fp) != Relation.ENEMY) continue;

        Location l = p.getLocation();
        double dx = Math.abs(x - l.getX());
        double dy = Math.abs(y - l.getY());
        double dz = Math.abs(z - l.getZ());
        double max = Conf.homesTeleportAllowedEnemyDistance;

        // box-shaped distance check
        if (dx > max || dy > max || dz > max) continue;

        fme.msg(
            "<b>You cannot teleport to your faction home while an enemy is within "
                + Conf.homesTeleportAllowedEnemyDistance
                + " blocks of you.");
        return;
      }
    }

    // if Essentials teleport handling is enabled and available, pass the
    // teleport off to it (for delay and cooldown)
    if (EssentialsFeatures.handleTeleport(me, myFaction.getHome())) return;

    // if economy is enabled, they're not on the bypass list, and this
    // command has a cost set, make 'em pay
    if (!payForCommand(
        Conf.econCostHome,
        "to teleport to your faction home",
        "for teleporting to your faction home")) return;

    // Create a smoke effect
    if (Conf.homesTeleportCommandSmokeEffectEnabled) {
      List<Location> smokeLocations = new ArrayList<Location>();
      smokeLocations.add(me.getLocation());
      smokeLocations.add(me.getLocation().clone().add(0, 1, 0));
      smokeLocations.add(myFaction.getHome());
      smokeLocations.add(myFaction.getHome().clone().add(0, 1, 0));
      SmokeUtil.spawnCloudRandom(smokeLocations, Conf.homesTeleportCommandSmokeEffectThickness);
    }

    me.teleport(myFaction.getHome());
  }
Example #20
0
 public String getFactionTag() {
   return faction.getTag();
 }
Example #21
0
 public String getFactionId() {
   return faction.getId();
 }
  @Override
  public void onPlayerMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    FPlayer me = FPlayer.get(player);

    // Did we change coord?
    FLocation from = me.getLastStoodAt();
    FLocation to = new FLocation(player.getLocation());

    if (from.equals(to)) {
      return;
    }

    // Yes we did change coord (:

    me.setLastStoodAt(to);

    if (me.isMapAutoUpdating()) {
      me.sendMessage(Board.getMap(me.getFaction(), to, player.getLocation().getYaw()));
    } else {
      // Did we change "host"(faction)?
      Faction factionFrom = Board.getFactionAt(from);
      Faction factionTo = Board.getFactionAt(to);
      Faction myFaction = me.getFaction();
      String ownersTo = myFaction.getOwnerListString(to);
      if (factionFrom != factionTo) {
        me.sendFactionHereMessage();
        if (Conf.ownedAreasEnabled
            && Conf.ownedMessageOnBorder
            && myFaction == factionTo
            && !ownersTo.isEmpty()) {
          me.sendMessage(Conf.ownedLandMessage + ownersTo);
        }
      } else if (Conf.ownedAreasEnabled
          && Conf.ownedMessageInsideTerritory
          && factionFrom == factionTo
          && myFaction == factionTo) {
        String ownersFrom = myFaction.getOwnerListString(from);
        if (Conf.ownedMessageByChunk || !ownersFrom.equals(ownersTo)) {
          if (!ownersTo.isEmpty()) {
            me.sendMessage(Conf.ownedLandMessage + ownersTo);
          } else if (!Conf.publicLandMessage.isEmpty()) {
            me.sendMessage(Conf.publicLandMessage);
          }
        }
      }
    }

    if (me.autoClaimEnabled()) {
      Faction myFaction = me.getFaction();
      Faction otherFaction = Board.getFactionAt(to);
      double cost = Econ.calculateClaimCost(myFaction.getLandRounded(), otherFaction.isNormal());

      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(to.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 if (!Econ.canAfford(player.getName(), cost)) {
        String costString = Econ.moneyString(cost);
        me.sendMessage(
            "Claiming this land will cost " + costString + ", which you can't currently afford.");
        me.enableAutoClaim(false);
      } else me.attemptClaim(false);
    } else if (me.autoSafeZoneEnabled()) {
      if (!Factions.hasPermManageSafeZone((CommandSender) player)) {
        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) player)) {
        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.");
        }
      }
    }
  }
  public boolean playerCanUseItemHere(Player player, Block block, Material material) {

    if (Conf.adminBypassPlayers.contains(player.getName())) {
      return true;
    }

    FLocation loc = new FLocation(block);
    Faction otherFaction = Board.getFactionAt(loc);

    if (otherFaction.hasPlayersOnline()) {
      if (!Conf.territoryDenyUseageMaterials.contains(material)) {
        return true; // Item isn't one we're preventing for online factions.
      }
    } else {
      if (!Conf.territoryDenyUseageMaterialsWhenOffline.contains(material)) {
        return true; // Item isn't one we're preventing for offline factions.
      }
    }

    FPlayer me = FPlayer.get(player);

    if (otherFaction.isNone()) {
      if (!Conf.wildernessDenyUseage
          || Factions.hasPermAdminBypass(player)
          || Conf.worldsNoWildernessProtection.contains(block.getWorld().getName())) {
        return true; // This is not faction territory. Use whatever you like here.
      }
      me.sendMessage("You can't use " + TextUtil.getMaterialName(material) + " in the wilderness.");
      return false;
    } else if (otherFaction.isSafeZone()) {
      if (!Conf.safeZoneDenyUseage || Factions.hasPermManageSafeZone(player)) {
        return true;
      }
      me.sendMessage("You can't use " + TextUtil.getMaterialName(material) + " in a safe zone.");
      return false;
    } else if (otherFaction.isWarZone()) {
      if (!Conf.warZoneDenyUseage || Factions.hasPermManageWarZone(player)) {
        return true;
      }
      me.sendMessage("You can't use " + TextUtil.getMaterialName(material) + " in a war zone.");
      return false;
    }

    Faction myFaction = me.getFaction();
    Relation rel = myFaction.getRelation(otherFaction);
    boolean ownershipFail =
        Conf.ownedAreasEnabled
            && Conf.ownedAreaDenyUseage
            && !otherFaction.playerHasOwnershipRights(me, loc);

    // Cancel if we are not in our own territory
    if (!rel.isMember() && rel.confDenyUseage()) {
      me.sendMessage(
          "You can't use "
              + TextUtil.getMaterialName(material)
              + " in the territory of "
              + otherFaction.getTag(myFaction));
      return false;
    }
    // Also cancel if player doesn't have ownership rights for this claim
    else if (rel.isMember() && ownershipFail && !Factions.hasPermOwnershipBypass(player)) {
      me.sendMessage(
          "You can't use "
              + TextUtil.getMaterialName(material)
              + " in this territory, it is owned by: "
              + myFaction.getOwnerListString(loc));
      return false;
    }

    return true;
  }