本文整理汇总了C#中ArgumentList.TryGetOnlinePlayer方法的典型用法代码示例。如果您正苦于以下问题:C# ArgumentList.TryGetOnlinePlayer方法的具体用法?C# ArgumentList.TryGetOnlinePlayer怎么用?C# ArgumentList.TryGetOnlinePlayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArgumentList
的用法示例。
在下文中一共展示了ArgumentList.TryGetOnlinePlayer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Ban
/// <summary>
/// Adds a player or ip (Exception) to the ban list.
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public static void Ban(ISender sender, ArgumentList args)
{
Player banee;
string playerName = null;
if (args.TryGetOnlinePlayer(0, out banee))
{
playerName = banee.Name;
banee.Kick("You have been banned from this Server.");
Server.BanList.addException(NetPlay.slots[banee.whoAmi].
remoteAddress.Split(':')[0]);
}
else if(!args.TryGetString(0, out playerName))
{
throw new CommandError("A player or IP was expected.");
}
Server.BanList.addException(playerName);
Server.notifyOps(playerName + " has been banned {" + sender.Name + "}", true);
if (!Server.BanList.Save())
{
Server.notifyOps("BanList Failed to Save due to " + sender.Name + "'s command", true);
}
}
示例2: DeopPlayer
/// <summary>
/// De-OPs a given Player.
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public static void DeopPlayer(ISender sender, ArgumentList args)
{
var playerName = args.GetString(0);
Player player;
if (args.TryGetOnlinePlayer(0, out player))
{
playerName = player.Name;
if (Player.isInOpList(playerName))
{
player.sendMessage("You have been De-Opped!.", ChatColor.Green);
}
player.Op = false;
if (player.HasClientMod)
{
NetMessage.SendData(Packet.CLIENT_MOD, player.whoAmi);
}
}
if (Player.isInOpList(playerName))
{
Server.notifyOps("De-Opping " + playerName + " {" + sender.Name + "}", true);
Server.OpList.removeException(playerName + ":" + Player.GetPlayerPassword(playerName));
}
if (!Server.OpList.Save())
{
Server.notifyOps("OpList Failed to Save due. {" + sender.Name + "}", true);
return;
}
}
示例3: Give
/// <summary>
/// Gives specified item to the specified player.
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public void Give(ISender sender, ArgumentList args)
{
// /give <stack> <item> [prefix] [player]
var index = 0;
int stack = args.GetInt(index++);
string name = args.GetString(index++);
// var max = Tools.AvailableItemSlots; //Perhaps remove a few incase of new drops
// if (stack > max)
// {
// stack = max; // Set to Tools.AvailableItemSlots because number given was larger than this.
// }
int id;
var results = Int32.TryParse(name, out id) ? DefinitionManager.FindItem(id) : DefinitionManager.FindItem(name);
if (results != null && results.Length > 0)
{
if (results.Length > 1)
throw new CommandError(String.Format("More than 1 item found, total is: {0}", results.Length));
var item = results[0];
string prefix;
if (args.TryGetString(index, out prefix))
{
try
{
Affix afx;
if (Enum.TryParse(prefix, out afx))
{
item.Prefix = (int)afx;
index++;
}
}
catch (ArgumentException)
{
throw new CommandError(String.Format("Error, the Prefix you entered was not found: {0}", args.GetString(3)));
}
}
Player receiver;
if (!args.TryGetOnlinePlayer(index, out receiver))
{
if (sender is Player)
receiver = sender as Player;
else throw new CommandError("Expected an online player");
}
receiver.GiveItem(item.Id, stack, item.MaxStack, sender, item.NetId, true, item.Prefix);
}
else
throw new CommandError(String.Format("No item known by: {0}", name));
}
示例4: OpPlayer
/// <summary>
/// Sets OP status to a given Player.
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public static void OpPlayer(ISender sender, ArgumentList args)
{
var playerName = args.GetString(0);
var password = args.GetString(1);
Player player;
if (args.TryGetOnlinePlayer(0, out player))
{
playerName = player.Name;
player.sendMessage("You are now OP!", ChatColor.Green);
player.Op = true;
if (player.HasClientMod)
{
NetMessage.SendData(Packet.CLIENT_MOD, player.whoAmi);
}
}
Server.notifyOps("Opping " + playerName + " {" + sender.Name + "}", true);
Server.OpList.addException(playerName + ":" + password, true, playerName.Length + 1);
if (!Server.OpList.Save())
{
Server.notifyOps("OpList Failed to Save due. {" + sender.Name + "}", true);
return;
}
}
示例5: Ban
/// <summary>
/// Adds a player or ip (Exception) to the ban list.
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public static void Ban(ISender sender, ArgumentList args)
{
Player banee;
string playerName = null;
if (args.TryGetOnlinePlayer(0, out banee))
{
playerName = banee.Name;
banee.Kick(Languages.Ban_You);
Server.BanList.addException(NetPlay.slots[banee.whoAmi].
remoteAddress.Split(':')[0]);
}
else if (!args.TryGetString(0, out playerName))
{
throw new CommandError(Languages.IPExpected);
}
Server.BanList.addException(playerName);
Server.notifyOps(playerName + Languages.Ban_Banned + " [" + sender.Name + "]", true);
if (!Server.BanList.Save())
{
Server.notifyOps(Languages.Ban_FailedToSave + sender.Name + "'s " + Languages.Command, true);
}
}
示例6: Kit
public static void Kit(ISender sender, ArgumentList args)
{
Player player = (Player)sender;
if (!(sender is Player))
{
if (!args.TryGetOnlinePlayer(1, out player))
{
sender.sendMessage("As a non player, Please specify one!");
return;
}
}
if (args.Count > 0)
{
if (Essentials.kitManager.ContainsKit(args[0]))
{
Kit.Kit kit = Essentials.kitManager.getKit(args[0]);
if (kit != null && kit.ItemList != null)
{
foreach (int ItemID in kit.ItemList)
{
Item.NewItem((int)player.Position.X, (int)player.Position.Y, player.Width, player.Height, ItemID, 1, false);
}
player.sendMessage("Recived the '" + kit.Name + "' Kit.");
}
else
{
player.sendMessage("Issue with null kit/list");
}
}
//Help ::: Shows what kits there are
else if (args[0].Equals("help"))
{
String Kits = "";
foreach (Kit.Kit kit in Essentials.kitManager.KitList)
{
if (kit.Name.Trim().Length > 0)
{
Kits = Kits + ", " + kit.Name;
}
}
if (Kits.StartsWith(","))
{
Kits = Kits.Remove(0, 1).Trim();
}
if (Kits.Length > 0)
{
player.sendMessage("Available Kits: " + Kits);
}
}
//If kit does not exist
else
{
player.sendMessage("Error: specified kit " + args[0] + " does not exist. Please do /kit help");
}
}
//Error message
else
{
player.sendMessage("Error: You did not specify a kit! Do /kit help!");
}
}
示例7: GodMode
public static void GodMode(ISender sender, ArgumentList args)
{
Player player = (Player)sender;
if (!(sender is Player))
{
if (!args.TryGetOnlinePlayer(1, out player))
{
sender.sendMessage("As a non player, Please specify one!");
return;
}
}
bool found = false;
bool godModeStatus = false;
for (int i = 0; i < Essentials.essentialsPlayerList.Count; i++ )
{
int PlayerID = Essentials.essentialsPlayerList.Keys.ElementAt(i);
Player eplayer = Main.players[PlayerID];
if (eplayer.Name.Equals(player.Name))
{
bool GodMode = !Essentials.essentialsPlayerList.Values.ElementAt(i);
Essentials.essentialsPlayerList.Remove(PlayerID);
Essentials.essentialsPlayerList.Add(PlayerID, GodMode);
godModeStatus = GodMode;
found = true;
break;
}
}
if (!found)
{
godModeStatus = true;
Essentials.essentialsPlayerList.Add(player.whoAmi, godModeStatus);
}
player.sendMessage("God Mode Status: " + godModeStatus.ToString());
}
示例8: SummonBoss
/// <summary>
/// Summon a Boss
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public void SummonBoss(ISender sender, ArgumentList args)
{
var bossName = args.GetString(0).ToLower();
var count = args.GetInt(1);
Player target;
if (!args.TryGetOnlinePlayer(2, out target))
{
if (sender is Player)
{
target = sender as Player;
}
else
throw new CommandError("Expected a player");
}
var position = World.GetRandomClearTile(target.position.X / 16f, target.position.X / 16f);
int type = -1, type1 = -1;
string name = null;
switch (bossName)
{
case "wyvern":
type = 87;
break;
case "brain":
case "brain of cthulhu":
type = 266;
break;
case "crimson mimic":
type = 474;
break;
case "corrupt mimic":
type = 473;
break;
case "hallowed mimic":
type = 475;
break;
case "duke fishron":
case "duke":
case "fishron":
type = 370;
break;
case "everscream":
type = 344;
break;
case "eye of cthulhu":
type = 4;
break;
case "dutchman":
case "flying dutchman":
type = 491;
break;
case "golem":
type = 245;
break;
case "gobin summoner":
type = 471;
break;
case "king":
case "king slime":
type = 50;
break;
case "ice golem":
type = 243;
break;
case "ice queen":
type = 345;
break;
case "lunatic":
case "cultist":
case "lunatic cultist":
type = 439;
break;
case "saucer":
case "martian saucer":
type = 395;
break;
case "moon":
case "moon lord":
type = 398;
//.........这里部分代码省略.........
示例9: SummonBoss
/// <summary>
/// Summon a Boss
/// </summary>
/// <param name="sender">Sending player</param>
/// <param name="args">Arguments sent with command</param>
public void SummonBoss(ISender sender, ArgumentList args)
{
var count = args.GetInt(0);
var bossName = args.GetString(1).ToLower();
Player target;
if (!args.TryGetOnlinePlayer(2, out target))
{
if (sender is Player)
{
target = sender as Player;
}
else
{
target = Main.player.Where(x => x.active).Random();
if (null == target)
{
throw new CommandError("No players online");
}
}
}
// int type = -1, type1 = -1;
// string name = null;
var queue = new Queue<Boss>();
switch (bossName)
{
case "wyvern":
// type = 87;
queue.Enqueue(new Boss()
{
type = 87
});
break;
case "brain":
case "brain of cthulhu":
// type = 266;
queue.Enqueue(new Boss()
{
type = 266
});
break;
// case "crimson mimic":
// type = 474;
// break;
case "corrupt mimic":
// type = 473;
queue.Enqueue(new Boss()
{
type = 473
});
break;
// case "hallowed mimic":
// type = 475;
// break;
case "duke fishron":
case "duke":
case "fishron":
// type = 370;
queue.Enqueue(new Boss()
{
type = 370
});
break;
case "everscream":
World.SetTime(16200.0, false);
// type = 344;
queue.Enqueue(new Boss()
{
type = 344
});
break;
case "eye":
case "cthulhu":
case "eye of cthulhu":
World.SetTime(16200.0, false);
// type = 4;
queue.Enqueue(new Boss()
{
type = 4
});
break;
case "dutchman":
case "flying dutchman":
// type = 491;
queue.Enqueue(new Boss()
{
type = 491
//.........这里部分代码省略.........