当前位置: 首页>>代码示例>>C#>>正文


C# ArgumentList.TryGetBool方法代码示例

本文整理汇总了C#中ArgumentList.TryGetBool方法的典型用法代码示例。如果您正苦于以下问题:C# ArgumentList.TryGetBool方法的具体用法?C# ArgumentList.TryGetBool怎么用?C# ArgumentList.TryGetBool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ArgumentList的用法示例。


在下文中一共展示了ArgumentList.TryGetBool方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UserPermission

        void UserPermission(ISender sender, ArgumentList args)
        {
            if (!Storage.IsAvailable)
                throw new CommandError("No permissions plugin or data plugin is attached");

            int a = 0;
            string username, groupName, node, password;
            DbPlayer user;
            Group grp;
            bool deny, op;

            var cmd = args.GetString(a++);
            switch (cmd)
            {
                case "addgroup":
                    //user addgroup "username" "group"
                    if (!args.TryGetString(a++, out username))
                        throw new CommandError("Expected username name after [" + cmd + "]");
                    if (!args.TryGetString(a++, out groupName))
                        throw new CommandError("Expected group name after username");

                    user = Authentication.GetPlayer(username);
                    if (null == user)
                        throw new CommandError("No user found by: " + username);

                    grp = Storage.FindGroup(groupName);
                    if (grp == null)
                        throw new CommandError("Group does not exist: " + groupName);

                    if (Storage.AddUserToGroup(user.Name, grp.Name))
                    {
                        sender.Message(String.Format("Successfully added {0} to group {1} ", user.Name, grp.Name), Color.Green);
                    }
                    else
                    {
                        sender.Message(String.Format("Failed to add {0} from group {1} ", user.Name, grp.Name), Color.Red);
                    }
                    break;
                case "removegroup":
                    //user removegroup "username" "group"
                    if (!args.TryGetString(a++, out username))
                        throw new CommandError("Expected username name after [" + cmd + "]");
                    if (!args.TryGetString(a++, out groupName))
                        throw new CommandError("Expected group name after username");

                    user = Authentication.GetPlayer(username);
                    if (null == user)
                        throw new CommandError("No user found by: " + username);

                    grp = Storage.FindGroup(groupName);
                    if (grp == null)
                        throw new CommandError("Group does not exist: " + groupName);

                    if (Storage.RemoveUserFromGroup(user.Name, grp.Name))
                    {
                        sender.Message(String.Format("Successfully removed {0} to group {1} ", user.Name, grp.Name), Color.Green);
                    }
                    else
                    {
                        sender.Message(String.Format("Failed to remove {0} from group {1} ", user.Name, grp.Name), Color.Red);
                    }
                    break;

                case "addnode":
                    //user addnode "username" "node" "deny"
                    if (!args.TryGetString(a++, out username))
                        throw new CommandError("Expected username name after [" + cmd + "]");
                    if (!args.TryGetString(a++, out node))
                        throw new CommandError("Expected node name after username");

                    if (!args.TryGetBool(a++, out deny))
                        deny = false;

                    user = Authentication.GetPlayer(username);
                    if (null == user)
                        throw new CommandError("No user found by: " + username);

                    if (Storage.AddNodeToUser(user.Name, node, deny ? Permission.Denied : Permission.Permitted))
                    {
                        sender.Message(String.Format("Successfully added {0} to user {1} ", node, user.Name), Color.Green);
                    }
                    else
                    {
                        sender.Message(String.Format("Failed to add {0} from user {1} ", node, user.Name), Color.Red);
                    }
                    break;
                case "removenode":
                    //user removenode "username" "node" "deny"
                    if (!args.TryGetString(a++, out username))
                        throw new CommandError("Expected username name after [" + cmd + "]");
                    if (!args.TryGetString(a++, out node))
                        throw new CommandError("Expected node name after username");

                    if (!args.TryGetBool(a++, out deny))
                        deny = false;

                    user = Authentication.GetPlayer(username);
                    if (null == user)
                        throw new CommandError("No user found by: " + username);

//.........这里部分代码省略.........
开发者ID:DeathCradle,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:101,代码来源:PermissionsCommand.cs

示例2: GroupPermission

        void GroupPermission(ISender sender, ArgumentList args)
        {
            if (!Storage.IsAvailable)
                throw new CommandError("No permissions plugin or data plugin is attached");

            int a = 0;
            string groupName;
            bool applyToGuests;
            string parent, prefix, suffix;
            byte r = 0, g = 0, b = 0;

            var cmd = args.GetString(a++);
            switch (cmd)
            {
                case "add":
                    //group add "Guest" <ApplyToGuests> <Parent> <R> <G> <B> <Prefix> <Suffix>
                    if (!args.TryGetString(a++, out groupName))
                        throw new CommandError("Expected group name after [" + cmd + "]");

                    args.TryGetBool(a++, out applyToGuests);
                    args.TryGetString(a++, out parent);

                    if (!args.TryGetByte(a++, out r))
                        r = 255;
                    if (!args.TryGetByte(a++, out g))
                        g = 255;
                    if (!args.TryGetByte(a++, out b))
                        b = 255;

                    args.TryGetString(a++, out prefix);
                    args.TryGetString(a++, out suffix);

                    if (Storage.FindGroup(groupName) != null)
                        throw new CommandError("There is already a group defined as " + groupName);

                    if (Storage.AddOrUpdateGroup(groupName, applyToGuests, parent, r, g, b, prefix, suffix) != null)
                    {
                        sender.Message("Successfully created group " + groupName, Color.Green);
                    }
                    else
                    {
                        sender.Message("Failed to create group " + groupName, Color.Red);
                    }
                    break;
                case "remove":
                    //group remove "Guest
                    if (!args.TryGetString(a++, out groupName))
                        throw new CommandError("Expected group name after [" + cmd + "]");

                    if (Storage.FindGroup(groupName) == null)
                        throw new CommandError("Group does not exist: " + groupName);

                    if (Storage.RemoveGroup(groupName))
                    {
                        sender.Message("Successfully removed group " + groupName, Color.Green);
                    }
                    else
                    {
                        sender.Message("Failed to remove group " + groupName, Color.Red);
                    }
                    break;

                case "update":
                    //group update "Guest" <ApplyToGuests> <Parent> <R> <G> <B> <Prefix> <Suffix>
                    if (!args.TryGetString(a++, out groupName))
                        throw new CommandError("Expected group name after [" + cmd + "]");

                    args.TryGetBool(a++, out applyToGuests);
                    args.TryGetString(a++, out parent);

                    if (!args.TryGetByte(a++, out r))
                        r = 255;
                    if (!args.TryGetByte(a++, out g))
                        g = 255;
                    if (!args.TryGetByte(a++, out b))
                        b = 255;

                    args.TryGetString(a++, out prefix);
                    args.TryGetString(a++, out suffix);

                    if (Storage.FindGroup(groupName) == null)
                        throw new CommandError("This is no group defined as " + groupName);

                    if (Storage.AddOrUpdateGroup(groupName, applyToGuests, parent, r, g, b, prefix, suffix) != null)
                    {
                        sender.Message("Successfully updated group " + groupName, Color.Green);
                    }
                    else
                    {
                        sender.Message("Failed to update group " + groupName, Color.Red);
                    }
                    break;

                case "addnode":
                    //group addnode "Guest" "tdsm.help" <deny>
                    if (!args.TryGetString(a++, out groupName))
                        throw new CommandError("Expected group name after [" + cmd + "]");

                    string addNode;
                    if (!args.TryGetString(a++, out addNode))
//.........这里部分代码省略.........
开发者ID:DeathCradle,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:101,代码来源:PermissionsCommand.cs

示例3: SpawnNPC

        /// <summary>
        /// Spawns specified NPC type.
        /// </summary>
        /// <param name="sender">Sending player</param>
        /// <param name="args">Arguments sent with command</param>
        /// <remarks>This function also allows NPC custom health.</remarks>
        public void SpawnNPC(ISender sender, ArgumentList args)
        {
            //if (Main.stopSpawns && !Program.properties.NPCSpawnsOverride)
            //    throw new CommandError("NPC Spawing is disabled.");

            //var health = -1;
            //var customHealth = args.TryPopAny<Int32>("-health", out health);

            Player player = sender as Player;
            int amount;
            if (args.Count > 4)
                throw new CommandError("Too many arguments");
            else if (sender is ConsoleSender && args.Count <= 2)
            {
                if (!Netplay.anyClients || !Tools.TryGetFirstOnlinePlayer(out player))
                    throw new CommandError("No players online.");
            }
            else if (args.Count >= 3)
                player = args.GetOnlinePlayer(2);

            var npcName = args.GetString(1).ToLower().Trim();

            // Get the class id of the npc
            var npcs = DefinitionManager.FindNPC(npcName);
            if (npcs.Length == 0)
                throw new CommandError("No npc exists by the name {0}", npcName);
            else if (npcs.Length > 1)
            {
                bool first;
                args.TryGetBool(3, out first);

                if (!first)
                    throw new CommandError("Too many results for {0}, total count {1}", npcName, npcs.Length);
            }

            var npc = npcs[0];
            if (npc.Boss.HasValue && npc.Boss == true)
                throw new CommandError("This NPC can only be summoned by the SPAWNBOSS command.");
            try
            {
                amount = args.GetInt(0);
                //if (NPCAmount > Program.properties.SpawnNPCMax && sender is Player)
                //{
                //    (sender as Player).Kick("Don't spawn that many.");
                //    return;
                //}
            }
            catch
            {
                throw new CommandError("Expected amount to spawn");
            }

            var max = Tools.AvailableNPCSlots; //Perhaps remove a few incase of spawns
            if (amount > max)
                throw new CommandError("Cannot spawn that many, available slots: {0}", max);

            string realNPCName = String.Empty;
            for (int i = 0; i < amount; i++)
            {
                Vector2 location = World.GetRandomClearTile(((int)player.position.X / 16), ((int)player.position.Y / 16), 100, 100, 50);
                int npcIndex = NPC.NewNPC(((int)location.X * 16), ((int)location.Y * 16), npc.Id, 0);

                //if (customHealth)
                //{
                //    Main.npc[npcIndex].life = health;
                //    Main.npc[npcIndex].lifeMax = health;
                //}
                Main.npc[npcIndex].netDefaults(npc.NetId);

                realNPCName = Main.npc[npcIndex].name;
            }
            Tools.NotifyAllOps("Spawned " + amount.ToString() + " of " +
                realNPCName + " [" + player.name + "]", true);
        }
开发者ID:carriercomm,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:80,代码来源:SpawnNpcCommand.cs


注:本文中的ArgumentList.TryGetBool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。