Ejemplo n.º 1
0
        public static void OnPlayerCommand(TShockAPI.Hooks.PlayerCommandEventArgs args)
        {
            var eplr = args.Player.EPlayer();
            var cmd  = args.Parameters;

            if (eplr != null)
            {
                switch (args.CommandName.ToLower())
                {
                case "home":
                    args.Handled = true;
                    args.Player.Teleport((float)(Main.spawnTileX * 16), (float)(Main.spawnTileY * 16 - 48), 1);
                    break;

                case "tp":
                    if (cmd.Count >= 1)
                    {
                        var temptp = TSPlayer.FindByNameOrID(cmd[0]);
                        if (temptp.Count > 1)
                        {
                            eplr.tsp.SendMultipleError(temptp);
                            args.Handled = true;
                            return;
                        }
                        else if (temptp.Any() && temptp[0].EPlayer() != null && eplr.MapUUID != temptp[0].EPlayer().MapUUID)
                        {
                            eplr.SendErrorEX($"你无法直接传送至位于其他世界的玩家.");
                            args.Handled = true;
                        }
                    }

                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public async void OnPlayerCommand(TShockAPI.Hooks.PlayerCommandEventArgs args)
        {
            if ((args.Player == null) || (args.Player == TSPlayer.Server))
            {
                return;
            }
            try
            {
                var logs = await Discord.DiscordBot.GetChannelAsync(Discord.Config.LogID);

                await Discord.DiscordBot.SendMessageAsync(logs, "**" + args.Player.Name + ":** " + args.CommandText);
            }
            catch (Exception ex)
            {
                TShock.Log.Error(ex.ToString());
            }
        }
        void OnPlayerCommand(TShockAPI.Hooks.PlayerCommandEventArgs args)
        {
            if (args.Player == null || !args.Player.IsLoggedIn)
            {
                return;
            }

            if (CheckIfPVPCommandExists() && args.CommandName == "pvp")
            {
                if (!args.Player.TPlayer.hostile && !pvPlayers.Contains(args.Player))
                {
                    pvPlayers.Add(args.Player);
                }
                else if (args.Player.TPlayer.hostile && pvPlayers.Contains(args.Player))
                {
                    pvPlayers.Remove(args.Player);
                }
            }
        }
Ejemplo n.º 4
0
        private void OnChat(TShockAPI.Hooks.PlayerCommandEventArgs args)
        {
            //If the used command is an existing command, ignore.
            if (Commands.TShockCommands.Count(p => p.Name == args.CommandName) > 0 || Commands.ChatCommands.Count(p => p.Name == args.CommandName) > 0)
            {
                return;
            }

            //Check if our config has the typed command
            if (config.shortcommands.ContainsKey(args.CommandName))
            {
                KeyValuePair <string, string> shortcmd = new KeyValuePair <string, string>();

                //Retrieve the long commands by finding the short command.
                foreach (KeyValuePair <string, string> thecommand in config.shortcommands)
                {
                    if (args.CommandName == thecommand.Key)
                    {
                        shortcmd = thecommand;
                    }
                }

                //Split the long commands into the different commands
                List <string> usecmds     = shortcmd.Value.Split(';').ToList();
                List <string> usecmdnames = new List <string>();

                //Make a separate list of the actual command names
                foreach (string cmd in usecmds)
                {
                    usecmdnames.Add(cmd.Split(' ')[0]);
                }

                //Loop through each bound command
                for (int j = 0; j < usecmds.Count; j++)
                {
                    //Temporarily store the individual command & name
                    string usecmd     = usecmds[j];
                    string usecmdname = usecmdnames[j];

                    //Check if the command is real or not (no shortcommands!)
                    if (Commands.TShockCommands.Count(p => p.Name == usecmdname) == 0 && Commands.ChatCommands.Count(p => p.Name == usecmdname) == 0)
                    {
                        args.Player.SendErrorMessage("Unknown command: {0}", usecmdname);
                        TShock.Log.Warn("Unknown ShortCommand entry: {0}", usecmdname);
                        args.Handled = true;
                        return;
                    }

                    //Handle replacing params with {0} and {+}
                    List <string> param = new List <string>();

                    for (int i = 0; i < args.Parameters.Count; i++)
                    {
                        param.Add(args.Parameters[i]);
                    }

                    int replaced = 0;

                    for (int i = 0; i < 10; i++)
                    {
                        string replacer = "{" + i.ToString() + "}";
                        if (usecmd.Contains(replacer) && param.Count > i)
                        {
                            usecmd = usecmd.Replace(replacer, param[i]);
                            replaced++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    while (replaced > 0)
                    {
                        param.RemoveAt(0);
                        replaced--;
                    }

                    string replacer2 = "{+}";
                    if (usecmd.Contains(replacer2) && param.Count > 0)
                    {
                        usecmd = usecmd.Replace(replacer2, string.Join(" ", param.Select(p => p)));
                    }

                    string replacer3 = "{player}";
                    if (usecmd.Contains(replacer3))
                    {
                        usecmd = usecmd.Replace(replacer3, args.Player.User.Name);
                    }

                    string replacer4 = "{website}";
                    if (usecmd.Contains(replacer4))
                    {
                        usecmd = usecmd.Replace(replacer4, config.website);
                    }

                    //Handle the Command.
                    Commands.HandleCommand(args.Player, string.Format("{0}{1}", args.CommandPrefix, usecmd));
                } //Loop back through the rest of the bound commands

                //Don't let TShock handle it (it would give "Invalid Command" after already running the commands.
                args.Handled = true;
            }
        }