@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);
 }
 @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();
 }
  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 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());
  }
  @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);
  }
Beispiel #7
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());
    }
  }
Beispiel #8
0
 public String getFactionTag() {
   return faction.getTag();
 }
  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;
  }