Пример #1
0
	public static void setRuleForFaction(Faction faction, UPlayer setter, String FPRule) {
				
		String[] argsa = new String[3];
		argsa[1] = setter.getName();
		argsa[2] = FPRule;

		File justAFactionsPlusRuleFile = new File(Config.folderFRules+File.separator+faction.getId()+".rules");
		
		if(faction.getId() == "0") {
			setter.msg(ChatColor.RED+"You must be in a Faction to set rules.");
			return;
		}
		
		if(!justAFactionsPlusRuleFile.exists()) {
			try {
				justAFactionsPlusRuleFile.createNewFile();
			} catch (IOException e) {
				setter.msg(ChatColor.RED+"Internal Error: Failed to create the FPRules file.");
				e.printStackTrace();
			}
		}
		
		try {
		    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(Config.folderFRules+File.separator+faction.getId()+".rules", true)));
		    out.println(FPRule);
		    out.close();
		} catch (IOException e) {
			setter.msg(ChatColor.RED+"Internal Error: Failed to append the rule.");
		}
		
		setter.msg(ChatColor.GREEN+"Rule '"+FPRule+"' added!");
		
	}
  @Override
  public void perform() throws MassiveException {
    // Arg: Faction
    Faction faction = this.arg(0, ARFaction.get(), msenderFaction);

    List<MFlag> flags = new ArrayList<MFlag>();

    // Case: Show All
    if (!this.argIsSet(1) || "all".equalsIgnoreCase(this.arg(1))) {
      for (MFlag mflag : MFlag.getAll()) {
        if (!mflag.isVisible() && !msender.isUsingAdminMode()) continue;
        flags.add(mflag);
      }
    } else {
      // Arg: MFlag. Maybe we should use ARSet but that is currently buggy.
      List<MFlag> mflags = this.arg(this.argConcatFrom(1), ARList.get(ARMFlag.get()));
      flags.addAll(mflags);
    }

    // Create messages
    List<String> messages = new ArrayList<String>();
    messages.add(Txt.titleize("Flag for " + faction.describeTo(msender, true)));
    for (MFlag mflag : flags) {
      messages.add(mflag.getStateDesc(faction.getFlag(mflag), true, true, true, true, true));
    }

    // Send messages
    sendMessage(messages);
  }
  @Override
  public void perform() {
    Double amount = this.arg(0, ARDouble.get());
    if (amount == null) return;

    UPlayer from = this.arg(1, ARUPlayer.getStartAny(sender));
    if (from == null) return;

    Faction to = this.arg(2, ARFaction.get(sender));
    if (to == null) return;

    boolean success = Econ.transferMoney(usender, from, to, amount);

    if (success && MConf.get().logMoneyTransactions) {
      Factions.get()
          .log(
              ChatColor.stripColor(
                  Txt.parse(
                      "%s transferred %s from the player \"%s\" to the faction \"%s\"",
                      usender.getName(),
                      Money.format(amount),
                      from.describeTo(null),
                      to.describeTo(null))));
    }
  }
  @Override
  public void perform() throws MassiveException {
    // Arguments
    Faction faction = this.readArg();

    // Apply
    CmdFactions.get()
        .cmdFactionsRelation
        .cmdFactionsRelationSet
        .execute(sender, MUtil.list(faction.getId(), this.relName));
  }
Пример #5
0
  @Override
  public void perform() throws MassiveException {
    // Args
    MPerm perm = this.readArg();
    Rel rel = this.readArg();
    Boolean value = this.readArg();
    Faction faction = this.readArg(msenderFaction);

    // Do the sender have the right to change perms for this faction?
    if (!MPerm.getPermPerms().has(msender, faction, true)) return;

    // Is this perm editable?
    if (!msender.isUsingAdminMode() && !perm.isEditable()) {
      msg("<b>The perm <h>%s <b>is not editable.", perm.getName());
      return;
    }

    // No change
    if (faction.getPermitted(perm).contains(rel) == value) {
      msg(
          "%s <i>already has %s <i>set to %s <i>for %s<i>.",
          faction.describeTo(msender),
          perm.getDesc(true, false),
          Txt.parse(value ? "<g>YES" : "<b>NOO"),
          rel.getColor() + rel.getDescPlayerMany());
      return;
    }

    // Apply
    faction.setRelationPermitted(perm, rel, value);

    // The following is to make sure the leader always has the right to change perms if that is our
    // goal.
    if (perm == MPerm.getPermPerms() && MPerm.getPermPerms().getStandard().contains(Rel.LEADER)) {
      faction.setRelationPermitted(MPerm.getPermPerms(), Rel.LEADER, true);
    }

    // Create messages
    List<String> messages = new ArrayList<String>();

    // Inform sender
    messages.add(Txt.titleize("Perm for " + faction.describeTo(msender, true)));
    messages.add(MPerm.getStateHeaders());
    messages.add(Txt.parse(perm.getStateInfo(faction.getPermitted(perm), true)));
    sendMessage(messages);

    // Inform faction (their message is slighly different)
    List<MPlayer> recipients = faction.getMPlayers();
    recipients.remove(msender);

    for (MPlayer recipient : recipients) {
      messages.add(
          0,
          Txt.parse(
              "<h>%s <i>set a perm for <h>%s<i>.",
              msender.describeTo(recipient, true), faction.describeTo(recipient, true)));
      recipient.sendMessage(messages);
    }
  }
Пример #6
0
  @Override
  public void perform() {
    Faction faction = this.arg(0, ARFaction.get(), msenderFaction);
    if (faction == null) return;

    if (!this.argIsSet(1)) {
      msg(Txt.titleize("Flags for " + faction.describeTo(msender, true)));
      for (FFlag flag : FFlag.values()) {
        msg(flag.getStateInfo(faction.getFlag(flag), true));
      }
      return;
    }

    FFlag flag = this.arg(1, ARFFlag.get());
    if (flag == null) return;

    if (!this.argIsSet(2)) {
      msg(Txt.titleize("Flag for " + faction.describeTo(msender, true)));
      msg(flag.getStateInfo(faction.getFlag(flag), true));
      return;
    }

    Boolean targetValue = this.arg(2, ARBoolean.get());
    if (targetValue == null) return;

    // Do the sender have the right to change flags?
    if (!Perm.FLAG_SET.has(sender, true)) return;

    // Do the change
    msg(Txt.titleize("Flag for " + faction.describeTo(msender, true)));
    faction.setFlag(flag, targetValue);
    msg(flag.getStateInfo(faction.getFlag(flag), true));
  }
  public static void setPlayerPending(
      final UPlayer p, String command, final String args, final boolean facCommand) {
    if (pendingTeleportCommands.containsKey(p.getPlayer())) {
      p.sendMessage(ChatColor.RED + "You already have a teleport pending!");
      return;
    } else {
      int timer = 0;
      Faction host = FactionManager.getFactionAt(p.getPlayer().getLocation().getBlock());
      Rel relation = host.getRelationTo(p);
      if (relation == Rel.ENEMY) {
        timer = 200;
        p.sendMessage(ChatColor.RED + "Commencing teleport from enemy land in 10 seconds");
      } else if (host.getName().equalsIgnoreCase("Warzone")) {
        timer = 100;
        p.sendMessage(ChatColor.RED + "Commencing teleport from warzone in 5 seconds");
      }
      if (facCommand) {
        command = "f " + command;
      }
      pendingTeleportCommands.put(p.getPlayer(), command);
      Bukkit.getScheduler()
          .runTaskLater(
              FactionsControl.instance,
              new Runnable() {

                @Override
                public void run() {
                  if (pendingTeleportCommands.containsKey(p.getPlayer())) {
                    ignore.add(p.getPlayer());
                    String full = "/" + pendingTeleportCommands.get(p.getPlayer());
                    if (facCommand) {
                      if (args.split(" ").length > 1) {
                        full += " " + args.split(" ", 2)[1];
                      }
                    } else if (args != null && args.length() > 0) {
                      full += " " + args;
                    }
                    p.getPlayer().chat(full);
                    ignore.remove(p.getPlayer());
                    pendingTeleportCommands.remove(p.getPlayer());
                  }
                }
              },
              timer);
    }
  }
  @Override
  public void perform() {
    Double amount = this.arg(0, ARDouble.get());
    if (amount == null) return;

    Faction from = this.arg(1, ARFaction.get(sender), myFaction);
    if (from == null) return;

    FPlayer to = fme;

    boolean success = Econ.transferMoney(fme, from, to, amount);

    if (success && MConf.get().logMoneyTransactions) {
      Factions.get()
          .log(
              ChatColor.stripColor(
                  Txt.parse(
                      "%s withdrew %s from the faction bank: %s",
                      fme.getName(), Money.format(from, amount), from.describeTo(null))));
    }
  }
Пример #9
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerDamageByPlayer(final EntityDamageByEntityEvent e) {
    if (e.getEntity() instanceof Player == false || e.getDamager() instanceof Player == false)
      return;

    Player player = (Player) e.getEntity();
    Player target = (Player) e.getDamager();
    SCPlayer scp = getSCPlayer(player.getUniqueId());
    SCPlayer sct = getSCPlayer(target.getUniqueId());
    Faction faction = BoardColl.get().getFactionAt(PS.valueOf(target.getLocation().getChunk()));

    if (faction.getName().equalsIgnoreCase("Safezone")) {
      return;
    }

    final Faction pFaction = MPlayerColl.get().get(player).getFaction();
    final Faction tFaction = MPlayerColl.get().get(target).getFaction();

    if (pFaction.getRelationTo(tFaction) == Rel.MEMBER && !pFaction.isNone()) {
      return;
    }

    if (pFaction.getRelationTo(tFaction) == Rel.ALLY) {
      return;
    }

    scp.combatTag();
    sct.combatTag();
  }
Пример #10
0
  @Override
  public void perform() {
    // Args
    Faction faction = this.arg(0, ARFaction.get(usender), usenderFaction);
    if (faction == null) return;

    // FPerm
    if (!FPerm.DISBAND.has(usender, faction, true)) return;

    // Verify
    if (faction.getFlag(FFlag.PERMANENT)) {
      msg("<i>This faction is designated as permanent, so you cannot disband it.");
      return;
    }

    // Event
    EventFactionsDisband event = new EventFactionsDisband(me, faction);
    event.run();
    if (event.isCancelled()) return;

    // Merged Apply and Inform

    // Run event for each player in the faction
    for (UPlayer uplayer : faction.getUPlayers()) {
      EventFactionsMembershipChange membershipChangeEvent =
          new EventFactionsMembershipChange(
              sender,
              uplayer,
              FactionColls.get().get(faction).getNone(),
              MembershipChangeReason.DISBAND);
      membershipChangeEvent.run();
    }

    // Inform all players
    for (UPlayer uplayer : UPlayerColls.get().get(usender).getAllOnline()) {
      String who = usender.describeTo(uplayer);
      if (uplayer.getFaction() == faction) {
        uplayer.msg("<h>%s<i> disbanded your faction.", who);
      } else {
        uplayer.msg("<h>%s<i> disbanded the faction %s.", who, faction.getName(uplayer));
      }
    }

    if (MConf.get().logFactionDisband) {
      Factions.get()
          .log(
              Txt.parse(
                  "<i>The faction <h>%s <i>(<h>%s<i>) was disbanded by <h>%s<i>.",
                  faction.getName(), faction.getId(), usender.getDisplayName()));
    }

    faction.detach();
  }
Пример #11
0
  public static int getCountOfWarps(Faction faction) {
    File currentWarpFile = new File(Config.folderWarps, faction.getId());

    int c = 0;
    if (currentWarpFile.exists()) {
      FileInputStream fstream = null;
      DataInputStream in = null;
      BufferedReader br = null;
      try {
        fstream = new FileInputStream(currentWarpFile);
        in = new DataInputStream(fstream);
        br = new BufferedReader(new InputStreamReader(in));
        String strLine;

        while ((strLine = br.readLine()) != null) {
          if (strLine.contains(":")) {
            c++;
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        if (null != br) {
          try {
            br.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
        if (null != in) {
          try {
            in.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
        if (null != fstream) {
          try {
            fstream.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
    }
    return c;
  }
 public static boolean canPlayerEnderPerlHere(UPlayer up, Location from, Location to) {
   Faction host = FactionManager.getFactionAt(to.getBlock());
   if (host.getName().equalsIgnoreCase("SafeZone")) {
     up.sendMessage(ChatColor.RED + "You are unable to enderpearl into the " + host.getName(up));
     return false;
   } else if (host.isNone()
       || host.getName().equalsIgnoreCase("WarZone")
       || host.getRelationTo(up).isAtLeast(Rel.TRUCE)) {
     return true;
   } else {
     up.sendMessage(
         ChatColor.RED + "You are unable to enderpearl into the faction " + host.getName(up));
     return false;
   }
 }
 public static boolean canPlayerTeleportHere(UPlayer up, Location from, Location to) {
   Faction host = FactionManager.getFactionAt(to.getBlock());
   if (host.getRelationTo(up).isAtLeast(Rel.TRUCE)) {
     return true;
   }
   if (host.isDefault() && !host.isNone()) {
     return true;
   }
   if (up.getPower() > 1 && host.isNone()) {
     return true;
   } else if (up.getPower() <= 1) {
     up.sendMessage(ChatColor.RED + "Your weak power is preventing you from teleporting");
     return false;
   } else {
     up.sendMessage(
         ChatColor.RED + "You are unable to teleport to the faction " + host.getName(up));
     return false;
   }
 }
Пример #14
0
  public static String replaceVariables(String string, Player player) {
    String newString = string;

    UPlayer uplayer = UPlayer.get(player);

    if (newString.contains("<factionsf") && !newString.contains("<factionsfin")) {
      Faction faction = uplayer.getFaction();

      if (newString.contains("<factionsfname>"))
        newString = newString.replaceAll("<factionsfname>", faction.getName());
      if (newString.contains("<factionsfland>"))
        newString = newString.replaceAll("<factionsfland>", String.valueOf(faction.getLandCount()));
      if (newString.contains("<factionsfpower>"))
        newString =
            newString.replaceAll("<factionsfpower>", String.valueOf(faction.getPowerRounded()));
      if (newString.contains("<factionsfmaxpower>"))
        newString =
            newString.replaceAll(
                "<factionsfmaxpower>", String.valueOf(faction.getPowerMaxRounded()));
      if (newString.contains("<factionsfonline>"))
        newString =
            newString.replaceAll(
                "<factionsfonline>", String.valueOf(faction.getOnlinePlayers().size()));
      if (newString.contains("<factionsfleader>"))
        newString =
            newString.replaceAll(
                "<factionsfleader>",
                String.valueOf(
                    faction.getLeader() != null ? faction.getLeader().getName() : "Unknown"));
      if (newString.contains("<factionsfofficers>"))
        newString =
            newString.replaceAll(
                "<factionsfofficers>",
                String.valueOf(faction.getUPlayersWhereRole(Rel.OFFICER).size()));
    }
    if (newString.contains("<factionspower>"))
      newString =
          newString.replaceAll("<factionspower>", String.valueOf(uplayer.getPowerRounded()));
    if (newString.contains("<factionsmaxpower>"))
      newString =
          newString.replaceAll("<factionsmaxpower>", String.valueOf(uplayer.getPowerMaxRounded()));
    if (newString.contains("<factionsrole>"))
      newString = newString.replaceAll("<factionsrole>", String.valueOf(uplayer.getRole()));

    if (newString.contains("<factionsfin")) {
      Faction inFaction =
          BoardColls.get().getFactionAt(PS.valueOf(uplayer.getPlayer().getLocation().getChunk()));

      if (newString.contains("<factionsfinname>"))
        newString = newString.replaceAll("<factionsfinname>", String.valueOf(inFaction.getName()));
      if (newString.contains("<factionsfinland>"))
        newString =
            newString.replaceAll("<factionsfland>", String.valueOf(inFaction.getLandCount()));
      if (newString.contains("<factionsfinpower>"))
        newString =
            newString.replaceAll("<factionsfinpower>", String.valueOf(inFaction.getPowerRounded()));
      if (newString.contains("<factionsfinmaxpower>"))
        newString =
            newString.replaceAll(
                "<factionsfinmaxpower>", String.valueOf(inFaction.getPowerMaxRounded()));
      if (newString.contains("<factionsfinonline>"))
        newString =
            newString.replaceAll(
                "<factionsfinonline>", String.valueOf(inFaction.getOnlinePlayers().size()));
      if (newString.contains("<factionsfinleader>"))
        newString =
            newString.replaceAll(
                "<factionsfinleader>",
                String.valueOf(
                    inFaction.getLeader() != null ? inFaction.getLeader().getName() : "Unknown"));
      if (newString.contains("<factionsfinland>"))
        newString =
            newString.replaceAll("<factionsfinland>", String.valueOf(inFaction.getLandCount()));
      if (newString.contains("<factionsfinofficer>"))
        newString =
            newString.replaceAll(
                "<factionsfinofficers>",
                String.valueOf(inFaction.getUPlayersWhereRole(Rel.OFFICER).size()));
    }
    return newString;
  }
Пример #15
0
	@Override
	public void performfp() {
		String warpname = this.arg(0);
		String setPassword = "******";

		if(this.arg(1) != null) {
			if(this.arg(1) != "-") {
				setPassword = this.arg(1);
			}
		}

		if(!FP.permission.has(sender, "factionsplus.warp")) {
			msg(ChatColor.RED + "No permission!");
			return;
		}
		
		Faction currentFaction;
				
		if(this.arg(2) != null) {
			currentFaction = Faction.get(this.arg(2));
			
			if(currentFaction == null ) {
				msg( "The faction " + this.arg(2) + " could not be found." );
				return; 
			}
			
			if( currentFaction.getId() != usender.getFactionId() && !usender.isUsingAdminMode() ) {
				if(!FP.permission.has(sender, "factionsplus.warpotherfactions" ) ) {
					msg( "You do not have permission to use other Factions warps. (factionsplus.warpotherfactions)" );
					return;
				}
			}
		} else {
			currentFaction = usender.getFaction();
		}
		
		if( (! usender.hasFaction() && currentFaction != usender.getFaction() ) || currentFaction.isNone() ) {
			
			msg( ChatColor.WHITE + "You are currently not in a Faction." );
			
		}

		
		
		File currentWarpFile = new File(Config.folderWarps,  currentFaction.getId());

		World world;

		// Check if player can teleport from enemy territory
		if(!Config._warps.warpTeleportAllowedFromEnemyTerritory._ && usender.isInEnemyTerritory() ){
			msg("<b>You cannot teleport to your faction warp while in the territory of an enemy faction.");
			return;
		}

		// Check if player can teleport from different world
		/*
		 * Move inside the try catch
		 * 
		 * if(!Conf.homesTeleportAllowedFromDifferentWorld && player.getWorld().getUID() != world){
		 * 		fme.msg("<b>You cannot teleport to your faction home while in a different world.");
		 * 		return;
		 * }
		 */

		// Check for enemies nearby
		// if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby
		Location loc = me.getLocation().clone();
		
		if(
				Config._warps.warpTeleportAllowedEnemyDistance._ > 0 && ! Utilities.isSafeZone(BoardColls.get().getFactionAt(PS.valueOf(loc))) 
				&& ( ! usender.isInOwnTerritory()
						|| ( usender.isInOwnTerritory() && ! Config._warps.warpTeleportIgnoreEnemiesIfInOwnTerritory._))){
			World w = loc.getWorld();
			double x = loc.getX();
			double y = loc.getY();
			double z = loc.getZ();

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

				UPlayer fp = UPlayer.get(playa);
				
				if (fp.equals(usender)) {
					continue;
				}
				
				
				if ( ! fp.getRelationTo(usender).equals (Rel.ENEMY ) ) {
					continue;
				}

				Location l = playa.getLocation();
				double dx = Math.abs(x - l.getX());
				double dy = Math.abs(y - l.getY());
				double dz = Math.abs(z - l.getZ());
				double max = Config._warps.warpTeleportAllowedEnemyDistance._;

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

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

		if (!currentWarpFile.exists()) {
			if(currentFaction != usender.getFaction() ) {
				
				msg( ChatColor.RED + currentFaction.getName() + " has no warps!" );
				
			} else {
				
				msg( ChatColor.RED + "Your faction has no warps!" );
				
			}
			return;
		}
		
		FileInputStream fstream=null;
		DataInputStream in=null;
		BufferedReader br=null;
		try {
			fstream = new FileInputStream(currentWarpFile);
			in = new DataInputStream(fstream);
			br = new BufferedReader(new InputStreamReader(in));
			String strLine;

			while ((strLine = br.readLine()) != null) {
				//sender.sendMessage(strLine);

				String[] warp_data =  strLine.split(":");

				if(warp_data[0].equalsIgnoreCase(warpname)) {
					//sender.sendMessage("warp found: " + warp_data[0]);
					double x = Double.parseDouble(warp_data[1]);
					double y = Double.parseDouble(warp_data[2]); // y axis
					double z = Double.parseDouble(warp_data[3]);

					float Y = Float.parseFloat(warp_data[4]); // yaw
					float playa = Float.parseFloat(warp_data[5]);

					world = Bukkit.getServer().getWorld(warp_data[6]);

					if(warp_data.length == 8) {
						if(warp_data[7] != "nullvalue") {
							if(!setPassword.trim().equals(warp_data[7].trim())) {
								msg(FactionsPlusTemplates.Go("warp_incorrect_password", null ));
								
								return;
							}
						}
					}

					Location newTel = new Location(world, x, y, z, Y, playa);
					
					String ownfid = usender.getFactionId();
					
					int count = 0;
					
					do {
						PS warpFLocation = PS.valueOf( newTel );
						String warpatFID = BoardColls.get().getFactionAt( warpFLocation ).getId();
						if ( !ownfid.equalsIgnoreCase( warpatFID ) ) {
							if ( Config._warps.mustBeInOwnTerritoryToCreate._ ) {
								// the the destination warp should be in player's own faction's territory, else deny tp-ing to it
								// XXX: this is a workaround for 1. not removing warps that violate this constraint(assuming it changed)...
								// 2. disbanding faction or unclaiming land won't remove the warp
								usender.msg( "<b>You cannot teleport to warp " + ChatColor.WHITE + warpname + " <b>because it "
									+ ( 0 < count ? "will make you land outside of" : "is not in" )
									+ " your faction territory."+(0<count?" <i>(because it's obstructed)":"") );
									if( Config._warps.removeWarpIfDeniedAccess._ ) {
										File currentWarpFileTMP = new File(Config.folderWarps,  currentFaction.getId() + ".tmp");
										PrintWriter wrt=null;
										BufferedReader rdr=null;
										try {
											wrt = new PrintWriter( new FileWriter( currentWarpFileTMP ) );
											rdr = new BufferedReader( new FileReader( currentWarpFile ) );
											
											String line;
											
											while ( ( line = rdr.readLine() ) != null ) {
												String[] warp = line.split( ":" );
												if ( ( warp.length >= 1 ) && ( warp[0].equalsIgnoreCase( warpname ) ) ) {
													continue;
												}
													
												wrt.println( line );
											}
										} finally {
											if ( null != rdr ) {
												try {
													rdr.close();
												} catch ( IOException e ) {
													e.printStackTrace();
												}
											}
											if ( null != wrt ) {
												wrt.close();
											}
										}
										
										if (!currentWarpFile.delete()) {
										   	System.out.println("[FactionsPlus] Cannot delete " + currentWarpFile.getName());
										    return;
										}
										    
										 if (!currentWarpFileTMP.renameTo(currentWarpFile)) {
											 System.out.println("[FactionsPlus] Cannot rename " + currentWarpFileTMP.getName() + " to " + currentWarpFile.getName());
											 return;
										 }
										String[] aargsa = { warpname };
											
										msg(FactionsPlusTemplates.Go("warped_removed", aargsa ));
										
										 //fplayer.msg( "The warp " + ChatColor.WHITE + warpname + " was removed." );
									}
										
								return;
							} else {// you can land anywhere if the 3 config options allows it below:
								Rel rel = usender.getFaction().getRelationTo(BoardColls.get().getFactionAt( warpFLocation ) );
								if (
										((Config._warps.denyWarpToEnemyLand._) && (Rel.ENEMY.equals( rel )))
										||((Config._warps.denyWarpToAllyLand._) && (Rel.ALLY.equals( rel )))
										||((Config._warps.denyWarpToNeutralOrTruceLand._) && 
												(Rel.NEUTRAL.equals( rel )
												|| Rel.NEUTRAL.equals( rel )) )
									) {
									msg( "<b>You cannot teleport to warp " + ChatColor.WHITE + warpname + " <b>because it "
											+ ( 0 < count ? "will make you land inside of" : "is in" )
											+ " "+ChatColor.WHITE+rel+"<b> faction territory."+(0<count?" <i>(because it's obstructed)":"") );
										return;
								}
							}
						}
						try {
							
							newTel = EssentialsIntegration.getSafeDestination( newTel );
							
						} catch(NoClassDefFoundError e) {
							
							FP.severe("Essentials is out of date. Can not get safe location.");
							
						}
					} while ( ++count < 2 );// XXX:make this 1 to not check for safedestination, or 2 to do check
					
					if(Config._economy.costToWarp._ > 0.0d) {
						if (!Utilities.doFinanceCrap(Config._economy.costToWarp._, "teleport to warp "+warpname, 
							usender)) {
							return;
						}
					}
					
					String[] aargsa = { warpname };
					
					msg(FactionsPlusTemplates.Go("warped_to", aargsa ));
					//player.sendMessage(ChatColor.RED + "Warped to " + ChatColor.WHITE + warpname);
					
					//XXX: this will fail (in Factions not FP) when Essentials is unloaded then loaded again via plugman, also /f home
					
					try {
						
						if (EssentialsIntegration.handleTeleport(me, newTel)) return;
						
					} catch( Exception e) {
						
						msg(ChatColor.RED + "Error: Error thrown on Essentials handling teleport.");
						FP.severe("Essentials is out of date. Can not handle teleport.");

						
					}
					//we still don't try to tp to the safe location. I better not be sorry for this
					newTel = new Location(world, x, y, z, Y, playa);
										
					// Create a smoke effect
					if ( Config._warps.smokeEffectOnWarp._ ) {
						List<Location> smokeLocations = new ArrayList<Location>();
						smokeLocations.add(me.getLocation());
						smokeLocations.add(me.getLocation().add(0, 1, 0));
						smokeLocations.add(newTel);
						smokeLocations.add(newTel.clone().add(0, 1, 0));
						SmokeUtil.spawnCloudRandom(smokeLocations, 3f);
					}

					me.teleport(newTel);
					
					return;
				}	
			}
			
			msg(FactionsPlusTemplates.Go("warp_non_existant", null));
			

		} catch (Exception e) {
			e.printStackTrace();

			sender.sendMessage(ChatColor.RED + "An internal error occured (02)");
		} finally {
			if (null != br) {
				try {
					br.close();
				} catch ( IOException e ) {
					e.printStackTrace();
				}
			}
			if (null != in) {
				try {
					in.close();
				} catch ( IOException e ) {
					e.printStackTrace();
				}
			}
			if (null != fstream) {
				try {
					fstream.close();
				} catch ( IOException e ) {
					e.printStackTrace();
				}
			}
		}
	}
Пример #16
0
	public static void removeRule(Faction faction, int ruleNo, UPlayer fplayer) {
		try {
			File readFile 	= 	new File(Config.folderFRules+File.separator+fplayer.getFactionId()+".rules");
			File outFile 	= 	new File(Config.folderFRules+File.separator+fplayer.getFactionId()+".new_rulesTMP");

			if(!readFile.exists()) {
				fplayer.msg(ChatColor.RED+"Your faction has no rules!");
				return;
			}
			
			if(Utilities.countLines(Config.folderFRules+File.separator+fplayer.getFactionId()+".rules") >= Config._rules.maxRulesPerFaction._) {
				fplayer.msg(ChatColor.RED+"The max rules a faction can have is "+Config._rules.maxRulesPerFaction._+ ".");
				return;
			}
			
			String workingLine = null;
			
			int i = 0;
			int c = 0;
			BufferedReader br = new BufferedReader(new FileReader(readFile));
			PrintWriter pw = new PrintWriter(new FileWriter(outFile));
			
			if(!outFile.exists()) { outFile.createNewFile(); }
			
			while ((workingLine = br.readLine()) != null) {
				i++;
				
				if(i != ruleNo) {
					c++;
					pw.println(workingLine);
					pw.flush();
				}
			}
			

			
			pw.close();
			br.close();
			
			if(c == 0) {
				fplayer.msg(ChatColor.RED+"Could not find that rule.");
				outFile.delete();
				return;
			} else if(i == c) {
				// 1 line was in the file, and 1 line was removed
				// which means there are no rules left. Remove the files. 
				readFile.delete();
				outFile.delete();
			} else {
				if (!readFile.delete()) {
					FPP.info("Could not remove the current rules file for Faction #" + faction.getId());
					fplayer.msg(ChatColor.RED+"Could not remove rule (internal error).");
					return;
				}
				
				if (!outFile.renameTo(readFile)) {
					FPP.info("Could not rename tmp file to current rules file for Faction #" + faction.getId());
					fplayer.msg(ChatColor.RED+"Could not remove rule (internal error).");
					return;
				}
			}
			
		} catch (FileNotFoundException ex) {
		  ex.printStackTrace();
		} catch (IOException ex) {
			ex.printStackTrace();
		}
		
		fplayer.msg(ChatColor.GREEN+"Rule removed, rules re-shuffled.");
	}
  @Override
  public void perform() {
    UPlayer newLeader = this.arg(0, ARUPlayer.getStartAny(sender));
    if (newLeader == null) return;

    Faction targetFaction = this.arg(1, ARFaction.get(sender), usenderFaction);
    if (targetFaction == null) return;

    UPlayer targetFactionCurrentLeader = targetFaction.getLeader();

    // We now have uplayer and the target faction
    if (this.senderIsConsole || usender.isUsingAdminMode() || Perm.LEADER_ANY.has(sender, false)) {
      // Do whatever you wish
    } else {
      // Follow the standard rules
      if (usender.getRole() != Rel.LEADER || targetFaction != usenderFaction) {
        sender.sendMessage(Txt.parse("<b>你必须是公会会长才能操作 %s.", this.getDesc()));
        return;
      }

      if (newLeader.getFaction() != usenderFaction) {
        msg("%s<i> 不是公会成员.", newLeader.describeTo(usender, true));
        return;
      }

      if (newLeader == usender) {
        msg("<b>目标不能是你自己.");
        return;
      }
    }

    // only run event when newLeader isn't actually in the faction
    if (newLeader.getFaction() != targetFaction) {
      FactionsEventMembershipChange event =
          new FactionsEventMembershipChange(
              sender, newLeader, targetFaction, MembershipChangeReason.LEADER);
      event.run();
      if (event.isCancelled()) return;
    }

    // if target player is currently leader, demote and replace him
    if (targetFactionCurrentLeader == newLeader) {
      targetFaction.promoteNewLeader();
      msg(
          "<i>You have demoted %s<i> from the position of faction leader.",
          newLeader.describeTo(usender, true));
      newLeader.msg(
          "<i>You have been demoted from the position of faction leader by %s<i>.",
          usender.describeTo(newLeader, true));
      return;
    }

    // Perform the switching
    if (targetFactionCurrentLeader != null) {
      targetFactionCurrentLeader.setRole(Rel.OFFICER);
    }
    newLeader.setFaction(targetFaction);
    newLeader.setRole(Rel.LEADER);
    msg("<i>你提升 %s<i> 成为公会会长.", newLeader.describeTo(usender, true));

    // Inform all players
    for (UPlayer uplayer : UPlayerColls.get().get(sender).getAllOnline()) {
      uplayer.msg(
          "%s<i> gave %s<i> the leadership of %s<i>.",
          senderIsConsole
              ? "A server admin"
              : RelationUtil.describeThatToMe(usender, uplayer, true),
          newLeader.describeTo(uplayer),
          targetFaction.describeTo(uplayer));
    }
  }
Пример #18
0
 /**
  * use this method instead of Conf.wildernessPowerLoss
  *
  * @return
  */
 public static final boolean confIs_wildernessPowerLoss() {
   return (Faction.get("0").getFlag(FFlag.POWERLOSS));
 }
Пример #19
0
 public static final boolean isPeaceful(Faction faction) {
   return (faction.getFlag(FFlag.PEACEFUL));
 }
Пример #20
0
 public static final void setPeaceful(Faction faction, boolean state) {
   assert Q.nn(faction);
   faction.setFlag(FFlag.PEACEFUL, state);
 }